Skip to main content

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_select! {
19        context = "stm32c031c6" => {
20            take_all_i2c_peripherals!(I2C1);
21        }
22        context = "stm32f042k6" => {
23            take_all_i2c_peripherals!(I2C1);
24        }
25        context = "stm32f303cb" => {
26            take_all_i2c_peripherals!(I2C1, I2C2);
27        }
28        context = "stm32f303re" => {
29            take_all_i2c_peripherals!(I2C1, I2C2, I2C3);
30        }
31        any(context = "stm32f401re", context = "stm32f411re") => {
32            take_all_i2c_peripherals!(I2C1, I2C2, I2C3);
33        }
34        any(context = "stm32h755zi", context = "stm32h753zi") => {
35            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
36        }
37        context = "stm32l475vg" => {
38            take_all_i2c_peripherals!(I2C1, I2C2, I2C3);
39        }
40        any(context = "stm32u073kc", context = "stm32u083mc") => {
41            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
42        }
43        context = "stm32u585ai" => {
44            take_all_i2c_peripherals!(I2C1, I2C2, I2C3, I2C4);
45        }
46        context = "stm32wb55rg" => {
47            take_all_i2c_peripherals!(I2C1, I2C3);
48        }
49        _ => {
50            compile_error!("this STM32 chip is not supported");
51        }
52    }
53}