AP_HAL_ChibiOS: correctly uninvert RX/TX on F4 with inverter support

This commit is contained in:
Andy Piper 2024-08-06 13:36:00 +01:00 committed by Randy Mackay
parent 3e5dbb225a
commit 7f37b83cdd
1 changed files with 17 additions and 1 deletions

View File

@ -1623,22 +1623,38 @@ bool UARTDriver::set_options(uint16_t options)
cr2 &= ~USART_CR2_SWAP;
_cr2_options &= ~USART_CR2_SWAP;
}
#else // STM32F4
#elif defined(STM32F4) // STM32F4
// F4 can do inversion by GPIO if enabled in hwdef.dat, using
// TXINV and RXINV options
if (options & OPTION_RXINV) {
if (sdef.rxinv_gpio >= 0) {
hal.gpio->write(sdef.rxinv_gpio, sdef.rxinv_polarity);
if (arx_line != 0) {
palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLDOWN);
}
} else {
ret = false;
}
} else if (sdef.rxinv_gpio >= 0) {
hal.gpio->write(sdef.rxinv_gpio, !sdef.rxinv_polarity);
if (arx_line != 0) {
palLineSetPushPull(arx_line, PAL_PUSHPULL_PULLUP);
}
}
if (options & OPTION_TXINV) {
if (sdef.txinv_gpio >= 0) {
hal.gpio->write(sdef.txinv_gpio, sdef.txinv_polarity);
if (atx_line != 0) {
palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLDOWN);
}
} else {
ret = false;
}
} else if (sdef.txinv_gpio >= 0) {
hal.gpio->write(sdef.txinv_gpio, !sdef.txinv_polarity);
if (atx_line != 0) {
palLineSetPushPull(atx_line, PAL_PUSHPULL_PULLUP);
}
}
if (options & OPTION_SWAP) {
ret = false;