Skip to content

Commit

Permalink
access-point-support (#21)
Browse files Browse the repository at this point in the history
+ build: reduce dep numbers and make dev builds default
+ feat: Initialize WiFi as both AP and STA modes, configure AP stack, and spawn AP task for handling connections.
+ build: replace local reqwless with crates.io version
  • Loading branch information
Sycrosity authored Aug 13, 2024
1 parent 8694337 commit fed8e90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
33 changes: 27 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,23 @@ async fn main(spawner: Spawner) -> ! {

let clocks = ClockControl::max(system.clock_control).freeze();

let timer_group0 = TimerGroup::new_async(peripherals.TIMG0, &clocks);
#[cfg(feature = "esp32")]
{
let timg1 = esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG1, &clocks, None);
esp_hal_embassy::init(
&clocks,
make_static!([OneShotTimer::new(timg1.timer0.into())]),
);
}

esp_hal_embassy::init(&clocks, timer_group0);
#[cfg(not(feature = "esp32"))]
{
let systimer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER);
esp_hal_embassy::init(
&clocks,
make_static!([OneShotTimer::new(systimer.alarm0.into())]),
);
}

let mut adc1_config = AdcConfig::new();

Expand All @@ -87,10 +101,17 @@ async fn main(spawner: Spawner) -> ! {
let adc1 =
&*SHARED_ADC.init_with(|| Mutex::new(Adc::<ADC1>::new(peripherals.ADC1, adc1_config)));

#[cfg(target_arch = "xtensa")]
let timer = TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0;
#[cfg(target_arch = "riscv32")]
let timer = esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0;
// #[cfg(target_arch = "xtensa")]
// let timer = TimerGroup::new(peripherals.TIMG1, &clocks, None).timer0;
// #[cfg(target_arch = "riscv32")]
// let timer =
// esp_hal::timer::systimer::SystemTimer::new(peripherals.SYSTIMER).alarm0;

let timer = PeriodicTimer::new(
esp_hal::timer::timg::TimerGroup::new(peripherals.TIMG0, &clocks, None)
.timer0
.into(),
);

let init = esp_wifi::initialize(
esp_wifi::EspWifiInitFor::Wifi,
Expand Down
12 changes: 8 additions & 4 deletions src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ pub async fn connection(mut controller: WifiController<'static>, _rng: Rng) {
ClientConfiguration {
ssid: SSID.try_into().unwrap_or_default(),
password: PASSWORD.try_into().unwrap_or_default(),
auth_method: if PASSWORD.is_empty() {
AuthMethod::None
} else {
AuthMethod::default()
auth_method: {
#[allow(clippy::const_is_empty)]
if PASSWORD.is_empty() {
AuthMethod::None
} else {
AuthMethod::default()
}
},
..Default::default()
},
Expand All @@ -76,6 +79,7 @@ pub async fn connection(mut controller: WifiController<'static>, _rng: Rng) {
controller.set_configuration(&config).unwrap();
info!("Starting wifi");
controller.start().await.unwrap();
// controller.connect()
info!("Wifi started!");
}

Expand Down

0 comments on commit fed8e90

Please sign in to comment.