diff options
| author | kbleeke <[email protected]> | 2023-03-21 19:32:39 +0100 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-03-21 19:32:39 +0100 |
| commit | 29494a9296552334cc9dd2359c16dfbf8f3e7efc (patch) | |
| tree | a98ff6e9fb5a0f32041ff2e850a6cfca61dba71f | |
| parent | f82f931dc2b8df2338fb8331ad27d667811e5c09 (diff) | |
| parent | 0e946dfb203dcf1ca3f165ffb06f3f58d4eaa119 (diff) | |
Merge branch 'master' into pio
| -rw-r--r-- | .vscode/extensions.json | 11 | ||||
| -rw-r--r-- | .vscode/settings.json | 14 | ||||
| -rw-r--r-- | examples/rpi-pico-w/src/main.rs | 11 | ||||
| -rw-r--r-- | src/events.rs | 14 | ||||
| -rw-r--r-- | src/lib.rs | 42 |
5 files changed, 71 insertions, 21 deletions
diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..a8bb78adb --- /dev/null +++ b/.vscode/extensions.json | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | { | ||
| 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
| 3 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
| 4 | // List of extensions which should be recommended for users of this workspace. | ||
| 5 | "recommendations": [ | ||
| 6 | "rust-lang.rust-analyzer", | ||
| 7 | "tamasfe.even-better-toml", | ||
| 8 | ], | ||
| 9 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. | ||
| 10 | "unwantedRecommendations": [] | ||
| 11 | } \ No newline at end of file | ||
diff --git a/.vscode/settings.json b/.vscode/settings.json index 082b286da..dd479929e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
| @@ -1,14 +1,12 @@ | |||
| 1 | { | 1 | { |
| 2 | "editor.formatOnSave": true, | 2 | "editor.formatOnSave": true, |
| 3 | "rust-analyzer.cargo.buildScripts.enable": true, | 3 | "[toml]": { |
| 4 | "rust-analyzer.cargo.noDefaultFeatures": true, | 4 | "editor.formatOnSave": false |
| 5 | }, | ||
| 5 | "rust-analyzer.cargo.target": "thumbv6m-none-eabi", | 6 | "rust-analyzer.cargo.target": "thumbv6m-none-eabi", |
| 6 | "rust-analyzer.checkOnSave.allTargets": false, | 7 | "rust-analyzer.cargo.noDefaultFeatures": true, |
| 7 | "rust-analyzer.checkOnSave.noDefaultFeatures": true, | 8 | "rust-analyzer.check.allTargets": false, |
| 8 | "rust-analyzer.imports.granularity.enforce": true, | 9 | "rust-analyzer.check.noDefaultFeatures": true, |
| 9 | "rust-analyzer.imports.granularity.group": "module", | ||
| 10 | "rust-analyzer.procMacro.attributes.enable": false, | ||
| 11 | "rust-analyzer.procMacro.enable": false, | ||
| 12 | "rust-analyzer.linkedProjects": [ | 10 | "rust-analyzer.linkedProjects": [ |
| 13 | "examples/rpi-pico-w/Cargo.toml", | 11 | "examples/rpi-pico-w/Cargo.toml", |
| 14 | ], | 12 | ], |
diff --git a/examples/rpi-pico-w/src/main.rs b/examples/rpi-pico-w/src/main.rs index f30a20bac..67348e454 100644 --- a/examples/rpi-pico-w/src/main.rs +++ b/examples/rpi-pico-w/src/main.rs | |||
| @@ -59,7 +59,7 @@ async fn main(spawner: Spawner) { | |||
| 59 | // To make flashing faster for development, you may want to flash the firmwares independently | 59 | // To make flashing faster for development, you may want to flash the firmwares independently |
| 60 | // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: | 60 | // at hardcoded addresses, instead of baking them into the program with `include_bytes!`: |
| 61 | // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 | 61 | // probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000 |
| 62 | // probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000 | 62 | // probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000 |
| 63 | //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; | 63 | //let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) }; |
| 64 | //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | 64 | //let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; |
| 65 | 65 | ||
| @@ -78,16 +78,11 @@ async fn main(spawner: Spawner) { | |||
| 78 | let state = singleton!(cyw43::State::new()); | 78 | let state = singleton!(cyw43::State::new()); |
| 79 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; | 79 | let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await; |
| 80 | 80 | ||
| 81 | spawner.spawn(wifi_task(runner)).unwrap(); | ||
| 82 | |||
| 83 | control.init(clm).await; | 81 | control.init(clm).await; |
| 84 | control | 82 | control |
| 85 | .set_power_management(cyw43::PowerManagementMode::PowerSave) | 83 | .set_power_management(cyw43::PowerManagementMode::PowerSave) |
| 86 | .await; | 84 | .await; |
| 87 | 85 | ||
| 88 | //control.join_open(env!("WIFI_NETWORK")).await; | ||
| 89 | control.join_wpa2(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await; | ||
| 90 | |||
| 91 | let config = Config::Dhcp(Default::default()); | 86 | let config = Config::Dhcp(Default::default()); |
| 92 | //let config = embassy_net::Config::Static(embassy_net::Config { | 87 | //let config = embassy_net::Config::Static(embassy_net::Config { |
| 93 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), | 88 | // address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24), |
| @@ -106,8 +101,12 @@ async fn main(spawner: Spawner) { | |||
| 106 | seed | 101 | seed |
| 107 | )); | 102 | )); |
| 108 | 103 | ||
| 104 | unwrap!(spawner.spawn(wifi_task(runner))); | ||
| 109 | unwrap!(spawner.spawn(net_task(stack))); | 105 | unwrap!(spawner.spawn(net_task(stack))); |
| 110 | 106 | ||
| 107 | //control.join_open(env!("WIFI_NETWORK")).await; | ||
| 108 | control.join_wpa2(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await; | ||
| 109 | |||
| 111 | // And now we can use it! | 110 | // And now we can use it! |
| 112 | 111 | ||
| 113 | let mut rx_buffer = [0; 4096]; | 112 | let mut rx_buffer = [0; 4096]; |
diff --git a/src/events.rs b/src/events.rs index a828eec98..9e6bb9625 100644 --- a/src/events.rs +++ b/src/events.rs | |||
| @@ -3,6 +3,9 @@ | |||
| 3 | 3 | ||
| 4 | use core::num; | 4 | use core::num; |
| 5 | 5 | ||
| 6 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 7 | use embassy_sync::pubsub::{PubSubChannel, Publisher, Subscriber}; | ||
| 8 | |||
| 6 | #[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)] | 9 | #[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)] |
| 7 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 10 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 8 | #[repr(u8)] | 11 | #[repr(u8)] |
| @@ -280,3 +283,14 @@ pub enum Event { | |||
| 280 | /// highest val + 1 for range checking | 283 | /// highest val + 1 for range checking |
| 281 | LAST = 190, | 284 | LAST = 190, |
| 282 | } | 285 | } |
| 286 | |||
| 287 | pub type EventQueue = PubSubChannel<CriticalSectionRawMutex, EventStatus, 2, 1, 1>; | ||
| 288 | pub type EventPublisher<'a> = Publisher<'a, CriticalSectionRawMutex, EventStatus, 2, 1, 1>; | ||
| 289 | pub type EventSubscriber<'a> = Subscriber<'a, CriticalSectionRawMutex, EventStatus, 2, 1, 1>; | ||
| 290 | |||
| 291 | #[derive(Clone, Copy)] | ||
| 292 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 293 | pub struct EventStatus { | ||
| 294 | pub event_type: Event, | ||
| 295 | pub status: u32, | ||
| 296 | } | ||
diff --git a/src/lib.rs b/src/lib.rs index f0a7aaa0f..1b7d603d7 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -20,13 +20,15 @@ use core::slice; | |||
| 20 | use ch::driver::LinkState; | 20 | use ch::driver::LinkState; |
| 21 | use embassy_futures::yield_now; | 21 | use embassy_futures::yield_now; |
| 22 | use embassy_net_driver_channel as ch; | 22 | use embassy_net_driver_channel as ch; |
| 23 | use embassy_sync::pubsub::PubSubBehavior; | ||
| 23 | use embassy_time::{block_for, Duration, Timer}; | 24 | use embassy_time::{block_for, Duration, Timer}; |
| 24 | use embedded_hal_1::digital::OutputPin; | 25 | use embedded_hal_1::digital::OutputPin; |
| 26 | use events::EventQueue; | ||
| 25 | 27 | ||
| 26 | use crate::bus::Bus; | 28 | use crate::bus::Bus; |
| 27 | pub use crate::bus::SpiBusCyw43; | 29 | pub use crate::bus::SpiBusCyw43; |
| 28 | use crate::consts::*; | 30 | use crate::consts::*; |
| 29 | use crate::events::Event; | 31 | use crate::events::{Event, EventStatus}; |
| 30 | use crate::structs::*; | 32 | use crate::structs::*; |
| 31 | 33 | ||
| 32 | const MTU: usize = 1514; | 34 | const MTU: usize = 1514; |
| @@ -128,6 +130,7 @@ enum IoctlState { | |||
| 128 | pub struct State { | 130 | pub struct State { |
| 129 | ioctl_state: Cell<IoctlState>, | 131 | ioctl_state: Cell<IoctlState>, |
| 130 | ch: ch::State<MTU, 4, 4>, | 132 | ch: ch::State<MTU, 4, 4>, |
| 133 | events: EventQueue, | ||
| 131 | } | 134 | } |
| 132 | 135 | ||
| 133 | impl State { | 136 | impl State { |
| @@ -135,12 +138,14 @@ impl State { | |||
| 135 | Self { | 138 | Self { |
| 136 | ioctl_state: Cell::new(IoctlState::Idle), | 139 | ioctl_state: Cell::new(IoctlState::Idle), |
| 137 | ch: ch::State::new(), | 140 | ch: ch::State::new(), |
| 141 | events: EventQueue::new(), | ||
| 138 | } | 142 | } |
| 139 | } | 143 | } |
| 140 | } | 144 | } |
| 141 | 145 | ||
| 142 | pub struct Control<'a> { | 146 | pub struct Control<'a> { |
| 143 | state_ch: ch::StateRunner<'a>, | 147 | state_ch: ch::StateRunner<'a>, |
| 148 | event_sub: &'a EventQueue, | ||
| 144 | ioctl_state: &'a Cell<IoctlState>, | 149 | ioctl_state: &'a Cell<IoctlState>, |
| 145 | } | 150 | } |
| 146 | 151 | ||
| @@ -314,6 +319,7 @@ impl<'a> Control<'a> { | |||
| 314 | evts.unset(Event::PROBREQ_MSG_RX); | 319 | evts.unset(Event::PROBREQ_MSG_RX); |
| 315 | evts.unset(Event::PROBRESP_MSG); | 320 | evts.unset(Event::PROBRESP_MSG); |
| 316 | evts.unset(Event::PROBRESP_MSG); | 321 | evts.unset(Event::PROBRESP_MSG); |
| 322 | evts.unset(Event::ROAM); | ||
| 317 | 323 | ||
| 318 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; | 324 | self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await; |
| 319 | 325 | ||
| @@ -394,8 +400,22 @@ impl<'a> Control<'a> { | |||
| 394 | ssid: [0; 32], | 400 | ssid: [0; 32], |
| 395 | }; | 401 | }; |
| 396 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); | 402 | i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes()); |
| 403 | |||
| 404 | let mut subscriber = self.event_sub.subscriber().unwrap(); | ||
| 397 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid | 405 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid |
| 398 | 406 | ||
| 407 | loop { | ||
| 408 | let msg = subscriber.next_message_pure().await; | ||
| 409 | if msg.event_type == Event::AUTH && msg.status != 0 { | ||
| 410 | // retry | ||
| 411 | defmt::warn!("JOIN failed with status={}", msg.status); | ||
| 412 | self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; | ||
| 413 | } else if msg.event_type == Event::JOIN && msg.status == 0 { | ||
| 414 | // successful join | ||
| 415 | break; | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 399 | info!("JOINED"); | 419 | info!("JOINED"); |
| 400 | } | 420 | } |
| 401 | 421 | ||
| @@ -490,6 +510,8 @@ pub struct Runner<'a, PWR, SPI> { | |||
| 490 | sdpcm_seq: u8, | 510 | sdpcm_seq: u8, |
| 491 | sdpcm_seq_max: u8, | 511 | sdpcm_seq_max: u8, |
| 492 | 512 | ||
| 513 | events: &'a EventQueue, | ||
| 514 | |||
| 493 | #[cfg(feature = "firmware-logs")] | 515 | #[cfg(feature = "firmware-logs")] |
| 494 | log: LogState, | 516 | log: LogState, |
| 495 | } | 517 | } |
| @@ -526,6 +548,8 @@ where | |||
| 526 | sdpcm_seq: 0, | 548 | sdpcm_seq: 0, |
| 527 | sdpcm_seq_max: 1, | 549 | sdpcm_seq_max: 1, |
| 528 | 550 | ||
| 551 | events: &state.events, | ||
| 552 | |||
| 529 | #[cfg(feature = "firmware-logs")] | 553 | #[cfg(feature = "firmware-logs")] |
| 530 | log: LogState { | 554 | log: LogState { |
| 531 | addr: 0, | 555 | addr: 0, |
| @@ -541,6 +565,7 @@ where | |||
| 541 | device, | 565 | device, |
| 542 | Control { | 566 | Control { |
| 543 | state_ch, | 567 | state_ch, |
| 568 | event_sub: &&state.events, | ||
| 544 | ioctl_state: &state.ioctl_state, | 569 | ioctl_state: &state.ioctl_state, |
| 545 | }, | 570 | }, |
| 546 | runner, | 571 | runner, |
| @@ -882,13 +907,16 @@ where | |||
| 882 | return; | 907 | return; |
| 883 | } | 908 | } |
| 884 | 909 | ||
| 910 | let evt_type = events::Event::from(event_packet.msg.event_type as u8); | ||
| 885 | let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize]; | 911 | let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize]; |
| 886 | debug!( | 912 | debug!("=== EVENT {}: {} {:02x}", evt_type, event_packet.msg, evt_data); |
| 887 | "=== EVENT {}: {} {:02x}", | 913 | |
| 888 | events::Event::from(event_packet.msg.event_type as u8), | 914 | if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN { |
| 889 | event_packet.msg, | 915 | self.events.publish_immediate(EventStatus { |
| 890 | evt_data | 916 | status: event_packet.msg.status, |
| 891 | ); | 917 | event_type: evt_type, |
| 918 | }); | ||
| 919 | } | ||
| 892 | } | 920 | } |
| 893 | CHANNEL_TYPE_DATA => { | 921 | CHANNEL_TYPE_DATA => { |
| 894 | let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap()); | 922 | let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap()); |
