-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(arch): split the
nrf
arch into multiple submodule files
Split the `nrf` arch to make it more manageable when it keeps growing.
- Loading branch information
1 parent
4623f02
commit bb8e08f
Showing
5 changed files
with
92 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::arch; | ||
|
||
embassy_nrf::bind_interrupts!(struct Irqs { | ||
RNG => embassy_nrf::rng::InterruptHandler<embassy_nrf::peripherals::RNG>; | ||
}); | ||
|
||
pub fn construct_rng(peripherals: &mut arch::OptionalPeripherals) { | ||
cfg_if::cfg_if! { | ||
// The union of all contexts that wind up in a construct_rng should be synchronized | ||
// with laze-project.yml's hwrng module. | ||
if #[cfg(any(context = "nrf51", context = "nrf52"))] { | ||
let rng = embassy_nrf::rng::Rng::new( | ||
peripherals | ||
.RNG | ||
// We don't even have to take it out, just use it to seed the RNG | ||
.as_mut() | ||
.expect("RNG has not been previously used"), | ||
arch::hwrng::Irqs, | ||
); | ||
|
||
riot_rs_random::construct_rng(rng); | ||
} else if #[cfg(context = "riot-rs")] { | ||
compile_error!("hardware RNG is not supported on this architecture"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#[cfg(feature = "hwrng")] | ||
pub mod hwrng; | ||
|
||
#[cfg(feature = "usb")] | ||
pub mod usb; | ||
|
||
pub(crate) use embassy_executor::InterruptExecutor as Executor; | ||
|
||
#[cfg(context = "nrf52")] | ||
pub use embassy_nrf::interrupt::SWI0_EGU0 as SWI; | ||
|
||
#[cfg(context = "nrf5340")] | ||
pub use embassy_nrf::interrupt::EGU0 as SWI; | ||
|
||
pub use embassy_nrf::{config::Config, interrupt, peripherals, OptionalPeripherals}; | ||
|
||
#[cfg(context = "nrf52")] | ||
#[interrupt] | ||
unsafe fn SWI0_EGU0() { | ||
// SAFETY: | ||
// - called from ISR | ||
// - not called before `start()`, as the interrupt is enabled by `start()` | ||
// itself | ||
unsafe { crate::EXECUTOR.on_interrupt() } | ||
} | ||
|
||
#[cfg(context = "nrf5340")] | ||
#[interrupt] | ||
unsafe fn EGU0() { | ||
unsafe { crate::EXECUTOR.on_interrupt() } | ||
} | ||
|
||
pub fn init(config: Config) -> OptionalPeripherals { | ||
let peripherals = embassy_nrf::init(config); | ||
OptionalPeripherals::from(peripherals) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use embassy_nrf::{ | ||
bind_interrupts, peripherals, | ||
usb::{ | ||
self, | ||
vbus_detect::{self, HardwareVbusDetect}, | ||
Driver, | ||
}, | ||
}; | ||
|
||
use crate::arch; | ||
|
||
#[cfg(context = "nrf52")] | ||
bind_interrupts!(struct Irqs { | ||
USBD => usb::InterruptHandler<peripherals::USBD>; | ||
POWER_CLOCK => vbus_detect::InterruptHandler; | ||
}); | ||
|
||
#[cfg(context = "nrf5340")] | ||
bind_interrupts!(struct Irqs { | ||
USBD => usb::InterruptHandler<peripherals::USBD>; | ||
USBREGULATOR => vbus_detect::InterruptHandler; | ||
}); | ||
|
||
pub type UsbDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>; | ||
|
||
pub fn driver(peripherals: &mut arch::OptionalPeripherals) -> UsbDriver { | ||
let usbd = peripherals.USBD.take().unwrap(); | ||
Driver::new(usbd, Irqs, HardwareVbusDetect::new(Irqs)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters