[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:
Bertrand Songis
2018-04-27 08:45:00 +02:00
committed by GitHub
parent 7979401675
commit a0c1beb61f
6 changed files with 72 additions and 17 deletions
Regular → Executable
+1 -1
View File
@@ -168,7 +168,7 @@ void setupPulses(uint8_t port)
switch (required_protocol) {
case PROTO_PXX:
setupPulsesPXX(port);
scheduleNextMixerCalculation(port, 9);
scheduleNextMixerCalculation(port, MODULES_TIMER_PXX_PERIOD);
break;
case PROTO_SBUS:
setupPulsesSbus(port);
+16
View File
@@ -44,6 +44,16 @@ template<class T> struct PpmPulsesData {
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)
PACK(struct PxxSerialPulsesData {
uint8_t pulses[64];
@@ -75,11 +85,17 @@ PACK(struct PxxUartPulsesData {
#define MULTIMODULE_BAUDRATE 100000
#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 */
/* 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 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 */
#if defined(PXX_FREQUENCY_HIGH)
#error "Pulses array needs to be increased (PXX_FREQUENCY=HIGH)"
#endif
PACK(struct PxxTimerPulsesData {
pulse_duration_t pulses[200];
pulse_duration_t * ptr;
+45 -10
View File
@@ -85,6 +85,10 @@ void uartPutPcmByte(uint8_t port, uint8_t byte)
void uartInitPcmArray(uint8_t port)
{
modulePulsesData[port].pxx_uart.ptr = modulePulsesData[port].pxx_uart.pulses;
}
void uartInitPcmCrc(uint8_t port)
{
modulePulsesData[port].pxx_uart.pcmCrc = 0;
}
@@ -159,7 +163,6 @@ void pxxPutPcmBit(uint8_t port, uint8_t bit)
pxxPutPcmPart(port, 0);
modulePulsesData[port].pxx.pcmOnesCount = 0;
}
}
void pxxPutPcmByte(uint8_t port, uint8_t byte)
@@ -179,10 +182,15 @@ void pxxInitPcmArray(uint8_t port)
#else
modulePulsesData[port].pxx.rest = 18000;
#endif
modulePulsesData[port].pxx.pcmCrc = 0;
modulePulsesData[port].pxx.pcmOnesCount = 0;
}
void pxxInitPcmCrc(uint8_t port)
{
modulePulsesData[port].pxx.pcmCrc = 0;
}
void pxxPutPcmHead(uint8_t port)
{
// send 7E, do not CRC
@@ -213,6 +221,14 @@ inline void initPcmArray(uint8_t 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)
{
if (IS_UART_MODULE(port))
@@ -248,6 +264,11 @@ inline void initPcmArray(uint8_t port)
pxxInitPcmArray(port);
}
inline void initPcmCrc(uint8_t port)
{
pxxInitPcmCrc(port);
}
inline void putPcmHead(uint8_t port)
{
pxxPutPcmHead(port);
@@ -269,11 +290,11 @@ inline void putPcmTail(uint8_t port)
}
#endif
void setupPulsesPXX(uint8_t port)
inline void setupFramePXX(uint8_t port, uint8_t sendUpperChannels)
{
uint16_t pulseValue=0, pulseValueLow=0;
initPcmArray(port);
initPcmCrc(port);
/* Sync */
putPcmHead(port);
@@ -304,12 +325,7 @@ void setupPulsesPXX(uint8_t port)
/* FLAG2 */
putPcmByte(port, 0);
/* PPM */
static uint8_t pass[NUM_MODULES] = { MODULES_INIT(0) };
int sendUpperChannels = 0;
if (pass[port]++ & 0x01) {
sendUpperChannels = g_model.moduleData[port].channelsCount;
}
/* CHANNELS */
for (int i=0; i<8; i++) {
if (flag1 & PXX_SEND_FAILSAFE) {
if (g_model.moduleData[port].failsafeMode == FAILSAFE_HOLD) {
@@ -405,3 +421,22 @@ void setupPulsesPXX(uint8_t 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
}