mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Refactor I2C to use I2Cx_SCL_PIN and I2Cx_SDA_PIN (#12357)
* Refactor I2C to use I2Cx_SCL_PIN and I2Cx_SDA_PIN * Keeping the default pins for F4 and F7
This commit is contained in:
parent
615adaf463
commit
4fe980384c
5 changed files with 82 additions and 85 deletions
|
@ -86,8 +86,8 @@
|
|||
#define USE_USB_ID
|
||||
#define USE_I2C
|
||||
#define USE_I2C_DEVICE_1
|
||||
#define I2C1_SCL PB8
|
||||
#define I2C1_SDA PB9
|
||||
#define I2C1_SCL_PIN PB8
|
||||
#define I2C1_SDA_PIN PB9
|
||||
#define I2C_DEVICE (I2CDEV_1)
|
||||
#define ENSURE_MPU_DATA_READY_IS_LOW
|
||||
#define USE_PID_AUDIO
|
||||
|
|
|
@ -80,8 +80,8 @@
|
|||
#define TARGET_IO_PORTH 0xffff
|
||||
#define USE_I2C
|
||||
#define USE_I2C_DEVICE_1
|
||||
#define I2C1_SCL PB8
|
||||
#define I2C1_SDA PB9
|
||||
#define I2C1_SCL_PIN PB8
|
||||
#define I2C1_SDA_PIN PB9
|
||||
#define USE_I2C_DEVICE_2
|
||||
#define I2C2_SCL PB10
|
||||
#define I2C2_SDA PB11
|
||||
|
|
|
@ -254,3 +254,52 @@ extern uint8_t _dmaram_end__;
|
|||
|
||||
#define USE_TIMER_MGMT
|
||||
#define USE_TIMER_AF
|
||||
|
||||
#ifdef STM32F4
|
||||
#ifndef I2C1_SCL_PIN
|
||||
#define I2C1_SCL_PIN PB6
|
||||
#endif
|
||||
#ifndef I2C1_SDA_PIN
|
||||
#define I2C1_SDA_PIN PB7
|
||||
#endif
|
||||
#ifndef I2C2_SCL_PIN
|
||||
#define I2C2_SCL_PIN PB10
|
||||
#endif
|
||||
#ifndef I2C2_SDA_PIN
|
||||
#define I2C2_SDA_PIN PB11
|
||||
#endif
|
||||
#ifndef I2C3_SCL_PIN
|
||||
#define I2C3_SCL_PIN PA8
|
||||
#endif
|
||||
#ifndef I2C3_SDA_PIN
|
||||
#define I2C3_SDA_PIN PC9
|
||||
#endif
|
||||
#endif // STM32F4
|
||||
|
||||
#ifdef STM32F7
|
||||
#ifndef I2C1_SCL_PIN
|
||||
#define I2C1_SCL_PIN PB6
|
||||
#endif
|
||||
#ifndef I2C1_SDA_PIN
|
||||
#define I2C1_SDA_PIN PB7
|
||||
#endif
|
||||
#ifndef I2C2_SCL_PIN
|
||||
#define I2C2_SCL_PIN PB10
|
||||
#endif
|
||||
#ifndef I2C2_SDA_PIN
|
||||
#define I2C2_SDA_PIN PB11
|
||||
#endif
|
||||
#ifndef I2C3_SCL_PIN
|
||||
#define I2C3_SCL_PIN PA8
|
||||
#endif
|
||||
#ifndef I2C3_SDA_PIN
|
||||
#define I2C3_SDA_PIN PB4
|
||||
#endif
|
||||
#ifndef I2C4_SCL_PIN
|
||||
#define I2C4_SCL_PIN PD12
|
||||
#endif
|
||||
#ifndef I2C4_SDA_PIN
|
||||
#define I2C4_SDA_PIN PD13
|
||||
#endif
|
||||
#endif // STM32F7
|
||||
|
||||
|
|
|
@ -39,6 +39,31 @@
|
|||
|
||||
#include "pg/bus_i2c.h"
|
||||
|
||||
#ifndef I2C1_SCL_PIN
|
||||
#define I2C1_SCL_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C1_SDA_PIN
|
||||
#define I2C1_SDA_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C2_SCL_PIN
|
||||
#define I2C2_SCL_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C2_SDA_PIN
|
||||
#define I2C2_SDA_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C3_SCL_PIN
|
||||
#define I2C3_SCL_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C3_SDA_PIN
|
||||
#define I2C3_SDA_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C4_SCL_PIN
|
||||
#define I2C4_SCL_PIN NONE
|
||||
#endif
|
||||
#ifndef I2C4_SDA_PIN
|
||||
#define I2C4_SDA_PIN NONE
|
||||
#endif
|
||||
|
||||
typedef struct i2cDefaultConfig_s {
|
||||
I2CDevice device;
|
||||
ioTag_t ioTagScl, ioTagSda;
|
||||
|
@ -48,16 +73,16 @@ typedef struct i2cDefaultConfig_s {
|
|||
|
||||
static const i2cDefaultConfig_t i2cDefaultConfig[] = {
|
||||
#ifdef USE_I2C_DEVICE_1
|
||||
{ I2CDEV_1, IO_TAG(I2C1_SCL), IO_TAG(I2C1_SDA), I2C1_PULLUP, I2C1_CLOCKSPEED },
|
||||
{ I2CDEV_1, IO_TAG(I2C1_SCL_PIN), IO_TAG(I2C1_SDA_PIN), I2C1_PULLUP, I2C1_CLOCKSPEED },
|
||||
#endif
|
||||
#ifdef USE_I2C_DEVICE_2
|
||||
{ I2CDEV_2, IO_TAG(I2C2_SCL), IO_TAG(I2C2_SDA), I2C2_PULLUP, I2C2_CLOCKSPEED },
|
||||
{ I2CDEV_2, IO_TAG(I2C2_SCL_PIN), IO_TAG(I2C2_SDA_PIN), I2C2_PULLUP, I2C2_CLOCKSPEED },
|
||||
#endif
|
||||
#ifdef USE_I2C_DEVICE_3
|
||||
{ I2CDEV_3, IO_TAG(I2C3_SCL), IO_TAG(I2C3_SDA), I2C3_PULLUP, I2C3_CLOCKSPEED },
|
||||
{ I2CDEV_3, IO_TAG(I2C3_SCL_PIN), IO_TAG(I2C3_SDA_PIN), I2C3_PULLUP, I2C3_CLOCKSPEED },
|
||||
#endif
|
||||
#ifdef USE_I2C_DEVICE_4
|
||||
{ I2CDEV_4, IO_TAG(I2C4_SCL), IO_TAG(I2C4_SDA), I2C4_PULLUP, I2C4_CLOCKSPEED },
|
||||
{ I2CDEV_4, IO_TAG(I2C4_SCL_PIN), IO_TAG(I2C4_SDA_PIN), I2C4_PULLUP, I2C4_CLOCKSPEED },
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -62,83 +62,6 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// pg/bus_i2c
|
||||
|
||||
#ifdef I2C_FULL_RECONFIGURABILITY
|
||||
#ifdef USE_I2C_DEVICE_1
|
||||
#define I2C1_SCL NONE
|
||||
#define I2C1_SDA NONE
|
||||
#endif
|
||||
|
||||
#ifdef USE_I2C_DEVICE_2
|
||||
#define I2C2_SCL NONE
|
||||
#define I2C2_SDA NONE
|
||||
#endif
|
||||
|
||||
#ifdef USE_I2C_DEVICE_3
|
||||
#define I2C3_SCL NONE
|
||||
#define I2C3_SDA NONE
|
||||
#endif
|
||||
|
||||
#ifdef USE_I2C_DEVICE_4
|
||||
#define I2C4_SCL NONE
|
||||
#define I2C4_SDA NONE
|
||||
#endif
|
||||
|
||||
#else // I2C_FULL_RECONFIGURABILITY
|
||||
|
||||
// Backward compatibility for exisiting targets
|
||||
|
||||
#ifdef STM32F4
|
||||
#ifndef I2C1_SCL
|
||||
#define I2C1_SCL PB6
|
||||
#endif
|
||||
#ifndef I2C1_SDA
|
||||
#define I2C1_SDA PB7
|
||||
#endif
|
||||
#ifndef I2C2_SCL
|
||||
#define I2C2_SCL PB10
|
||||
#endif
|
||||
#ifndef I2C2_SDA
|
||||
#define I2C2_SDA PB11
|
||||
#endif
|
||||
#ifndef I2C3_SCL
|
||||
#define I2C3_SCL PA8
|
||||
#endif
|
||||
#ifndef I2C3_SDA
|
||||
#define I2C3_SDA PC9
|
||||
#endif
|
||||
#endif // STM32F4
|
||||
|
||||
#ifdef STM32F7
|
||||
#ifndef I2C1_SCL
|
||||
#define I2C1_SCL PB6
|
||||
#endif
|
||||
#ifndef I2C1_SDA
|
||||
#define I2C1_SDA PB7
|
||||
#endif
|
||||
#ifndef I2C2_SCL
|
||||
#define I2C2_SCL PB10
|
||||
#endif
|
||||
#ifndef I2C2_SDA
|
||||
#define I2C2_SDA PB11
|
||||
#endif
|
||||
#ifndef I2C3_SCL
|
||||
#define I2C3_SCL PA8
|
||||
#endif
|
||||
#ifndef I2C3_SDA
|
||||
#define I2C3_SDA PB4
|
||||
#endif
|
||||
#ifndef I2C4_SCL
|
||||
#define I2C4_SCL PD12
|
||||
#endif
|
||||
#ifndef I2C4_SDA
|
||||
#define I2C4_SDA PD13
|
||||
#endif
|
||||
#endif // STM32F7
|
||||
|
||||
#endif // I2C_FULL_RECONFIGURABILITY
|
||||
|
||||
#ifndef I2C1_CLOCKSPEED
|
||||
#define I2C1_CLOCKSPEED 800
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue