Skip to content

Commit

Permalink
refactor(arch): split the rp2040 arch into multiple submodule files
Browse files Browse the repository at this point in the history
Split the `rp2040` arch to make it more manageable when it keeps growing.
  • Loading branch information
ROMemories committed Apr 22, 2024
1 parent bb8e08f commit bead939
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(feature = "usb")]
pub mod usb;

pub(crate) use embassy_executor::InterruptExecutor as Executor;
pub use embassy_rp::interrupt;
pub use embassy_rp::interrupt::SWI_IRQ_1 as SWI;
Expand All @@ -12,27 +15,6 @@ unsafe fn SWI_IRQ_1() {
unsafe { crate::EXECUTOR.on_interrupt() }
}

#[cfg(feature = "usb")]
pub mod usb {
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, Irqs)
}
}

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};
Expand Down
17 changes: 17 additions & 0 deletions src/riot-rs-embassy/src/arch/rp2040/usb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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, Irqs)
}
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 @@ -11,7 +11,7 @@ cfg_if::cfg_if! {
#[path = "arch/nrf/mod.rs"]
pub mod arch;
} else if #[cfg(context = "rp2040")] {
#[path = "arch/rp2040.rs"]
#[path = "arch/rp2040/mod.rs"]
pub mod arch;
} else if #[cfg(context = "esp")] {
#[path = "arch/esp.rs"]
Expand Down

0 comments on commit bead939

Please sign in to comment.