Merge branch 'master' into pio
This commit is contained in:
commit
29494a9296
11
.vscode/extensions.json
vendored
Normal file
11
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
|
||||||
|
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
|
||||||
|
// List of extensions which should be recommended for users of this workspace.
|
||||||
|
"recommendations": [
|
||||||
|
"rust-lang.rust-analyzer",
|
||||||
|
"tamasfe.even-better-toml",
|
||||||
|
],
|
||||||
|
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
|
||||||
|
"unwantedRecommendations": []
|
||||||
|
}
|
14
.vscode/settings.json
vendored
14
.vscode/settings.json
vendored
@ -1,14 +1,12 @@
|
|||||||
{
|
{
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"rust-analyzer.cargo.buildScripts.enable": true,
|
"[toml]": {
|
||||||
"rust-analyzer.cargo.noDefaultFeatures": true,
|
"editor.formatOnSave": false
|
||||||
|
},
|
||||||
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
|
"rust-analyzer.cargo.target": "thumbv6m-none-eabi",
|
||||||
"rust-analyzer.checkOnSave.allTargets": false,
|
"rust-analyzer.cargo.noDefaultFeatures": true,
|
||||||
"rust-analyzer.checkOnSave.noDefaultFeatures": true,
|
"rust-analyzer.check.allTargets": false,
|
||||||
"rust-analyzer.imports.granularity.enforce": true,
|
"rust-analyzer.check.noDefaultFeatures": true,
|
||||||
"rust-analyzer.imports.granularity.group": "module",
|
|
||||||
"rust-analyzer.procMacro.attributes.enable": false,
|
|
||||||
"rust-analyzer.procMacro.enable": false,
|
|
||||||
"rust-analyzer.linkedProjects": [
|
"rust-analyzer.linkedProjects": [
|
||||||
"examples/rpi-pico-w/Cargo.toml",
|
"examples/rpi-pico-w/Cargo.toml",
|
||||||
],
|
],
|
||||||
|
@ -59,7 +59,7 @@ async fn main(spawner: Spawner) {
|
|||||||
// To make flashing faster for development, you may want to flash the firmwares independently
|
// To make flashing faster for development, you may want to flash the firmwares independently
|
||||||
// at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
|
// at hardcoded addresses, instead of baking them into the program with `include_bytes!`:
|
||||||
// probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
|
// probe-rs-cli download 43439A0.bin --format bin --chip RP2040 --base-address 0x10100000
|
||||||
// probe-rs-cli download 43439A0.clm_blob --format bin --chip RP2040 --base-address 0x10140000
|
// probe-rs-cli download 43439A0_clm.bin --format bin --chip RP2040 --base-address 0x10140000
|
||||||
//let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
|
//let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 224190) };
|
||||||
//let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
|
//let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) };
|
||||||
|
|
||||||
@ -78,16 +78,11 @@ async fn main(spawner: Spawner) {
|
|||||||
let state = singleton!(cyw43::State::new());
|
let state = singleton!(cyw43::State::new());
|
||||||
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
|
let (net_device, mut control, runner) = cyw43::new(state, pwr, spi, fw).await;
|
||||||
|
|
||||||
spawner.spawn(wifi_task(runner)).unwrap();
|
|
||||||
|
|
||||||
control.init(clm).await;
|
control.init(clm).await;
|
||||||
control
|
control
|
||||||
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
.set_power_management(cyw43::PowerManagementMode::PowerSave)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
//control.join_open(env!("WIFI_NETWORK")).await;
|
|
||||||
control.join_wpa2(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await;
|
|
||||||
|
|
||||||
let config = Config::Dhcp(Default::default());
|
let config = Config::Dhcp(Default::default());
|
||||||
//let config = embassy_net::Config::Static(embassy_net::Config {
|
//let config = embassy_net::Config::Static(embassy_net::Config {
|
||||||
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
// address: Ipv4Cidr::new(Ipv4Address::new(192, 168, 69, 2), 24),
|
||||||
@ -106,8 +101,12 @@ async fn main(spawner: Spawner) {
|
|||||||
seed
|
seed
|
||||||
));
|
));
|
||||||
|
|
||||||
|
unwrap!(spawner.spawn(wifi_task(runner)));
|
||||||
unwrap!(spawner.spawn(net_task(stack)));
|
unwrap!(spawner.spawn(net_task(stack)));
|
||||||
|
|
||||||
|
//control.join_open(env!("WIFI_NETWORK")).await;
|
||||||
|
control.join_wpa2(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await;
|
||||||
|
|
||||||
// And now we can use it!
|
// And now we can use it!
|
||||||
|
|
||||||
let mut rx_buffer = [0; 4096];
|
let mut rx_buffer = [0; 4096];
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
use core::num;
|
use core::num;
|
||||||
|
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::pubsub::{PubSubChannel, Publisher, Subscriber};
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)]
|
#[derive(Clone, Copy, PartialEq, Eq, num_enum::FromPrimitive)]
|
||||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
@ -280,3 +283,14 @@ pub enum Event {
|
|||||||
/// highest val + 1 for range checking
|
/// highest val + 1 for range checking
|
||||||
LAST = 190,
|
LAST = 190,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type EventQueue = PubSubChannel<CriticalSectionRawMutex, EventStatus, 2, 1, 1>;
|
||||||
|
pub type EventPublisher<'a> = Publisher<'a, CriticalSectionRawMutex, EventStatus, 2, 1, 1>;
|
||||||
|
pub type EventSubscriber<'a> = Subscriber<'a, CriticalSectionRawMutex, EventStatus, 2, 1, 1>;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||||
|
pub struct EventStatus {
|
||||||
|
pub event_type: Event,
|
||||||
|
pub status: u32,
|
||||||
|
}
|
||||||
|
42
src/lib.rs
42
src/lib.rs
@ -20,13 +20,15 @@ use core::slice;
|
|||||||
use ch::driver::LinkState;
|
use ch::driver::LinkState;
|
||||||
use embassy_futures::yield_now;
|
use embassy_futures::yield_now;
|
||||||
use embassy_net_driver_channel as ch;
|
use embassy_net_driver_channel as ch;
|
||||||
|
use embassy_sync::pubsub::PubSubBehavior;
|
||||||
use embassy_time::{block_for, Duration, Timer};
|
use embassy_time::{block_for, Duration, Timer};
|
||||||
use embedded_hal_1::digital::OutputPin;
|
use embedded_hal_1::digital::OutputPin;
|
||||||
|
use events::EventQueue;
|
||||||
|
|
||||||
use crate::bus::Bus;
|
use crate::bus::Bus;
|
||||||
pub use crate::bus::SpiBusCyw43;
|
pub use crate::bus::SpiBusCyw43;
|
||||||
use crate::consts::*;
|
use crate::consts::*;
|
||||||
use crate::events::Event;
|
use crate::events::{Event, EventStatus};
|
||||||
use crate::structs::*;
|
use crate::structs::*;
|
||||||
|
|
||||||
const MTU: usize = 1514;
|
const MTU: usize = 1514;
|
||||||
@ -128,6 +130,7 @@ enum IoctlState {
|
|||||||
pub struct State {
|
pub struct State {
|
||||||
ioctl_state: Cell<IoctlState>,
|
ioctl_state: Cell<IoctlState>,
|
||||||
ch: ch::State<MTU, 4, 4>,
|
ch: ch::State<MTU, 4, 4>,
|
||||||
|
events: EventQueue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
@ -135,12 +138,14 @@ impl State {
|
|||||||
Self {
|
Self {
|
||||||
ioctl_state: Cell::new(IoctlState::Idle),
|
ioctl_state: Cell::new(IoctlState::Idle),
|
||||||
ch: ch::State::new(),
|
ch: ch::State::new(),
|
||||||
|
events: EventQueue::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Control<'a> {
|
pub struct Control<'a> {
|
||||||
state_ch: ch::StateRunner<'a>,
|
state_ch: ch::StateRunner<'a>,
|
||||||
|
event_sub: &'a EventQueue,
|
||||||
ioctl_state: &'a Cell<IoctlState>,
|
ioctl_state: &'a Cell<IoctlState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +319,7 @@ impl<'a> Control<'a> {
|
|||||||
evts.unset(Event::PROBREQ_MSG_RX);
|
evts.unset(Event::PROBREQ_MSG_RX);
|
||||||
evts.unset(Event::PROBRESP_MSG);
|
evts.unset(Event::PROBRESP_MSG);
|
||||||
evts.unset(Event::PROBRESP_MSG);
|
evts.unset(Event::PROBRESP_MSG);
|
||||||
|
evts.unset(Event::ROAM);
|
||||||
|
|
||||||
self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await;
|
self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await;
|
||||||
|
|
||||||
@ -394,8 +400,22 @@ impl<'a> Control<'a> {
|
|||||||
ssid: [0; 32],
|
ssid: [0; 32],
|
||||||
};
|
};
|
||||||
i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes());
|
i.ssid[..ssid.len()].copy_from_slice(ssid.as_bytes());
|
||||||
|
|
||||||
|
let mut subscriber = self.event_sub.subscriber().unwrap();
|
||||||
self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid
|
self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await; // set_ssid
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let msg = subscriber.next_message_pure().await;
|
||||||
|
if msg.event_type == Event::AUTH && msg.status != 0 {
|
||||||
|
// retry
|
||||||
|
defmt::warn!("JOIN failed with status={}", msg.status);
|
||||||
|
self.ioctl(IoctlType::Set, 26, 0, &mut i.to_bytes()).await;
|
||||||
|
} else if msg.event_type == Event::JOIN && msg.status == 0 {
|
||||||
|
// successful join
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
info!("JOINED");
|
info!("JOINED");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,6 +510,8 @@ pub struct Runner<'a, PWR, SPI> {
|
|||||||
sdpcm_seq: u8,
|
sdpcm_seq: u8,
|
||||||
sdpcm_seq_max: u8,
|
sdpcm_seq_max: u8,
|
||||||
|
|
||||||
|
events: &'a EventQueue,
|
||||||
|
|
||||||
#[cfg(feature = "firmware-logs")]
|
#[cfg(feature = "firmware-logs")]
|
||||||
log: LogState,
|
log: LogState,
|
||||||
}
|
}
|
||||||
@ -526,6 +548,8 @@ where
|
|||||||
sdpcm_seq: 0,
|
sdpcm_seq: 0,
|
||||||
sdpcm_seq_max: 1,
|
sdpcm_seq_max: 1,
|
||||||
|
|
||||||
|
events: &state.events,
|
||||||
|
|
||||||
#[cfg(feature = "firmware-logs")]
|
#[cfg(feature = "firmware-logs")]
|
||||||
log: LogState {
|
log: LogState {
|
||||||
addr: 0,
|
addr: 0,
|
||||||
@ -541,6 +565,7 @@ where
|
|||||||
device,
|
device,
|
||||||
Control {
|
Control {
|
||||||
state_ch,
|
state_ch,
|
||||||
|
event_sub: &&state.events,
|
||||||
ioctl_state: &state.ioctl_state,
|
ioctl_state: &state.ioctl_state,
|
||||||
},
|
},
|
||||||
runner,
|
runner,
|
||||||
@ -882,13 +907,16 @@ where
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let evt_type = events::Event::from(event_packet.msg.event_type as u8);
|
||||||
let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize];
|
let evt_data = &bcd_packet[EventMessage::SIZE..][..event_packet.msg.datalen as usize];
|
||||||
debug!(
|
debug!("=== EVENT {}: {} {:02x}", evt_type, event_packet.msg, evt_data);
|
||||||
"=== EVENT {}: {} {:02x}",
|
|
||||||
events::Event::from(event_packet.msg.event_type as u8),
|
if evt_type == events::Event::AUTH || evt_type == events::Event::JOIN {
|
||||||
event_packet.msg,
|
self.events.publish_immediate(EventStatus {
|
||||||
evt_data
|
status: event_packet.msg.status,
|
||||||
);
|
event_type: evt_type,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CHANNEL_TYPE_DATA => {
|
CHANNEL_TYPE_DATA => {
|
||||||
let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap());
|
let bcd_header = BcdHeader::from_bytes(&payload[..BcdHeader::SIZE].try_into().unwrap());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user