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:
+39
-47
@@ -25,6 +25,10 @@
|
||||
#include "opentx.h"
|
||||
#include "diskio.h"
|
||||
#include "timers_driver.h"
|
||||
#include "hal/module_port.h"
|
||||
|
||||
#include "tasks.h"
|
||||
#include "tasks/mixer_task.h"
|
||||
|
||||
#include "cli.h"
|
||||
|
||||
@@ -34,10 +38,6 @@
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
#if defined(INTMODULE_USART)
|
||||
#include "intmodule_serial_driver.h"
|
||||
#endif
|
||||
|
||||
#define CLI_COMMAND_MAX_ARGS 8
|
||||
#define CLI_COMMAND_MAX_LEN 256
|
||||
|
||||
@@ -581,7 +581,7 @@ int cliTestGraphics()
|
||||
if (pulsesStarted()) {
|
||||
pausePulses();
|
||||
}
|
||||
pauseMixerCalculations();
|
||||
mixerTaskStop();
|
||||
perMainEnabled = false;
|
||||
|
||||
float result = 0;
|
||||
@@ -607,7 +607,7 @@ int cliTestGraphics()
|
||||
if (pulsesStarted()) {
|
||||
resumePulses();
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
mixerTaskStart();
|
||||
watchdogSuspend(0);
|
||||
|
||||
return 0;
|
||||
@@ -714,7 +714,7 @@ int cliTestMemorySpeed()
|
||||
if (pulsesStarted()) {
|
||||
pausePulses();
|
||||
}
|
||||
pauseMixerCalculations();
|
||||
mixerTaskStop();
|
||||
perMainEnabled = false;
|
||||
|
||||
float result = 0;
|
||||
@@ -749,7 +749,7 @@ int cliTestMemorySpeed()
|
||||
if (pulsesStarted()) {
|
||||
resumePulses();
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
mixerTaskStart();
|
||||
watchdogSuspend(0);
|
||||
|
||||
return 0;
|
||||
@@ -906,7 +906,7 @@ int cliReboot(const char ** argv)
|
||||
#if !defined(SIMU)
|
||||
if (!strcmp(argv[1], "wdt")) {
|
||||
// do a user requested watchdog test by pausing mixer thread
|
||||
pausePulses();
|
||||
pulsesStop();
|
||||
}
|
||||
else {
|
||||
NVIC_SystemReset();
|
||||
@@ -973,17 +973,9 @@ int cliSet(const char **argv)
|
||||
}
|
||||
if (!strcmp(argv[3], "power")) {
|
||||
if (!strcmp("on", argv[4])) {
|
||||
if (module == 0) {
|
||||
INTERNAL_MODULE_ON();
|
||||
} else {
|
||||
EXTERNAL_MODULE_ON();
|
||||
}
|
||||
modulePortSetPower(module, true);
|
||||
} else if (!strcmp("off", argv[4])) {
|
||||
if (module == 0) {
|
||||
INTERNAL_MODULE_OFF();
|
||||
} else {
|
||||
EXTERNAL_MODULE_OFF();
|
||||
}
|
||||
modulePortSetPower(module, false);
|
||||
} else {
|
||||
cliSerialPrint("%s: invalid power argument '%s'", argv[0], argv[4]);
|
||||
return -1;
|
||||
@@ -1026,10 +1018,10 @@ int cliSet(const char **argv)
|
||||
|
||||
if (level) {
|
||||
cliSerialPrint("%s: pulses start", argv[0]);
|
||||
startPulses();
|
||||
pulsesStart();
|
||||
} else {
|
||||
cliSerialPrint("%s: pulses stop", argv[0]);
|
||||
stopPulses();
|
||||
pulsesStop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1037,21 +1029,24 @@ int cliSet(const char **argv)
|
||||
}
|
||||
|
||||
#if defined(ENABLE_SERIAL_PASSTHROUGH)
|
||||
static void *spInternalModuleCTX = nullptr;
|
||||
static etx_module_state_t *spInternalModuleState = nullptr;
|
||||
|
||||
static void spInternalModuleTx(uint8_t* buf, uint32_t len)
|
||||
{
|
||||
auto drv = modulePortGetSerialDrv(spInternalModuleState->tx);
|
||||
auto ctx = modulePortGetCtx(spInternalModuleState->tx);
|
||||
|
||||
while (len > 0) {
|
||||
IntmoduleSerialDriver.sendByte(spInternalModuleCTX, *(buf++));
|
||||
drv->sendByte(ctx, *(buf++));
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
static const etx_serial_init spIntmoduleSerialInitParams = {
|
||||
.baudrate = 0,
|
||||
.parity = ETX_Parity_None,
|
||||
.stop_bits = ETX_StopBits_One,
|
||||
.word_length = ETX_WordLength_8,
|
||||
.rx_enable = true,
|
||||
.encoding = ETX_Encoding_8N1,
|
||||
.direction = ETX_Dir_TX_RX,
|
||||
.polarity = ETX_Pol_Normal,
|
||||
};
|
||||
|
||||
// TODO: use proper method instead
|
||||
@@ -1100,7 +1095,7 @@ int cliSerialPassthrough(const char **argv)
|
||||
|
||||
// stop pulses
|
||||
watchdogSuspend(200/*2s*/);
|
||||
stopPulses();
|
||||
pulsesStop();
|
||||
|
||||
// suspend RTOS scheduler
|
||||
vTaskSuspendAll();
|
||||
@@ -1114,30 +1109,27 @@ int cliSerialPassthrough(const char **argv)
|
||||
etx_serial_init params(spIntmoduleSerialInitParams);
|
||||
params.baudrate = baudrate;
|
||||
|
||||
void* uart_ctx = IntmoduleSerialDriver.init(¶ms);
|
||||
spInternalModuleCTX = uart_ctx;
|
||||
spInternalModuleState = modulePortInitSerial(port_n, ETX_MOD_PORT_UART,
|
||||
¶ms);
|
||||
|
||||
auto drv = modulePortGetSerialDrv(spInternalModuleState->rx);
|
||||
auto ctx = modulePortGetCtx(spInternalModuleState->rx);
|
||||
|
||||
// backup and swap CLI input
|
||||
auto backupCB = cliReceiveCallBack;
|
||||
cliReceiveCallBack = spInternalModuleTx;
|
||||
|
||||
|
||||
// loop until cable disconnected
|
||||
while (cdcConnected) {
|
||||
|
||||
uint32_t cli_br = cliGetBaudRate();
|
||||
if (cli_br && (cli_br != (uint32_t)baudrate)) {
|
||||
baudrate = cli_br;
|
||||
|
||||
etx_serial_init params(spIntmoduleSerialInitParams);
|
||||
params.baudrate = baudrate;
|
||||
|
||||
// re-configure serial port
|
||||
spInternalModuleCTX = IntmoduleSerialDriver.init(¶ms);
|
||||
drv->setBaudrate(ctx, baudrate);
|
||||
}
|
||||
|
||||
uint8_t data;
|
||||
if (IntmoduleSerialDriver.getByte(uart_ctx, &data) > 0) {
|
||||
if (drv->getByte(ctx, &data) > 0) {
|
||||
|
||||
uint8_t timeout = 10; // 10 ms
|
||||
while(!usbSerialFreeSpace() && (timeout > 0)) {
|
||||
@@ -1154,13 +1146,13 @@ int cliSerialPassthrough(const char **argv)
|
||||
|
||||
// restore callsbacks
|
||||
cliReceiveCallBack = backupCB;
|
||||
spInternalModuleCTX = nullptr;
|
||||
|
||||
// and stop module
|
||||
IntmoduleSerialDriver.deinit(uart_ctx);
|
||||
modulePortDeInit(spInternalModuleState);
|
||||
spInternalModuleState = nullptr;
|
||||
|
||||
// power off the module and wait for a bit
|
||||
INTERNAL_MODULE_OFF();
|
||||
modulePortSetPower(port_n, false);
|
||||
delay_ms(200);
|
||||
}
|
||||
#endif
|
||||
@@ -1169,7 +1161,7 @@ int cliSerialPassthrough(const char **argv)
|
||||
// - external module (S.PORT?)
|
||||
|
||||
watchdogSuspend(200/*2s*/);
|
||||
startPulses();
|
||||
pulsesStart();
|
||||
|
||||
// suspend RTOS scheduler
|
||||
xTaskResumeAll();
|
||||
@@ -1549,7 +1541,7 @@ int cliCrypt(const char ** argv)
|
||||
if (pulsesStarted()) {
|
||||
pausePulses();
|
||||
}
|
||||
pauseMixerCalculations();
|
||||
mixerTaskStop();
|
||||
perMainEnabled = false;
|
||||
|
||||
uint32_t startMs = RTOS_GET_MS();
|
||||
@@ -1564,7 +1556,7 @@ int cliCrypt(const char ** argv)
|
||||
if (pulsesStarted()) {
|
||||
resumePulses();
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
mixerTaskStart();
|
||||
watchdogSuspend(0);
|
||||
|
||||
return 0;
|
||||
@@ -1587,7 +1579,7 @@ int cliResetGT911(const char** argv)
|
||||
|
||||
// stop pulses & suspend RTOS scheduler
|
||||
watchdogSuspend(200/*2s*/);
|
||||
stopPulses();
|
||||
pulsesStop();
|
||||
vTaskSuspendAll();
|
||||
|
||||
// reset touch controller
|
||||
@@ -1598,7 +1590,7 @@ int cliResetGT911(const char** argv)
|
||||
cliSerialPrintf("GT911: new config version is %u\n", tp_gt911_cfgVer);
|
||||
|
||||
// restart pulses & RTOS scheduler
|
||||
startPulses();
|
||||
pulsesStart();
|
||||
xTaskResumeAll();
|
||||
|
||||
return 0;
|
||||
@@ -1719,7 +1711,7 @@ void cliTask(void * pdata)
|
||||
const TickType_t xTimeout = 100 / RTOS_MS_PER_TICK;
|
||||
size_t xReceivedBytes = xStreamBufferReceive(cliRxBuffer, &c, 1, xTimeout);
|
||||
|
||||
if (s_pulses_paused) {
|
||||
if (!mixerTaskRunning()) {
|
||||
WDG_RESET();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user