Skip to content

Commit

Permalink
Merge pull request #718 from stm32-rs/build-rs-2
Browse files Browse the repository at this point in the history
device-selected to build.rs
  • Loading branch information
therealprof authored Jan 10, 2024
2 parents 1c41a58 + 2899cd6 commit c568bb9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 122 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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 @@ -47,6 +47,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 @@ -99,27 +100,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 @@ -255,16 +259,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 @@ -328,8 +345,6 @@ uart8 = []
uart9 = []
uart10 = []

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

[profile.dev]
debug = true
lto = true
Expand All @@ -355,11 +370,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 @@ -371,27 +386,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 @@ -415,15 +430,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 @@ -467,7 +482,7 @@ required-features = ["gpiod", "sdio", "sdio-host"] # stm32f405

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

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

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

[[example]]
name = "st7789-lcd"
Expand All @@ -499,11 +514,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 @@ -515,4 +530,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();
}
10 changes: 5 additions & 5 deletions src/i2s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::pac;
use crate::rcc::{self, Clocks, Reset};
use fugit::HertzU32 as Hertz;

#[cfg(feature = "stm32_i2s_v12x")]
#[cfg(feature = "i2s")]
pub extern crate stm32_i2s_v12x;

// I2S pins are mostly the same as the corresponding SPI pins:
Expand Down Expand Up @@ -202,7 +202,7 @@ macro_rules! i2s {
}
}

#[cfg(feature = "stm32_i2s_v12x")]
#[cfg(feature = "i2s")]
impl stm32_i2s_v12x::WsPin for gpio::alt::$i2s::Ws {
fn is_high(&self) -> bool {
use crate::gpio::ReadPin;
Expand All @@ -214,7 +214,7 @@ macro_rules! i2s {
}
}

#[cfg(feature = "stm32_i2s_v12x")]
#[cfg(feature = "i2s")]
unsafe impl stm32_i2s_v12x::I2sPeripheral for I2s<$SPI>
where
$SPI: rcc::Reset,
Expand Down Expand Up @@ -388,7 +388,7 @@ macro_rules! dual_i2s {
type I2sExtPeripheral = $I2SEXT;
}

#[cfg(feature = "stm32_i2s_v12x")]
#[cfg(feature = "i2s")]
unsafe impl stm32_i2s_v12x::DualI2sPeripheral for DualI2s<$SPI>
where
$SPI: rcc::Reset,
Expand Down Expand Up @@ -445,7 +445,7 @@ dual_i2s!(pac::SPI3, pac::I2S3EXT, DualI2s3, i2s3, i2s_clk);
dual_i2s!(pac::SPI3, pac::I2S3EXT, DualI2s3, i2s3, i2s_apb1_clk);

// DMA support: reuse existing mappings for SPI
#[cfg(feature = "stm32_i2s_v12x")]
#[cfg(feature = "i2s")]
mod dma {
use super::*;
use crate::dma::traits::{DMASet, PeriAddress};
Expand Down
Loading

0 comments on commit c568bb9

Please sign in to comment.