Skip to content

Commit

Permalink
refactor(arch): move arch modules to their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
ROMemories committed Jan 10, 2024
1 parent 5843680 commit fb70e06
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 64 deletions.
70 changes: 6 additions & 64 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

pub mod assign_resources;

#[cfg(context = "nrf52")]
pub mod nrf52;

#[cfg(context = "rp2040")]
pub mod rp2040;

use core::cell::OnceCell;

pub use linkme::distributed_slice;
Expand Down Expand Up @@ -41,70 +47,6 @@ pub static EXECUTOR: InterruptExecutor = InterruptExecutor::new();
#[distributed_slice]
pub static EMBASSY_TASKS: [Task] = [..];

#[cfg(context = "nrf52")]
pub mod nrf52 {
pub use embassy_nrf::interrupt;
pub use embassy_nrf::interrupt::SWI0_EGU0 as SWI;
pub use embassy_nrf::{init, OptionalPeripherals};

#[cfg(feature = "usb")]
use embassy_nrf::{bind_interrupts, peripherals, 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>;
});

#[interrupt]
unsafe fn SWI0_EGU0() {
crate::EXECUTOR.on_interrupt()
}

#[cfg(feature = "usb")]
pub mod usb {
use embassy_nrf::peripherals;
use embassy_nrf::usb::{vbus_detect::HardwareVbusDetect, Driver};
pub type UsbDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
pub fn driver(usbd: peripherals::USBD) -> UsbDriver {
use super::Irqs;
Driver::new(usbd, Irqs, HardwareVbusDetect::new(Irqs))
}
}
}

#[cfg(context = "rp2040")]
pub mod rp2040 {
pub use embassy_rp::interrupt;
pub use embassy_rp::interrupt::SWI_IRQ_1 as SWI;
pub use embassy_rp::{init, 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>;
});

#[interrupt]
unsafe fn SWI_IRQ_1() {
crate::EXECUTOR.on_interrupt()
}

#[cfg(feature = "usb")]
pub mod usb {
use embassy_rp::peripherals;
use embassy_rp::usb::Driver;
pub type UsbDriver = Driver<'static, peripherals::USB>;
pub fn driver(usb: peripherals::USB) -> UsbDriver {
Driver::new(usb, super::Irqs)
}
}
}

#[cfg(context = "nrf52")]
pub use nrf52 as arch;

Expand Down
29 changes: 29 additions & 0 deletions src/riot-rs-embassy/src/nrf52.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pub use embassy_nrf::interrupt;
pub use embassy_nrf::interrupt::SWI0_EGU0 as SWI;
pub use embassy_nrf::{init, OptionalPeripherals};

#[cfg(feature = "usb")]
use embassy_nrf::{bind_interrupts, peripherals, 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>;
});

#[interrupt]
unsafe fn SWI0_EGU0() {
crate::EXECUTOR.on_interrupt()
}

#[cfg(feature = "usb")]
pub mod usb {
use embassy_nrf::peripherals;
use embassy_nrf::usb::{vbus_detect::HardwareVbusDetect, Driver};
pub type UsbDriver = Driver<'static, peripherals::USBD, HardwareVbusDetect>;
pub fn driver(usbd: peripherals::USBD) -> UsbDriver {
use super::Irqs;
Driver::new(usbd, Irqs, HardwareVbusDetect::new(Irqs))
}
}
27 changes: 27 additions & 0 deletions src/riot-rs-embassy/src/rp2040.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pub use embassy_rp::interrupt;
pub use embassy_rp::interrupt::SWI_IRQ_1 as SWI;
pub use embassy_rp::{init, 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>;
});

#[interrupt]
unsafe fn SWI_IRQ_1() {
crate::EXECUTOR.on_interrupt()
}

#[cfg(feature = "usb")]
pub mod usb {
use embassy_rp::peripherals;
use embassy_rp::usb::Driver;
pub type UsbDriver = Driver<'static, peripherals::USB>;
pub fn driver(usb: peripherals::USB) -> UsbDriver {
Driver::new(usb, super::Irqs)
}
}

0 comments on commit fb70e06

Please sign in to comment.