Skip to content

Commit

Permalink
feat(arch): introduce riot-rs-arch dispatch crate
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Oct 24, 2024
1 parent d049aff commit 65dc3ed
Show file tree
Hide file tree
Showing 15 changed files with 641 additions and 64 deletions.
16 changes: 12 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"src/lib/ringbuffer",
"src/lib/coapcore",
"src/riot-rs",
"src/riot-rs-arch",
"src/riot-rs-bench",
"src/riot-rs-boards",
"src/riot-rs-boards/nrf52",
Expand Down Expand Up @@ -82,6 +83,7 @@ esp-wifi = { git = "https://github.com/kaspar030/esp-hal", branch = "for-riot-rs
linkme = { version = "0.3.21", features = ["used_linker"] }

riot-rs = { path = "src/riot-rs", default-features = false }
riot-rs-arch = { path = "src/riot-rs-arch", default-features = false }
riot-rs-bench = { path = "src/riot-rs-bench", default-features = false }
riot-rs-boards = { path = "src/riot-rs-boards", default-features = false }
riot-rs-debug = { path = "src/riot-rs-debug", default-features = false }
Expand Down
80 changes: 80 additions & 0 deletions src/riot-rs-arch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[package]
name = "riot-rs-arch"
version = "0.1.0"
license.workspace = true
edition = "2021"

[lints]
workspace = true

[dependencies]
cfg-if.workspace = true

[target.'cfg(context = "esp")'.dependencies]
riot-rs-esp = { path = "../riot-rs-esp" }

[target.'cfg(context = "nrf")'.dependencies]
riot-rs-nrf = { path = "../riot-rs-nrf" }

[target.'cfg(context = "rp")'.dependencies]
riot-rs-rp = { path = "../riot-rs-rp" }

[target.'cfg(context = "stm32")'.dependencies]
riot-rs-stm32 = { workspace = true }

[features]
external-interrupts = [
"riot-rs-esp/external-interrupts",
"riot-rs-nrf/external-interrupts",
"riot-rs-rp/external-interrupts",
"riot-rs-stm32/external-interrupts",
]

i2c = [
"riot-rs-esp/i2c",
"riot-rs-nrf/i2c",
"riot-rs-rp/i2c",
"riot-rs-stm32/i2c",
]

spi = [
"riot-rs-esp/spi",
"riot-rs-nrf/spi",
"riot-rs-rp/spi",
"riot-rs-stm32/spi",
]

usb = [
#"riot-rs-esp/usb",
"riot-rs-nrf/usb",
"riot-rs-rp/usb",
"riot-rs-stm32/usb",
]

hwrng = [
#"riot-rs-esp/hwrng",
"riot-rs-nrf/hwrng",
"riot-rs-rp/hwrng",
"riot-rs-stm32/hwrng",
]

wifi-cyw43 = ["riot-rs-rp/wifi-cyw43"]
wifi-esp = ["riot-rs-esp/wifi-esp"]

threading = ["riot-rs-esp/threading"]

executor-single-thread = ["riot-rs-esp/executor-single-thread"]

executor-interrupt = [
#"riot-rs-esp/executor-interrupt",
"riot-rs-nrf/executor-interrupt",
"riot-rs-rp/executor-interrupt",
"riot-rs-stm32/executor-interrupt",
]

defmt = [
"riot-rs-esp/defmt",
"riot-rs-nrf/defmt",
"riot-rs-rp/defmt",
"riot-rs-stm32/defmt",
]
32 changes: 32 additions & 0 deletions src/riot-rs-arch/src/dummy/executor.rs
Original file line number Diff line number Diff line change
@@ -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<S>(&self, _token: SpawnToken<S>) -> Result<(), ()> {
unimplemented!();
}
pub fn must_spawn<S>(&self, _token: SpawnToken<S>) {}
}
188 changes: 188 additions & 0 deletions src/riot-rs-arch/src/dummy/gpio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
macro_rules! define_input_like {
($type:ident) => {
pub struct $type<'d> {
_marker: core::marker::PhantomData<&'d ()>,
}

impl $type<'_> {
pub fn is_high(&self) -> bool {
unimplemented!();
}

pub fn is_low(&self) -> bool {
unimplemented!();
}

pub fn get_level(&self) -> crate::arch::gpio::input::Level {

Check failure on line 16 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: unresolved import

error[E0433]: failed to resolve: unresolved import --> src/riot-rs-arch/src/dummy/gpio.rs:16:47 | 16 | pub fn get_level(&self) -> crate::arch::gpio::input::Level { | ^^^^ | | | unresolved import | help: a similar path exists: `core::arch` ... 103 | define_input_like!(Input); | ------------------------- in this macro invocation | = note: this error originates in the macro `define_input_like` (in Nightly builds, run with -Z macro-backtrace for more info)
unimplemented!();
}

pub async fn wait_for_high(&mut self) {
unimplemented!();
}

pub async fn wait_for_low(&mut self) {
unimplemented!();
}

pub async fn wait_for_rising_edge(&mut self) {
unimplemented!();
}

pub async fn wait_for_falling_edge(&mut self) {
unimplemented!();
}

pub async fn wait_for_any_edge(&mut self) {
unimplemented!();
}
}

impl embedded_hal::digital::ErrorType for $type<'_> {

Check failure on line 41 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `embedded_hal`

error[E0433]: failed to resolve: use of undeclared crate or module `embedded_hal` --> src/riot-rs-arch/src/dummy/gpio.rs:41:14 | 41 | impl embedded_hal::digital::ErrorType for $type<'_> { | ^^^^^^^^^^^^ use of undeclared crate or module `embedded_hal` ... 103 | define_input_like!(Input); | ------------------------- in this macro invocation | = note: this error originates in the macro `define_input_like` (in Nightly builds, run with -Z macro-backtrace for more info)
type Error = core::convert::Infallible;
}

