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:
Raphael Coeffic
2023-02-09 19:44:32 +10:00
committed by GitHub
parent d80adc6c4d
commit 72193eda82
189 changed files with 7960 additions and 8364 deletions
+45 -145
View File
@@ -25,15 +25,13 @@
#include "definitions.h"
#include "dataconstants.h"
#include "pulses_common.h"
#include "pxx1.h"
#include "pxx2.h"
#include "multi.h"
#include "afhds2.h"
#include "afhds3_module.h"
#include "modules_helpers.h"
#include "ff.h"
#include "hal/module_driver.h"
#if defined(PXX2)
#include "pxx2.h"
#include "pxx2_ota.h"
#endif
#if defined(DSM2)
#define IS_DSM2_PROTOCOL(protocol) (protocol>=PROTOCOL_CHANNELS_DSM2_LP45 && protocol<=PROTOCOL_CHANNELS_DSM2_DSMX)
@@ -62,17 +60,16 @@
#define IS_AFHDS3_PROTOCOL(protocol) (0)
#endif
extern uint8_t s_pulses_paused;
typedef void (* ModuleCallback)();
PACK(struct ModuleState {
uint8_t protocol;
uint8_t mode:4;
uint8_t paused:1;
uint8_t forced_off:1;
uint8_t spare:3;
uint16_t counter;
#if defined(PXX2)
// PXX specific items
union
{
@@ -90,6 +87,7 @@ PACK(struct ModuleState {
void writeModuleSettings(ModuleSettings * source);
void readReceiverSettings(ReceiverSettings * destination);
void writeReceiverSettings(ReceiverSettings * source);
#endif
});
extern ModuleState moduleState[NUM_MODULES];
@@ -130,98 +128,13 @@ typedef Dsm2TimerPulsesData Dsm2PulsesData;
#define SBUS_MAX_PERIOD 325 /*Overflows uint16_t if set higher*/
#define SBUS_DEF_PERIOD 225
#define SBUS_STEPSIZE 5 /* SBUS Step Size 0.5ms */
#define SBUS_PERIOD_HALF_US ((g_model.moduleData[EXTERNAL_MODULE].sbus.refreshRate * SBUS_STEPSIZE + SBUS_DEF_PERIOD) * 200) /*half us*/
#define SBUS_PERIOD (SBUS_PERIOD_HALF_US / 2) /*us*/
#define SBUS_PERIOD_HALF_US(m) ((g_model.moduleData[m].sbus.refreshRate * SBUS_STEPSIZE + SBUS_DEF_PERIOD) * 200) /*half us*/
#define SBUS_PERIOD(m) (SBUS_PERIOD_HALF_US(m) / 2) /*us*/
#define MULTIMODULE_BAUDRATE 100000
#define MULTIMODULE_PERIOD 7000 /*us*/
#define CROSSFIRE_FRAME_MAXLEN 64
PACK(struct CrossfirePulsesData {
uint8_t pulses[CROSSFIRE_FRAME_MAXLEN];
uint8_t length;
});
#define GHOST_FRAME_MAXLEN 16
PACK(struct GhostPulsesData {
uint8_t pulses[GHOST_FRAME_MAXLEN];
uint8_t length;
});
union InternalModulePulsesData {
#if defined(INTERNAL_MODULE_PXX1)
#if defined(INTMODULE_USART)
UartPxx1Pulses pxx_uart;
#else
PwmPxx1Pulses pxx;
#endif
#endif
#if defined(INTERNAL_MODULE_PXX2)
Pxx2Pulses pxx2;
#endif
#if defined(INTERNAL_MODULE_AFHDS2A)
FlySkySerialPulsesData flysky;
#endif
#if defined(INTERNAL_MODULE_MULTI)
UartMultiPulses multi;
#endif
#if defined(INTERNAL_MODULE_CRSF)
CrossfirePulsesData crossfire;
#endif
#if defined(INTERNAL_MODULE_AFHDS3)
afhds3::IntmoduleData afhds3;
#endif
#if defined(INTERNAL_MODULE_PPM)
PpmPulsesData<pulse_duration_t> ppm;
#endif
} __ALIGNED(4);
union ExternalModulePulsesData {
#if defined(PXX1)
#if defined(HARDWARE_EXTERNAL_MODULE_SIZE_SML)
UartPxx1Pulses pxx_uart;
#endif
PwmPxx1Pulses pxx;
#endif
#if defined(PXX2)
Pxx2Pulses pxx2;
#endif
#if defined(DSM2) || defined(MULTIMODULE) || defined(SBUS)
Dsm2PulsesData dsm2;
#endif
#if defined(AFHDS3)
afhds3::ExtmoduleData afhds3;
#endif
PpmPulsesData<pulse_duration_t> ppm;
#if defined(CROSSFIRE)
CrossfirePulsesData crossfire;
#endif
#if defined(GHOST)
GhostPulsesData ghost;
#endif
} __ALIGNED(4);
/* The __ALIGNED keyword is required to align the struct inside the modulePulsesData below,
* which is also defined to be __DMA (which includes __ALIGNED) aligned.
* Arrays in C/C++ are always defined to be *contiguously*. The first byte of the second element is therefore always
* sizeof(ModulePulsesData). __ALIGNED is required for sizeof(ModulePulsesData) to be a multiple of the alignment.
*/
extern InternalModulePulsesData intmodulePulsesData;
extern ExternalModulePulsesData extmodulePulsesData;
union TrainerPulsesData {
PpmPulsesData<trainer_pulse_duration_t> ppm;
@@ -229,63 +142,50 @@ union TrainerPulsesData {
extern TrainerPulsesData trainerPulsesData;
#if defined(HARDWARE_INTERNAL_MODULE)
bool setupPulsesInternalModule();
void stopPulsesInternalModule();
void intmoduleSendNextFrame();
const etx_module_driver_t* getIntModuleDriver();
void* getIntModuleCtx();
#if !defined(AFHDS3)
#define MODULE_BUFFER_SIZE 64
#else
#define MODULE_BUFFER_SIZE 128
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
bool setupPulsesExternalModule();
void stopPulsesExternalModule();
void extmoduleSendNextFrame();
const etx_module_driver_t* getExtModuleDriver();
void* getExtModuleCtx();
#endif
void restartModule(uint8_t idx);
void setupPulsesDSM2();
void setupPulsesLemonDSMP();
void setupPulsesCrossfire(uint8_t idx);
void setupPulsesGhost();
void setupPulsesMultiExternalModule();
void setupPulsesSbus();
void setupPulsesPPMInternalModule();
void setupPulsesPPMExternalModule();
struct module_pulse_buffer {
uint8_t _buffer[MODULE_BUFFER_SIZE];
};
struct module_pulse_driver {
module_pulse_buffer buffer;
const etx_proto_driver_t* drv;
void* ctx;
};
module_pulse_driver* pulsesGetModuleDriver(uint8_t module);
uint8_t* pulsesGetModuleBuffer(uint8_t module);
void pulsesStopModule(uint8_t module);
void pulsesSendNextFrame(uint8_t module);
void pulsesSendChannels();
typedef void (*module_init_cb_t)(uint8_t, const etx_proto_driver_t*);
typedef void (*module_deinit_cb_t)(uint8_t, const etx_proto_driver_t*);
void pulsesSetModuleInitCb(module_init_cb_t cb);
void pulsesSetModuleDeInitCb(module_deinit_cb_t cb);
void restartModule(uint8_t module);
bool restartModuleAsync(uint8_t module, uint8_t cnt_delay);
void setupPulsesPPMTrainer();
void putDsm2Flush();
void sendByteSbus(uint8_t b);
void intmodulePpmStart();
void intmodulePxx1PulsesStart();
void intmodulePxx1SerialStart();
void extmodulePxx1PulsesStart();
void extmodulePpmStart();
void intmoduleStop();
void extmoduleStop();
void getModuleStatusString(uint8_t moduleIdx, char * statusText);
void getModuleSyncStatusString(uint8_t moduleIdx, char * statusText);
#if defined(AFHDS3)
uint8_t actualAfhdsRunPower(int moduleIndex);
#endif
void extramodulePpmStart();
void startPulses();
void stopPulses();
inline bool pulsesStarted()
{
return moduleState[0].protocol != PROTOCOL_CHANNELS_UNINITIALIZED;
}
inline void pausePulses()
{
s_pulses_paused = true;
}
inline void resumePulses()
{
s_pulses_paused = false;
}
void pulsesInit();
void pulsesStart();
void pulsesStop();
inline void SEND_FAILSAFE_NOW(uint8_t idx)
{