Pulses refactoring (another one!) (#6510)
Pulses refactoring (another one!)
This commit is contained in:
@@ -197,7 +197,6 @@ set(FIRMWARE_TARGET_SRC
|
||||
|
||||
set(TARGET_SRC
|
||||
${TARGET_SRC}
|
||||
pulses_driver.cpp
|
||||
keys_driver.cpp
|
||||
telemetry_driver.cpp
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ void intmoduleStop()
|
||||
GPIO_ResetBits(INTMODULE_GPIO, INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN);
|
||||
}
|
||||
|
||||
void intmodulePxxStart()
|
||||
void intmodulePxx1SerialStart()
|
||||
{
|
||||
intmoduleSerialStart(INTMODULE_PXX_BAUDRATE, false);
|
||||
}
|
||||
|
||||
@@ -208,31 +208,15 @@ void SDRAM_Init(void);
|
||||
#define IS_PXX1_INTERNAL_ENABLED() (true)
|
||||
#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 check_intmodule_heartbeat();
|
||||
|
||||
void intmoduleStop();
|
||||
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable);
|
||||
void intmodulePxxStart();
|
||||
void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
|
||||
void intmoduleSendNextFrame();
|
||||
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us, bool inverted);
|
||||
void extmoduleSendNextFrame();
|
||||
void extmoduleStop();
|
||||
void extmodulePpmStart();
|
||||
void extmodulePxxStart();
|
||||
void extmodulePxx2Start();
|
||||
|
||||
// Trainer driver
|
||||
void init_trainer_ppm(void);
|
||||
|
||||
@@ -83,7 +83,7 @@ void extmodulePpmStart()
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
void extmodulePxxStart()
|
||||
void extmodulePxx1PulsesStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
@@ -127,11 +127,6 @@ void extmodulePxxStart()
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_IRQn, 7);
|
||||
}
|
||||
|
||||
void extmodulePxx2Start()
|
||||
{
|
||||
// TODO just enable the S.PORT line (or let telemetry init do it)
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
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->SR &= ~TIM_SR_CC2IF;
|
||||
if (setupPulses(EXTERNAL_MODULE))
|
||||
if (setupPulsesExternalModule())
|
||||
extmoduleSendNextFrame();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -60,6 +60,7 @@ Pio Pioa, Piob, Pioc;
|
||||
Pmc pmc;
|
||||
Ssc ssc;
|
||||
Pwm pwm;
|
||||
Tc tc1;
|
||||
Twi Twio;
|
||||
Usart Usart0;
|
||||
Dacc dacc;
|
||||
|
||||
@@ -172,6 +172,12 @@ extern Pmc pmc;
|
||||
extern Ssc ssc;
|
||||
#undef 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 Twi Twio;
|
||||
extern Dacc dacc;
|
||||
|
||||
@@ -229,14 +229,6 @@ uint32_t readTrims(void);
|
||||
#define KEYS_PRESSED() readKeys()
|
||||
|
||||
// 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 extmoduleSendNextFrame();
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ void init_second_ppm(uint32_t period)
|
||||
setExtraModulePolarity();
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO re-add it later
|
||||
void disable_second_ppm()
|
||||
{
|
||||
Pio * pioptr = PIOC;
|
||||
@@ -115,16 +117,6 @@ void disable_second_ppm()
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void disable_module_timer(uint32_t port)
|
||||
void extmodulePpmStart()
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
init_main_ppm(3000, 1);
|
||||
}
|
||||
|
||||
void init_ppm(uint32_t port)
|
||||
void extramodulePpmStart()
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
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();
|
||||
}
|
||||
init_second_ppm(3000);
|
||||
}
|
||||
|
||||
// Initialise the SSC to allow PXX output.
|
||||
@@ -201,26 +177,16 @@ void disable_ssc()
|
||||
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_ssc(125); // 8us per bit
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125); // 8us per bit
|
||||
}
|
||||
|
||||
void disable_pxx1_pulses(uint32_t port)
|
||||
void extmoduleStop()
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
disable_ppm(EXTERNAL_MODULE);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
disable_ssc();
|
||||
disable_main_ppm();
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
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
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setupPulsesExternalModule();
|
||||
setExternalModulePolarity();
|
||||
}
|
||||
else {
|
||||
@@ -297,7 +252,7 @@ extern "C" void PWM_IRQHandler(void)
|
||||
}
|
||||
pwmptr->PWM_CH_NUM[3].PWM_CPDRUPD = period; // Period in half uS
|
||||
if (period != 2500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
else {
|
||||
// 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
|
||||
if (period != 3500 * 2) {
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
else {
|
||||
// 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++;
|
||||
if (*extmodulePulsesData.ppm.ptr == 0) {
|
||||
setExternalModulePolarity();
|
||||
setupPulses(EXTERNAL_MODULE);
|
||||
setupPulsesExternalModule();
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ if(PCB STREQUAL XLITE OR PCB STREQUAL XLITES OR PCB STREQUAL X9LITE)
|
||||
${TARGET_SRC}
|
||||
../common/arm/stm32/intmodule_serial_driver.cpp
|
||||
)
|
||||
else()
|
||||
elseif(NOT (PCB STREQUAL X7 AND PCBREV STREQUAL T12))
|
||||
set(TARGET_SRC
|
||||
${TARGET_SRC}
|
||||
intmodule_pulses_driver.cpp
|
||||
|
||||
@@ -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)
|
||||
#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);
|
||||
#if defined(INTERNAL_MODULE_PPM)
|
||||
void intmodulePpmStart(void);
|
||||
#endif
|
||||
void intmoduleSendBuffer(const uint8_t * data, uint8_t size);
|
||||
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 extmoduleInvertedSerialStart(uint32_t baudrate);
|
||||
void extmoduleSendBuffer(const uint8_t * data, uint8_t size);
|
||||
|
||||
@@ -196,20 +196,10 @@ extern "C" void EXTMODULE_USART_IRQHandler(void)
|
||||
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
|
||||
|
||||
#if defined(PXX1)
|
||||
void extmodulePxxPulsesStart()
|
||||
void extmodulePxx1PulsesStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
@@ -246,7 +236,7 @@ void extmodulePxxPulsesStart()
|
||||
#endif
|
||||
|
||||
#if defined(PXX1) && defined(EXTMODULE_USART)
|
||||
void extmodulePxxSerialStart()
|
||||
void extmodulePxx1SerialStart()
|
||||
{
|
||||
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->SR &= ~TIM_SR_CC2IF;
|
||||
if (setupPulses(EXTERNAL_MODULE)) {
|
||||
if (setupPulsesExternalModule()) {
|
||||
extmoduleSendNextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +83,7 @@ void intmoduleSendNextFrame()
|
||||
}
|
||||
}
|
||||
|
||||
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable)
|
||||
{
|
||||
// nothing, the pulses will be sent through telemetry port
|
||||
}
|
||||
|
||||
void intmodulePxxStart()
|
||||
void intmodulePxx1PulsesStart()
|
||||
{
|
||||
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->SR &= ~TIM_SR_CC2IF;
|
||||
if (setupPulses(INTERNAL_MODULE)) {
|
||||
if (setupPulsesInternalModule()) {
|
||||
intmoduleSendNextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user