From 10641ae450e04a19ba9525243339ce422316aaf3 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 10 Dec 2023 16:41:18 +0100 Subject: [PATCH] cpu/stm32: allow arbitrary I2C clocks --- cpu/stm32/periph/i2c_2.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/cpu/stm32/periph/i2c_2.c b/cpu/stm32/periph/i2c_2.c index f2814961b4dd..0c29a0a69602 100644 --- a/cpu/stm32/periph/i2c_2.c +++ b/cpu/stm32/periph/i2c_2.c @@ -205,22 +205,8 @@ static void _init(i2c_t dev) I2C_TypeDef *i2c = i2c_config[dev].dev; uint32_t ccr = 0; - /* read speed configuration */ - switch (i2c_config[dev].speed) { - case I2C_SPEED_LOW: - /* 10Kbit/s */ - ccr = i2c_config[dev].clk / 20000; - break; - - case I2C_SPEED_NORMAL: - /* 100Kbit/s */ - ccr = i2c_config[dev].clk / 200000; - break; - - case I2C_SPEED_FAST: - ccr = i2c_config[dev].clk / 800000; - break; - } + /* apply speed configuration */ + ccr = i2c_config[dev].clk / (i2c_config[dev].speed << 1); /* make peripheral soft reset */ i2c->CR1 |= I2C_CR1_SWRST;