feat: Automatic soft-serial fallback for module ports (#3823)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "sbus.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "hal/serial_driver.h"
|
||||
#include "mixer_scheduler.h"
|
||||
|
||||
#include "opentx.h"
|
||||
@@ -96,7 +97,7 @@ const etx_serial_init sbusUartParams = {
|
||||
.baudrate = SBUS_BAUDRATE,
|
||||
.encoding = ETX_Encoding_8E2,
|
||||
.direction = ETX_Dir_TX,
|
||||
.polarity = ETX_Pol_Normal,
|
||||
.polarity = ETX_Pol_Inverted,
|
||||
};
|
||||
|
||||
static void* sbusInit(uint8_t module)
|
||||
@@ -106,13 +107,8 @@ static void* sbusInit(uint8_t module)
|
||||
if (module == INTERNAL_MODULE) return nullptr;
|
||||
#endif
|
||||
|
||||
// auto mod_st = modulePortInitSerial(module, ETX_MOD_PORT_UART, &sbusUartParams);
|
||||
// TODO: check if inverter is there, or mandate it somehow...
|
||||
// if (!mod_st) {
|
||||
// -> SOFT_INV has 'setPolarity'
|
||||
auto mod_st = modulePortInitSerial(module, ETX_MOD_PORT_SOFT_INV, &sbusUartParams);
|
||||
auto mod_st = modulePortInitSerial(module, ETX_MOD_PORT_UART, &sbusUartParams, true);
|
||||
if (!mod_st) return nullptr;
|
||||
// }
|
||||
|
||||
mixerSchedulerSetPeriod(module, SBUS_PERIOD(module));
|
||||
return (void*)mod_st;
|
||||
@@ -139,9 +135,12 @@ static void sbusSendPulses(void* ctx, uint8_t* buffer, int16_t* channels, uint8_
|
||||
auto drv = modulePortGetSerialDrv(mod_st->tx);
|
||||
auto drv_ctx = modulePortGetCtx(mod_st->tx);
|
||||
|
||||
// TODO: check if the port has an inverter and use it instead
|
||||
if(drv->setPolarity)
|
||||
auto port = mod_st->tx.port;
|
||||
if (port && port->set_inverted) {
|
||||
port->set_inverted(GET_SBUS_POLARITY(module));
|
||||
} else if (drv->setPolarity) {
|
||||
drv->setPolarity(drv_ctx, GET_SBUS_POLARITY(module));
|
||||
}
|
||||
|
||||
drv->sendBuffer(drv_ctx, buffer, p_data - buffer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user