Skip to content

Commit

Permalink
device-selected to build-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Dec 23, 2023
1 parent fd2855a commit 3faa011
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 115 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Check features enabled in `build-rs`
- bump embedded-hal to `1.0-rc2`
- Use `as_ptr` for register address casting
- Updated `synopsys-usb-otg` to `0.4.0`
Expand Down
95 changes: 55 additions & 40 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ systick-monotonic = { version = "1.0", optional = true }
enumflags2 = "0.7.8"
embedded-storage = "0.3"
vcell = "0.1.3"
document-features = "0.2"

[dependencies.time]
version = "0.3.14"
Expand Down Expand Up @@ -94,27 +95,30 @@ default-features = false
features = ["macros"]

[features]
device-selected = []
rt = [] # deprecated
#! Use one of the supported STM32-serie related features:
#! `stm32f401`, `stm32f405`, `stm32f407`, `stm32f415`, `stm32f417`, `stm32f410`,
#! `stm32f411`, `stm32f412`, `stm32f413`, `stm32f423`, `stm32f427`, `stm32f429`,
#! `stm32f437`, `stm32f439`, `stm32f446`, `stm32f469`, `stm32f479`.

# Note: stm32f4 has only one feature for some very similar device families,
# so it's intended for e.g. stm32f405/415 to both enable stm32f4/stm32f405.
stm32f401 = ["stm32f4/stm32f401", "device-selected", "gpio-f401",]
stm32f405 = ["stm32f4/stm32f405", "device-selected", "gpio-f417"]
stm32f407 = ["stm32f4/stm32f407", "device-selected", "gpio-f417"]
stm32f415 = ["stm32f4/stm32f405", "device-selected", "gpio-f417", "cryp"]
stm32f417 = ["stm32f4/stm32f407", "device-selected", "gpio-f417", "cryp"]
stm32f410 = ["stm32f4/stm32f410", "device-selected", "gpio-f410"]
stm32f411 = ["stm32f4/stm32f411", "device-selected", "gpio-f411"]
stm32f412 = ["stm32f4/stm32f412", "device-selected", "gpio-f412"]
stm32f413 = ["stm32f4/stm32f413", "device-selected", "gpio-f413"]
stm32f423 = ["stm32f4/stm32f413", "device-selected", "gpio-f413", "aes"]
stm32f427 = ["stm32f4/stm32f427", "device-selected", "gpio-f427", "fsmc"]
stm32f429 = ["stm32f4/stm32f429", "device-selected", "gpio-f427", "fmc"]
stm32f437 = ["stm32f4/stm32f427", "device-selected", "gpio-f427", "fsmc", "cryp"]
stm32f439 = ["stm32f4/stm32f429", "device-selected", "gpio-f427", "fmc", "cryp"]
stm32f446 = ["stm32f4/stm32f446", "device-selected", "gpio-f446"]
stm32f469 = ["stm32f4/stm32f469", "device-selected", "gpio-f469"]
stm32f479 = ["stm32f4/stm32f469", "device-selected", "gpio-f469", "cryp"]
stm32f401 = ["stm32f4/stm32f401", "gpio-f401",]
stm32f405 = ["stm32f4/stm32f405", "gpio-f417"]
stm32f407 = ["stm32f4/stm32f407", "gpio-f417"]
stm32f415 = ["stm32f4/stm32f405", "gpio-f417", "cryp"]
stm32f417 = ["stm32f4/stm32f407", "gpio-f417", "cryp"]
stm32f410 = ["stm32f4/stm32f410", "gpio-f410"]
stm32f411 = ["stm32f4/stm32f411", "gpio-f411"]
stm32f412 = ["stm32f4/stm32f412", "gpio-f412"]
stm32f413 = ["stm32f4/stm32f413", "gpio-f413"]
stm32f423 = ["stm32f4/stm32f413", "gpio-f413", "aes"]
stm32f427 = ["stm32f4/stm32f427", "gpio-f427", "fsmc"]
stm32f429 = ["stm32f4/stm32f429", "gpio-f427", "fmc"]
stm32f437 = ["stm32f4/stm32f427", "gpio-f427", "fsmc", "cryp"]
stm32f439 = ["stm32f4/stm32f429", "gpio-f427", "fmc", "cryp"]
stm32f446 = ["stm32f4/stm32f446", "gpio-f446"]
stm32f469 = ["stm32f4/stm32f469", "gpio-f469"]
stm32f479 = ["stm32f4/stm32f469", "gpio-f469", "cryp"]

