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:
+46
-102
@@ -31,16 +31,7 @@
|
||||
#include "telemetry/telemetry.h"
|
||||
#include "mixer_scheduler.h"
|
||||
#include "hal/module_driver.h"
|
||||
|
||||
#if defined(INTMODULE_USART)
|
||||
#include "intmodule_serial_driver.h"
|
||||
#endif
|
||||
|
||||
#if defined(AFHDS3_EXT_UART)
|
||||
#include "extmodule_serial_driver.h"
|
||||
#else
|
||||
#include "extmodule_driver.h"
|
||||
#endif
|
||||
#include "hal/module_port.h"
|
||||
|
||||
#define FAILSAFE_HOLD 1
|
||||
#define FAILSAFE_CUSTOM 2
|
||||
@@ -192,8 +183,7 @@ class ProtoState
|
||||
* @param moduleIndex index of module one of INTERNAL_MODULE, EXTERNAL_MODULE
|
||||
* @param resetFrameCount flag if current frame count should be reseted
|
||||
*/
|
||||
void init(uint8_t moduleIndex, void* buffer, const etx_serial_driver_t* drv);
|
||||
void deinit() { trsp.deinit(); }
|
||||
void init(uint8_t moduleIndex, void* buffer, etx_module_state_t* mod_st);
|
||||
|
||||
/**
|
||||
* Fills DMA buffers with frame to be send depending on actual state
|
||||
@@ -205,11 +195,6 @@ class ProtoState
|
||||
*/
|
||||
void sendFrame() { trsp.sendBuffer(); }
|
||||
|
||||
/**
|
||||
* Fetch telemetry byte
|
||||
*/
|
||||
int getTelemetryByte(uint8_t* data) { return trsp.getTelemetryByte(data); }
|
||||
|
||||
/**
|
||||
* Gets actual module status into provided buffer
|
||||
* @param statusText target buffer for status
|
||||
@@ -320,7 +305,7 @@ static const COMMAND periodicRequestCommands[] =
|
||||
};
|
||||
|
||||
//Static collection of afhds3 object instances by module
|
||||
static ProtoState protoState[NUM_MODULES];
|
||||
static ProtoState protoState[MAX_MODULES];
|
||||
|
||||
void getStatusString(uint8_t module, char* buffer)
|
||||
{
|
||||
@@ -330,7 +315,8 @@ void getStatusString(uint8_t module, char* buffer)
|
||||
//friends function that can access telemetry parsing method
|
||||
void processTelemetryData(void* ctx, uint8_t data, uint8_t* buffer, uint8_t* len)
|
||||
{
|
||||
auto p_state = (ProtoState*)ctx;
|
||||
auto mod_st = (etx_module_state_t*)ctx;
|
||||
auto p_state = (ProtoState*)mod_st->user_data;
|
||||
p_state->processTelemetryData(data, buffer, len);
|
||||
}
|
||||
|
||||
@@ -482,16 +468,10 @@ void ProtoState::setupFrame()
|
||||
}
|
||||
}
|
||||
|
||||
void ProtoState::init(uint8_t moduleIndex, void* buffer, const etx_serial_driver_t* drv)
|
||||
void ProtoState::init(uint8_t moduleIndex, void* buffer, etx_module_state_t* mod_st)
|
||||
{
|
||||
module_index = moduleIndex;
|
||||
|
||||
// TODO: move bit/byte transport to serial driver
|
||||
if (drv) {
|
||||
trsp.init(ByteTransport::Serial, buffer, drv);
|
||||
} else {
|
||||
trsp.init(ByteTransport::Pulses, buffer, nullptr);
|
||||
}
|
||||
trsp.init(buffer, mod_st);
|
||||
|
||||
//clear local vars because it is member of union
|
||||
moduleData = &g_model.moduleData[module_index];
|
||||
@@ -861,106 +841,70 @@ void applyModelConfig(uint8_t module)
|
||||
p_state->applyConfigFromModel();
|
||||
}
|
||||
|
||||
static void* initExternal(uint8_t module)
|
||||
static const etx_serial_init _uartParams = {
|
||||
.baudrate = 0, //AFHDS3_UART_BAUDRATE,
|
||||
.encoding = ETX_Encoding_8N1,
|
||||
.direction = ETX_Dir_TX_RX,
|
||||
.polarity = ETX_Pol_Normal,
|
||||
};
|
||||
|
||||
static void* initModule(uint8_t module)
|
||||
{
|
||||
#if defined(AFHDS3_EXT_UART)
|
||||
auto drv = extmoduleGetSerialPort();
|
||||
if (!drv) return nullptr;
|
||||
etx_module_state_t* mod_st = nullptr;
|
||||
etx_serial_init params(_uartParams);
|
||||
uint16_t period = AFHDS3_UART_COMMAND_TIMEOUT * 1000;
|
||||
|
||||
uint16_t period = AFHDS3_UART_COMMAND_TIMEOUT * 1000 /* us */;
|
||||
#else
|
||||
const etx_serial_driver_t* drv = nullptr;
|
||||
uint16_t period = AFHDS3_SOFTSERIAL_COMMAND_TIMEOUT * 1000 /* us */;
|
||||
params.baudrate = AFHDS3_UART_BAUDRATE;
|
||||
params.polarity =
|
||||
module == INTERNAL_MODULE ? ETX_Pol_Normal : ETX_Pol_Inverted;
|
||||
mod_st = modulePortInitSerial(module, ETX_MOD_PORT_UART, ¶ms);
|
||||
|
||||
telemetryPortInvertedInit(AFHDS3_SOFTSERIAL_BAUDRATE);
|
||||
telemetryPortSetDirectionInput();
|
||||
#endif
|
||||
if (module == EXTERNAL_MODULE && !mod_st) {
|
||||
// soft-serial fallback
|
||||
params.baudrate = AFHDS3_SOFTSERIAL_BAUDRATE;
|
||||
params.direction = ETX_Dir_RX;
|
||||
period = AFHDS3_SOFTSERIAL_COMMAND_TIMEOUT * 1000 /* us */;
|
||||
mod_st = modulePortInitSerial(module, ETX_MOD_PORT_SOFT_INV, ¶ms);
|
||||
// TODO: telemetry RX ???
|
||||
}
|
||||
|
||||
if (!mod_st) return nullptr;
|
||||
|
||||
auto p_state = &protoState[module];
|
||||
p_state->init(module, &extmodulePulsesData.afhds3, drv);
|
||||
p_state->init(module, pulsesGetModuleBuffer(module), mod_st);
|
||||
mod_st->user_data = (void*)p_state;
|
||||
|
||||
mixerSchedulerSetPeriod(module, period);
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
return p_state;
|
||||
return mod_st;
|
||||
}
|
||||
|
||||
static void deinitExternal(void* context)
|
||||
static void deinitModule(void* ctx)
|
||||
{
|
||||
EXTERNAL_MODULE_OFF();
|
||||
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0);
|
||||
|
||||
auto p_state = (ProtoState*)context;
|
||||
p_state->deinit();
|
||||
auto mod_st = (etx_module_state_t*)ctx;
|
||||
modulePortDeInit(mod_st);
|
||||
}
|
||||
|
||||
static void sendPulses(void* context)
|
||||
{
|
||||
auto p_state = (ProtoState*)context;
|
||||
p_state->sendFrame();
|
||||
}
|
||||
|
||||
static void setupPulses(void* context, int16_t* channels, uint8_t nChannels)
|
||||
static void sendPulses(void* ctx, uint8_t* buffer, int16_t* channels, uint8_t nChannels)
|
||||
{
|
||||
(void)buffer;
|
||||
(void)channels;
|
||||
(void)nChannels;
|
||||
|
||||
auto p_state = (ProtoState*)context;
|
||||
auto mod_st = (etx_module_state_t*)ctx;
|
||||
auto p_state = (ProtoState*)mod_st->user_data;
|
||||
p_state->setupFrame();
|
||||
p_state->sendFrame();
|
||||
}
|
||||
|
||||
etx_module_driver_t externalDriver = {
|
||||
etx_proto_driver_t ProtoDriver = {
|
||||
.protocol = PROTOCOL_CHANNELS_AFHDS3,
|
||||
.init = initExternal,
|
||||
.deinit = deinitExternal,
|
||||
.setupPulses = setupPulses,
|
||||
.init = initModule,
|
||||
.deinit = deinitModule,
|
||||
.sendPulses = sendPulses,
|
||||
.getByte = nullptr, // TODO
|
||||
.processData = processTelemetryData,
|
||||
};
|
||||
|
||||
#if defined(INTERNAL_MODULE_AFHDS3)
|
||||
|
||||
static void* initInternal(uint8_t module)
|
||||
{
|
||||
auto p_state = &protoState[module];
|
||||
p_state->init(module, &intmodulePulsesData, &IntmoduleSerialDriver);
|
||||
|
||||
telemetryProtocol = PROTOCOL_TELEMETRY_AFHDS3;
|
||||
mixerSchedulerSetPeriod(module, AFHDS3_UART_COMMAND_TIMEOUT * 1000 /* us */);
|
||||
INTERNAL_MODULE_ON();
|
||||
|
||||
return p_state;
|
||||
}
|
||||
|
||||
static void deinitInternal(void* context)
|
||||
{
|
||||
INTERNAL_MODULE_OFF();
|
||||
telemetryProtocol = 0xFF;
|
||||
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
|
||||
|
||||
auto p_state = (ProtoState*)context;
|
||||
p_state->deinit();
|
||||
}
|
||||
|
||||
static int getByteInternal(void* context, uint8_t* data)
|
||||
{
|
||||
auto p_state = (ProtoState*)context;
|
||||
return p_state->getTelemetryByte(data);
|
||||
}
|
||||
|
||||
etx_module_driver_t internalDriver = {
|
||||
.protocol = PROTOCOL_CHANNELS_AFHDS3,
|
||||
.init = initInternal,
|
||||
.deinit = deinitInternal,
|
||||
.setupPulses = setupPulses,
|
||||
.sendPulses = sendPulses,
|
||||
.getByte = getByteInternal,
|
||||
.processData = processTelemetryData,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user