|
|
|
@ -105,6 +105,45 @@ void I2CBus::clear_all()
@@ -105,6 +105,45 @@ void I2CBus::clear_all()
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
If bus exists, set its data and clock lines to floating |
|
|
|
|
*/ |
|
|
|
|
void I2CBus::set_bus_to_floating(uint8_t busidx) |
|
|
|
|
{ |
|
|
|
|
if (busidx < ARRAY_SIZE(I2CD)) { |
|
|
|
|
const struct I2CInfo &info = I2CD[busidx]; |
|
|
|
|
const ioline_t sda_line = GPIO::resolve_alt_config(info.sda_line, PERIPH_TYPE::I2C_SDA, info.instance); |
|
|
|
|
const ioline_t scl_line = GPIO::resolve_alt_config(info.scl_line, PERIPH_TYPE::I2C_SCL, info.instance); |
|
|
|
|
palSetLineMode(sda_line, PAL_MODE_INPUT); |
|
|
|
|
palSetLineMode(scl_line, PAL_MODE_INPUT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
Check enabled I2C/CAN select pins against check_pins bitmask |
|
|
|
|
*/ |
|
|
|
|
bool I2CBus::check_select_pins(uint8_t check_pins) |
|
|
|
|
{ |
|
|
|
|
uint8_t enabled_pins = 0; |
|
|
|
|
|
|
|
|
|
#ifdef HAL_GPIO_PIN_GPIO_CAN_I2C1_SEL |
|
|
|
|
enabled_pins |= palReadLine(HAL_GPIO_PIN_GPIO_CAN_I2C1_SEL) << 0; |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_GPIO_PIN_GPIO_CAN_I2C2_SEL |
|
|
|
|
enabled_pins |= palReadLine(HAL_GPIO_PIN_GPIO_CAN_I2C2_SEL) << 1; |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_GPIO_PIN_GPIO_CAN_I2C3_SEL |
|
|
|
|
enabled_pins |= palReadLine(HAL_GPIO_PIN_GPIO_CAN_I2C3_SEL) << 2; |
|
|
|
|
#endif |
|
|
|
|
#ifdef HAL_GPIO_PIN_GPIO_CAN_I2C4_SEL |
|
|
|
|
enabled_pins |= palReadLine(HAL_GPIO_PIN_GPIO_CAN_I2C4_SEL) << 3; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
return (enabled_pins & check_pins) == check_pins; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
clear a stuck bus (bus held by a device that is holding SDA low) by |
|
|
|
|
clocking out pulses on SCL to let the device complete its |
|
|
|
|