diff --git a/flight/pios/inc/pios_i2c_priv.h b/flight/pios/inc/pios_i2c_priv.h index ea4dbccdb..8086f5074 100644 --- a/flight/pios/inc/pios_i2c_priv.h +++ b/flight/pios/inc/pios_i2c_priv.h @@ -32,7 +32,8 @@ struct pios_i2c_adapter_cfg { I2C_TypeDef *regs; - uint32_t remap; + uint32_t remapSDA; + uint32_t remapSCL; I2C_InitTypeDef init; uint32_t transfer_timeout_ms; diff --git a/flight/pios/stm32f0x/pios_i2c.c b/flight/pios/stm32f0x/pios_i2c.c index 42df0b22b..b73355262 100644 --- a/flight/pios/stm32f0x/pios_i2c.c +++ b/flight/pios/stm32f0x/pios_i2c.c @@ -551,9 +551,11 @@ int32_t PIOS_I2C_Init(uint32_t *i2c_id, const struct pios_i2c_adapter_cfg *cfg) break; } - if (i2c_adapter->cfg->remap) { - GPIO_PinAFConfig(i2c_adapter->cfg->scl.gpio, i2c_adapter->cfg->scl.pin_source, i2c_adapter->cfg->remap); - GPIO_PinAFConfig(i2c_adapter->cfg->sda.gpio, i2c_adapter->cfg->sda.pin_source, i2c_adapter->cfg->remap); + if (i2c_adapter->cfg->remapSCL) { + GPIO_PinAFConfig(i2c_adapter->cfg->scl.gpio, i2c_adapter->cfg->scl.pin_source, i2c_adapter->cfg->remapSCL); + } + if (i2c_adapter->cfg->remapSDA) { + GPIO_PinAFConfig(i2c_adapter->cfg->sda.gpio, i2c_adapter->cfg->sda.pin_source, i2c_adapter->cfg->remapSDA); } GPIO_Init(i2c_adapter->cfg->scl.gpio, &i2c_adapter->cfg->scl.init); diff --git a/flight/pios/stm32f4xx/pios_i2c.c b/flight/pios/stm32f4xx/pios_i2c.c index bc5d4db37..171669ac4 100644 --- a/flight/pios/stm32f4xx/pios_i2c.c +++ b/flight/pios/stm32f4xx/pios_i2c.c @@ -773,13 +773,15 @@ static void i2c_adapter_reset_bus(struct pios_i2c_adapter *i2c_adapter) /* Bus signals are guaranteed to be high (ie. free) after this point */ /* Initialize the GPIO pins to the peripheral function */ - if (i2c_adapter->cfg->remap) { + if (i2c_adapter->cfg->remapSCL) { GPIO_PinAFConfig(i2c_adapter->cfg->scl.gpio, __builtin_ctz(i2c_adapter->cfg->scl.init.GPIO_Pin), - i2c_adapter->cfg->remap); + i2c_adapter->cfg->remapSCL); + } + if (i2c_adapter->cfg->remapSDA) { GPIO_PinAFConfig(i2c_adapter->cfg->sda.gpio, __builtin_ctz(i2c_adapter->cfg->sda.init.GPIO_Pin), - i2c_adapter->cfg->remap); + i2c_adapter->cfg->remapSDA); } GPIO_Init(i2c_adapter->cfg->scl.gpio, (GPIO_InitTypeDef *)&(i2c_adapter->cfg->scl.init)); // Struct is const, function signature not GPIO_Init(i2c_adapter->cfg->sda.gpio, (GPIO_InitTypeDef *)&(i2c_adapter->cfg->sda.init)); diff --git a/flight/targets/boards/discoveryf4bare/board_hw_defs.c b/flight/targets/boards/discoveryf4bare/board_hw_defs.c index 097a8e193..345864847 100644 --- a/flight/targets/boards/discoveryf4bare/board_hw_defs.c +++ b/flight/targets/boards/discoveryf4bare/board_hw_defs.c @@ -994,9 +994,10 @@ void I2C1_ER_IRQHandler() __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = { - .regs = I2C1, - .remap = GPIO_AF_I2C1, - .init = { + .regs = I2C1, + .remapSCL = GPIO_AF_I2C1, + .remapSDA = GPIO_AF_I2C1, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, @@ -1065,9 +1066,10 @@ void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_ir void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = { - .regs = I2C2, - .remap = GPIO_AF_I2C2, - .init = { + .regs = I2C2, + .remapSCL = GPIO_AF_I2C2, + .remapSDA = GPIO_AF_I2C2, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, diff --git a/flight/targets/boards/gpsplatinum/board_hw_defs.c b/flight/targets/boards/gpsplatinum/board_hw_defs.c index 8913e0572..83b7f4528 100644 --- a/flight/targets/boards/gpsplatinum/board_hw_defs.c +++ b/flight/targets/boards/gpsplatinum/board_hw_defs.c @@ -350,9 +350,10 @@ void PIOS_I2C_gps_irq_handler(void); void I2C1_IRQHandler() __attribute__((alias("PIOS_I2C_gps_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_gps_cfg = { - .remap = GPIO_AF_1, - .regs = I2C1, - .init = { + .remapSDA = GPIO_AF_1, + .remapSCL = GPIO_AF_1, + .regs = I2C1, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_AnalogFilter = I2C_AnalogFilter_Enable, .I2C_DigitalFilter = 0x00, diff --git a/flight/targets/boards/osd/board_hw_defs.c b/flight/targets/boards/osd/board_hw_defs.c index d465f09bf..5ef3cc7b5 100644 --- a/flight/targets/boards/osd/board_hw_defs.c +++ b/flight/targets/boards/osd/board_hw_defs.c @@ -388,9 +388,10 @@ void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_ir void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = { - .regs = I2C2, - .remap = GPIO_AF_I2C2, - .init = { + .regs = I2C2, + .remapSDA = GPIO_AF_I2C2, + .remapSCL = GPIO_AF_I2C2, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, diff --git a/flight/targets/boards/revolution/board_hw_defs.c b/flight/targets/boards/revolution/board_hw_defs.c index 1b169634b..d77666147 100644 --- a/flight/targets/boards/revolution/board_hw_defs.c +++ b/flight/targets/boards/revolution/board_hw_defs.c @@ -1218,9 +1218,10 @@ void I2C1_ER_IRQHandler() __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = { - .regs = I2C1, - .remap = GPIO_AF_I2C1, - .init = { + .regs = I2C1, + .remapSCL = GPIO_AF_I2C1, + .remapSDA = GPIO_AF_I2C1, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, @@ -1289,9 +1290,10 @@ void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_ir void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = { - .regs = I2C2, - .remap = GPIO_AF_I2C2, - .init = { + .regs = I2C2, + .remapSCL = GPIO_AF_I2C2, + .remapSDA = GPIO_AF_I2C2, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, diff --git a/flight/targets/boards/revonano/board_hw_defs.c b/flight/targets/boards/revonano/board_hw_defs.c index c224eb466..8c407d0de 100644 --- a/flight/targets/boards/revonano/board_hw_defs.c +++ b/flight/targets/boards/revonano/board_hw_defs.c @@ -628,9 +628,11 @@ void I2C1_ER_IRQHandler() __attribute__((alias("PIOS_I2C_mag_pressure_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_mag_pressure_adapter_cfg = { - .regs = I2C3, - .remap = GPIO_AF_I2C3, - .init = { +void PIOS_I2C_pressure_adapter_ev_irq_handler(void); + .regs = I2C3, + .remapSCL = GPIO_AF_I2C3, + .remapSDA = GPIO_AF9_I2C3, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, @@ -699,9 +701,10 @@ void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_ir void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = { - .regs = I2C1, - .remap = GPIO_AF_I2C1, - .init = { + .regs = I2C1, + .remapSCL = GPIO_AF_I2C1, + .remapSDA = GPIO_AF_I2C1, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, diff --git a/flight/targets/boards/revoproto/board_hw_defs.c b/flight/targets/boards/revoproto/board_hw_defs.c index 574ab2fe8..332320935 100644 --- a/flight/targets/boards/revoproto/board_hw_defs.c +++ b/flight/targets/boards/revoproto/board_hw_defs.c @@ -1197,9 +1197,10 @@ void I2C1_ER_IRQHandler() __attribute__((alias("PIOS_I2C_mag_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_mag_adapter_cfg = { - .regs = I2C1, - .remap = GPIO_AF_I2C1, - .init = { + .regs = I2C1, + .remapSCL = GPIO_AF_I2C1, + .remapSDA = GPIO_AF_I2C1, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, @@ -1268,9 +1269,10 @@ void I2C2_EV_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_ev_ir void I2C2_ER_IRQHandler() __attribute__((alias("PIOS_I2C_flexiport_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_flexiport_adapter_cfg = { - .regs = I2C2, - .remap = GPIO_AF_I2C2, - .init = { + .regs = I2C2, + .remapSCL = GPIO_AF_I2C2, + .remapSDA = GPIO_AF_I2C2, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable, @@ -1339,9 +1341,10 @@ void I2C3_EV_IRQHandler() __attribute__((alias("PIOS_I2C_pressure_adapter_ev_irq void I2C3_ER_IRQHandler() __attribute__((alias("PIOS_I2C_pressure_adapter_er_irq_handler"))); static const struct pios_i2c_adapter_cfg pios_i2c_pressure_adapter_cfg = { - .regs = I2C3, - .remap = GPIO_AF_I2C3, - .init = { + .regs = I2C3, + .remapSCL = GPIO_AF_I2C3, + .remapSDA = GPIO_AF_I2C3, + .init = { .I2C_Mode = I2C_Mode_I2C, .I2C_OwnAddress1 = 0, .I2C_Ack = I2C_Ack_Enable,