1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

REVONANO - Support distinct remaps for SDA and SCL

This commit is contained in:
Alessio Morale 2014-10-25 16:32:24 +02:00
parent 375f23ff0c
commit 805750050c
9 changed files with 57 additions and 40 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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));

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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,