summaryrefslogtreecommitdiff
path: root/drivers/arm/i2c_master.c
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2019-06-05 18:16:02 -0700
committerFlorian Didron <fdidron@users.noreply.github.com>2019-06-06 10:16:02 +0900
commit61d1932f7cb164ef46d1004ee50718e43007d90a (patch)
tree87f8ecf9cdc5c59d0f4fddf44c5af43fea6df272 /drivers/arm/i2c_master.c
parent1ba27782efb76081013fadbf6a7c1cee27ab3d4c (diff)
Parameterise STM32 I2C pin modes and timing parameters. (#5671) (#71)
I2C timing parameters were seemingly set up for an STM32F303 target MCU, at a specific clock speed. This commit allows specifying the timing parameters via config.h, allowing other STM32 MCUs to be targeted, potentially at different clock frequencies. Alternate function modes for the I2C pins are now also configurable, allowing for remapping to other pins.
Diffstat (limited to 'drivers/arm/i2c_master.c')
-rw-r--r--drivers/arm/i2c_master.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/drivers/arm/i2c_master.c b/drivers/arm/i2c_master.c
index 7369398cc4..5814375f37 100644
--- a/drivers/arm/i2c_master.c
+++ b/drivers/arm/i2c_master.c
@@ -32,12 +32,10 @@
static uint8_t i2c_address;
-// This configures the I2C clock to 400khz assuming a 72Mhz clock
-// For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html
static const I2CConfig i2cconfig = {
- STM32_TIMINGR_PRESC(15U) |
- STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) |
- STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U),
+ STM32_TIMINGR_PRESC(I2C1_TIMINGR_PRESC) |
+ STM32_TIMINGR_SCLDEL(I2C1_TIMINGR_SCLDEL) | STM32_TIMINGR_SDADEL(I2C1_TIMINGR_SDADEL) |
+ STM32_TIMINGR_SCLH(I2C1_TIMINGR_SCLH) | STM32_TIMINGR_SCLL(I2C1_TIMINGR_SCLL),
0,
0
};
@@ -58,13 +56,13 @@ __attribute__ ((weak))
void i2c_init(void)
{
// Try releasing special pins for a short time
- palSetPadMode(I2C1_BANK, I2C1_SCL, PAL_MODE_INPUT);
- palSetPadMode(I2C1_BANK, I2C1_SDA, PAL_MODE_INPUT);
+ palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_INPUT);
+ palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_INPUT);
chThdSleepMilliseconds(10);
- palSetPadMode(I2C1_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
- palSetPadMode(I2C1_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
+ palSetPadMode(I2C1_SCL_BANK, I2C1_SCL, PAL_MODE_ALTERNATE(I2C1_SCL_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
+ palSetPadMode(I2C1_SDA_BANK, I2C1_SDA, PAL_MODE_ALTERNATE(I2C1_SDA_PAL_MODE) | PAL_STM32_OTYPE_OPENDRAIN);
//i2cInit(); //This is invoked by halInit() so no need to redo it.
}