gpio-f401 = [
"gpiod", "gpioe",
Expand Down Expand Up @@ -250,16 +254,29 @@ gpio-f469 = [
"usart3", "uart4", "uart5", "uart7", "uart8",
]

usb_fs = ["synopsys-usb-otg", "synopsys-usb-otg/fs"]
usb_hs = ["synopsys-usb-otg", "synopsys-usb-otg/hs"]
## Support monotonic timers that can be used by [RTIC framework](https://crates.io/crates/cortex-m-rtic)
rtic = ["dep:rtic-monotonic", "dep:systick-monotonic"]

## Implementation of `defmt::Format` for public enums and structures. See [defmt](https://crates.io/crates/defmt)
defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3"]

can = ["bxcan"]
## bxCAN peripheral support. See [bxcan](https://crates.io/crates/bxcan)
can = ["dep:bxcan"]

i2s = ["stm32_i2s_v12x"]
## I2S peripheral support. See [stm32_i2s_v12x](https://crates.io/crates/stm32_i2s_v12x)
i2s = ["dep:stm32_i2s_v12x"]

fsmc_lcd = ["display-interface"]
## USB OTG-FS peripheral support. See [synopsys-usb-otg](https://crates.io/crates/synopsys-usb-otg)
usb_fs = ["dep:synopsys-usb-otg", "synopsys-usb-otg/fs"]
## USB OTG-HS peripheral support. See [synopsys-usb-otg](https://crates.io/crates/synopsys-usb-otg)
usb_hs = ["dep:synopsys-usb-otg", "synopsys-usb-otg/hs"]

## LCD support via FMC/FSMC peripheral. See [display-interface](https://crates.io/crates/display-interface)
fsmc_lcd = ["dep:display-interface"]

## SDIO peripheral support. See [sdio-host](https://crates.io/crates/sdio-host)
sdio-host = ["dep:sdio-host"]

defmt = ["dep:defmt", "fugit/defmt", "nb/defmt-0-3"]
dfsdm = []
sai = []

Expand Down Expand Up @@ -323,8 +340,6 @@ uart8 = []
uart9 = []
uart10 = []

rtic = ["rtic-monotonic", "systick-monotonic"]

[profile.dev]
debug = true
lto = true
Expand All @@ -350,11 +365,11 @@ required-features = ["can", "stm32f405"]

[[example]]
name = "delay-syst-blinky"
required-features = ["device-selected"] # stm32f411
required-features = [] # stm32f411

[[example]]
name = "delay-timer-blinky"
required-features = ["device-selected"] # stm32f411
required-features = [] # stm32f411

[[example]]
name = "display-touch"
Expand All @@ -366,27 +381,27 @@ required-features = ["gpiog"] # "stm32f429"

[[example]]
name = "dynamic-gpio"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "f413disco-lcd-ferris"
required-features = ["gpiod", "gpioe", "gpiof", "gpiog", "fsmc", "fsmc_lcd"] # stm32f413

[[example]]
name = "hd44780"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "i2s-audio-out"
required-features = ["stm32f411", "i2s"]

[[example]]
name = "ist7920-bidi-normal-spi"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "pwm"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "pwm-input"
Expand All @@ -410,15 +425,15 @@ required-features = ["rng"] # stm32f407

[[example]]
name = "rtc"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "rtc_alarm"
required-features = ["stm32f411"]

[[example]]
name = "rtic-adc-dma"
required-features = ["device-selected", "rtic"] # stm32f401
required-features = ["rtic"] # stm32f401

[[example]]
name = "rtic-button"
Expand Down Expand Up @@ -462,7 +477,7 @@ required-features = ["gpiod", "sdio", "sdio-host"] # stm32f405

[[example]]
name = "serial"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "serial-9bit"
Expand All @@ -478,7 +493,7 @@ required-features = ["stm32f405"]

[[example]]
name = "ssd1306-image"
required-features = ["device-selected"] # stm32f411
required-features = [] # stm32f411

[[example]]
name = "st7789-lcd"
Expand All @@ -494,11 +509,11 @@ required-features = ["tim2", "stm32f411"] # stm32f411

[[example]]
name = "timer-periph"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "timer-syst"
required-features = ["device-selected"]
required-features = []

[[example]]
name = "usb-serial-irq"
Expand All @@ -510,4 +525,4 @@ required-features = ["otg-fs", "usb_fs"] # stm32f401

[[example]]
name = "ws2812-spi"
required-features = ["device-selected"]
required-features = []
36 changes: 36 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use std::env;

#[derive(Clone, Copy, Debug)]
enum GetOneError {
None,
Multiple,
}

trait IteratorExt: Iterator {
fn get_one(self) -> Result<Self::Item, GetOneError>;
}

impl<T: Iterator> IteratorExt for T {
fn get_one(mut self) -> Result<Self::Item, GetOneError> {
match (self.next(), self.next()) {
(Some(res), None) => Ok(res),
(None, _) => Err(GetOneError::None),
_ => Err(GetOneError::Multiple),
}
}
}

fn main() {
let _chip_name = match env::vars()
.map(|(a, _)| a)
.filter(|x| x.starts_with("CARGO_FEATURE_STM32F4"))
.get_one()
{
Ok(x) => x,
Err(GetOneError::None) => panic!("No stm32xx Cargo feature enabled"),
Err(GetOneError::Multiple) => panic!("Multiple stm32xx Cargo features enabled"),
}
.strip_prefix("CARGO_FEATURE_")
.unwrap()
.to_ascii_lowercase();
}
79 changes: 11 additions & 68 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,15 @@
//! Multi device hardware abstraction on top of the peripheral access API for the STMicro STM32F4 series microcontrollers.
//!
//! ## Feature flags
#![doc = document_features::document_features!()]
#![no_std]
#![allow(non_camel_case_types)]

use enumflags2::{BitFlag, BitFlags};

#[cfg(not(feature = "device-selected"))]
compile_error!(
"This crate requires one of the following device features enabled:
stm32f401
stm32f405
stm32f407
stm32f410
stm32f411
stm32f412
stm32f413
stm32f415
stm32f417
stm32f423
stm32f427
stm32f429
stm32f437
stm32f439
stm32f446
stm32f469
stm32f479"
);

#[cfg(feature = "device-selected")]
pub use embedded_hal as hal;

#[cfg(feature = "device-selected")]
pub use nb;
#[cfg(feature = "device-selected")]
pub use nb::block;

#[cfg(feature = "stm32f401")]
Expand Down Expand Up @@ -104,88 +83,52 @@ pub use stm32f4::stm32f469 as pac;
// Enable use of interrupt macro
pub use crate::pac::interrupt;

#[cfg(feature = "device-selected")]
pub mod adc;
#[cfg(feature = "device-selected")]
pub mod bb;
#[cfg(all(
feature = "device-selected",
feature = "can",
any(feature = "can1", feature = "can2",)
))]
#[cfg(all(feature = "can", any(feature = "can1", feature = "can2",)))]
pub mod can;
#[cfg(feature = "device-selected")]
pub mod crc32;
#[cfg(all(feature = "device-selected", feature = "dac"))]
#[cfg(feature = "dac")]
pub mod dac;
#[cfg(feature = "device-selected")]
#[cfg(feature = "fmpi2c1")]
pub mod fmpi2c;
#[cfg(feature = "device-selected")]
pub mod gpio;
#[cfg(feature = "device-selected")]
pub mod i2c;
#[cfg(feature = "device-selected")]
pub mod i2s;
#[cfg(all(feature = "device-selected", feature = "usb_fs", feature = "otg-fs"))]
#[cfg(all(feature = "usb_fs", feature = "otg-fs"))]
pub mod otg_fs;
#[cfg(all(
feature = "device-selected",
any(feature = "usb_hs", docsrs),
feature = "otg-hs",
))]
#[cfg(all(any(feature = "usb_hs", docsrs), feature = "otg-hs",))]
pub mod otg_hs;

