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 9d2e378
Show file tree
Hide file tree
Showing 15 changed files with 127 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",
]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/riot-rs-arch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! This module dispatches between the riot-rs architecture support crates.

#![no_std]

cfg_if::cfg_if! {
if #[cfg(context = "nrf")] {
pub use riot_rs_nrf::*;
} else if #[cfg(context = "rp")] {
pub use riot_rs_rp::*;
} else if #[cfg(context = "esp")] {
pub use riot_rs_esp::*;
} else if #[cfg(context = "stm32")] {
pub use riot_rs_stm32::*;
} else if #[cfg(context = "riot-rs")] {
compile_error!("this architecture is not supported");
} else {
mod dummy;
pub use dummy::*;
}
}
57 changes: 12 additions & 45 deletions src/riot-rs-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ embassy-usb = { workspace = true, optional = true }
embedded-hal = { workspace = true }
embedded-hal-async = { workspace = true }

riot-rs-arch = { path = "../riot-rs-arch" }
riot-rs-embassy-common = { workspace = true }
riot-rs-threads = { path = "../riot-rs-threads", optional = true }
riot-rs-debug = { workspace = true }
Expand All @@ -45,87 +46,53 @@ embassy-executor = { workspace = true, default-features = false, features = [
"arch-cortex-m",
] }

# Manufacturer-specific
[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]
## Enables GPIO interrupt support.
external-interrupts = [
"riot-rs-embassy-common/external-interrupts",
"riot-rs-esp/external-interrupts",
"riot-rs-nrf/external-interrupts",
"riot-rs-rp/external-interrupts",
"riot-rs-stm32/external-interrupts",
"riot-rs-arch/external-interrupts",
]
time = ["dep:embassy-time", "embassy-executor/integrated-timers"]

## Enables I2C support.
i2c = [
"dep:embassy-embedded-hal",
"riot-rs-embassy-common/i2c",
"riot-rs-esp/i2c",
"riot-rs-nrf/i2c",
"riot-rs-rp/i2c",
"riot-rs-stm32/i2c",
"riot-rs-arch/i2c",
]
## Enables SPI support.
spi = [
"dep:embassy-embedded-hal",
"riot-rs-embassy-common/spi",
"riot-rs-esp/spi",
"riot-rs-nrf/spi",
"riot-rs-rp/spi",
"riot-rs-stm32/spi",
]
usb = [
"dep:embassy-usb",
"riot-rs-nrf/usb",
"riot-rs-rp/usb",
"riot-rs-stm32/usb",
"riot-rs-arch/spi",
]
usb = ["dep:embassy-usb", "riot-rs-arch/usb"]
# embassy-net requires embassy-time and support for timeouts in the executor
net = ["dep:embassy-net", "time"]
usb-ethernet = ["usb", "net"]
## Use a hardware RNG to seed into the riot-rs-random system-wide RNG
hwrng = ["riot-rs-nrf/hwrng", "riot-rs-rp/hwrng", "riot-rs-stm32/hwrng"]
hwrng = ["riot-rs-arch/hwrng"]

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

threading = ["dep:riot-rs-threads", "riot-rs-esp/threading"]
threading = ["dep:riot-rs-threads", "riot-rs-arch/threading"]
override-network-config = []
override-usb-config = []

executor-single-thread = [
"riot-rs-rt/executor-single-thread",
"riot-rs-esp/executor-single-thread",
]
executor-interrupt = [
"riot-rs-nrf/executor-interrupt",
"riot-rs-rp/executor-interrupt",
"riot-rs-stm32/executor-interrupt",
"riot-rs-arch/executor-single-thread",
]
executor-interrupt = ["riot-rs-arch/executor-interrupt"]
executor-thread = ["threading"]
executor-none = []

defmt = [
"embassy-net?/defmt",
"embassy-time?/defmt",
"embassy-usb?/defmt",
"riot-rs-arch/defmt",
"riot-rs-embassy-common/defmt",
"riot-rs-esp/defmt",
"riot-rs-nrf/defmt",
"riot-rs-rp/defmt",
"riot-rs-stm32/defmt",
]
16 changes: 1 addition & 15 deletions src/riot-rs-embassy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,7 @@
pub mod define_peripherals;
pub mod gpio;

cfg_if::cfg_if! {
if #[cfg(context = "nrf")] {
pub use riot_rs_nrf as arch;
} else if #[cfg(context = "rp")] {
pub use riot_rs_rp as arch;
} else if #[cfg(context = "esp")] {
pub use riot_rs_esp as arch;
} else if #[cfg(context = "stm32")] {
pub use riot_rs_stm32 as arch;
} else if #[cfg(context = "riot-rs")] {
compile_error!("this architecture is not supported");
} else {
pub mod arch;
}
}
pub use riot_rs_arch as arch;

#[cfg(feature = "i2c")]
pub mod i2c;
Expand Down

0 comments on commit 9d2e378

Please sign in to comment.