-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(embassy-init): move out peripherals required for drivers earlier #337
base: main
Are you sure you want to change the base?
Changes from 2 commits
d2cbe4e
9377054
ecc6870
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,13 +143,23 @@ | |
|
||
#[embassy_executor::task] | ||
async fn init_task(mut peripherals: arch::OptionalPeripherals) { | ||
use crate::define_peripherals::TakePeripherals; | ||
Check warning on line 146 in src/riot-rs-embassy/src/lib.rs GitHub Actions / lintunused import: `crate::define_peripherals::TakePeripherals`
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style: move imports to top of file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather keep this import closer to its usage locations, given that its usage is non-obvious. |
||
|
||
println!("riot-rs-embassy::init_task()"); | ||
|
||
#[cfg(feature = "hwrng")] | ||
arch::hwrng::construct_rng(&mut peripherals); | ||
// Clock startup and entropy collection may lend themselves to parallelization, provided that | ||
// doesn't impact runtime RAM or flash use. | ||
|
||
// Move out the peripherals required for drivers, so that tasks cannot mistakenly take them. | ||
#[cfg(feature = "usb")] | ||
let usb_peripherals: arch::usb::Peripherals = (&mut peripherals).take_peripherals(); | ||
#[cfg(feature = "wifi-cyw43")] | ||
let wifi_cyw43_peripherals: wifi::cyw43::Peripherals = (&mut peripherals).take_peripherals(); | ||
#[cfg(feature = "wifi-esp")] | ||
let esp_wifi_peripherals: wifi::esp_wifi::Peripherals = (&mut peripherals).take_peripherals(); | ||
|
||
#[cfg(all(context = "nrf", feature = "usb"))] | ||
{ | ||
// nrf52840 | ||
|
@@ -162,6 +172,8 @@ | |
|
||
let spawner = Spawner::for_current_executor().await; | ||
|
||
// Tasks have to be started before driver initializations so that the tasks are able to | ||
// configure the drivers using hooks. | ||
for task in EMBASSY_TASKS { | ||
task(spawner, &mut peripherals); | ||
} | ||
|
@@ -170,7 +182,7 @@ | |
let mut usb_builder = { | ||
let usb_config = usb::config(); | ||
|
||
let usb_driver = arch::usb::driver(&mut peripherals); | ||
let usb_driver = arch::usb::driver(usb_peripherals); | ||
|
||
// Create embassy-usb DeviceBuilder using the driver and config. | ||
let builder = usb::UsbBuilder::new( | ||
|
@@ -226,13 +238,10 @@ | |
} | ||
|
||
#[cfg(feature = "wifi-cyw43")] | ||
let (device, control) = { | ||
let (net_device, control) = wifi::cyw43::device(&mut peripherals, &spawner).await; | ||
(net_device, control) | ||
}; | ||
let (device, control) = wifi::cyw43::init(wifi_cyw43_peripherals, &spawner).await; | ||
|
||
#[cfg(feature = "wifi-esp")] | ||
let device = wifi::esp_wifi::init(&mut peripherals, spawner); | ||
let device = wifi::esp_wifi::init(esp_wifi_peripherals, spawner); | ||
|
||
#[cfg(feature = "net")] | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,10 @@ use embassy_rp::{ | |
|
||
use riot_rs_debug::println; | ||
|
||
use self::rpi_pico_w::{Cyw43Periphs, CywSpi, Irqs}; | ||
use crate::{arch::OptionalPeripherals, make_static}; | ||
use self::rpi_pico_w::{CywSpi, Irqs}; | ||
use crate::make_static; | ||
|
||
pub use rpi_pico_w::Cyw43Periphs as Peripherals; | ||
|
||
pub type NetworkDevice = cyw43::NetDriver<'static>; | ||
|
||
|
@@ -34,14 +36,10 @@ async fn wifi_cyw43_task(runner: Runner<'static, Output<'static>, CywSpi>) -> ! | |
runner.run().await | ||
} | ||
|
||
pub async fn device<'a, 'b: 'a>( | ||
mut p: &'a mut OptionalPeripherals, | ||
pub async fn init<'a>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I renamed this function for consistency with other driver modules; this is not a breaking change as this module is private. |
||
periperals: Peripherals, | ||
spawner: &crate::Spawner, | ||
) -> (embassy_net_driver_channel::Device<'b, 1514>, Control<'b>) { | ||
use crate::define_peripherals::TakePeripherals; | ||
|
||
let pins: Cyw43Periphs = p.take_peripherals(); | ||
|
||
) -> (embassy_net_driver_channel::Device<'a, 1514>, Control<'a>) { | ||
let fw = include_bytes!("cyw43/firmware/43439A0.bin"); | ||
let clm = include_bytes!("cyw43/firmware/43439A0_clm.bin"); | ||
|
||
|
@@ -52,17 +50,17 @@ pub async fn device<'a, 'b: 'a>( | |
//let fw = unsafe { core::slice::from_raw_parts(0x10100000 as *const u8, 230321) }; | ||
//let clm = unsafe { core::slice::from_raw_parts(0x10140000 as *const u8, 4752) }; | ||
|
||
let pwr = Output::new(pins.pwr, Level::Low); | ||
let cs = Output::new(pins.cs, Level::High); | ||
let mut pio = Pio::new(pins.pio, Irqs); | ||
let pwr = Output::new(periperals.pwr, Level::Low); | ||
let cs = Output::new(periperals.cs, Level::High); | ||
let mut pio = Pio::new(periperals.pio, Irqs); | ||
let spi = CywSpi::new( | ||
&mut pio.common, | ||
pio.sm0, | ||
pio.irq0, | ||
cs, | ||
pins.dio, | ||
pins.clk, | ||
pins.dma, | ||
periperals.dio, | ||
periperals.clk, | ||
periperals.dma, | ||
); | ||
|
||
let state = make_static!(cyw43::State::new()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
error[E0599]: no method named `take_peripherals` found for mutable reference `&mut OptionalPeripherals` in the current scope | ||
error[E0308]: mismatched types | ||
--> tests/ui/task/incorrect_fn_peripheral_param_type.rs:7:1 | ||
| | ||
7 | #[riot_rs::task(autostart, peripherals)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `&mut OptionalPeripherals` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Bar`, found `Peripherals` | ||
8 | async fn main(_foo: Bar) {} | ||
| ---- arguments to this function are incorrect | ||
| | ||
note: function defined here | ||
--> tests/ui/task/incorrect_fn_peripheral_param_type.rs:8:10 | ||
| | ||
8 | async fn main(_foo: Bar) {} | ||
| ^^^^ --------- | ||
= note: this error originates in the attribute macro `riot_rs::task` (in Nightly builds, run with -Z macro-backtrace for more info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definition is what triggers the different macro error message. As the error message is clearer this way, this doesn't seem like an issue.