chore: New module/serial API (#3055)
* WiP: new module interface * WiP: softserial timer DMA * WiP: setup() and send() in one step and remove methods specific to internal or external module * fixes and extra port config * horus targets * module ports have moved * T8 support (only internal module) * fix nv14 * stupid GCC.... * disable BT * remove nv14 telem driver * remove old aux serial driver * Move module buffers out of pulses.h * Soft serial fixes and PXX1 support * Fixed PPM module output * Fixed CLI * compilation fixes * Ported bluetooth and flysky gimbal to new serial driver * Re-enable soft-serial RX * fixes and cleanup * nv14 fixes * Fix flysky gimbals * Ghost module * 16 bytes of RAM * Remove getByte from module API * Ghost cleanup * fix: _half_duplex_input() must be called after usart init * WiP * more cleanup * Remove board specific settings from PXX1 / PXX2 drivers * A bit of PXX2 header cleanup * Add support for OVER8 and ONEBIT * Add some support for inverters (NV14 / EL18) * Support NV14 power fixes in generic board * Fix polarity handling * Fix RX DMA * Fix mixer not running * Add soft-serial polarity control * Quick fix for telemetry polling while module port is changed * Fix bootloader DEBUG * Fix MPM telemetry * Fix pulse start * DSM2 soft-serial fallback * DSMP async module restart * Fix CRSF LUA upstream * Remove global variable telemetryProtocol * Use HAL/LL constants * Fix various issue with AFHDS3 and NV14/EL18 internal module * Fixed S.PORT unit tests * fix: update widx after writing at current index * fix: init error condition * Fix: possible infinite loop in _find_port() * Add support for bidir S.PORT init * Add support for "getLastByte" in HW serial driver * PXX1: Add support for S.PORT based on IDLE callback * Fix rebase error * Fix softserial _rx_fifo_push() * Add softserial support for waitForTxCompleted() * Fix MPM flashing (internal / external) * Fixed external MPM * Activate RX DMA on internal module Seems to work with serial passthrough without issues, at least on the L3R PRO. * Fix softserial DMA on stdlcd F4 targets * Add softserial support for 32bit timers (mostly TIM2) * More precise soft-serial * Fix MPM update using inverters & HW uart * Raise S.PORT DMA/USART IRQ prio to achieve faster switching to input * Remove useless delays * Fix flashing external ELRS module * Added a retry mechanism for FrSky S.PORT update * Remove useless enableRx() * External FrSky modules are all flashed via S.PORT * Remove power management unit update This was only used on the first batch of X-lite.
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal/serial_driver.h"
|
||||
#include "intmodule_serial_driver.h"
|
||||
#include "extmodule_serial_driver.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "dataconstants.h"
|
||||
|
||||
void intmoduleStop() {}
|
||||
void intmoduleFifoError() {}
|
||||
@@ -60,54 +60,165 @@ void stop_trainer_module_sbus() {}
|
||||
void init_intmodule_heartbeat() {}
|
||||
void stop_intmodule_heartbeat() {}
|
||||
|
||||
static void* init(const etx_serial_init*) { return nullptr; }
|
||||
static void* init(void*, const etx_serial_init*) { return (void*)1; }
|
||||
static void deinit(void*) {}
|
||||
static void sendByte(void*, uint8_t) {}
|
||||
static void sendBuffer(void*, const uint8_t*, uint8_t) {}
|
||||
static void sendBuffer(void*, const uint8_t*, uint32_t) {}
|
||||
static void waitForTxCompleted(void*) {}
|
||||
static int getByte(void*,uint8_t*) { return -1; }
|
||||
|
||||
const etx_serial_driver_t IntmoduleSerialDriver = {
|
||||
const etx_serial_driver_t _fakeSerialDriver = {
|
||||
.init = init,
|
||||
.deinit = deinit,
|
||||
.sendByte = sendByte,
|
||||
.sendBuffer = sendBuffer,
|
||||
.txCompleted = nullptr,
|
||||
.waitForTxCompleted = waitForTxCompleted,
|
||||
.enableRx = nullptr,
|
||||
.getByte = getByte,
|
||||
.getLastByte = nullptr,
|
||||
.clearRxBuffer = nullptr,
|
||||
.getBaudrate = nullptr,
|
||||
.setBaudrate = nullptr,
|
||||
.setPolarity = nullptr,
|
||||
.setHWOption = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setIdleCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
};
|
||||
|
||||
#if defined(EXTMODULE_USART)
|
||||
static const etx_serial_driver_t _extmoduleSerialDriver = {
|
||||
.init = init,
|
||||
.deinit = deinit,
|
||||
.sendByte = sendByte,
|
||||
.sendBuffer = sendBuffer,
|
||||
.waitForTxCompleted = waitForTxCompleted,
|
||||
.getByte = getByte,
|
||||
.clearRxBuffer = nullptr,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
static void* module_timer_init(void* hw_def, const etx_timer_config_t* cfg)
|
||||
{ return (void*)1; }
|
||||
|
||||
static void module_timer_deinit(void* ctx) {}
|
||||
|
||||
static void module_timer_send(void* ctx, const etx_timer_config_t* cfg,
|
||||
const void* pulses, uint16_t length)
|
||||
{}
|
||||
|
||||
const etx_timer_driver_t _fakeTimerDriver = {
|
||||
.init = module_timer_init,
|
||||
.deinit = module_timer_deinit,
|
||||
.send = module_timer_send,
|
||||
};
|
||||
|
||||
constexpr const etx_serial_driver_t* _ext_default_drv = &_extmoduleSerialDriver;
|
||||
#else
|
||||
constexpr const etx_serial_driver_t* _ext_default_drv = nullptr;
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
const etx_module_port_t _internal_ports[] = {
|
||||
#if defined(INTMODULE_USART)
|
||||
{
|
||||
.port = ETX_MOD_PORT_UART,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX_RX | ETX_MOD_FULL_DUPLEX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#else // INTMODULE_USART
|
||||
{
|
||||
.port = ETX_MOD_PORT_SOFT_INV,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX,
|
||||
.drv = { .timer = &_fakeTimerDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#endif
|
||||
#if defined(INTERNAL_MODULE_PXX1)
|
||||
{
|
||||
.port = ETX_MOD_PORT_SPORT,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX | ETX_MOD_DIR_RX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static const etx_module_t _internal_module = {
|
||||
.ports = _internal_ports,
|
||||
.set_pwr = nullptr,
|
||||
.set_bootcmd = nullptr,
|
||||
.n_ports = DIM(_internal_ports),
|
||||
};
|
||||
#endif
|
||||
|
||||
const etx_serial_driver_t* _ext_drv = _ext_default_drv;
|
||||
#if defined(SPORT_UPDATE_PWR_GPIO)
|
||||
void _sport_set_pwr(uint8_t) {}
|
||||
const etx_module_t _sport_module = {
|
||||
.ports = nullptr,
|
||||
.set_pwr = _sport_set_pwr,
|
||||
.set_bootcmd = nullptr,
|
||||
.n_ports = 0,
|
||||
};
|
||||
#endif
|
||||
|
||||
void extmoduleSetSerialPort(const etx_serial_driver_t* drv)
|
||||
{
|
||||
if (drv) _ext_drv = drv;
|
||||
else _ext_drv = _ext_default_drv;
|
||||
}
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
const etx_module_port_t _external_ports[] = {
|
||||
#if defined(EXTMODULE_USART)
|
||||
// TX on PPM, RX on HEARTBEAT
|
||||
{
|
||||
.port = ETX_MOD_PORT_UART,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX_RX | ETX_MOD_FULL_DUPLEX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#endif
|
||||
// Timer output on PPM
|
||||
{
|
||||
.port = ETX_MOD_PORT_TIMER,
|
||||
.type = ETX_MOD_TYPE_TIMER,
|
||||
.dir_flags = ETX_MOD_DIR_TX,
|
||||
.drv = { .timer = &_fakeTimerDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
// TX inverted DMA pulse train on S.PORT
|
||||
{
|
||||
.port = ETX_MOD_PORT_SOFT_INV,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
// TX/RX half-duplex on S.PORT
|
||||
{
|
||||
.port = ETX_MOD_PORT_SPORT,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_TX | ETX_MOD_DIR_RX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#if defined(TELEMETRY_TIMER)
|
||||
// RX soft-serial sampled bit-by-bit via timer IRQ on S.PORT
|
||||
{
|
||||
.port = ETX_MOD_PORT_SPORT_INV,
|
||||
.type = ETX_MOD_TYPE_SERIAL,
|
||||
.dir_flags = ETX_MOD_DIR_RX,
|
||||
.drv = { .serial = &_fakeSerialDriver },
|
||||
.hw_def = nullptr,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
const etx_serial_driver_t* extmoduleGetSerialPort()
|
||||
{
|
||||
return _ext_drv;
|
||||
}
|
||||
static const etx_module_t _external_module = {
|
||||
.ports = _external_ports,
|
||||
.set_pwr = nullptr,
|
||||
.set_bootcmd = nullptr,
|
||||
.n_ports = DIM(_external_ports),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
BEGIN_MODULES()
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
&_internal_module,
|
||||
#else
|
||||
nullptr,
|
||||
#endif
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||
&_external_module,
|
||||
#else
|
||||
nullptr,
|
||||
#endif
|
||||
#if defined(SPORT_UPDATE_PWR_GPIO)
|
||||
&_sport_module,
|
||||
#endif
|
||||
END_MODULES()
|
||||
|
||||
Reference in New Issue
Block a user