From c61a99d053d5ea230e41efe11772bac12ca2d51a Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 20 Jun 2012 14:28:32 -0400 Subject: i2c_set_input_clk(): fix an F1-ism. i2c_set_input_clk()'s documentation says that the maximum peripheral clock frequency is 36 MHz, but that's a hard-coded magic number. The actual limit is the device's APB frequency or 46 MHz, whichever is lower (F2 and F4 share the 46 MHz limit). Fix the documentation to reflect that fact, and add an internal series-provided function to get the maximum clock frequency for a device. To help users porting to F2, have i2c_set_input_clk() assert-check that the provided frequency is less than that maximum value and the hard 46 MHz limit. Signed-off-by: Marti Bolivar --- libmaple/stm32f1/include/series/i2c.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libmaple/stm32f1') diff --git a/libmaple/stm32f1/include/series/i2c.h b/libmaple/stm32f1/include/series/i2c.h index f9f1e43..0c89df4 100644 --- a/libmaple/stm32f1/include/series/i2c.h +++ b/libmaple/stm32f1/include/series/i2c.h @@ -34,6 +34,7 @@ #define _LIBMAPLE_STM32F1_I2C_H_ #include +#include /* * Register maps @@ -53,4 +54,13 @@ struct i2c_reg_map; extern i2c_dev* const I2C1; extern i2c_dev* const I2C2; +/* + * For internal use + */ + +static inline uint32 _i2c_bus_clk(i2c_dev *dev) { + /* Both I2C peripherals are on APB1 */ + return STM32_PCLK1 / (1000 * 1000); +} + #endif /* _LIBMAPLE_STM32F1_I2C_H_ */ -- cgit v1.2.3