ariel_os_stm32/spi/
mod.rs

1//! Provides support for the SPI communication bus.
2
3#[doc(alias = "master")]
4pub mod main;
5
6use ariel_os_embassy_common::spi::{BitOrder, Mode};
7
8fn from_mode(mode: Mode) -> embassy_stm32::spi::Mode {
9    match mode {
10        Mode::Mode0 => embassy_stm32::spi::MODE_0,
11        Mode::Mode1 => embassy_stm32::spi::MODE_1,
12        Mode::Mode2 => embassy_stm32::spi::MODE_2,
13        Mode::Mode3 => embassy_stm32::spi::MODE_3,
14    }
15}
16
17fn from_bit_order(bit_order: BitOrder) -> embassy_stm32::spi::BitOrder {
18    match bit_order {
19        BitOrder::MsbFirst => embassy_stm32::spi::BitOrder::MsbFirst,
20        BitOrder::LsbFirst => embassy_stm32::spi::BitOrder::LsbFirst,
21    }
22}
23
24#[doc(hidden)]
25pub fn init(peripherals: &mut crate::OptionalPeripherals) {
26    // This macro has to be defined in this function so that the `peripherals` variables exists.
27    macro_rules! take_all_spi_peripherals {
28        ($peripherals:ident, $( $peripheral:ident ),*) => {
29            $(
30                let _ = peripherals.$peripheral.take().unwrap();
31            )*
32        }
33    }
34
35    // Take all SPI peripherals and do nothing with them.
36    cfg_if::cfg_if! {
37        if #[cfg(context = "stm32c031c6")] {
38            take_all_spi_peripherals!(Peripherals, SPI1);
39        } else if #[cfg(context = "stm32f401re")] {
40            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
41        } else if #[cfg(context = "stm32f411re")] {
42            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3, SPI4, SPI5);
43        } else if #[cfg(any(context = "stm32h755zi", context = "stm32h753zi"))] {
44            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3, SPI4, SPI5, SPI6);
45        }else if #[cfg(context= "stm32l475vg")]{
46            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
47        } else if #[cfg(any(context = "stm32u073kc", context = "stm32u083mc"))] {
48            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
49        } else if #[cfg(context = "stm32u585ai")] {
50            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
51        } else if #[cfg(context = "stm32wb55rg")] {
52            take_all_spi_peripherals!(Peripherals, SPI1, SPI2);
53        } else {
54            compile_error!("this STM32 chip is not supported");
55        }
56    }
57}