Pulses refactoring (another one!) (#6510)

Pulses refactoring (another one!)
This commit is contained in:
Bertrand Songis
2019-06-17 12:02:42 +02:00
committed by GitHub
parent 1f1ccf277c
commit b20e4a6be4
18 changed files with 183 additions and 494 deletions
+25 -10
View File
@@ -359,15 +359,18 @@ void FrskyDeviceFirmwareUpdate::flashFirmware(const char * filename)
{ {
pausePulses(); pausePulses();
#if defined(HARDWARE_INTERNAL_MODULE)
uint8_t intPwr = IS_INTERNAL_MODULE_ON(); uint8_t intPwr = IS_INTERNAL_MODULE_ON();
INTERNAL_MODULE_OFF();
#endif
uint8_t extPwr = IS_EXTERNAL_MODULE_ON(); uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF();
drawProgressScreen(getBasename(filename), STR_DEVICE_RESET, 0, 0); drawProgressScreen(getBasename(filename), STR_DEVICE_RESET, 0, 0);
INTERNAL_MODULE_OFF();
EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF();
/* wait 2s off */ /* wait 2s off */
watchdogSuspend(2000); watchdogSuspend(2000);
RTOS_WAIT_MS(2000); RTOS_WAIT_MS(2000);
@@ -399,13 +402,16 @@ void FrskyDeviceFirmwareUpdate::flashFirmware(const char * filename)
RTOS_WAIT_MS(2000); RTOS_WAIT_MS(2000);
telemetryClearFifo(); telemetryClearFifo();
#if defined(HARDWARE_INTERNAL_MODULE)
if (intPwr) { if (intPwr) {
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
setupPulses(INTERNAL_MODULE); setupPulsesInternalModule();
} }
#endif
if (extPwr) { if (extPwr) {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
} }
state = SPORT_IDLE; state = SPORT_IDLE;
@@ -620,11 +626,14 @@ void FrskyChipFirmwareUpdate::flashFirmware(const char * filename)
pausePulses(); pausePulses();
#if defined(HARDWARE_INTERNAL_MODULE)
uint8_t intPwr = IS_INTERNAL_MODULE_ON(); uint8_t intPwr = IS_INTERNAL_MODULE_ON();
uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
#endif
uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
EXTERNAL_MODULE_OFF(); EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF(); SPORT_UPDATE_POWER_OFF();
/* wait 2s off */ /* wait 2s off */
@@ -646,7 +655,10 @@ void FrskyChipFirmwareUpdate::flashFirmware(const char * filename)
POPUP_INFORMATION(STR_FIRMWARE_UPDATE_SUCCESS); POPUP_INFORMATION(STR_FIRMWARE_UPDATE_SUCCESS);
} }
#if defined(HARDWARE_INTERNAL_MODULE)
INTERNAL_MODULE_OFF(); INTERNAL_MODULE_OFF();
#endif
EXTERNAL_MODULE_OFF(); EXTERNAL_MODULE_OFF();
SPORT_UPDATE_POWER_OFF(); SPORT_UPDATE_POWER_OFF();
@@ -654,13 +666,16 @@ void FrskyChipFirmwareUpdate::flashFirmware(const char * filename)
watchdogSuspend(2000); watchdogSuspend(2000);
RTOS_WAIT_MS(2000); RTOS_WAIT_MS(2000);
#if defined(HARDWARE_INTERNAL_MODULE)
if (intPwr) { if (intPwr) {
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
setupPulses(INTERNAL_MODULE); setupPulsesInternalModule();
} }
#endif
if (extPwr) { if (extPwr) {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
} }
resumePulses(); resumePulses();
+102 -127
View File
@@ -133,76 +133,21 @@ uint8_t getRequiredProtocol(uint8_t module)
return protocol; return protocol;
} }
void disablePulses(uint8_t module, uint8_t protocol) void enablePulsesExternalModule(uint8_t protocol)
{
// stop existing protocol hardware
switch (protocol) {
#if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1_PULSES:
disable_pxx1_pulses(module);
break;
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
disable_pxx1_serial(module);
break;
#endif
#endif
#if defined(DSM2)
case PROTOCOL_CHANNELS_DSM2_LP45:
case PROTOCOL_CHANNELS_DSM2_DSM2:
case PROTOCOL_CHANNELS_DSM2_DSMX:
disable_serial(module);
break;
#endif
#if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_CROSSFIRE:
// TODO disable_module_timer(module);
break;
#endif
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2:
disable_pxx2(module);
break;
#endif
#if defined(MULTIMODULE)
case PROTOCOL_CHANNELS_MULTIMODULE:
#endif
#if defined(SBUS)
case PROTOCOL_CHANNELS_SBUS:
disable_serial(module);
break;
#endif
#if defined(PPM)
case PROTOCOL_CHANNELS_PPM:
disable_ppm(module);
break;
#endif
}
}
void enablePulses(uint8_t module, uint8_t protocol)
{ {
// start new protocol hardware here // start new protocol hardware here
switch (protocol) { switch (protocol) {
#if defined(PXX1) #if defined(PXX1)
case PROTOCOL_CHANNELS_PXX1_PULSES: case PROTOCOL_CHANNELS_PXX1_PULSES:
init_pxx1_pulses(module); extmodulePxx1PulsesStart();
break;
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
init_pxx1_serial(module);
break; break;
#endif #endif
#if defined(PXX1) && defined(EXTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
extmodulePxx1SerialStart();
break;
#endif #endif
#if defined(DSM2) #if defined(DSM2)
@@ -215,13 +160,13 @@ void enablePulses(uint8_t module, uint8_t protocol)
#if defined(CROSSFIRE) #if defined(CROSSFIRE)
case PROTOCOL_CHANNELS_CROSSFIRE: case PROTOCOL_CHANNELS_CROSSFIRE:
// TODO init_module_timer(module, CROSSFIRE_PERIOD, true); EXTERNAL_MODULE_ON();
break; break;
#endif #endif
#if defined(PXX2) #if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2: case PROTOCOL_CHANNELS_PXX2:
init_pxx2(module); extmoduleInvertedSerialStart(PXX2_EXTERNAL_MODULE_BAUDRATE);
break; break;
#endif #endif
@@ -239,54 +184,7 @@ void enablePulses(uint8_t module, uint8_t protocol)
#if defined(PPM) #if defined(PPM)
case PROTOCOL_CHANNELS_PPM: case PROTOCOL_CHANNELS_PPM:
init_ppm(module); extmodulePpmStart();
break;
#endif
default:
// TODO some reworking needed here ...
#if defined(PXX2)
disable_pxx2(module);
#endif
break;
}
}
void setupPulsesInternalModule(uint8_t protocol)
{
switch (protocol) {
#if defined(HARDWARE_INTERNAL_MODULE) && defined(PXX1) && !defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_PULSES:
intmodulePulsesData.pxx.setupFrame(INTERNAL_MODULE);
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX_PERIOD);
break;
#endif
#if defined(PXX1) && defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
intmodulePulsesData.pxx_uart.setupFrame(INTERNAL_MODULE);
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX_PERIOD);
break;
#endif
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2:
intmodulePulsesData.pxx2.setupFrame(INTERNAL_MODULE);
if (moduleState[INTERNAL_MODULE].mode == MODULE_MODE_SPECTRUM_ANALYSER || moduleState[INTERNAL_MODULE].mode == MODULE_MODE_POWER_METER) {
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_TOOLS_PERIOD);
}
#if !defined(INTMODULE_HEARTBEAT)
else {
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_PERIOD);
}
#endif
break;
#endif
#if defined(PCBTARANIS) && defined(INTERNAL_MODULE_PPM)
case PROTOCOL_CHANNELS_PPM:
setupPulsesPPM(&extmodulePulsesData.ppm, g_model.moduleData[INTERNAL_MODULE].channelsStart, g_model.moduleData[INTERNAL_MODULE].channelsCount, g_model.moduleData[INTERNAL_MODULE].ppm.frameLength);
scheduleNextMixerCalculation(INTERNAL_MODULE, PPM_PERIOD(INTERNAL_MODULE));
break; break;
#endif #endif
@@ -361,35 +259,112 @@ void setupPulsesExternalModule(uint8_t protocol)
} }
} }
void setupPulses(uint8_t module, uint8_t protocol)
{
switch (module) {
#if defined(HARDWARE_INTERNAL_MODULE) #if defined(HARDWARE_INTERNAL_MODULE)
case INTERNAL_MODULE:
setupPulsesInternalModule(protocol); void enablePulsesInternalModule(uint8_t protocol)
{
// start new protocol hardware here
switch (protocol) {
#if defined(PXX1) && !defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_PULSES:
intmodulePxx1PulsesStart();
break; break;
#endif #endif
case EXTERNAL_MODULE: #if defined(PXX1) && defined(INTMODULE_USART)
setupPulsesExternalModule(protocol); case PROTOCOL_CHANNELS_PXX1_SERIAL:
intmodulePxx1SerialStart();
break;
#endif
#if defined(PXX2)
case PROTOCOL_CHANNELS_PXX2:
intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, true);
break;
#endif
default:
break; break;
} }
} }
bool setupPulses(uint8_t module) void setupPulsesInternalModule(uint8_t protocol)
{ {
uint8_t protocol = getRequiredProtocol(module); switch (protocol) {
#if defined(HARDWARE_INTERNAL_MODULE) && defined(PXX1) && !defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_PULSES:
intmodulePulsesData.pxx.setupFrame(INTERNAL_MODULE);
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX_PERIOD);
break;
#endif
heartbeat |= (HEART_TIMER_PULSES << module); #if defined(PXX1) && defined(INTMODULE_USART)
case PROTOCOL_CHANNELS_PXX1_SERIAL:
intmodulePulsesData.pxx_uart.setupFrame(INTERNAL_MODULE);
scheduleNextMixerCalculation(INTERNAL_MODULE, INTMODULE_PXX_PERIOD);
break;
#endif
if (moduleState[module].protocol != protocol) { #if defined(PXX2)
disablePulses(module, moduleState[module].protocol); case PROTOCOL_CHANNELS_PXX2:
moduleState[module].protocol = protocol; intmodulePulsesData.pxx2.setupFrame(INTERNAL_MODULE);
enablePulses(module, protocol); if (moduleState[INTERNAL_MODULE].mode == MODULE_MODE_SPECTRUM_ANALYSER || moduleState[INTERNAL_MODULE].mode == MODULE_MODE_POWER_METER) {
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_TOOLS_PERIOD);
}
#if !defined(INTMODULE_HEARTBEAT)
else {
scheduleNextMixerCalculation(INTERNAL_MODULE, PXX2_PERIOD);
}
#endif
break;
#endif
#if defined(PCBTARANIS) && defined(INTERNAL_MODULE_PPM)
case PROTOCOL_CHANNELS_PPM:
setupPulsesPPM(&extmodulePulsesData.ppm, g_model.moduleData[INTERNAL_MODULE].channelsStart, g_model.moduleData[INTERNAL_MODULE].channelsCount, g_model.moduleData[INTERNAL_MODULE].ppm.frameLength);
scheduleNextMixerCalculation(INTERNAL_MODULE, PPM_PERIOD(INTERNAL_MODULE));
break;
#endif
default:
break;
}
}
bool setupPulsesInternalModule()
{
uint8_t protocol = getRequiredProtocol(INTERNAL_MODULE);
heartbeat |= (HEART_TIMER_PULSES << INTERNAL_MODULE);
if (moduleState[INTERNAL_MODULE].protocol != protocol) {
intmoduleStop();
moduleState[INTERNAL_MODULE].protocol = protocol;
enablePulsesInternalModule(protocol);
return false; return false;
} }
else { else {
setupPulses(module, protocol); setupPulsesInternalModule(protocol);
return true;
}
}
#endif
bool setupPulsesExternalModule()
{
uint8_t protocol = getRequiredProtocol(EXTERNAL_MODULE);
heartbeat |= (HEART_TIMER_PULSES << EXTERNAL_MODULE);
if (moduleState[EXTERNAL_MODULE].protocol != protocol) {
extmoduleStop();
moduleState[EXTERNAL_MODULE].protocol = protocol;
enablePulsesExternalModule(protocol);
return false;
}
else {
setupPulsesExternalModule(protocol);
return true; return true;
} }
} }
+14 -15
View File
@@ -302,7 +302,8 @@ union TrainerPulsesData {
extern TrainerPulsesData trainerPulsesData; extern TrainerPulsesData trainerPulsesData;
bool setupPulses(uint8_t module); bool setupPulsesInternalModule();
bool setupPulsesExternalModule();
void setupPulsesDSM2(); void setupPulsesDSM2();
void setupPulsesCrossfire(); void setupPulsesCrossfire();
void setupPulsesMultimodule(); void setupPulsesMultimodule();
@@ -314,28 +315,26 @@ void sendByteDsm2(uint8_t b);
void putDsm2Flush(); void putDsm2Flush();
void putDsm2SerialBit(uint8_t bit); void putDsm2SerialBit(uint8_t bit);
void sendByteSbus(uint8_t b); void sendByteSbus(uint8_t b);
void intmodulePxx1PulsesStart();
#if defined(HUBSAN) void intmodulePxx1SerialStart();
void Hubsan_Init(); void extmodulePxx1PulsesStart();
#endif void extmodulePxx1SerialStart();
void extmodulePpmStart();
void intmoduleStop();
void extmoduleStop();
inline void startPulses() inline void startPulses()
{ {
s_pulses_paused = false; s_pulses_paused = false;
#if defined(PCBTARANIS) || defined(PCBHORUS) #if defined(HARDWARE_INTERNAL_MODULE)
setupPulses(INTERNAL_MODULE); setupPulsesInternalModule();
setupPulses(EXTERNAL_MODULE);
#else
setupPulses(EXTERNAL_MODULE);
#endif #endif
#if defined(PCBSKY9X) setupPulsesExternalModule();
init_ppm(EXTRA_MODULE);
#endif
#if defined(HUBSAN) #if defined(HARDWARE_EXTRA_MODULE)
Hubsan_Init(); extramodulePpmStart();
#endif #endif
} }
@@ -197,7 +197,6 @@ set(FIRMWARE_TARGET_SRC
set(TARGET_SRC set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
pulses_driver.cpp
keys_driver.cpp keys_driver.cpp
telemetry_driver.cpp telemetry_driver.cpp
) )
@@ -41,7 +41,7 @@ void intmoduleStop()
GPIO_ResetBits(INTMODULE_GPIO, INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN); GPIO_ResetBits(INTMODULE_GPIO, INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN);
} }
void intmodulePxxStart() void intmodulePxx1SerialStart()
{ {
intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, false); intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, false);
} }
-16
View File
@@ -208,31 +208,15 @@ void SDRAM_Init(void);
#define IS_PXX1_INTERNAL_ENABLED() (true) #define IS_PXX1_INTERNAL_ENABLED() (true)
#endif #endif
void init_ppm(uint8_t module);
void disable_ppm(uint8_t module);
void init_pxx1_pulses(uint8_t module);
void init_pxx1_serial(uint8_t module);
void disable_pxx1_pulses(uint8_t module);
void disable_pxx1_serial(uint8_t module);
void init_pxx2(uint8_t module);
void disable_pxx2(uint8_t module);
void disable_serial(uint8_t module);
void init_intmodule_heartbeat(); void init_intmodule_heartbeat();
void check_intmodule_heartbeat(); void check_intmodule_heartbeat();
void intmoduleStop();
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable); void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable);
void intmodulePxxStart();
void intmoduleSendBuffer(const uint8_t * data, uint8_t size); void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
void intmoduleSendNextFrame(); void intmoduleSendNextFrame();
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted);
void extmoduleSendNextFrame(); void extmoduleSendNextFrame();
void extmoduleStop();
void extmodulePpmStart();
void extmodulePxxStart();
void extmodulePxx2Start();
// Trainer driver // Trainer driver
void init_trainer_ppm(void); void init_trainer_ppm(void);
+2 -7
View File
@@ -83,7 +83,7 @@ void extmodulePpmStart()
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
} }
void extmodulePxxStart() void extmodulePxx1PulsesStart()
{ {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
@@ -127,11 +127,6 @@ void extmodulePxxStart()
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7); NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
} }
void extmodulePxx2Start()
{
// TODO just enable the S.PORT line (or let telemetry init do it)
}
#if defined(DSM2) #if defined(DSM2)
void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us, bool inverted) void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us, bool inverted)
{ {
@@ -284,6 +279,6 @@ extern "C" void EXTMODULE_TIMER_IRQHandler()
{ {
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
if (setupPulses(EXTERNAL_MODULE)) if (setupPulsesExternalModule())
extmoduleSendNextFrame(); extmoduleSendNextFrame();
} }
-93
View File
@@ -1,93 +0,0 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
void init_ppm(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmodulePpmStart();
}
}
void disable_ppm(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmoduleStop();
}
}
void init_pxx2(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, true);
else
extmodulePxx2Start();
}
void disable_pxx2(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
void init_pxx1_pulses(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmodulePxxStart();
else
extmodulePxxStart();
}
void init_pxx1_serial(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmodulePxxStart();
else
extmodulePxxStart();
}
void disable_pxx1_pulses(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
void disable_pxx1_serial(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
#if defined(DSM2)
void disable_serial(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmoduleStop();
}
}
#endif
+1
View File
@@ -60,6 +60,7 @@ Pio Pioa, Piob, Pioc;
Pmc pmc; Pmc pmc;
Ssc ssc; Ssc ssc;
Pwm pwm; Pwm pwm;
Tc tc1;
Twi Twio; Twi Twio;
Usart Usart0; Usart Usart0;
Dacc dacc; Dacc dacc;
+6
View File
@@ -172,6 +172,12 @@ extern Pmc pmc;
extern Ssc ssc; extern Ssc ssc;
#undef SSC #undef SSC
#define SSC (&ssc) #define SSC (&ssc)
extern Pmc pmc;
#undef PMC
#define PMC (&pmc)
extern Tc tc1;
#undef TC1
#define TC1 (&tc1)
extern Pio Pioa, Piob, Pioc; extern Pio Pioa, Piob, Pioc;
extern Twi Twio; extern Twi Twio;
extern Dacc dacc; extern Dacc dacc;
-8
View File
@@ -229,14 +229,6 @@ uint32_t readTrims(void);
#define KEYS_PRESSED() readKeys() #define KEYS_PRESSED() readKeys()
// Pulses driver // Pulses driver
void init_no_pulses(uint32_t port);
void init_ppm(uint32_t port);
void disable_ppm(uint32_t port);
void init_pxx1_pulses(uint32_t port);
void disable_pxx1_pulses(uint32_t port);
void disable_serial(uint32_t port);
void init_module_timer( uint32_t module_index, uint32_t period, uint8_t state);
void disable_module_timer( uint32_t module_index);
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted);
void extmoduleSendNextFrame(); void extmoduleSendNextFrame();
+18 -63
View File
@@ -108,6 +108,8 @@ void init_second_ppm(uint32_t period)
setExtraModulePolarity(); setExtraModulePolarity();
} }
/*
// TODO re-add it later
void disable_second_ppm() void disable_second_ppm()
{ {
Pio * pioptr = PIOC; Pio * pioptr = PIOC;
@@ -115,16 +117,6 @@ void disable_second_ppm()
PWM->PWM_IDR1 = PWM_IDR1_CHID1; PWM->PWM_IDR1 = PWM_IDR1_CHID1;
} }
void init_no_pulses(uint32_t port)
{
if (port == EXTERNAL_MODULE) {
init_main_ppm(3000, 0);
}
else {
// TODO
}
}
void init_module_timer(uint32_t port, uint32_t period, uint8_t state) void init_module_timer(uint32_t port, uint32_t period, uint8_t state)
{ {
if (port == EXTERNAL_MODULE) { if (port == EXTERNAL_MODULE) {
@@ -132,32 +124,16 @@ void init_module_timer(uint32_t port, uint32_t period, uint8_t state)
init_main_ppm(3000, 0); init_main_ppm(3000, 0);
} }
} }
*/
void disable_module_timer(uint32_t port) void extmodulePpmStart()
{ {
if (port == EXTERNAL_MODULE) { init_main_ppm(3000, 1);
disable_ppm(EXTERNAL_MODULE);
}
} }
void init_ppm(uint32_t port) void extramodulePpmStart()
{ {
if (port == EXTERNAL_MODULE) { init_second_ppm(3000);
init_main_ppm(3000, 1);
}
else {
init_second_ppm(3000);
}
}
void disable_ppm(uint32_t port)
{
if (port == EXTERNAL_MODULE) {
disable_main_ppm();
}
else {
disable_second_ppm();
}
} }
// Initialise the SSC to allow PXX output. // Initialise the SSC to allow PXX output.
@@ -201,26 +177,16 @@ void disable_ssc()
sscptr->SSC_CR = SSC_CR_TXDIS; sscptr->SSC_CR = SSC_CR_TXDIS;
} }
void init_pxx1_pulses(uint32_t port) void extmodulePxx1PulsesStart()
{ {
if (port == EXTERNAL_MODULE) { init_main_ppm(2500 * 2, 0);
init_main_ppm(2500 * 2, 0); init_ssc(125); // 8us per bit
init_ssc(125); // 8us per bit
}
else {
// TODO
}
} }
void disable_pxx1_pulses(uint32_t port) void extmoduleStop()
{ {
if (port == EXTERNAL_MODULE) { disable_ssc();
disable_ssc(); disable_main_ppm();
disable_ppm(EXTERNAL_MODULE);
}
else {
// TODO
}
} }
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted) void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted)
@@ -236,21 +202,10 @@ void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inver
} }
} }
void disable_serial(uint32_t port)
{
if (port == EXTERNAL_MODULE) {
disable_ssc();
disable_ppm(EXTERNAL_MODULE);
}
else {
// TODO
}
}
void extmoduleSendNextFrame() void extmoduleSendNextFrame()
{ {
} }
#if !defined(SIMU) #if !defined(SIMU)
extern "C" void PWM_IRQHandler(void) extern "C" void PWM_IRQHandler(void)
{ {
@@ -272,7 +227,7 @@ extern "C" void PWM_IRQHandler(void)
} }
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
if (period != 2500 * 2) { if (period != 2500 * 2) {
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
setExternalModulePolarity(); setExternalModulePolarity();
} }
else { else {
@@ -297,7 +252,7 @@ extern "C" void PWM_IRQHandler(void)
} }
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
if (period != 2500 * 2) { if (period != 2500 * 2) {
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
} }
else { else {
// Kick off serial output here // Kick off serial output here
@@ -323,7 +278,7 @@ extern "C" void PWM_IRQHandler(void)
} }
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
if (period != 3500 * 2) { if (period != 3500 * 2) {
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
} }
else { else {
// Kick off serial output here // Kick off serial output here
@@ -338,7 +293,7 @@ extern "C" void PWM_IRQHandler(void)
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = *extmodulePulsesData.ppm.ptr++; pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = *extmodulePulsesData.ppm.ptr++;
if (*extmodulePulsesData.ppm.ptr == 0) { if (*extmodulePulsesData.ppm.ptr == 0) {
setExternalModulePolarity(); setExternalModulePolarity();
setupPulses(EXTERNAL_MODULE); setupPulsesExternalModule();
} }
break; break;
+1 -1
View File
@@ -178,7 +178,7 @@ if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES OR PCB STREQUAL X9LITE)
${TARGET_SRC} ${TARGET_SRC}
../common/arm/stm32/intmodule_serial_driver.cpp ../common/arm/stm32/intmodule_serial_driver.cpp
) )
else() elseif(NOT (PCB STREQUAL X7 AND PCBREV STREQUAL T12))
set(TARGET_SRC set(TARGET_SRC
${TARGET_SRC} ${TARGET_SRC}
intmodule_pulses_driver.cpp intmodule_pulses_driver.cpp
-19
View File
@@ -199,29 +199,10 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
#define IS_INTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) == Bit_SET) #define IS_INTERNAL_MODULE_ON() (GPIO_ReadInputDataBit(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN) == Bit_SET)
#endif #endif
void init_ppm(uint8_t module);
void disable_ppm(uint8_t module);
void init_pxx2(uint8_t module);
void disable_pxx2(uint8_t module);
void init_pxx1_pulses(uint8_t module);
void init_pxx1_serial(uint8_t module);
void disable_pxx1_pulses(uint8_t module);
void disable_pxx1_serial(uint8_t module);
void disable_serial(uint8_t module);
void intmoduleStop();
void intmodulePxxStart();
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable); void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable);
#if defined(INTERNAL_MODULE_PPM)
void intmodulePpmStart(void);
#endif
void intmoduleSendBuffer(const uint8_t * data, uint8_t size); void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
void intmoduleSendNextFrame(); void intmoduleSendNextFrame();
void extmoduleStop();
void extmodulePpmStart();
void extmodulePxxPulsesStart();
void extmodulePxxSerialStart();
void extmodulePxx2Start();
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted); void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted);
void extmoduleInvertedSerialStart(uint32_t baudrate); void extmoduleInvertedSerialStart(uint32_t baudrate);
void extmoduleSendBuffer(const uint8_t * data, uint8_t size); void extmoduleSendBuffer(const uint8_t * data, uint8_t size);
+3 -13
View File
@@ -196,20 +196,10 @@ extern "C" void EXTMODULE_USART_IRQHandler(void)
status = EXTMODULE_USART->SR; status = EXTMODULE_USART->SR;
} }
} }
void extmodulePxx2Start()
{
extmoduleInvertedSerialStart(PXX2_EXTERNAL_MODULE_BAUDRATE);
}
#else
void extmodulePxx2Start()
{
// TODO just enable the S.PORT line (or let telemetry init do it)
}
#endif #endif
#if defined(PXX1) #if defined(PXX1)
void extmodulePxxPulsesStart() void extmodulePxx1PulsesStart()
{ {
EXTERNAL_MODULE_ON(); EXTERNAL_MODULE_ON();
@@ -246,7 +236,7 @@ void extmodulePxxPulsesStart()
#endif #endif
#if defined(PXX1) && defined(EXTMODULE_USART) #if defined(PXX1) && defined(EXTMODULE_USART)
void extmodulePxxSerialStart() void extmodulePxx1SerialStart()
{ {
extmoduleInvertedSerialStart(EXTMODULE_PXX_SERIAL_BAUDRATE); extmoduleInvertedSerialStart(EXTMODULE_PXX_SERIAL_BAUDRATE);
} }
@@ -340,7 +330,7 @@ extern "C" void EXTMODULE_TIMER_CC_IRQHandler()
{ {
EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt EXTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
if (setupPulses(EXTERNAL_MODULE)) { if (setupPulsesExternalModule()) {
extmoduleSendNextFrame(); extmoduleSendNextFrame();
} }
} }
@@ -83,12 +83,7 @@ void intmoduleSendNextFrame()
} }
} }
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable) void intmodulePxx1PulsesStart()
{
// nothing, the pulses will be sent through telemetry port
}
void intmodulePxxStart()
{ {
INTERNAL_MODULE_ON(); INTERNAL_MODULE_ON();
@@ -172,7 +167,7 @@ extern "C" void INTMODULE_TIMER_CC_IRQHandler()
{ {
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE; // Stop this interrupt
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
if (setupPulses(INTERNAL_MODULE)) { if (setupPulsesInternalModule()) {
intmoduleSendNextFrame(); intmoduleSendNextFrame();
} }
} }
-106
View File
@@ -1,106 +0,0 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#if defined(PXX1)
void init_pxx1_pulses(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmodulePxxStart();
else
extmodulePxxPulsesStart();
}
void init_pxx1_serial(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmodulePxxStart();
#if defined(EXTMODULE_USART)
else
extmodulePxxSerialStart();
#endif
}
void disable_pxx1_pulses(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
void disable_pxx1_serial(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
#endif
void init_pxx2(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, true);
else
extmodulePxx2Start();
}
void disable_pxx2(uint8_t module)
{
if (module == INTERNAL_MODULE)
intmoduleStop();
else
extmoduleStop();
}
#if defined(DSM2)
void disable_serial(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmoduleStop();
}
}
#endif
void init_ppm(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmodulePpmStart();
}
#if defined(INTERNAL_MODULE_PPM)
else {
intmodulePpmStart();
}
#endif
}
void disable_ppm(uint8_t module)
{
if (module == EXTERNAL_MODULE) {
extmoduleStop();
}
#if defined(INTERNAL_MODULE_PPM)
else {
intmoduleStop();
}
#endif
}
+8 -7
View File
@@ -87,15 +87,16 @@ bool isModuleSynchronous(uint8_t module)
void sendSynchronousPulses() void sendSynchronousPulses()
{ {
for (uint8_t module = 0; module < NUM_MODULES; module++) {
if (isModuleSynchronous(module) && setupPulses(module)) {
#if defined(HARDWARE_INTERNAL_MODULE) #if defined(HARDWARE_INTERNAL_MODULE)
if (module == INTERNAL_MODULE) if (isModuleSynchronous(INTERNAL_MODULE)) {
intmoduleSendNextFrame(); if (setupPulsesInternalModule())
intmoduleSendNextFrame();
}
#endif #endif
if (module == EXTERNAL_MODULE)
extmoduleSendNextFrame(); if (isModuleSynchronous(EXTERNAL_MODULE)) {
} if (setupPulsesExternalModule())
extmoduleSendNextFrame();
} }
} }