aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmaple/i2c.c15
-rw-r--r--libmaple/include/libmaple/i2c.h2
-rw-r--r--libmaple/stm32f1/include/series/i2c.h16
3 files changed, 26 insertions, 7 deletions
diff --git a/libmaple/i2c.c b/libmaple/i2c.c
index 291bf16..d2447a4 100644
--- a/libmaple/i2c.c
+++ b/libmaple/i2c.c
@@ -153,6 +153,11 @@ void i2c_init(i2c_dev *dev) {
rcc_clk_enable(dev->clk_id);
}
+/* Hack for deprecated bit of STM32F1 functionality */
+#ifndef _I2C_HAVE_DEPRECATED_I2C_REMAP
+#define _i2c_handle_remap(dev, flags) ((void)0)
+#endif
+
/**
* @brief Initialize an I2C device as bus master
* @param dev Device to enable
@@ -163,7 +168,8 @@ void i2c_init(i2c_dev *dev) {
* I2C_BUS_RESET: Reset the bus and clock out any hung slaves on
* initialization,
* I2C_10BIT_ADDRESSING: Enable 10-bit addressing,
- * I2C_REMAP: Remap I2C1 to SCL/PB8 SDA/PB9.
+ * I2C_REMAP: (deprecated, STM32F1 only) Remap I2C1 to SCL/PB8
+ * SDA/PB9.
*/
void i2c_master_enable(i2c_dev *dev, uint32 flags) {
#define I2C_CLK (STM32_PCLK1/1000000)
@@ -173,11 +179,8 @@ void i2c_master_enable(i2c_dev *dev, uint32 flags) {
/* PE must be disabled to configure the device */
ASSERT(!(dev->regs->CR1 & I2C_CR1_PE));
- if ((dev == I2C1) && (flags & I2C_REMAP)) {
- afio_remap(AFIO_REMAP_I2C1);
- I2C1->sda_pin = 9;
- I2C1->scl_pin = 8;
- }
+ /* Ugh */
+ _i2c_handle_remap(dev, flags);
/* Reset the bus. Clock out any hung slaves. */
if (flags & I2C_BUS_RESET) {
diff --git a/libmaple/include/libmaple/i2c.h b/libmaple/include/libmaple/i2c.h
index c66ebcb..f7821af 100644
--- a/libmaple/include/libmaple/i2c.h
+++ b/libmaple/include/libmaple/i2c.h
@@ -193,7 +193,7 @@ typedef struct i2c_msg {
/* I2C enable options */
#define I2C_FAST_MODE 0x1 // 400 khz
#define I2C_DUTY_16_9 0x2 // 16/9 duty ratio
-#define I2C_REMAP 0x4 // Use alternate pin mapping
+/* Flag 0x4 is reserved; DO NOT USE. */
#define I2C_BUS_RESET 0x8 // Perform a bus reset
void i2c_master_enable(i2c_dev *dev, uint32 flags);
diff --git a/libmaple/stm32f1/include/series/i2c.h b/libmaple/stm32f1/include/series/i2c.h
index 315a7e3..a0822e8 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 <libmaple/i2c_common.h>
+#include <libmaple/gpio.h>
#include <libmaple/stm32.h>
/*
@@ -66,4 +67,19 @@ static inline uint32 _i2c_bus_clk(i2c_dev *dev) {
#define _I2C_HAVE_IRQ_FIXUP 1
void _i2c_irq_priority_fixup(i2c_dev *dev);
+/*
+ * Deprecated functionality
+ */
+
+/* Flag to use alternate pin mapping in i2c_master_enable(). */
+#define _I2C_HAVE_DEPRECATED_I2C_REMAP 1
+#define I2C_REMAP 0x4
+static inline void _i2c_handle_remap(i2c_dev *dev, uint32 flags) {
+ if ((dev == I2C1) && (flags & I2C_REMAP)) {
+ afio_remap(AFIO_REMAP_I2C1);
+ I2C1->sda_pin = 9;
+ I2C1->scl_pin = 8;
+ }
+}
+
#endif /* _LIBMAPLE_STM32F1_I2C_H_ */