Move all serial internal module functions into proper drivers

This commit is contained in:
Raphael Coeffic
2022-03-20 16:22:12 +01:00
parent f733810c79
commit 803b472c85
15 changed files with 216 additions and 81 deletions
+18 -31
View File
@@ -21,6 +21,7 @@
#include "opentx.h"
#include "mixer_scheduler.h"
#include "heartbeat_driver.h"
#include "io/frsky_pxx2.h"
#include "io/multi_protolist.h"
@@ -322,13 +323,11 @@ void enablePulsesExternalModule(uint8_t protocol)
#if defined(PXX2) && defined(EXTMODULE_USART)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
extmoduleInvertedSerialStart(PXX2_HIGHSPEED_BAUDRATE);
mixerSchedulerSetPeriod(EXTERNAL_MODULE, PXX2_NO_HEARTBEAT_PERIOD);
Pxx2ModuleDriver.init(EXTERNAL_MODULE);
break;
case PROTOCOL_CHANNELS_PXX2_LOWSPEED:
extmoduleInvertedSerialStart(PXX2_LOWSPEED_BAUDRATE);
mixerSchedulerSetPeriod(EXTERNAL_MODULE, PXX2_NO_HEARTBEAT_PERIOD);
Pxx2LowSpeedModuleDriver.init(EXTERNAL_MODULE);
break;
#endif
@@ -375,6 +374,10 @@ void enablePulsesExternalModule(uint8_t protocol)
bool setupPulsesExternalModule(uint8_t protocol)
{
int16_t* channels =
&channelOutputs[g_model.moduleData[EXTERNAL_MODULE].channelsStart];
uint8_t nChannels = 16; // TODO: MAX_CHANNELS - channelsStart
switch (protocol) {
#if defined(PXX1)
@@ -392,7 +395,7 @@ bool setupPulsesExternalModule(uint8_t protocol)
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
case PROTOCOL_CHANNELS_PXX2_LOWSPEED:
extmodulePulsesData.pxx2.setupFrame(EXTERNAL_MODULE);
Pxx2ModuleDriver.setupPulses((void*)EXTERNAL_MODULE, channels, nChannels);
return true;
#endif
@@ -415,9 +418,6 @@ bool setupPulsesExternalModule(uint8_t protocol)
#if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_CROSSFIRE:
if (CrossfireModuleDriver.setupPulses) {
int16_t* channels =
&channelOutputs[g_model.moduleData[EXTERNAL_MODULE].channelsStart];
uint8_t nChannels = 16; // TODO: MAX_CHANNELS - channelsStart
CrossfireModuleDriver.setupPulses((void*)EXTERNAL_MODULE, channels,
nChannels);
}
@@ -496,17 +496,9 @@ static void enablePulsesInternalModule(uint8_t protocol)
#endif
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED: {
intmoduleFifo.clear();
IntmoduleSerialDriver.init(&pxx2SerialInitParams)
resetAccessAuthenticationCount();
#if defined(INTMODULE_HEARTBEAT)
// use backup trigger (1 ms later)
init_intmodule_heartbeat();
#endif
mixerSchedulerSetPeriod(INTERNAL_MODULE, PXX2_PERIOD);
} break;
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
Pxx2ModuleDriver.init(INTERNAL_MODULE);
break;
#endif
#if defined(INTERNAL_MODULE_MULTI)
@@ -568,6 +560,10 @@ static void enablePulsesInternalModule(uint8_t protocol)
bool setupPulsesInternalModule(uint8_t protocol)
{
int16_t* channels =
&channelOutputs[g_model.moduleData[INTERNAL_MODULE].channelsStart];
uint8_t nChannels = 16; // TODO: MAX_CHANNELS - channelsStart
switch (protocol) {
#if defined(HARDWARE_INTERNAL_MODULE) && defined(PXX1) && !defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_PULSES:
@@ -583,16 +579,8 @@ bool setupPulsesInternalModule(uint8_t protocol)
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
{
bool result = intmodulePulsesData.pxx2.setupFrame(INTERNAL_MODULE);
if (moduleState[INTERNAL_MODULE].mode == MODULE_MODE_SPECTRUM_ANALYSER || moduleState[INTERNAL_MODULE].mode == MODULE_MODE_POWER_METER) {
mixerSchedulerSetPeriod(INTERNAL_MODULE, PXX2_TOOLS_PERIOD);
}
else {
mixerSchedulerSetPeriod(INTERNAL_MODULE, PXX2_PERIOD);
}
return result;
}
Pxx2ModuleDriver.setupPulses((void*)INTERNAL_MODULE, channels, nChannels);
return true;
#endif
#if defined(PCBTARANIS) && defined(INTERNAL_MODULE_PPM)
@@ -652,8 +640,7 @@ void intmoduleSendNextFrame()
switch (moduleState[INTERNAL_MODULE].protocol) {
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2_HIGHSPEED:
intmoduleSendBuffer(intmodulePulsesData.pxx2.getData(),
intmodulePulsesData.pxx2.getSize());
Pxx2ModuleDriver.sendPulses((void*)INTERNAL_MODULE);
break;
#endif