1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 17:25:13 +03:00

Missing initialization on module type change

XJT / R9M should not reboot (still not tested)
This commit is contained in:
Bertrand Songis 2019-03-13 09:57:11 +01:00
parent 0309b1ee84
commit b62ab2bd62
9 changed files with 55 additions and 40 deletions

View file

@ -910,7 +910,13 @@ void menuModelSetup(event_t event)
lcdDrawTextAlignedLeft(y, STR_MODE);
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_TARANIS_PROTOCOLS, g_model.moduleData[INTERNAL_MODULE].type, attr);
if (attr) {
g_model.moduleData[INTERNAL_MODULE].type = checkIncDec(event, g_model.moduleData[INTERNAL_MODULE].type, MODULE_TYPE_NONE, MODULE_TYPE_MAX, EE_MODEL, isInternalModuleAvailable);
uint8_t moduleType = checkIncDec(event, g_model.moduleData[INTERNAL_MODULE].type, MODULE_TYPE_NONE, MODULE_TYPE_MAX, EE_MODEL, isInternalModuleAvailable);
if (checkIncDec_Ret) {
// TODO this code should be common, in module.h (X10_new_UI branch)
memclear(&g_model.moduleData[INTERNAL_MODULE], sizeof(ModuleData));
g_model.moduleData[INTERNAL_MODULE].type = moduleType;
g_model.moduleData[INTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(INTERNAL_MODULE);
}
}
break;
#endif
@ -951,20 +957,23 @@ void menuModelSetup(event_t event)
if (attr && editMode > 0) {
switch (menuHorizontalPosition) {
case 0:
g_model.moduleData[EXTERNAL_MODULE].type = checkIncDec(event, g_model.moduleData[EXTERNAL_MODULE].type,
{
uint8_t moduleType = checkIncDec(event, g_model.moduleData[EXTERNAL_MODULE].type,
MODULE_TYPE_NONE,
IS_TRAINER_EXTERNAL_MODULE() ? MODULE_TYPE_NONE :
MODULE_TYPE_COUNT - 1, EE_MODEL,
isExternalModuleAvailable);
if (checkIncDec_Ret) {
g_model.moduleData[EXTERNAL_MODULE].rfProtocol = 0;
g_model.moduleData[EXTERNAL_MODULE].channelsStart = 0;
// TODO this code should be common, in module.h (X10_new_UI branch)
memclear(&g_model.moduleData[EXTERNAL_MODULE], sizeof(ModuleData));
g_model.moduleData[EXTERNAL_MODULE].type = moduleType;
g_model.moduleData[EXTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(EXTERNAL_MODULE);
if (isModuleSBUS(EXTERNAL_MODULE))
g_model.moduleData[EXTERNAL_MODULE].sbus.refreshRate = -31;
if (isModulePPM(EXTERNAL_MODULE))
SET_DEFAULT_PPM_FRAME_LENGTH(EXTERNAL_MODULE);
}
}
break;
case 1:
if (isModuleDSM2(EXTERNAL_MODULE))

View file

@ -23,10 +23,6 @@
#include "../fifo.h"
#define PXX2_BAUDRATE 230400
#define PXX2_PERIOD 4 // 4ms
#define PXX2_FRAME_MAXLENGTH 64
class ModuleFifo : public Fifo<uint8_t, PXX2_FRAME_MAXLENGTH> {
public:
bool getFrame(uint8_t * frame)

View file

@ -200,7 +200,7 @@ inline bool isModuleDSM2(uint8_t idx)
#endif
// order is the same as in enum Protocols in myeeprom.h (none, ppm, pxx, pxx2, dsm, crossfire, multi, r9m, r9m2, sbus)
static const int8_t maxChannelsModules[] = { 0, 8, 8, 16, -2, 8, 4, 8, 16, 8}; // relative to 8!
static const int8_t maxChannelsModules[] = { 0, 8, 8, 8, -2, 8, 4, 8, 16, 8}; // relative to 8!
static const int8_t maxChannelsXJT[] = { 0, 8, 0, 4 }; // relative to 8!
constexpr int8_t MAX_TRAINER_CHANNELS_M8 = MAX_TRAINER_CHANNELS - 8;

View file

@ -219,7 +219,7 @@ void setupPulsesInternalModule(uint8_t protocol)
#if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1:
setupPulsesPXXInternalModule();
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX_PERIOD);
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX_PERIOD);
break;
#endif
@ -248,7 +248,7 @@ void setupPulsesExternalModule(uint8_t protocol)
#if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1:
setupPulsesPXXExternalModule();
scheduleNextMixerCalculation(EXTERNAL_MODULE, PXX_PERIOD);
scheduleNextMixerCalculation(EXTERNAL_MODULE, EXTMODULE_PXX_PERIOD);
break;
#endif

View file

@ -27,16 +27,22 @@
#define PXX_SEND_FAILSAFE (1 << 4)
#define PXX_SEND_RANGECHECK (1 << 5)
#define PXX2_ON_SPORT_BAUDRATE 230400
#define PXX2_PERIOD 4 // 4ms
#define PXX2_FRAME_MAXLENGTH 64
#define EXTMODULE_PXX_PERIOD 9/*ms*/
#if defined(PXX_FREQUENCY_HIGH)
#define EXTMODULE_USART_PXX_BAUDRATE 450000
#define INTMODULE_USART_PXX_BAUDRATE 450000
#define PXX_PERIOD 4/*ms*/
#define INTMODULE_PXX_PERIOD 4/*ms*/
#else
#define EXTMODULE_USART_PXX_BAUDRATE 115200
#define INTMODULE_USART_PXX_BAUDRATE 115200
#define PXX_PERIOD 9/*ms*/
#define INTMODULE_PXX_PERIOD 9/*ms*/
#endif
#define EXTMODULE_USART_PXX2_BAUDRATE 450000
#if defined(PXX_FREQUENCY_HIGH) && (!defined(INTMODULE_USART) || !defined(EXTMODULE_USART))
/* PXX uses 20 bytes (as of Rev 1.1 document) with 8 changes per byte + stop bit ~= 162 max pulses */
/* DSM2 uses 2 header + 12 channel bytes, with max 10 changes (8n2) per byte + 16 bits trailer ~= 156 max pulses */
@ -56,7 +62,7 @@ class SerialPxxBitTransport: public DataBuffer<uint8_t, 64> {
uint8_t byte;
uint8_t bits_count;
void initFrame()
void initFrame(uint32_t period)
{
initBuffer();
byte = 0;
@ -97,10 +103,10 @@ class PwmPxxBitTransport: public PulsesBuffer<pulse_duration_t, 200> {
protected:
uint16_t rest;
void initFrame()
void initFrame(uint32_t period)
{
initBuffer();
rest = PXX_PERIOD_HALF_US;
rest = period * 2000; // 0.5uS (2Mhz)
}
void addPart(uint8_t value)

View file

@ -216,20 +216,24 @@ void Pxx1Pulses<PxxTransport>::add8ChannelsFrame(uint8_t module, uint8_t sendUpp
template <class PxxTransport>
void Pxx1Pulses<PxxTransport>::setupFrame(uint8_t module)
{
PxxTransport::initFrame();
PxxTransport::initFrame(module == INTERNAL_MODULE ? INTMODULE_PXX_PERIOD : EXTMODULE_PXX_PERIOD);
#if defined(PXX_FREQUENCY_HIGH)
if (module == INTERNAL_MODULE) {
add8ChannelsFrame(module, 0);
if (sentModuleChannels(module) > 8) {
add8ChannelsFrame(module, 8);
}
#else
return;
}
#endif
uint8_t sendUpperChannels = 0;
if (moduleSettings[module].counter & 0x01) {
sendUpperChannels = g_model.moduleData[module].channelsCount;
}
add8ChannelsFrame(module, sendUpperChannels);
#endif
}
template class Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport> >;

View file

@ -44,9 +44,9 @@ class StandardPxx1Transport: public BitTransport, public Pxx1CrcMixin {
protected:
uint8_t ones_count;
void initFrame()
void initFrame(uint32_t period)
{
BitTransport::initFrame();
BitTransport::initFrame(period);
ones_count = 0;
}
@ -93,7 +93,7 @@ class StandardPxx1Transport: public BitTransport, public Pxx1CrcMixin {
class UartPxx1Transport: public DataBuffer<uint8_t, 64>, public Pxx1CrcMixin {
protected:
void initFrame()
void initFrame(uint32_t period)
{
initBuffer();
}

View file

@ -197,7 +197,7 @@ extern "C" void EXTMODULE_USART_IRQHandler(void)
void extmodulePxx2Start()
{
extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE);
extmoduleInvertedSerialStart(EXTMODULE_USART_PXX2_BAUDRATE);
}
#else
void extmodulePxx2Start()
@ -223,7 +223,7 @@ void extmodulePxxStart()
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
EXTMODULE_TIMER->ARR = PXX_PERIOD_HALF_US;
EXTMODULE_TIMER->ARR = EXTMODULE_PXX_PERIOD * 2000; // 0.5uS (2Mhz)
EXTMODULE_TIMER->CCER = EXTMODULE_TIMER_OUTPUT_ENABLE | EXTMODULE_TIMER_OUTPUT_POLARITY; // polarity, default low
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE; // Enable outputs
EXTMODULE_TIMER->CCR1 = 18;

View file

@ -288,7 +288,7 @@ void telemetryInit(uint8_t protocol)
#endif
else if (protocol == PROTOCOL_TELEMETRY_PXX2) {
telemetryPortInit(PXX2_BAUDRATE, TELEMETRY_SERIAL_WITHOUT_DMA);
telemetryPortInit(PXX2_ON_SPORT_BAUDRATE, TELEMETRY_SERIAL_WITHOUT_DMA);
#if defined(LUA)
outputTelemetryBufferSize = 0;
outputTelemetryBufferTrigger = 0x7E;