[X-Lite] Next round of changes (#5847)
* [X-Lite] PXX is now sent every 4ms * New option PXX_FREQUENCY (HIGH / LOW) * [X-Lite] It now sends 16 channels per 4ms
This commit is contained in:
Regular → Executable
+1
-1
@@ -168,7 +168,7 @@ void setupPulses(uint8_t port)
|
|||||||
switch (required_protocol) {
|
switch (required_protocol) {
|
||||||
case PROTO_PXX:
|
case PROTO_PXX:
|
||||||
setupPulsesPXX(port);
|
setupPulsesPXX(port);
|
||||||
scheduleNextMixerCalculation(port, 9);
|
scheduleNextMixerCalculation(port, MODULES_TIMER_PXX_PERIOD);
|
||||||
break;
|
break;
|
||||||
case PROTO_SBUS:
|
case PROTO_SBUS:
|
||||||
setupPulsesSbus(port);
|
setupPulsesSbus(port);
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ template<class T> struct PpmPulsesData {
|
|||||||
T * ptr;
|
T * ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(PXX_FREQUENCY_HIGH)
|
||||||
|
#define EXTMODULE_USART_PXX_BAUDRATE 420000
|
||||||
|
#define INTMODULE_USART_PXX_BAUDRATE 450000
|
||||||
|
#define MODULES_TIMER_PXX_PERIOD 4 // 4ms
|
||||||
|
#else
|
||||||
|
#define EXTMODULE_USART_PXX_BAUDRATE 115200
|
||||||
|
#define INTMODULE_USART_PXX_BAUDRATE 115200
|
||||||
|
#define MODULES_TIMER_PXX_PERIOD 9 // 9ms
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(PPM_PIN_SERIAL)
|
#if defined(PPM_PIN_SERIAL)
|
||||||
PACK(struct PxxSerialPulsesData {
|
PACK(struct PxxSerialPulsesData {
|
||||||
uint8_t pulses[64];
|
uint8_t pulses[64];
|
||||||
@@ -75,11 +85,17 @@ PACK(struct PxxUartPulsesData {
|
|||||||
|
|
||||||
#define MULTIMODULE_BAUDRATE 100000
|
#define MULTIMODULE_BAUDRATE 100000
|
||||||
#if defined(INTMODULE_PULSES) || defined(EXTMODULE_PULSES)
|
#if defined(INTMODULE_PULSES) || defined(EXTMODULE_PULSES)
|
||||||
|
|
||||||
/* PXX uses 20 bytes (as of Rev 1.1 document) with 8 changes per byte + stop bit ~= 162 max pulses */
|
/* 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 */
|
/* DSM2 uses 2 header + 12 channel bytes, with max 10 changes (8n2) per byte + 16 bits trailer ~= 156 max pulses */
|
||||||
/* Multimodule uses 3 bytes header + 22 channel bytes with max 11 changes per byte (8e2) + 16 bits trailer ~= 291 max pulses */
|
/* Multimodule uses 3 bytes header + 22 channel bytes with max 11 changes per byte (8e2) + 16 bits trailer ~= 291 max pulses */
|
||||||
/* Multimodule reuses some of the DSM2 function and structs since the protocols are similar enough */
|
/* Multimodule reuses some of the DSM2 function and structs since the protocols are similar enough */
|
||||||
/* sbus is 1 byte header, 22 channel bytes (11bit * 16ch) + 1 byte flags */
|
/* sbus is 1 byte header, 22 channel bytes (11bit * 16ch) + 1 byte flags */
|
||||||
|
|
||||||
|
#if defined(PXX_FREQUENCY_HIGH)
|
||||||
|
#error "Pulses array needs to be increased (PXX_FREQUENCY=HIGH)"
|
||||||
|
#endif
|
||||||
|
|
||||||
PACK(struct PxxTimerPulsesData {
|
PACK(struct PxxTimerPulsesData {
|
||||||
pulse_duration_t pulses[200];
|
pulse_duration_t pulses[200];
|
||||||
pulse_duration_t * ptr;
|
pulse_duration_t * ptr;
|
||||||
|
|||||||
@@ -85,6 +85,10 @@ void uartPutPcmByte(uint8_t port, uint8_t byte)
|
|||||||
void uartInitPcmArray(uint8_t port)
|
void uartInitPcmArray(uint8_t port)
|
||||||
{
|
{
|
||||||
modulePulsesData[port].pxx_uart.ptr = modulePulsesData[port].pxx_uart.pulses;
|
modulePulsesData[port].pxx_uart.ptr = modulePulsesData[port].pxx_uart.pulses;
|
||||||
|
}
|
||||||
|
|
||||||
|
void uartInitPcmCrc(uint8_t port)
|
||||||
|
{
|
||||||
modulePulsesData[port].pxx_uart.pcmCrc = 0;
|
modulePulsesData[port].pxx_uart.pcmCrc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,7 +163,6 @@ void pxxPutPcmBit(uint8_t port, uint8_t bit)
|
|||||||
pxxPutPcmPart(port, 0);
|
pxxPutPcmPart(port, 0);
|
||||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pxxPutPcmByte(uint8_t port, uint8_t byte)
|
void pxxPutPcmByte(uint8_t port, uint8_t byte)
|
||||||
@@ -179,10 +182,15 @@ void pxxInitPcmArray(uint8_t port)
|
|||||||
#else
|
#else
|
||||||
modulePulsesData[port].pxx.rest = 18000;
|
modulePulsesData[port].pxx.rest = 18000;
|
||||||
#endif
|
#endif
|
||||||
modulePulsesData[port].pxx.pcmCrc = 0;
|
|
||||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pxxInitPcmCrc(uint8_t port)
|
||||||
|
{
|
||||||
|
modulePulsesData[port].pxx.pcmCrc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void pxxPutPcmHead(uint8_t port)
|
void pxxPutPcmHead(uint8_t port)
|
||||||
{
|
{
|
||||||
// send 7E, do not CRC
|
// send 7E, do not CRC
|
||||||
@@ -213,6 +221,14 @@ inline void initPcmArray(uint8_t port)
|
|||||||
pxxInitPcmArray(port);
|
pxxInitPcmArray(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void initPcmCrc(uint8_t port)
|
||||||
|
{
|
||||||
|
if (IS_UART_MODULE(port))
|
||||||
|
uartInitPcmCrc(port);
|
||||||
|
else
|
||||||
|
pxxInitPcmCrc(port);
|
||||||
|
}
|
||||||
|
|
||||||
inline void putPcmHead(uint8_t port)
|
inline void putPcmHead(uint8_t port)
|
||||||
{
|
{
|
||||||
if (IS_UART_MODULE(port))
|
if (IS_UART_MODULE(port))
|
||||||
@@ -248,6 +264,11 @@ inline void initPcmArray(uint8_t port)
|
|||||||
pxxInitPcmArray(port);
|
pxxInitPcmArray(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void initPcmCrc(uint8_t port)
|
||||||
|
{
|
||||||
|
pxxInitPcmCrc(port);
|
||||||
|
}
|
||||||
|
|
||||||
inline void putPcmHead(uint8_t port)
|
inline void putPcmHead(uint8_t port)
|
||||||
{
|
{
|
||||||
pxxPutPcmHead(port);
|
pxxPutPcmHead(port);
|
||||||
@@ -269,11 +290,11 @@ inline void putPcmTail(uint8_t port)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setupPulsesPXX(uint8_t port)
|
inline void setupFramePXX(uint8_t port, uint8_t sendUpperChannels)
|
||||||
{
|
{
|
||||||
uint16_t pulseValue=0, pulseValueLow=0;
|
uint16_t pulseValue=0, pulseValueLow=0;
|
||||||
|
|
||||||
initPcmArray(port);
|
initPcmCrc(port);
|
||||||
|
|
||||||
/* Sync */
|
/* Sync */
|
||||||
putPcmHead(port);
|
putPcmHead(port);
|
||||||
@@ -304,12 +325,7 @@ void setupPulsesPXX(uint8_t port)
|
|||||||
/* FLAG2 */
|
/* FLAG2 */
|
||||||
putPcmByte(port, 0);
|
putPcmByte(port, 0);
|
||||||
|
|
||||||
/* PPM */
|
/* CHANNELS */
|
||||||
static uint8_t pass[NUM_MODULES] = { MODULES_INIT(0) };
|
|
||||||
int sendUpperChannels = 0;
|
|
||||||
if (pass[port]++ & 0x01) {
|
|
||||||
sendUpperChannels = g_model.moduleData[port].channelsCount;
|
|
||||||
}
|
|
||||||
for (int i=0; i<8; i++) {
|
for (int i=0; i<8; i++) {
|
||||||
if (flag1 & PXX_SEND_FAILSAFE) {
|
if (flag1 & PXX_SEND_FAILSAFE) {
|
||||||
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
|
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
|
||||||
@@ -405,3 +421,22 @@ void setupPulsesPXX(uint8_t port)
|
|||||||
|
|
||||||
putPcmTail(port);
|
putPcmTail(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupPulsesPXX(uint8_t port)
|
||||||
|
{
|
||||||
|
initPcmArray(port);
|
||||||
|
|
||||||
|
#if defined(PXX_FREQUENCY_HIGH)
|
||||||
|
setupFramePXX(port, 0);
|
||||||
|
if (NUM_CHANNELS(port) > 8) {
|
||||||
|
setupFramePXX(port, 8);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static uint8_t pass[NUM_MODULES] = { MODULES_INIT(0) };
|
||||||
|
uint8_t sendUpperChannels = 0;
|
||||||
|
if (pass[port]++ & 0x01) {
|
||||||
|
sendUpperChannels = g_model.moduleData[port].channelsCount;
|
||||||
|
}
|
||||||
|
setupFramePXX(port, sendUpperChannels);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
Regular → Executable
+3
-3
@@ -86,7 +86,7 @@ void intmodulePxxStart()
|
|||||||
// UART config
|
// UART config
|
||||||
USART_DeInit(INTMODULE_USART);
|
USART_DeInit(INTMODULE_USART);
|
||||||
USART_InitTypeDef USART_InitStructure;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
USART_InitStructure.USART_BaudRate = 115200;
|
USART_InitStructure.USART_BaudRate = INTMODULE_USART_PXX_BAUDRATE;
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
@@ -98,8 +98,8 @@ void intmodulePxxStart()
|
|||||||
// Timer
|
// Timer
|
||||||
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||||
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
|
||||||
INTMODULE_TIMER->ARR = 18000; // 9mS
|
INTMODULE_TIMER->ARR = 2000 * MODULES_TIMER_PXX_PERIOD;
|
||||||
INTMODULE_TIMER->CCR2 = 15000; // Update time
|
INTMODULE_TIMER->CCR2 = (2000 * MODULES_TIMER_PXX_PERIOD) - 2000; // Update time
|
||||||
INTMODULE_TIMER->CCER = TIM_CCER_CC3E;
|
INTMODULE_TIMER->CCER = TIM_CCER_CC3E;
|
||||||
INTMODULE_TIMER->CCMR2 = 0;
|
INTMODULE_TIMER->CCMR2 = 0;
|
||||||
INTMODULE_TIMER->EGR = 1; // Restart
|
INTMODULE_TIMER->EGR = 1; // Restart
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ elseif(PCB STREQUAL X7)
|
|||||||
set(LCD_DRIVER lcd_driver_spi.cpp)
|
set(LCD_DRIVER lcd_driver_spi.cpp)
|
||||||
set(GVAR_SCREEN model_gvars.cpp)
|
set(GVAR_SCREEN model_gvars.cpp)
|
||||||
elseif(PCB STREQUAL XLITE)
|
elseif(PCB STREQUAL XLITE)
|
||||||
|
option(PXX_FREQUENCY "PXX Frequency (LOW / HIGH)" HIGH)
|
||||||
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
set(PWR_BUTTON "PRESS" CACHE STRING "Pwr button type (PRESS/SWITCH)")
|
||||||
set(CPU_TYPE STM32F2)
|
set(CPU_TYPE STM32F2)
|
||||||
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
set(CPU_TYPE_FULL STM32F205xE) # for size report
|
||||||
@@ -94,6 +95,9 @@ elseif(PCB STREQUAL XLITE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PCB STREQUAL XLITE)
|
if(PCB STREQUAL XLITE)
|
||||||
|
if(PXX_FREQUENCY STREQUAL HIGH)
|
||||||
|
add_definitions(-DPXX_FREQUENCY_HIGH)
|
||||||
|
endif()
|
||||||
set(TARGET_SRC
|
set(TARGET_SRC
|
||||||
${TARGET_SRC}
|
${TARGET_SRC}
|
||||||
../common/arm/stm32/intmodule_serial_driver.cpp
|
../common/arm/stm32/intmodule_serial_driver.cpp
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ void extmodulePxxStart()
|
|||||||
// UART config
|
// UART config
|
||||||
USART_DeInit(EXTMODULE_USART);
|
USART_DeInit(EXTMODULE_USART);
|
||||||
USART_InitTypeDef USART_InitStructure;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
USART_InitStructure.USART_BaudRate = 115200;
|
USART_InitStructure.USART_BaudRate = EXTMODULE_USART_PXX_BAUDRATE;
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
@@ -150,8 +150,8 @@ void extmodulePxxStart()
|
|||||||
// Timer
|
// Timer
|
||||||
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
EXTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
|
||||||
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
EXTMODULE_TIMER->PSC = EXTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS from 30MHz
|
||||||
EXTMODULE_TIMER->ARR = 18000; // 9mS
|
EXTMODULE_TIMER->ARR = 2000 * MODULES_TIMER_PXX_PERIOD;
|
||||||
EXTMODULE_TIMER->CCR2 = 16000; // Update time
|
EXTMODULE_TIMER->CCR2 = (2000 * MODULES_TIMER_PXX_PERIOD) - 2000; // Update time
|
||||||
EXTMODULE_TIMER->EGR = 1; // Restart
|
EXTMODULE_TIMER->EGR = 1; // Restart
|
||||||
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
|
EXTMODULE_TIMER->SR &= ~TIM_SR_CC2IF;
|
||||||
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
EXTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
|
||||||
|
|||||||
Reference in New Issue
Block a user