aboutsummaryrefslogtreecommitdiff
path: root/platforms/chibios/drivers/i2c_master.c
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/chibios/drivers/i2c_master.c')
-rw-r--r--platforms/chibios/drivers/i2c_master.c45
1 files changed, 22 insertions, 23 deletions
diff --git a/platforms/chibios/drivers/i2c_master.c b/platforms/chibios/drivers/i2c_master.c
index 0d5fb1e985..20850859b5 100644
--- a/platforms/chibios/drivers/i2c_master.c
+++ b/platforms/chibios/drivers/i2c_master.c
@@ -29,17 +29,37 @@
#include "i2c_master.h"
#include "gpio.h"
#include "chibios_config.h"
-#include <string.h>
#include <ch.h>
#include <hal.h>
+#ifndef I2C_DRIVER
+# define I2C_DRIVER I2CD1
+#endif
+
#ifndef I2C1_SCL_PIN
# define I2C1_SCL_PIN B6
#endif
+
+#ifndef I2C1_SCL_PAL_MODE
+# ifdef USE_GPIOV1
+# define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
+# else
+# define I2C1_SCL_PAL_MODE 4
+# endif
+#endif
+
#ifndef I2C1_SDA_PIN
# define I2C1_SDA_PIN B7
#endif
+#ifndef I2C1_SDA_PAL_MODE
+# ifdef USE_GPIOV1
+# define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
+# else
+# define I2C1_SDA_PAL_MODE 4
+# endif
+#endif
+
#ifdef USE_I2CV1
# ifndef I2C1_OPMODE
# define I2C1_OPMODE OPMODE_I2C
@@ -70,27 +90,6 @@
# endif
#endif
-#ifndef I2C_DRIVER
-# define I2C_DRIVER I2CD1
-#endif
-
-#ifdef USE_GPIOV1
-# ifndef I2C1_SCL_PAL_MODE
-# define I2C1_SCL_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
-# endif
-# ifndef I2C1_SDA_PAL_MODE
-# define I2C1_SDA_PAL_MODE PAL_MODE_ALTERNATE_OPENDRAIN
-# endif
-#else
-// The default PAL alternate modes are used to signal that the pins are used for I2C
-# ifndef I2C1_SCL_PAL_MODE
-# define I2C1_SCL_PAL_MODE 4
-# endif
-# ifndef I2C1_SDA_PAL_MODE
-# define I2C1_SDA_PAL_MODE 4
-# endif
-#endif
-
static const I2CConfig i2cconfig = {
#if defined(USE_I2CV1_CONTRIB)
I2C1_CLOCK_SPEED,
@@ -207,4 +206,4 @@ __attribute__((weak)) i2c_status_t i2c_ping_address(uint8_t address, uint16_t ti
// This approach may produce false negative results for I2C devices that do not respond to a register 0 read request.
uint8_t data = 0;
return i2c_read_register(address, 0, &data, sizeof(data), timeout);
-} \ No newline at end of file
+}