@@ -98,8 +98,8 @@ void intmodulePxxStart()
|
||||
// Timer
|
||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
INTMODULE_TIMER->ARR = 2000 * MODULES_TIMER_PXX_PERIOD;
|
||||
INTMODULE_TIMER->CCR2 = (2000 * MODULES_TIMER_PXX_PERIOD) - 2000; // Update time
|
||||
INTMODULE_TIMER->ARR = PXX_PERIOD_HALF_US;
|
||||
INTMODULE_TIMER->CCR2 = PXX_PERIOD_HALF_US - 2000; // Update time
|
||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E;
|
||||
INTMODULE_TIMER->CCMR2 = 0;
|
||||
INTMODULE_TIMER->EGR = 1; // Restart
|
||||
|
||||
@@ -196,12 +196,10 @@ void init_ppm(uint32_t module_index);
|
||||
void disable_ppm(uint32_t module_index);
|
||||
void init_pxx(uint32_t module_index);
|
||||
void disable_pxx(uint32_t module_index);
|
||||
void init_dsm2(uint32_t module_index);
|
||||
void disable_dsm2(uint32_t module_index);
|
||||
void init_serial(uint32_t module_index, uint32_t baudrate, uint32_t period_half_us);
|
||||
void disable_serial(uint32_t module_index);
|
||||
void init_crossfire(uint32_t module_index);
|
||||
void disable_crossfire(uint32_t module_index);
|
||||
void init_sbusOut(uint32_t module_index);
|
||||
void disable_sbusOut(uint32_t module_index);
|
||||
|
||||
// Trainer driver
|
||||
void init_trainer_ppm(void);
|
||||
|
||||
@@ -162,7 +162,7 @@ void extmodulePxxStart()
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
void extmoduleDsm2Start()
|
||||
void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us)
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
@@ -178,7 +178,7 @@ void extmoduleDsm2Start()
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
EXTMODULE_TIMER->ARR = 44000; // 22mS
|
||||
EXTMODULE_TIMER->ARR = period_half_us;
|
||||
|
||||
#if defined(PCBX10) || PCBREV >= 13
|
||||
EXTMODULE_TIMER->CCER = TIM_CCER_CC3E | TIM_CCER_CC3P;
|
||||
@@ -226,8 +226,8 @@ void extmoduleCrossfireStart()
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
EXTMODULE_TIMER->ARR = (2000 * CROSSFIRE_FRAME_PERIOD);
|
||||
EXTMODULE_TIMER->CCR2 = (2000 * CROSSFIRE_FRAME_PERIOD) - 1000;
|
||||
EXTMODULE_TIMER->ARR = (2000 * CROSSFIRE_PERIOD);
|
||||
EXTMODULE_TIMER->CCR2 = (2000 * CROSSFIRE_PERIOD) - 1000;
|
||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
||||
|
||||
@@ -29,9 +29,7 @@ void intmodulePxxStart(void);
|
||||
void extmoduleNoneStart(void);
|
||||
void extmodulePpmStart(void);
|
||||
void extmodulePxxStart(void);
|
||||
#if defined(DSM2)
|
||||
void extmoduleDsm2Start(void);
|
||||
#endif
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
|
||||
void extmoduleCrossfireStart(void);
|
||||
|
||||
void init_no_pulses(uint32_t port)
|
||||
@@ -81,14 +79,14 @@ void disable_pxx(uint32_t port)
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
void init_dsm2(uint32_t port)
|
||||
void init_serial(uint32_t port, uint32_t baudrate, uint32_t period_half_us)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleDsm2Start();
|
||||
extmoduleSerialStart(baudrate, period_half_us);
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
void disable_serial(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleStop();
|
||||
@@ -96,16 +94,6 @@ void disable_dsm2(uint32_t port)
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_sbusOut(uint32_t port)
|
||||
{
|
||||
init_dsm2(port);
|
||||
}
|
||||
|
||||
void disable_sbusOut(uint32_t port)
|
||||
{
|
||||
disable_dsm2(port);
|
||||
}
|
||||
|
||||
void init_crossfire(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
|
||||
@@ -262,11 +262,8 @@ void init_ppm(uint32_t port);
|
||||
void disable_ppm(uint32_t port);
|
||||
void init_pxx(uint32_t port);
|
||||
void disable_pxx(uint32_t port);
|
||||
void init_dsm2(uint32_t port);
|
||||
void disable_dsm2(uint32_t port);
|
||||
|
||||
void init_sbusOut(uint32_t module_index);
|
||||
void disable_sbusOut(uint32_t module_index);
|
||||
void init_serial(uint32_t port, uint32_t baudrate, uint32_t period_half_us);
|
||||
void disable_serial(uint32_t port);
|
||||
|
||||
// SD driver
|
||||
#if defined(SIMU)
|
||||
|
||||
@@ -222,18 +222,25 @@ void disable_pxx(uint32_t port)
|
||||
}
|
||||
}
|
||||
|
||||
void init_dsm2(uint32_t port)
|
||||
void init_serial(uint32_t port, uint32_t baudrate, uint32_t period_half_us)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125);
|
||||
if (baudrate == 125000) {
|
||||
// TODO init_main_ppm could take the period as parameter?
|
||||
init_main_ppm(2500 * 2, 0);
|
||||
init_ssc(125);
|
||||
}
|
||||
else {
|
||||
init_main_ppm(3500 * 2, 0);
|
||||
init_ssc(100);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
void disable_serial(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
disable_ssc();
|
||||
@@ -244,22 +251,6 @@ void disable_dsm2(uint32_t port)
|
||||
}
|
||||
}
|
||||
|
||||
void init_sbusOut(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
init_main_ppm(3500 * 2, 0);
|
||||
init_ssc(100);
|
||||
}
|
||||
else {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
void disable_sbusOut(uint32_t port)
|
||||
{
|
||||
disable_dsm2(port);
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
extern "C" void PWM_IRQHandler(void)
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ elseif(PCB STREQUAL X7)
|
||||
set(LCD_DRIVER lcd_driver_spi.cpp)
|
||||
set(GVAR_SCREEN model_gvars.cpp)
|
||||
elseif(PCB STREQUAL XLITE)
|
||||
option(PXX_FREQUENCY "PXX Frequency (LOW / HIGH)" HIGH)
|
||||
set(PXX_FREQUENCY "HIGH" CACHE STRING "PXX frequency (LOW / HIGH)")
|
||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||
set(CPU_TYPE STM32F2)
|
||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||
|
||||
@@ -189,12 +189,10 @@ void init_ppm( uint32_t module_index );
|
||||
void disable_ppm( uint32_t module_index );
|
||||
void init_pxx( uint32_t module_index );
|
||||
void disable_pxx( uint32_t module_index );
|
||||
void init_dsm2( uint32_t module_index );
|
||||
void disable_dsm2( uint32_t module_index );
|
||||
void init_serial( uint32_t module_index, uint32_t baudrate, uint32_t period );
|
||||
void disable_serial( uint32_t module_index );
|
||||
void init_crossfire( uint32_t module_index );
|
||||
void disable_crossfire( uint32_t module_index );
|
||||
void init_sbusOut(uint32_t module_index);
|
||||
void disable_sbusOut(uint32_t module_index);
|
||||
|
||||
// Trainer driver
|
||||
#define SLAVE_MODE() (g_model.trainerMode == TRAINER_MODE_SLAVE)
|
||||
|
||||
@@ -105,8 +105,42 @@ void extmodulePpmStart()
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7);
|
||||
}
|
||||
|
||||
void extmoduleSerialStart(uint32_t /*baudrate*/, uint32_t period_half_us)
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
GPIO_PinAFConfig(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PinSource, EXTMODULE_TIMER_TX_GPIO_AF);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_TX_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->ARR = period_half_us;
|
||||
EXTMODULE_TIMER->CCER = EXTMODULE_TIMER_OUTPUT_ENABLE | EXTMODULE_TIMER_OUTPUT_POLARITY;
|
||||
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE; // Enable outputs
|
||||
EXTMODULE_TIMER->CCR1 = 0;
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0; // Force O/P high
|
||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_UDE; // Enable DMA on update
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0;
|
||||
EXTMODULE_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
extmoduleSendNextFrame();
|
||||
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_DMA_STREAM_IRQn);
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_DMA_STREAM_IRQn, 7);
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn);
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7);
|
||||
}
|
||||
|
||||
#if defined(EXTMODULE_USART)
|
||||
void extmodulePxxStart()
|
||||
void extmoduleInvertedSerialStart(uint32_t baudrate, uint32_t period_half_us)
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
@@ -138,7 +172,7 @@ void extmodulePxxStart()
|
||||
// UART config
|
||||
USART_DeInit(EXTMODULE_USART);
|
||||
USART_InitTypeDef USART_InitStructure;
|
||||
USART_InitStructure.USART_BaudRate = EXTMODULE_USART_PXX_BAUDRATE;
|
||||
USART_InitStructure.USART_BaudRate = baudrate;
|
||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||
@@ -150,8 +184,8 @@ void extmodulePxxStart()
|
||||
// Timer
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->ARR = 2000 * MODULES_TIMER_PXX_PERIOD;
|
||||
EXTMODULE_TIMER->CCR2 = (2000 * MODULES_TIMER_PXX_PERIOD) - 2000; // Update time
|
||||
EXTMODULE_TIMER->ARR = period_half_us;
|
||||
EXTMODULE_TIMER->CCR2 = period_half_us - 2000; // Update time
|
||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
||||
@@ -160,6 +194,11 @@ void extmodulePxxStart()
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn);
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7);
|
||||
}
|
||||
|
||||
void extmodulePxxStart()
|
||||
{
|
||||
extmoduleInvertedSerialStart(EXTMODULE_USART_PXX_BAUDRATE, PXX_PERIOD_HALF_US);
|
||||
}
|
||||
#else
|
||||
void extmodulePxxStart()
|
||||
{
|
||||
@@ -177,7 +216,7 @@ void extmodulePxxStart()
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||
EXTMODULE_TIMER->ARR = 18000;
|
||||
EXTMODULE_TIMER->ARR = PXX_PERIOD_HALF_US;
|
||||
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;
|
||||
@@ -196,42 +235,6 @@ void extmodulePxxStart()
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(DSM2) || defined(MULTIMODULE)
|
||||
void extmoduleDsm2Start()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
|
||||
GPIO_PinAFConfig(EXTMODULE_TX_GPIO, EXTMODULE_TX_GPIO_PinSource, EXTMODULE_TIMER_TX_GPIO_AF);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_TX_GPIO_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
||||
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->ARR = 44000; // 22mS
|
||||
EXTMODULE_TIMER->CCER = EXTMODULE_TIMER_OUTPUT_ENABLE | EXTMODULE_TIMER_OUTPUT_POLARITY;
|
||||
EXTMODULE_TIMER->BDTR = TIM_BDTR_MOE; // Enable outputs
|
||||
EXTMODULE_TIMER->CCR1 = 0;
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0; // Force O/P high
|
||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_UDE; // Enable DMA on update
|
||||
EXTMODULE_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0;
|
||||
EXTMODULE_TIMER->CR1 |= TIM_CR1_CEN;
|
||||
|
||||
extmoduleSendNextFrame();
|
||||
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_DMA_STREAM_IRQn);
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_DMA_STREAM_IRQn, 7);
|
||||
NVIC_EnableIRQ(EXTMODULE_TIMER_CC_IRQn);
|
||||
NVIC_SetPriority(EXTMODULE_TIMER_CC_IRQn, 7);
|
||||
}
|
||||
#endif
|
||||
|
||||
void extmoduleCrossfireStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
@@ -249,8 +252,8 @@ void extmoduleCrossfireStart()
|
||||
|
||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
||||
EXTMODULE_TIMER->ARR = (2000 * CROSSFIRE_FRAME_PERIOD);
|
||||
EXTMODULE_TIMER->CCR2 = (2000 * CROSSFIRE_FRAME_PERIOD) - 1000;
|
||||
EXTMODULE_TIMER->ARR = (2000 * CROSSFIRE_PERIOD);
|
||||
EXTMODULE_TIMER->CCR2 = (2000 * CROSSFIRE_PERIOD) - 1000;
|
||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
|
||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
||||
@@ -308,7 +311,7 @@ void extmoduleSendNextFrame()
|
||||
}
|
||||
else if (IS_DSM2_PROTOCOL(s_current_protocol[EXTERNAL_MODULE]) || IS_MULTIMODULE_PROTOCOL(s_current_protocol[EXTERNAL_MODULE]) || IS_SBUS_PROTOCOL(s_current_protocol[EXTERNAL_MODULE])) {
|
||||
if (IS_SBUS_PROTOCOL(s_current_protocol[EXTERNAL_MODULE]))
|
||||
EXTMODULE_TIMER->CCER = TIM_CCER_CC1NE | (GET_SBUS_POLARITY(EXTERNAL_MODULE) ? TIM_CCER_CC1NP : 0); // reverse polarity for Sbus if needed
|
||||
EXTMODULE_TIMER->CCER = EXTMODULE_TIMER_OUTPUT_ENABLE | (GET_SBUS_POLARITY(EXTERNAL_MODULE) ? EXTMODULE_TIMER_OUTPUT_POLARITY : 0); // reverse polarity for Sbus if needed
|
||||
EXTMODULE_TIMER->CCR2 = *(modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - 1) - 4000; // 2mS in advance
|
||||
EXTMODULE_TIMER_DMA_STREAM->CR &= ~DMA_SxCR_EN; // Disable DMA
|
||||
EXTMODULE_TIMER_DMA_STREAM->CR |= EXTMODULE_TIMER_DMA_CHANNEL | DMA_SxCR_DIR_0 | DMA_SxCR_MINC | DMA_SxCR_PSIZE_0 | DMA_SxCR_MSIZE_0 | DMA_SxCR_PL_0 | DMA_SxCR_PL_1;
|
||||
|
||||
@@ -32,9 +32,7 @@ void intmodulePpmStart(void);
|
||||
void extmoduleNoneStart(void);
|
||||
void extmodulePpmStart(void);
|
||||
void extmodulePxxStart(void);
|
||||
#if defined(DSM2) || defined(MULTIMODULE)
|
||||
void extmoduleDsm2Start(void);
|
||||
#endif
|
||||
void extmoduleSerialStart(uint32_t baudrate, uint32_t period_half_us);
|
||||
void extmoduleCrossfireStart(void);
|
||||
|
||||
void init_pxx(uint32_t port)
|
||||
@@ -54,14 +52,14 @@ void disable_pxx(uint32_t port)
|
||||
}
|
||||
|
||||
#if defined(DSM2)
|
||||
void init_dsm2(uint32_t port)
|
||||
void init_serial(uint32_t port, uint32_t baudrate, uint32_t period_half_us)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleDsm2Start();
|
||||
extmoduleSerialStart(baudrate, period_half_us);
|
||||
}
|
||||
}
|
||||
|
||||
void disable_dsm2(uint32_t port)
|
||||
void disable_serial(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
extmoduleStop();
|
||||
@@ -69,17 +67,6 @@ void disable_dsm2(uint32_t port)
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_sbusOut(uint32_t port)
|
||||
{
|
||||
init_dsm2(port);
|
||||
}
|
||||
|
||||
void disable_sbusOut(uint32_t port)
|
||||
{
|
||||
disable_dsm2(port);
|
||||
}
|
||||
|
||||
|
||||
void init_ppm(uint32_t port)
|
||||
{
|
||||
if (port == EXTERNAL_MODULE) {
|
||||
|
||||
Reference in New Issue
Block a user