#[cfg(all(feature = "device-selected", feature = "rng"))]
#[cfg(feature = "rng")]
pub mod rng;

#[cfg(feature = "device-selected")]
pub mod dma;
#[cfg(feature = "device-selected")]
pub mod dwt;
#[cfg(feature = "device-selected")]
pub mod flash;
#[cfg(all(
feature = "device-selected",
feature = "fsmc_lcd",
any(feature = "fmc", feature = "fsmc")
))]
#[cfg(all(feature = "fsmc_lcd", any(feature = "fmc", feature = "fsmc")))]
pub mod fsmc_lcd;
#[cfg(feature = "device-selected")]
pub mod prelude;
#[cfg(feature = "device-selected")]
pub mod qei;
#[cfg(feature = "quadspi")]
pub mod qspi;
#[cfg(feature = "device-selected")]
pub mod rcc;
#[cfg(feature = "device-selected")]
pub mod rtc;
#[cfg(all(feature = "device-selected", feature = "sdio-host", feature = "sdio"))]
#[cfg(all(feature = "sdio-host", feature = "sdio"))]
pub mod sdio;
#[cfg(feature = "device-selected")]
pub mod serial;
#[cfg(feature = "device-selected")]
pub mod signature;
#[cfg(feature = "device-selected")]
pub mod spi;
#[cfg(feature = "device-selected")]
pub mod syscfg;
#[cfg(feature = "device-selected")]
pub mod time;
#[cfg(feature = "device-selected")]
pub mod timer;
#[cfg(feature = "device-selected")]
#[cfg(feature = "uart4")]
pub mod uart;
#[cfg(feature = "device-selected")]
pub mod watchdog;

#[cfg(feature = "device-selected")]
mod sealed {
pub trait Sealed {}
}
#[cfg(feature = "device-selected")]
pub(crate) use sealed::Sealed;

fn stripped_type_name<T>() -> &'static str {
Expand Down
Loading

0 comments on commit 3faa011

Please sign in to comment.