Skip to content
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

feat(embassy-arch): return OptionalPeripherals from init() #124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/riot-rs-embassy/src/arch/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
pub struct Executor;

impl Executor {
pub const fn new() -> Self {
Self {}
}

Check warning on line 26 in src/riot-rs-embassy/src/arch/dummy.rs

View workflow job for this annotation

GitHub Actions / lint

you should consider adding a `Default` implementation for `Executor`

warning: you should consider adding a `Default` implementation for `Executor` --> src/riot-rs-embassy/src/arch/dummy.rs:24:9 | 24 | / pub const fn new() -> Self { 25 | | Self {} 26 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default = note: `#[warn(clippy::new_without_default)]` on by default help: try adding this | 23 ~ impl Default for Executor { 24 + fn default() -> Self { 25 + Self::new() 26 + } 27 + } 28 + 29 ~ impl Executor { |

pub fn start(&self, _: super::SWI) {}

Expand All @@ -43,8 +43,11 @@
}
pub use executor::{Executor, Spawner};

pub fn init(_: OptionalPeripherals) -> Peripherals {
Peripherals {}
#[derive(Default)]
pub struct Config;

pub fn init(_config: Config) -> OptionalPeripherals {
unimplemented!();
}

pub struct SWI;
34 changes: 18 additions & 16 deletions src/riot-rs-embassy/src/arch/nrf52.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
pub(crate) use embassy_executor::InterruptExecutor as Executor;
pub use embassy_nrf::interrupt::SWI0_EGU0 as SWI;
pub use embassy_nrf::{init, OptionalPeripherals};
pub use embassy_nrf::{interrupt, peripherals};

#[cfg(feature = "usb")]
use embassy_nrf::{bind_interrupts, rng, usb as nrf_usb};

#[cfg(feature = "usb")]
bind_interrupts!(struct Irqs {
USBD => nrf_usb::InterruptHandler<peripherals::USBD>;
POWER_CLOCK => nrf_usb::vbus_detect::InterruptHandler;
RNG => rng::InterruptHandler<peripherals::RNG>;
});
pub use embassy_nrf::{config::Config, interrupt, peripherals, OptionalPeripherals};

#[interrupt]
unsafe fn SWI0_EGU0() {
Expand All @@ -21,18 +10,31 @@ unsafe fn SWI0_EGU0() {
#[cfg(feature = "usb")]
pub mod usb {
use embassy_nrf::{
peripherals,
usb::{vbus_detect::HardwareVbusDetect, Driver},
bind_interrupts, peripherals, rng,
usb::{
self,
vbus_detect::{self, HardwareVbusDetect},
Driver,
},
};

use crate::arch;

bind_interrupts!(struct Irqs {
USBD => usb::InterruptHandler<peripherals::USBD>;
POWER_CLOCK => vbus_detect::InterruptHandler;
RNG => rng::InterruptHandler<peripherals::RNG>;
});

pub type UsbDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;

pub fn driver(peripherals: &mut arch::OptionalPeripherals) -> UsbDriver {
use super::Irqs;

let usbd = peripherals.USBD.take().unwrap();
Driver::new(usbd, Irqs, HardwareVbusDetect::new(Irqs))
}
}

pub fn init(config: Config) -> OptionalPeripherals {
let peripherals = embassy_nrf::init(config);
OptionalPeripherals::from(peripherals)
}
28 changes: 13 additions & 15 deletions src/riot-rs-embassy/src/arch/rp2040.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
pub(crate) use embassy_executor::InterruptExecutor as Executor;
pub use embassy_rp::interrupt;
pub use embassy_rp::interrupt::SWI_IRQ_1 as SWI;
pub use embassy_rp::{config::Config, peripherals, OptionalPeripherals, Peripherals};

#[cfg(feature = "usb")]
use embassy_rp::{bind_interrupts, peripherals::USB, usb::InterruptHandler};

// rp2040 usb start
#[cfg(feature = "usb")]
bind_interrupts!(struct Irqs {
USBCTRL_IRQ => InterruptHandler<USB>;
});
pub use embassy_rp::{config::Config, peripherals, OptionalPeripherals};

#[interrupt]
unsafe fn SWI_IRQ_1() {
Expand All @@ -19,23 +10,30 @@ unsafe fn SWI_IRQ_1() {

#[cfg(feature = "usb")]
pub mod usb {
use embassy_rp::peripherals;
use embassy_rp::usb::Driver;
use embassy_rp::{
bind_interrupts, peripherals,
usb::{Driver, InterruptHandler},
};

use crate::arch;

bind_interrupts!(struct Irqs {
USBCTRL_IRQ => InterruptHandler<peripherals::USB>;
});

pub type UsbDriver = Driver<'static, peripherals::USB>;

pub fn driver(peripherals: &mut arch::OptionalPeripherals) -> UsbDriver {
let usb = peripherals.USB.take().unwrap();
Driver::new(usb, super::Irqs)
Driver::new(usb, Irqs)
}
}

pub fn init(config: Config) -> Peripherals {
pub fn init(config: Config) -> OptionalPeripherals {
// SWI & DMA priority need to match. DMA is hard-coded to P3 by upstream.
use embassy_rp::interrupt::{InterruptExt, Priority};
SWI.set_priority(Priority::P3);

embassy_rp::init(config)
let peripherals = embassy_rp::init(config);
OptionalPeripherals::from(peripherals)
}
2 changes: 1 addition & 1 deletion src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub static EMBASSY_TASKS: [Task] = [..];
#[distributed_slice(riot_rs_rt::INIT_FUNCS)]
pub(crate) fn init() {
riot_rs_rt::debug::println!("riot-rs-embassy::init()");
let p = arch::OptionalPeripherals::from(arch::init(Default::default()));
let p = arch::init(Default::default());
ROMemories marked this conversation as resolved.
Show resolved Hide resolved
EXECUTOR.start(arch::SWI);
EXECUTOR.spawner().spawn(init_task(p)).unwrap();

Expand Down
Loading