Skip to main content

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_select! {
37        context = "stm32c031c6" => {
38            take_all_spi_peripherals!(Peripherals, SPI1);
39        }
40        context = "stm32f303cb" => {
41            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
42        }
43        context = "stm32f303re" => {
44            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
45        }
46        context = "stm32f401re" => {
47            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
48        }
49        context = "stm32f411re" => {
50            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3, SPI4, SPI5);
51        }
52        any(context = "stm32h755zi", context = "stm32h753zi") => {
53            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3, SPI4, SPI5, SPI6);
54        }
55        context = "stm32l475vg" =>{
56            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
57        }
58        any(context = "stm32u073kc", context = "stm32u083mc") => {
59            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
60        }
61        context = "stm32u585ai" => {
62            take_all_spi_peripherals!(Peripherals, SPI1, SPI2, SPI3);
63        }
64        context = "stm32wb55rg" => {
65            take_all_spi_peripherals!(Peripherals, SPI1, SPI2);
66        }
67        _ => {
68            compile_error!("this STM32 chip is not supported");
69        }
70    }
71}