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 2264bff
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 65 deletions.
19 changes: 12 additions & 7 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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-bench", 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/spi",
"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-nrf/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 {
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<'_> {
type Error = core::convert::Infallible;
}

impl embedded_hal::digital::InputPin for $type<'_> {
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;

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> {
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> {
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!();
}

pub mod output {
use embedded_hal::digital::StatefulOutputPin;
use riot_rs_embassy_common::gpio::{FromDriveStrength, FromSpeed};

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

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 2264bff

Please sign in to comment.