impl embedded_hal::digital::InputPin for $type<'_> {

Check failure on line 45 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `embedded_hal`

error[E0433]: failed to resolve: use of undeclared crate or module `embedded_hal` --> src/riot-rs-arch/src/dummy/gpio.rs:45:14 | 45 | impl embedded_hal::digital::InputPin for $type<'_> { | ^^^^^^^^^^^^ use of undeclared crate or module `embedded_hal` ... 103 | define_input_like!(Input); | ------------------------- in this macro invocation | = note: this error originates in the macro `define_input_like` (in Nightly builds, run with -Z macro-backtrace for more info)
fn is_low(&mut self) -> Result<bool, Self::Error> {
unimplemented!();
}

fn is_high(&mut self) -> Result<bool, Self::Error> {
unimplemented!();
}
}

impl embedded_hal_async::digital::Wait for $type<'_> {
async fn wait_for_high(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}

async fn wait_for_low(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}

async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}

async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}

async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}
}
};
}

pub mod input {
use crate::arch::peripheral::Peripheral;

Check failure on line 80 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: unresolved import

error[E0433]: failed to resolve: unresolved import --> src/riot-rs-arch/src/dummy/gpio.rs:80:16 | 80 | use crate::arch::peripheral::Peripheral; | ^^^^ | | | unresolved import | help: a similar path exists: `core::arch`

pub(crate) const SCHMITT_TRIGGER_CONFIGURABLE: bool = false;

pub trait InputPin {}

pub(crate) fn new(
_pin: impl Peripheral<P: InputPin> + 'static,
_pull: crate::gpio::Pull,
_schmitt_trigger: bool,
) -> Result<Input<'static>, riot_rs_embassy_common::gpio::input::Error> {

Check failure on line 90 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `riot_rs_embassy_common`

error[E0433]: failed to resolve: use of undeclared crate or module `riot_rs_embassy_common` --> src/riot-rs-arch/src/dummy/gpio.rs:90:33 | 90 | ) -> Result<Input<'static>, riot_rs_embassy_common::gpio::input::Error> { | ^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `riot_rs_embassy_common`
unimplemented!();
}

#[cfg(feature = "external-interrupts")]
pub(crate) fn new_int_enabled(
_pin: impl Peripheral<P: InputPin> + 'static,
_pull: crate::gpio::Pull,
_schmitt_trigger: bool,
) -> Result<IntEnabledInput<'static>, riot_rs_embassy_common::gpio::input::Error> {

