New trainer modes:

- Master / SBUS module
- Master / CPPM module
- Master / SBUS in battery compartment
Thanks to Mike for this feature!
This commit is contained in:
bsongis
2014-09-29 07:47:08 +02:00
parent 3aaa4b014b
commit 440cd6a162
12 changed files with 200 additions and 32 deletions
@@ -54,6 +54,19 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0xCCCC ; // start
}
// Start TIMER7 at 2000000Hz
void init2MhzTimer()
{
// Now for timer 7
RCC->APB1ENR |= RCC_APB1ENR_TIM7EN ; // Enable clock
TIM7->PSC = 0 ; // Max speed
TIM7->ARR = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5 uS, 2 MHz
TIM7->CR2 = 0 ;
TIM7->CR2 = 0x20 ;
TIM7->CR1 = TIM_CR1_CEN ;
}
// Starts TIMER at 200Hz, 5mS period
void init5msTimer()
{
@@ -108,6 +121,7 @@ void boardInit()
adcInit();
delaysInit();
audioInit();
init2MhzTimer();
init5msTimer();
__enable_irq();
eepromInit();
+9 -5
View File
@@ -108,7 +108,7 @@ void configure_pins( uint32_t pins, uint16_t config );
extern uint16_t sessionTimer;
#define SLAVE_MODE() (g_model.trainerMode == 1)
#define SLAVE_MODE() (g_model.trainerMode == TRAINER_MODE_SLAVE)
#define TRAINER_CONNECTED() (GPIO_ReadInputDataBit(GPIOTRNDET, PIN_TRNDET) == Bit_RESET)
void delaysInit(void);
@@ -156,6 +156,10 @@ void init_trainer_ppm(void);
void stop_trainer_ppm(void);
void init_trainer_capture(void);
void stop_trainer_capture(void);
void init_cppm_on_heartbeat_capture(void);
void stop_cppm_on_heartbeat_capture(void);
void init_sbus_on_heartbeat_capture(void);
void stop_sbus_on_heartbeat_capture(void);
// Keys driver
void keysInit(void);
@@ -197,8 +201,8 @@ void pwrOff(void);
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
#define INTERNAL_RF_ON() GPIO_SetBits(GPIO_INT_RF_PWR, PIN_INT_RF_PWR)
#define INTERNAL_RF_OFF() GPIO_ResetBits(GPIO_INT_RF_PWR, PIN_INT_RF_PWR)
#define EXTERNAL_RF_ON() GPIO_SetBits(GPIO_EXT_RF_PWR, PIN_EXT_RF_PWR)
#define EXTERNAL_RF_OFF() GPIO_ResetBits(GPIO_EXT_RF_PWR, PIN_EXT_RF_PWR)
#define EXTERNAL_MODULE_ON() GPIO_SetBits(GPIO_EXT_RF_PWR, PIN_EXT_RF_PWR)
#define EXTERNAL_MODULE_OFF() GPIO_ResetBits(GPIO_EXT_RF_PWR, PIN_EXT_RF_PWR)
// Backlight driver
#if defined(REVPLUS)
@@ -259,7 +263,7 @@ void hapticOff(void);
void uart3Init(unsigned int mode, unsigned int protocol);
void uart3Putc(const char c);
#define telemetrySecondPortInit(protocol) uart3Init(UART_MODE_TELEMETRY, protocol)
extern uint8_t currentTrainerMode;
void uart3SbusInit();
void uart3Stop();
#endif
+1
View File
@@ -193,6 +193,7 @@
#define PIN_PER_3 0x0030
#define PIN_PER_5 0x0050
#define PIN_PER_6 0x0060
#define PIN_PER_8 0x0080
// #define PIN_OS2 0x0000
#define PIN_OS25 0x2000
#define PIN_OS50 0x4000
+16 -8
View File
@@ -172,10 +172,11 @@ static void disable_pa10_none()
static void init_pa7_none()
{
EXTERNAL_RF_OFF();
if (!IS_TRAINER_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
// Timer8
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIO_EXTPPM, ENABLE);
@@ -374,7 +375,7 @@ extern "C" void TIM1_UP_TIM10_IRQHandler()
static void init_pa7_pxx()
{
EXTERNAL_RF_ON();
EXTERNAL_MODULE_ON();
// Timer8
setupPulsesPXX(EXTERNAL_MODULE);
@@ -442,13 +443,15 @@ static void disable_pa7_pxx()
NVIC_DisableIRQ(TIM8_CC_IRQn) ;
TIM8->DIER &= ~TIM_DIER_CC2IE ;
TIM8->CR1 &= ~TIM_CR1_CEN ;
EXTERNAL_RF_OFF();
if (!IS_TRAINER_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
}
#if defined(DSM2)
static void init_pa7_dsm2()
{
EXTERNAL_RF_ON();
EXTERNAL_MODULE_ON();
// Timer8
setupPulsesDSM2(EXTERNAL_MODULE);
@@ -516,7 +519,9 @@ static void disable_pa7_dsm2()
NVIC_DisableIRQ(TIM8_CC_IRQn) ;
TIM8->DIER &= ~TIM_DIER_CC2IE ;
TIM8->CR1 &= ~TIM_CR1_CEN ;
EXTERNAL_RF_OFF();
if (!IS_TRAINER_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
}
#endif
@@ -525,7 +530,8 @@ static void disable_pa7_dsm2()
// Pin is AF1 function for timer 1
static void init_pa7_ppm()
{
EXTERNAL_RF_ON();
EXTERNAL_MODULE_ON();
// Timer1
setupPulsesPPM(EXTERNAL_MODULE) ;
ppmStreamPtr[EXTERNAL_MODULE] = ppmStream[EXTERNAL_MODULE];
@@ -573,7 +579,9 @@ static void disable_pa7_ppm()
NVIC_DisableIRQ(TIM8_UP_TIM13_IRQn) ;
TIM8->DIER &= ~TIM_DIER_CC2IE & ~TIM_DIER_UIE ;
TIM8->CR1 &= ~TIM_CR1_CEN ;
EXTERNAL_RF_OFF();
if (!IS_TRAINER_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
}
extern "C" void TIM8_CC_IRQHandler()
+79 -7
View File
@@ -36,9 +36,9 @@
#include "../../opentx.h"
uint8_t currentTrainerMode;
uint16_t * TrainerPulsePtr;
extern uint16_t ppmStream[NUM_MODULES+1][20];
extern Fifo<28> sbusFifo;
#define setupTrainerPulses() setupPulsesPPM(TRAINER_MODULE)
@@ -79,8 +79,7 @@ void stop_trainer_ppm()
{
configure_pins( PIN_TR_PPM_OUT, PIN_INPUT | PIN_PORTC ) ; // Pin as input
TIM3->CR1 &= ~TIM_CR1_CEN ; // Stop counter
TIM3->DIER &= ~TIM_DIER_CC2IE ; // Stop Interrupt
TIM3->DIER &= ~TIM_DIER_UIE ; // Stop Interrupt
TIM3->DIER = 0 ; // Stop Interrupt
NVIC_DisableIRQ(TIM3_IRQn) ; // Stop Interrupt
}
@@ -99,28 +98,38 @@ void init_trainer_capture()
TIM3->SR &= ~TIM_SR_CC3IF & ~TIM_SR_CC2IF & ~TIM_SR_UIF ; // Clear flags
TIM3->DIER |= TIM_DIER_CC3IE ;
TIM3->CR1 = TIM_CR1_CEN ;
NVIC_EnableIRQ(TIM3_IRQn) ;
NVIC_SetPriority(TIM3_IRQn, 7);
NVIC_EnableIRQ(TIM3_IRQn) ;
}
void stop_trainer_capture()
{
TIM3->CR1 &= ~TIM_CR1_CEN ; // Stop counter
TIM3->DIER &= ~TIM_DIER_CC3IE ; // Stop Interrupt
TIM3->DIER = 0; // Stop Interrupt
NVIC_DisableIRQ(TIM3_IRQn) ; // Stop Interrupt
}
extern "C" void TIM3_IRQHandler()
{
uint16_t capture ;
uint16_t capture = 0;
static uint16_t lastCapt ;
uint16_t val ;
bool doCapture = false ;
// What mode? in or out?
if ( (TIM3->DIER & TIM_DIER_CC3IE ) && ( TIM3->SR & TIM_SR_CC3IF ) ) {
// capture mode
// capture mode on trainer jack
capture = TIM3->CCR3 ;
doCapture = true;
}
if ( (TIM3->DIER & TIM_DIER_CC2IE ) && ( TIM3->SR & TIM_SR_CC2IF ) ) {
// capture mode on heartbeat pin (external module)
capture = TIM3->CCR2 ;
doCapture = true ;
}
if (doCapture) {
val = (uint16_t)(capture - lastCapt) / 2 ;
lastCapt = capture;
@@ -168,3 +177,66 @@ extern "C" void TIM3_IRQHandler()
}
}
void init_cppm_on_heartbeat_capture(void)
{
EXTERNAL_MODULE_ON();
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN ; // Enable portC clock
configure_pins( 0x0080, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_2 ) ;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN ; // Enable clock
TIM3->ARR = 0xFFFF ;
TIM3->PSC = (PERI1_FREQUENCY * TIMER_MULT_APB1) / 2000000 - 1 ; // 0.5uS
TIM3->CR2 = 0 ;
TIM3->CCMR1 = TIM_CCMR1_IC2F_0 | TIM_CCMR1_IC2F_1 | TIM_CCMR1_CC2S_0 ;
TIM3->CCER = TIM_CCER_CC2E ;
TIM3->SR &= ~TIM_SR_CC2IF ; // Clear flag
TIM3->DIER |= TIM_DIER_CC2IE ;
TIM3->CR1 = TIM_CR1_CEN ;
NVIC_SetPriority(TIM3_IRQn, 7);
NVIC_EnableIRQ(TIM3_IRQn) ;
}
void stop_cppm_on_heartbeat_capture(void)
{
TIM3->DIER = 0 ;
TIM3->CR1 &= ~TIM_CR1_CEN ; // Stop counter
NVIC_DisableIRQ(TIM3_IRQn) ; // Stop Interrupt
if (!IS_PULSES_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
}
void init_sbus_on_heartbeat_capture(void)
{
EXTERNAL_MODULE_ON();
RCC->APB2ENR |= RCC_APB2ENR_USART6EN ; // Enable clock
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOCEN ; // Enable portC clock
// GPIOC->MODER = (GPIOC->MODER & 0xFFFFBFFF ) | 0x00008000 ; // Alternate func.
// GPIOC->AFR[0] = (GPIOC->AFR[0] & 0x0FFFFFFF ) | 0x80000000 ; // Alternate func.
configure_pins( 0x0080, PIN_PERIPHERAL | PIN_PORTC | PIN_PER_8 ) ;
USART6->BRR = PERI2_FREQUENCY / 100000 ;
USART6->CR1 = USART_CR1_UE | USART_CR1_RXNEIE | USART_CR1_RE | USART_CR1_M | USART_CR1_PCE ;
USART6->CR2 = 0 ;
USART6->CR3 = 0 ;
(void) USART6->DR ;
NVIC_EnableIRQ(USART6_IRQn) ;
}
void stop_sbus_on_heartbeat_capture(void)
{
configure_pins( 0x0080, PIN_INPUT | PIN_PORTC ) ;
NVIC_DisableIRQ(USART6_IRQn) ;
if (!IS_PULSES_EXTERNAL_MODULE()) {
EXTERNAL_MODULE_OFF();
}
}
extern "C" void USART6_IRQHandler()
{
uint8_t data = USART6->DR;
sbusFifo.push(data);
}
+11 -4
View File
@@ -97,10 +97,6 @@ void uart3Init(unsigned int mode, unsigned int protocol)
uart3Setup(FRSKY_D_BAUDRATE);
}
break;
case UART_MODE_SBUS_TRAINER:
uart3Setup(100000);
USART3->CR1 |= USART_CR1_M | USART_CR1_PCE ;
break;
}
uart3Mode = mode;
@@ -121,6 +117,17 @@ void debugPutc(const char c)
}
#endif
void uart3SbusInit()
{
uart3Setup(100000);
USART3->CR1 |= USART_CR1_M | USART_CR1_PCE ;
}
void uart3Stop()
{
USART_DeInit(USART3);
}
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
extern "C" void USART3_IRQHandler(void)