diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-21 17:04:32 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-22 14:06:10 -0400 |
commit | 001997b815e70f6a7707e765982b6f321afb961a (patch) | |
tree | 7a6fc846bbfaaf18350dffa334adf9e0ad6f91dd /libmaple/stm32f1 | |
parent | 9ba028ef647bc033e5ec078acd7de9d5c28432a9 (diff) | |
download | librambutan-001997b815e70f6a7707e765982b6f321afb961a.tar.gz librambutan-001997b815e70f6a7707e765982b6f321afb961a.zip |
i2c_dev: deprecate .gpio_port.
This won't work on F2, which at times has SDA and SCL on different
ports (e.g. I2C3 SDA on PC9, SCL on PA8). Add .sda_port and .scl_port
replacements, which are used when the now-deprecated .gpio_port is
null. Use them correctly everywhere, with some new i2c_private.h
helper functionality.
Sigh. The F1 I2C code tries too hard to guess what you wanted; it's
not porting well at all.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'libmaple/stm32f1')
-rw-r--r-- | libmaple/stm32f1/i2c.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/libmaple/stm32f1/i2c.c b/libmaple/stm32f1/i2c.c index 5797940..d864464 100644 --- a/libmaple/stm32f1/i2c.c +++ b/libmaple/stm32f1/i2c.c @@ -31,8 +31,8 @@ * Devices */ -static i2c_dev i2c1 = I2C_DEV(1, &gpiob, 7, 6); -static i2c_dev i2c2 = I2C_DEV(2, &gpiob, 11, 10); +static i2c_dev i2c1 = I2C_DEV_OLD(1, &gpiob, 7, 6); +static i2c_dev i2c2 = I2C_DEV_OLD(2, &gpiob, 11, 10); /** STM32F1 I2C device 1 */ i2c_dev* const I2C1 = &i2c1; @@ -43,20 +43,28 @@ i2c_dev* const I2C2 = &i2c2; * Routines */ +static int i2c1_wants_remap(const i2c_dev *dev) { + /* Check if we've got I2C1 configured for SDA/SCL remap on PB9/PB8 */ + return (dev->clk_id == RCC_I2C1) && + (scl_port(dev)->clk_id == RCC_GPIOB) && + (sda_port(dev)->clk_id == RCC_GPIOB) && + (dev->sda_pin == 9) && + (dev->scl_pin == 8); +} + void i2c_config_gpios(const i2c_dev *dev) { - if ((dev->clk_id == RCC_I2C1) && - (dev->sda_pin == 9) && (dev->scl_pin == 8)) { + if (i2c1_wants_remap(dev)) { afio_remap(AFIO_REMAP_I2C1); } - gpio_set_mode(dev->gpio_port, dev->sda_pin, GPIO_AF_OUTPUT_OD); - gpio_set_mode(dev->gpio_port, dev->scl_pin, GPIO_AF_OUTPUT_OD); + gpio_set_mode(sda_port(dev), dev->sda_pin, GPIO_AF_OUTPUT_OD); + gpio_set_mode(scl_port(dev), dev->scl_pin, GPIO_AF_OUTPUT_OD); } void i2c_master_release_bus(const i2c_dev *dev) { - gpio_write_bit(dev->gpio_port, dev->scl_pin, 1); - gpio_write_bit(dev->gpio_port, dev->sda_pin, 1); - gpio_set_mode(dev->gpio_port, dev->scl_pin, GPIO_OUTPUT_OD); - gpio_set_mode(dev->gpio_port, dev->sda_pin, GPIO_OUTPUT_OD); + gpio_write_bit(scl_port(dev), dev->scl_pin, 1); + gpio_write_bit(sda_port(dev), dev->sda_pin, 1); + gpio_set_mode(scl_port(dev), dev->scl_pin, GPIO_OUTPUT_OD); + gpio_set_mode(sda_port(dev), dev->sda_pin, GPIO_OUTPUT_OD); } /* |