Check failure on line 99 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `riot_rs_embassy_common`

error[E0433]: failed to resolve: use of undeclared crate or module `riot_rs_embassy_common` --> src/riot-rs-arch/src/dummy/gpio.rs:99:43 | 99 | ) -> Result<IntEnabledInput<'static>, riot_rs_embassy_common::gpio::input::Error> { | ^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `riot_rs_embassy_common`
unimplemented!();
}

define_input_like!(Input);
#[cfg(feature = "external-interrupts")]
define_input_like!(IntEnabledInput);

pub enum Level {
Low,
High,
}

riot_rs_embassy_common::define_into_level!();

Check failure on line 112 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `riot_rs_embassy_common`

error[E0433]: failed to resolve: use of undeclared crate or module `riot_rs_embassy_common` --> src/riot-rs-arch/src/dummy/gpio.rs:112:5 | 112 | riot_rs_embassy_common::define_into_level!(); | ^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `riot_rs_embassy_common`
}

pub mod output {
use embedded_hal::digital::StatefulOutputPin;

Check failure on line 116 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `embedded_hal`

error[E0433]: failed to resolve: use of undeclared crate or module `embedded_hal` --> src/riot-rs-arch/src/dummy/gpio.rs:116:9 | 116 | use embedded_hal::digital::StatefulOutputPin; | ^^^^^^^^^^^^ use of undeclared crate or module `embedded_hal`
use riot_rs_embassy_common::gpio::{FromDriveStrength, FromSpeed};

Check failure on line 117 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: use of undeclared crate or module `riot_rs_embassy_common`

error[E0433]: failed to resolve: use of undeclared crate or module `riot_rs_embassy_common` --> src/riot-rs-arch/src/dummy/gpio.rs:117:9 | 117 | use riot_rs_embassy_common::gpio::{FromDriveStrength, FromSpeed}; | ^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `riot_rs_embassy_common`

use crate::arch::peripheral::Peripheral;

Check failure on line 119 in src/riot-rs-arch/src/dummy/gpio.rs

View workflow job for this annotation

GitHub Actions / lint

failed to resolve: unresolved import

error[E0433]: failed to resolve: unresolved import --> src/riot-rs-arch/src/dummy/gpio.rs:119:16 | 119 | use crate::arch::peripheral::Peripheral; | ^^^^ | | | unresolved import | help: a similar path exists: `core::arch`

pub(crate) const DRIVE_STRENGTH_CONFIGURABLE: bool = false;
pub(crate) const SPEED_CONFIGURABLE: bool = false;

pub trait OutputPin {}

pub(crate) fn new(
_pin: impl Peripheral<P: OutputPin> + 'static,
_initial_level: crate::gpio::Level,
_drive_strength: DriveStrength,
_speed: Speed,
) -> Output<'static> {
unimplemented!();
}

/// Actual type is architecture-specific.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum DriveStrength {
#[doc(hidden)]
Hidden,
}

impl FromDriveStrength for DriveStrength {
fn from(_drive_strength: crate::gpio::DriveStrength<DriveStrength>) -> Self {
unimplemented!();
}
}

/// Actual type is architecture-specific.
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum Speed {
#[doc(hidden)]
Hidden,
}

impl FromSpeed for Speed {
fn from(_speed: crate::gpio::Speed<Speed>) -> Self {
unimplemented!();
}
}

pub struct Output<'d> {
_marker: core::marker::PhantomData<&'d ()>,
}

impl embedded_hal::digital::ErrorType for Output<'_> {
type Error = core::convert::Infallible;
}

impl embedded_hal::digital::OutputPin for Output<'_> {
fn set_low(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}

fn set_high(&mut self) -> Result<(), Self::Error> {
unimplemented!();
}
}

impl StatefulOutputPin for Output<'_> {
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
unimplemented!();
}

fn is_set_low(&mut self) -> Result<bool, Self::Error> {
unimplemented!();
}
}
}
5 changes: 5 additions & 0 deletions src/riot-rs-arch/src/dummy/hwrng.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::arch;

pub fn construct_rng(_peripherals: &mut arch::OptionalPeripherals) {
unimplemented!();
}
Loading

0 comments on commit 65dc3ed

Please sign in to comment.