From c16dd7c6ffbebca853e8aa9ea34a6cb947ebf23b Mon Sep 17 00:00:00 2001 From: ROMemories Date: Thu, 18 Apr 2024 16:38:09 +0200 Subject: [PATCH] refactor(arch): split the `dummy` arch into multiple submodule files Split the `dummy` arch to make it more manageable when it keeps growing. --- src/riot-rs-embassy/src/arch/dummy.rs | 206 ------------------ .../src/arch/dummy/executor.rs | 32 +++ src/riot-rs-embassy/src/arch/dummy/hwrng.rs | 5 + src/riot-rs-embassy/src/arch/dummy/mod.rs | 34 +++ src/riot-rs-embassy/src/arch/dummy/usb.rs | 135 ++++++++++++ src/riot-rs-embassy/src/lib.rs | 2 +- 6 files changed, 207 insertions(+), 207 deletions(-) delete mode 100644 src/riot-rs-embassy/src/arch/dummy.rs create mode 100644 src/riot-rs-embassy/src/arch/dummy/executor.rs create mode 100644 src/riot-rs-embassy/src/arch/dummy/hwrng.rs create mode 100644 src/riot-rs-embassy/src/arch/dummy/mod.rs create mode 100644 src/riot-rs-embassy/src/arch/dummy/usb.rs diff --git a/src/riot-rs-embassy/src/arch/dummy.rs b/src/riot-rs-embassy/src/arch/dummy.rs deleted file mode 100644 index 8302bdb91..000000000 --- a/src/riot-rs-embassy/src/arch/dummy.rs +++ /dev/null @@ -1,206 +0,0 @@ -//! Dummy module used to satisfy platform-independent tooling. - -/// Dummy type. -/// -/// See the `OptionalPeripherals` type of your Embassy architecture crate instead. -pub struct OptionalPeripherals; - -/// Dummy type. -pub struct Peripherals; - -impl From for OptionalPeripherals { - fn from(_peripherals: Peripherals) -> Self { - Self {} - } -} - -mod executor { - use embassy_executor::SpawnToken; - - pub struct Executor; - - impl Executor { - #[allow(clippy::new_without_default)] - pub const fn new() -> Self { - // Actually return a value instead of marking it unimplemented like other dummy - // functions, because this function is const and is thus run during compilation - Self {} - } - - pub fn start(&self, _: super::SWI) { - unimplemented!(); - } - - pub fn spawner(&self) -> Spawner { - unimplemented!(); - } - } - - pub struct Spawner; - - impl Spawner { - #[allow(clippy::result_unit_err)] - pub fn spawn(&self, _token: SpawnToken) -> Result<(), ()> { - unimplemented!(); - } - pub fn must_spawn(&self, _token: SpawnToken) {} - } -} -pub use executor::{Executor, Spawner}; - -#[derive(Default)] -pub struct Config; - -pub fn init(_config: Config) -> OptionalPeripherals { - unimplemented!(); -} - -pub struct SWI; - -#[cfg(feature = "usb")] -pub mod usb { - use embassy_usb::driver::{ - Bus, ControlPipe, Driver, Endpoint, EndpointAddress, EndpointAllocError, EndpointError, - EndpointIn, EndpointInfo, EndpointOut, EndpointType, Event, Unsupported, - }; - - use super::OptionalPeripherals; - - pub struct UsbDriver; - - impl<'a> Driver<'a> for UsbDriver { - type EndpointOut = DummyEndpointOut; - type EndpointIn = DummyEndpointIn; - type ControlPipe = DummyControlPipe; - type Bus = DummyBus; - - fn alloc_endpoint_out( - &mut self, - _ep_type: EndpointType, - _max_packet_size: u16, - _interval_ms: u8, - ) -> Result { - unimplemented!(); - } - fn alloc_endpoint_in( - &mut self, - _ep_type: EndpointType, - _max_packet_size: u16, - _interval_ms: u8, - ) -> Result { - unimplemented!(); - } - fn start(self, _control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { - unimplemented!(); - } - } - - pub fn driver(_peripherals: &mut OptionalPeripherals) -> UsbDriver { - unimplemented!(); - } - - pub struct DummyEndpointOut; - - impl Endpoint for DummyEndpointOut { - fn info(&self) -> &EndpointInfo { - unimplemented!(); - } - async fn wait_enabled(&mut self) { - unimplemented!(); - } - } - - impl EndpointOut for DummyEndpointOut { - async fn read(&mut self, _buf: &mut [u8]) -> Result { - unimplemented!(); - } - } - - pub struct DummyEndpointIn; - - impl Endpoint for DummyEndpointIn { - fn info(&self) -> &EndpointInfo { - unimplemented!(); - } - async fn wait_enabled(&mut self) { - unimplemented!(); - } - } - - impl EndpointIn for DummyEndpointIn { - async fn write(&mut self, _buf: &[u8]) -> Result<(), EndpointError> { - unimplemented!(); - } - } - - pub struct DummyControlPipe; - - impl ControlPipe for DummyControlPipe { - fn max_packet_size(&self) -> usize { - unimplemented!(); - } - async fn setup(&mut self) -> [u8; 8] { - unimplemented!(); - } - async fn data_out( - &mut self, - _buf: &mut [u8], - _first: bool, - _last: bool, - ) -> Result { - unimplemented!(); - } - async fn data_in( - &mut self, - _data: &[u8], - _first: bool, - _last: bool, - ) -> Result<(), EndpointError> { - unimplemented!(); - } - async fn accept(&mut self) { - unimplemented!(); - } - async fn reject(&mut self) { - unimplemented!(); - } - async fn accept_set_address(&mut self, _addr: u8) { - unimplemented!(); - } - } - - pub struct DummyBus; - - impl Bus for DummyBus { - async fn enable(&mut self) { - unimplemented!(); - } - async fn disable(&mut self) { - unimplemented!(); - } - async fn poll(&mut self) -> Event { - unimplemented!(); - } - fn endpoint_set_enabled(&mut self, _ep_addr: EndpointAddress, _enabled: bool) { - unimplemented!(); - } - fn endpoint_set_stalled(&mut self, _ep_addr: EndpointAddress, _stalled: bool) { - unimplemented!(); - } - fn endpoint_is_stalled(&mut self, _ep_addr: EndpointAddress) -> bool { - unimplemented!(); - } - async fn remote_wakeup(&mut self) -> Result<(), Unsupported> { - unimplemented!(); - } - } -} - -#[cfg(feature = "hwrng")] -pub mod hwrng { - use super::OptionalPeripherals; - - pub fn construct_rng(_peripherals: &mut OptionalPeripherals) { - unimplemented!(); - } -} diff --git a/src/riot-rs-embassy/src/arch/dummy/executor.rs b/src/riot-rs-embassy/src/arch/dummy/executor.rs new file mode 100644 index 000000000..4abf1f11e --- /dev/null +++ b/src/riot-rs-embassy/src/arch/dummy/executor.rs @@ -0,0 +1,32 @@ +use embassy_executor::SpawnToken; + +use crate::arch; + +pub struct Executor; + +impl Executor { + #[allow(clippy::new_without_default)] + pub const fn new() -> Self { + // Actually return a value instead of marking it unimplemented like other dummy + // functions, because this function is const and is thus run during compilation + Self {} + } + + pub fn start(&self, _: arch::SWI) { + unimplemented!(); + } + + pub fn spawner(&self) -> Spawner { + unimplemented!(); + } +} + +pub struct Spawner; + +impl Spawner { + #[allow(clippy::result_unit_err)] + pub fn spawn(&self, _token: SpawnToken) -> Result<(), ()> { + unimplemented!(); + } + pub fn must_spawn(&self, _token: SpawnToken) {} +} diff --git a/src/riot-rs-embassy/src/arch/dummy/hwrng.rs b/src/riot-rs-embassy/src/arch/dummy/hwrng.rs new file mode 100644 index 000000000..901ec360c --- /dev/null +++ b/src/riot-rs-embassy/src/arch/dummy/hwrng.rs @@ -0,0 +1,5 @@ +use crate::arch; + +pub fn construct_rng(_peripherals: &mut arch::OptionalPeripherals) { + unimplemented!(); +} diff --git a/src/riot-rs-embassy/src/arch/dummy/mod.rs b/src/riot-rs-embassy/src/arch/dummy/mod.rs new file mode 100644 index 000000000..c98e4919b --- /dev/null +++ b/src/riot-rs-embassy/src/arch/dummy/mod.rs @@ -0,0 +1,34 @@ +//! Dummy module used to satisfy platform-independent tooling. + +mod executor; + +#[cfg(feature = "hwrng")] +pub mod hwrng; + +#[cfg(feature = "usb")] +pub mod usb; + +pub use executor::{Executor, Spawner}; + +/// Dummy type. +/// +/// See the `OptionalPeripherals` type of your Embassy architecture crate instead. +pub struct OptionalPeripherals; + +/// Dummy type. +pub struct Peripherals; + +impl From for OptionalPeripherals { + fn from(_peripherals: Peripherals) -> Self { + Self {} + } +} + +#[derive(Default)] +pub struct Config; + +pub fn init(_config: Config) -> OptionalPeripherals { + unimplemented!(); +} + +pub struct SWI; diff --git a/src/riot-rs-embassy/src/arch/dummy/usb.rs b/src/riot-rs-embassy/src/arch/dummy/usb.rs new file mode 100644 index 000000000..39e8aac2c --- /dev/null +++ b/src/riot-rs-embassy/src/arch/dummy/usb.rs @@ -0,0 +1,135 @@ +use embassy_usb::driver::{ + Bus, ControlPipe, Driver, Endpoint, EndpointAddress, EndpointAllocError, EndpointError, + EndpointIn, EndpointInfo, EndpointOut, EndpointType, Event, Unsupported, +}; + +use crate::arch; + +pub struct UsbDriver; + +impl<'a> Driver<'a> for UsbDriver { + type EndpointOut = DummyEndpointOut; + type EndpointIn = DummyEndpointIn; + type ControlPipe = DummyControlPipe; + type Bus = DummyBus; + + fn alloc_endpoint_out( + &mut self, + _ep_type: EndpointType, + _max_packet_size: u16, + _interval_ms: u8, + ) -> Result { + unimplemented!(); + } + fn alloc_endpoint_in( + &mut self, + _ep_type: EndpointType, + _max_packet_size: u16, + _interval_ms: u8, + ) -> Result { + unimplemented!(); + } + fn start(self, _control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { + unimplemented!(); + } +} + +pub fn driver(_peripherals: &mut arch::OptionalPeripherals) -> UsbDriver { + unimplemented!(); +} + +pub struct DummyEndpointOut; + +impl Endpoint for DummyEndpointOut { + fn info(&self) -> &EndpointInfo { + unimplemented!(); + } + async fn wait_enabled(&mut self) { + unimplemented!(); + } +} + +impl EndpointOut for DummyEndpointOut { + async fn read(&mut self, _buf: &mut [u8]) -> Result { + unimplemented!(); + } +} + +pub struct DummyEndpointIn; + +impl Endpoint for DummyEndpointIn { + fn info(&self) -> &EndpointInfo { + unimplemented!(); + } + async fn wait_enabled(&mut self) { + unimplemented!(); + } +} + +impl EndpointIn for DummyEndpointIn { + async fn write(&mut self, _buf: &[u8]) -> Result<(), EndpointError> { + unimplemented!(); + } +} + +pub struct DummyControlPipe; + +impl ControlPipe for DummyControlPipe { + fn max_packet_size(&self) -> usize { + unimplemented!(); + } + async fn setup(&mut self) -> [u8; 8] { + unimplemented!(); + } + async fn data_out( + &mut self, + _buf: &mut [u8], + _first: bool, + _last: bool, + ) -> Result { + unimplemented!(); + } + async fn data_in( + &mut self, + _data: &[u8], + _first: bool, + _last: bool, + ) -> Result<(), EndpointError> { + unimplemented!(); + } + async fn accept(&mut self) { + unimplemented!(); + } + async fn reject(&mut self) { + unimplemented!(); + } + async fn accept_set_address(&mut self, _addr: u8) { + unimplemented!(); + } +} + +pub struct DummyBus; + +impl Bus for DummyBus { + async fn enable(&mut self) { + unimplemented!(); + } + async fn disable(&mut self) { + unimplemented!(); + } + async fn poll(&mut self) -> Event { + unimplemented!(); + } + fn endpoint_set_enabled(&mut self, _ep_addr: EndpointAddress, _enabled: bool) { + unimplemented!(); + } + fn endpoint_set_stalled(&mut self, _ep_addr: EndpointAddress, _stalled: bool) { + unimplemented!(); + } + fn endpoint_is_stalled(&mut self, _ep_addr: EndpointAddress) -> bool { + unimplemented!(); + } + async fn remote_wakeup(&mut self) -> Result<(), Unsupported> { + unimplemented!(); + } +} diff --git a/src/riot-rs-embassy/src/lib.rs b/src/riot-rs-embassy/src/lib.rs index c27d54152..e9c726d2b 100644 --- a/src/riot-rs-embassy/src/lib.rs +++ b/src/riot-rs-embassy/src/lib.rs @@ -19,7 +19,7 @@ cfg_if::cfg_if! { } else if #[cfg(context = "riot-rs")] { compile_error!("this architecture is not supported"); } else { - #[path = "arch/dummy.rs"] + #[path = "arch/dummy/mod.rs"] pub mod arch; } }