ariel_os_stm32/i2c/
mod.rs

1//! Provides support for the I2C communication bus.
2
3#[doc(alias = "master")]
4pub mod controller;
5
6#[doc(hidden)]
7pub fn init(peripherals: &mut crate::OptionalPeripherals) {
8    // This macro has to be defined in this function so that the `peripherals` variables exists.
9    macro_rules! take_all_i2c_peripherals {
10        ($( $peripheral:ident ),*) => {
11            $(
12                let _ = peripherals.$peripheral.take().unwrap();
13            )*
14        }
15    }
16
17    // Take all I2c peripherals and do nothing with them.
18    cfg_if::cfg_if! {
19        if #[cfg(context = "stm32c031c6")] {
20            take_all_i2c_peripherals!(I2C1);
21        } else if #[cfg(context = "stm32f042k6")] {
22            take_all_i2c_peripherals!(I2C1);
23        } else if #[cfg(any(context = "stm32f401re", context = "stm32f411re"))] {
24            take_all_i2c_peripherals!(I2C1, I2C2, I2C3);
25        } else if #[cfg(any(context = "stm32h755zi", context = "stm32h753zi"))] {
26            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
27        } else if #[cfg(context = "stm32l475vg")]{
28            take_all_i2c_peripherals!(I2C1, I2C2, I2C3);
29        } else if #[cfg(any(context = "stm32u073kc", context = "stm32u083mc"))] {
30            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
31        } else if #[cfg(context = "stm32u585ai")] {
32            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
33        } else if #[cfg(context = "stm32wb55rg")] {
34            take_all_i2c_peripherals!(I2C1, I2C3);
35        } else {
36            compile_error!("this STM32 chip is not supported");
37        }
38    }
39}