Bsongis/horus xjt external module (#3566)
* [Horus] PXX and DSM2 in external module * [Taranis] Pulses driver refactoring (uses DMA also for PPM in external module and saves 800bytes RAM) * Cosmetics (Pulses driver splitted)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -18,7 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define DSM2_SEND_BIND (1 << 7)
|
||||
#define DSM2_SEND_RANGECHECK (1 << 5)
|
||||
@@ -35,17 +35,17 @@ uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
|
||||
|
||||
#define BITLEN_DSM2 (8*2) //125000 Baud => 8uS per bit
|
||||
|
||||
#if !defined(PPM_PIN_HW_SERIAL)
|
||||
#if !defined(PPM_PIN_SERIAL)
|
||||
void _send_1(uint8_t v)
|
||||
{
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index == 0)
|
||||
v -= 2;
|
||||
else
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index & 1)
|
||||
v += 2;
|
||||
else
|
||||
v -= 2;
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value += v;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = (modulePulsesData[EXTERNAL_MODULE].dsm2.index+1) % 2;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = v;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index += 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest -= v;
|
||||
}
|
||||
|
||||
void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1
|
||||
@@ -69,8 +69,10 @@ void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1
|
||||
|
||||
void putDsm2Flush()
|
||||
{
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr--; //remove last stopbits and
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = 44010; // Past the 44000 of the ARR
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index & 1)
|
||||
*(modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - 1) = modulePulsesData[EXTERNAL_MODULE].dsm2.rest;
|
||||
else
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.rest;
|
||||
}
|
||||
#else
|
||||
void putDsm2SerialBit(uint8_t bit)
|
||||
@@ -108,26 +110,20 @@ void putDsm2Flush()
|
||||
// This is the data stream to send, prepare after 19.5 mS
|
||||
// Send after 22.5 mS
|
||||
|
||||
//static uint8_t *Dsm2_pulsePtr = pulses2MHz.pbyte ;
|
||||
void setupPulsesDSM2(unsigned int port)
|
||||
void setupPulsesDSM2(uint8_t port)
|
||||
{
|
||||
static uint8_t dsmDat[2+6*2]={0xFF,0x00, 0x00,0xAA, 0x05,0xFF, 0x09,0xFF, 0x0D,0xFF, 0x13,0x54, 0x14,0xAA};
|
||||
uint8_t dsmDat[14];
|
||||
|
||||
#if defined(PPM_PIN_HW_SERIAL)
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
#else
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 0;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = 1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = 44000;
|
||||
#endif
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
|
||||
#if !defined(PPM_PIN_HW_SERIAL)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 100;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
#endif
|
||||
|
||||
switch (s_current_protocol[port]) {
|
||||
case PROTO_DSM2_LP45:
|
||||
dsmDat[0] = 0x00;
|
||||
@@ -140,13 +136,7 @@ void setupPulsesDSM2(unsigned int port)
|
||||
break;
|
||||
}
|
||||
|
||||
#if !defined(PPM_PIN_HW_SERIAL)
|
||||
if (moduleFlag[port] == MODULE_BIND)
|
||||
dsmDat[0] |= DSM2_SEND_BIND;
|
||||
else if (moduleFlag[port] == MODULE_RANGECHECK)
|
||||
dsmDat[0] |= DSM2_SEND_RANGECHECK;
|
||||
#else
|
||||
#if defined(PCBSKY9X) // TODO needed?
|
||||
#if defined(PCBSKY9X)
|
||||
if (dsm2BindTimer > 0) {
|
||||
dsm2BindTimer--;
|
||||
if (switchState(SW_DSM2_BIND)) {
|
||||
@@ -154,14 +144,19 @@ void setupPulsesDSM2(unsigned int port)
|
||||
dsmDat[0] |= DSM2_SEND_BIND;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (moduleFlag[port] == MODULE_RANGECHECK) {
|
||||
else if (moduleFlag[port] == MODULE_RANGECHECK) {
|
||||
dsmDat[0] |= DSM2_SEND_RANGECHECK;
|
||||
}
|
||||
else {
|
||||
moduleFlag[port] = 0;
|
||||
}
|
||||
#else
|
||||
if (moduleFlag[port] == MODULE_BIND) {
|
||||
dsmDat[0] |= DSM2_SEND_BIND;
|
||||
}
|
||||
else if (moduleFlag[port] == MODULE_RANGECHECK) {
|
||||
dsmDat[0] |= DSM2_SEND_RANGECHECK;
|
||||
}
|
||||
#endif
|
||||
|
||||
dsmDat[1] = g_model.header.modelId[port]; // DSM2 Header second byte for model match
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
#define BITLEN_MULTI (10*2) //100000 Baud => 10uS per bit
|
||||
|
||||
#if defined(PPM_PIN_HW_SERIAL)
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
static void sendByteMulti(uint8_t b)
|
||||
{
|
||||
uint8_t parity = 1;
|
||||
@@ -56,14 +56,14 @@ static void _send_level(uint8_t v)
|
||||
{
|
||||
/* Copied over from DSM, this looks doubious and in my logic analyzer
|
||||
output the low->high is about 2 ns late */
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index == 0)
|
||||
v -= 2;
|
||||
else
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index & 1)
|
||||
v += 2;
|
||||
else
|
||||
v -= 2;
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value += v;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = (modulePulsesData[EXTERNAL_MODULE].dsm2.index+1) % 2;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = v;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index+=1;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest -=v;
|
||||
}
|
||||
|
||||
static void sendByteMulti(uint8_t b) //max 11 changes 0 10 10 10 10 P 1
|
||||
@@ -99,24 +99,18 @@ static void sendByteMulti(uint8_t b) //max 11 changes 0 10 10 10 10 P 1
|
||||
|
||||
#define MULTI_CHANS 16
|
||||
#define MULTI_CHAN_BITS 11
|
||||
void setupPulsesMultimodule(unsigned int port)
|
||||
void setupPulsesMultimodule(uint8_t port)
|
||||
{
|
||||
|
||||
#if defined(PPM_PIN_HW_SERIAL)
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
#else
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 0;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = 44000;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = 1;
|
||||
#endif
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.value = 100;
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.value;
|
||||
#endif
|
||||
|
||||
// header, byte 0, always 0x55
|
||||
sendByteMulti(0x55);
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
void setupPulsesPPM(unsigned int port) // Don't enable interrupts through here
|
||||
void setupPulsesPPM(uint8_t port) // Don't enable interrupts through here
|
||||
{
|
||||
int16_t PPM_range = g_model.extendedLimits ? (512*LIMIT_EXT_PERCENT/100) * 2 : 512 * 2; //range of 0.7..1.7msec
|
||||
|
||||
@@ -43,23 +43,35 @@ void setupPulsesPPM(unsigned int port) // Don't enable interru
|
||||
#endif
|
||||
|
||||
PpmPulsesData * ppmPulsesData = (port == TRAINER_MODULE ? &trainerPulsesData.ppm : &modulePulsesData[port].ppm);
|
||||
uint16_t * ptr = ppmPulsesData->pulses;
|
||||
|
||||
#if defined(CPUSTM32)
|
||||
ppmPulsesData->ptr = ppmPulsesData->pulses;
|
||||
#else
|
||||
uint16_t * ptr = ppmPulsesData->pulses;
|
||||
ppmPulsesData->ptr = ptr;
|
||||
#endif
|
||||
|
||||
int32_t rest = 22500u * 2;
|
||||
rest += (int32_t(g_model.moduleData[port].ppm.frameLength)) * 1000;
|
||||
for (uint32_t i=firstCh; i<lastCh; i++) {
|
||||
int16_t v = limit((int16_t)-PPM_range, channelOutputs[i], (int16_t)PPM_range) + 2*PPM_CH_CENTER(i);
|
||||
rest -= v;
|
||||
#if defined(CPUSTM32)
|
||||
*ppmPulsesData->ptr++ = v; /* as Pat MacKenzie suggests */
|
||||
#else
|
||||
*ptr++ = v; /* as Pat MacKenzie suggests */
|
||||
#endif
|
||||
}
|
||||
if (rest > 65535) rest = 65535; /* prevents overflows */
|
||||
if (rest < 9000) rest = 9000; /* avoids that CCR2 is bigger than ARR which would cause reboot */
|
||||
#if defined(CPUSTM32)
|
||||
*ppmPulsesData->ptr++ = rest;
|
||||
#else
|
||||
*ptr = rest;
|
||||
*(ptr + 1) = 0;
|
||||
#endif
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
#if defined(CPUSTM32)
|
||||
rest -= 1000;
|
||||
uint32_t ppmDelay = (g_model.moduleData[port].ppm.delay * 50 + 300) * 2;
|
||||
// set idle time, ppm delay and ppm polarity
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "../opentx.h"
|
||||
#include "opentx.h"
|
||||
|
||||
uint8_t s_pulses_paused = 0;
|
||||
uint8_t s_current_protocol[NUM_MODULES] = { MODULES_INIT(255) };
|
||||
@@ -28,7 +28,7 @@ uint8_t moduleFlag[NUM_MODULES] = { 0 };
|
||||
ModulePulsesData modulePulsesData[NUM_MODULES] __DMA;
|
||||
TrainerPulsesData trainerPulsesData __DMA;
|
||||
|
||||
void setupPulses(unsigned int port)
|
||||
void setupPulses(uint8_t port)
|
||||
{
|
||||
uint8_t required_protocol;
|
||||
|
||||
@@ -202,9 +202,10 @@ void setupPulses(unsigned int port)
|
||||
}
|
||||
#endif
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
setupPulsesMultimodule(port);
|
||||
break;
|
||||
case PROTO_MULTIMODULE:
|
||||
setupPulsesMultimodule(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
break;
|
||||
#endif
|
||||
case PROTO_PPM:
|
||||
setupPulsesPPM(port);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -27,17 +27,23 @@
|
||||
#define MODULES_INIT(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
#define pulse_duration_t uint32_t
|
||||
#else
|
||||
#define pulse_duration_t uint16_t
|
||||
#endif
|
||||
|
||||
extern uint8_t s_current_protocol[NUM_MODULES];
|
||||
extern uint8_t s_pulses_paused;
|
||||
extern uint16_t failsafeCounter[NUM_MODULES];
|
||||
|
||||
PACK(struct PpmPulsesData {
|
||||
uint16_t pulses[20];
|
||||
uint16_t * ptr;
|
||||
pulse_duration_t pulses[20];
|
||||
pulse_duration_t * ptr;
|
||||
});
|
||||
|
||||
#if defined(PPM_PIN_HW_SERIAL)
|
||||
PACK(struct PxxPulsesData {
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PACK(struct PxxSerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint16_t pcmValue;
|
||||
@@ -46,26 +52,49 @@ PACK(struct PxxPulsesData {
|
||||
uint16_t serialByte;
|
||||
uint16_t serialBitCount;
|
||||
});
|
||||
PACK(struct Dsm2PulsesData {
|
||||
|
||||
PACK(struct Dsm2SerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t *ptr;
|
||||
uint8_t serialByte ;
|
||||
uint8_t serialBitCount;
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(PPM_PIN_UART)
|
||||
PACK(struct PxxUartPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t * ptr;
|
||||
uint16_t pcmCrc;
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(PPM_PIN_TIMER)
|
||||
/* 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 */
|
||||
#if defined(MULTIMODULE)
|
||||
#define NUM_TIMER_PULSES 300
|
||||
#else
|
||||
PACK(struct PxxPulsesData {
|
||||
uint16_t pulses[400];
|
||||
uint16_t *ptr;
|
||||
uint16_t pcmValue;
|
||||
#define NUM_TIMER_PULSES 200
|
||||
#endif
|
||||
|
||||
PACK(struct PxxTimerPulsesData {
|
||||
pulse_duration_t pulses[NUM_TIMER_PULSES];
|
||||
pulse_duration_t * ptr;
|
||||
uint16_t rest;
|
||||
uint16_t pcmCrc;
|
||||
uint32_t pcmOnesCount;
|
||||
});
|
||||
PACK(struct Dsm2PulsesData {
|
||||
uint16_t pulses[400];
|
||||
uint16_t *ptr;
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
|
||||
PACK(struct Dsm2TimerPulsesData {
|
||||
pulse_duration_t pulses[NUM_TIMER_PULSES];
|
||||
pulse_duration_t * ptr;
|
||||
uint16_t rest;
|
||||
uint8_t index;
|
||||
});
|
||||
#undef NUM_TIMER_PULSES
|
||||
#endif
|
||||
|
||||
#define CROSSFIRE_BAUDRATE 400000
|
||||
@@ -77,8 +106,16 @@ PACK(struct CrossfirePulsesData {
|
||||
});
|
||||
|
||||
union ModulePulsesData {
|
||||
PxxPulsesData pxx;
|
||||
Dsm2PulsesData dsm2;
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PxxSerialPulsesData pxx;
|
||||
Dsm2SerialPulsesData dsm2;
|
||||
#else
|
||||
PxxTimerPulsesData pxx;
|
||||
Dsm2TimerPulsesData dsm2;
|
||||
#endif
|
||||
#if defined(PPM_PIN_UART)
|
||||
PxxUartPulsesData pxx_uart;
|
||||
#endif
|
||||
PpmPulsesData ppm;
|
||||
CrossfirePulsesData crossfire;
|
||||
};
|
||||
@@ -91,11 +128,11 @@ extern ModulePulsesData modulePulsesData[NUM_MODULES];
|
||||
extern TrainerPulsesData trainerPulsesData;
|
||||
extern const uint16_t CRCTable[];
|
||||
|
||||
void setupPulses(unsigned int port);
|
||||
void setupPulsesDSM2(unsigned int port);
|
||||
void setupPulsesMultimodule(unsigned int port);
|
||||
void setupPulsesPXX(unsigned int port);
|
||||
void setupPulsesPPM(unsigned int port);
|
||||
void setupPulses(uint8_t port);
|
||||
void setupPulsesDSM2(uint8_t port);
|
||||
void setupPulsesMultimodule(uint8_t port);
|
||||
void setupPulsesPXX(uint8_t port);
|
||||
void setupPulsesPPM(uint8_t port);
|
||||
void sendByteDsm2(uint8_t b);
|
||||
void putDsm2Flush();
|
||||
void putDsm2SerialBit(uint8_t bit);
|
||||
|
||||
+154
-84
@@ -2,7 +2,7 @@
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
@@ -60,44 +60,50 @@ const uint16_t CRCTable[]=
|
||||
0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78
|
||||
};
|
||||
|
||||
void crc(uint8_t data, unsigned int port)
|
||||
{
|
||||
modulePulsesData[port].pxx.pcmCrc = (modulePulsesData[port].pxx.pcmCrc<<8) ^ (CRCTable[((modulePulsesData[port].pxx.pcmCrc>>8)^data) & 0xFF]);
|
||||
}
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
void putPcmPart(uint8_t byte, unsigned int port)
|
||||
#if defined(PPM_PIN_UART)
|
||||
inline void uartPutPcmPart(uint8_t port, uint8_t byte)
|
||||
{
|
||||
if (0x7E == byte) {
|
||||
*modulePulsesData[port].pxx.ptr++ = 0x7D;
|
||||
*modulePulsesData[port].pxx.ptr++ = 0x5E;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = 0x7D;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = 0x5E;
|
||||
}
|
||||
else if (0x7D == byte) {
|
||||
*modulePulsesData[port].pxx.ptr++ = 0x7D;
|
||||
*modulePulsesData[port].pxx.ptr++ = 0x5D;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = 0x7D;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = 0x5D;
|
||||
}
|
||||
else {
|
||||
*modulePulsesData[port].pxx.ptr++ = byte;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = byte;
|
||||
}
|
||||
}
|
||||
|
||||
void putPcmByte(uint8_t byte, unsigned int port)
|
||||
void uartPutPcmByte(uint8_t port, uint8_t byte)
|
||||
{
|
||||
crc(byte, port);
|
||||
putPcmPart(byte, port);
|
||||
modulePulsesData[port].pxx_uart.pcmCrc = (modulePulsesData[port].pxx_uart.pcmCrc<<8) ^ (CRCTable[((modulePulsesData[port].pxx_uart.pcmCrc>>8)^byte) & 0xFF]);
|
||||
uartPutPcmPart(port, byte);
|
||||
}
|
||||
|
||||
void putPcmHead(unsigned int port)
|
||||
void uartInitPcmArray(uint8_t port)
|
||||
{
|
||||
modulePulsesData[port].pxx_uart.ptr = modulePulsesData[port].pxx_uart.pulses;
|
||||
modulePulsesData[port].pxx_uart.pcmCrc = 0;
|
||||
}
|
||||
|
||||
void uartPutPcmHead(uint8_t port)
|
||||
{
|
||||
// send 7E, do not CRC
|
||||
*modulePulsesData[port].pxx.ptr++ = 0x7E;
|
||||
*modulePulsesData[port].pxx_uart.ptr++ = 0x7E;
|
||||
}
|
||||
|
||||
#define putPcmFlush(port)
|
||||
#define putPcmPreamble(port)
|
||||
#else
|
||||
#if defined(PPM_PIN_HW_SERIAL)
|
||||
void putPcmSerialBit(uint8_t bit, unsigned int port)
|
||||
void uartPutPcmCrc(uint8_t port)
|
||||
{
|
||||
uint16_t pulseValue = modulePulsesData[port].pxx_uart.pcmCrc;
|
||||
uartPutPcmByte(port, pulseValue >> 8);
|
||||
uartPutPcmByte(port, pulseValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
void pxxPutPcmSerialBit(uint8_t port, uint8_t bit)
|
||||
{
|
||||
modulePulsesData[port].pxx.serialByte >>= 1;
|
||||
if (bit & 1) {
|
||||
@@ -110,103 +116,169 @@ void putPcmSerialBit(uint8_t bit, unsigned int port)
|
||||
}
|
||||
|
||||
// 8uS/bit 01 = 0, 001 = 1
|
||||
void putPcmPart(uint8_t value, unsigned int port)
|
||||
void pxxPutPcmPart(uint8_t port, uint8_t value)
|
||||
{
|
||||
putPcmSerialBit(0, port);
|
||||
pxxPutPcmSerialBit(port, 0);
|
||||
if (value) {
|
||||
putPcmSerialBit(0, port);
|
||||
pxxPutPcmSerialBit(port, 0);
|
||||
}
|
||||
putPcmSerialBit(1, port);
|
||||
pxxPutPcmSerialBit(port, 1);
|
||||
}
|
||||
|
||||
void putPcmFlush(unsigned int port)
|
||||
void pxxPutPcmTail(uint8_t port)
|
||||
{
|
||||
while (modulePulsesData[port].pxx.serialBitCount != 0) {
|
||||
putPcmSerialBit(1, port);
|
||||
pxxPutPcmSerialBit(port, 1);
|
||||
}
|
||||
}
|
||||
#else
|
||||
void putPcmPart(uint8_t value, unsigned int port)
|
||||
void pxxPutPcmPart(uint8_t port, uint8_t value)
|
||||
{
|
||||
modulePulsesData[port].pxx.pcmValue += 18 ; // Output 1 for this time
|
||||
*modulePulsesData[port].pxx.ptr++ = modulePulsesData[port].pxx.pcmValue ;
|
||||
modulePulsesData[port].pxx.pcmValue += 14 ;
|
||||
if (value) {
|
||||
modulePulsesData[port].pxx.pcmValue += 16 ;
|
||||
}
|
||||
*modulePulsesData[port].pxx.ptr++ = modulePulsesData[port].pxx.pcmValue ; // Output 0 for this time
|
||||
pulse_duration_t duration = value ? 48 : 32;
|
||||
*modulePulsesData[port].pxx.ptr++ = duration;
|
||||
modulePulsesData[port].pxx.rest -= duration + 1;
|
||||
}
|
||||
|
||||
void putPcmFlush(unsigned int port)
|
||||
void pxxPutPcmTail(uint8_t port)
|
||||
{
|
||||
*modulePulsesData[port].pxx.ptr++ = 18010 ; // Past the 18000 of the ARR
|
||||
*(modulePulsesData[port].pxx.ptr-1) += modulePulsesData[port].pxx.rest;
|
||||
}
|
||||
#endif
|
||||
|
||||
void putPcmBit(uint8_t bit, unsigned int port)
|
||||
void pxxPutPcmBit(uint8_t port, uint8_t bit)
|
||||
{
|
||||
if (bit) {
|
||||
modulePulsesData[port].pxx.pcmOnesCount += 1;
|
||||
putPcmPart(1, port);
|
||||
pxxPutPcmPart(port, 1);
|
||||
if (++modulePulsesData[port].pxx.pcmOnesCount == 5) {
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
pxxPutPcmPart(port, 0); // Stuff a 0 bit in
|
||||
}
|
||||
}
|
||||
else {
|
||||
pxxPutPcmPart(port, 0);
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
putPcmPart(0, port);
|
||||
}
|
||||
if (modulePulsesData[port].pxx.pcmOnesCount >= 5) {
|
||||
putPcmBit(0, port); // Stuff a 0 bit in
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void putPcmByte(uint8_t byte, unsigned int port)
|
||||
void pxxPutPcmByte(uint8_t port, uint8_t byte)
|
||||
{
|
||||
crc(byte, port);
|
||||
modulePulsesData[port].pxx.pcmCrc = (modulePulsesData[port].pxx.pcmCrc<<8) ^ (CRCTable[((modulePulsesData[port].pxx.pcmCrc>>8)^byte) & 0xFF]);
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
putPcmBit(byte & 0x80, port);
|
||||
pxxPutPcmBit(port, byte & 0x80);
|
||||
byte <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void putPcmHead(unsigned int port)
|
||||
void pxxInitPcmArray(uint8_t port)
|
||||
{
|
||||
modulePulsesData[port].pxx.ptr = modulePulsesData[port].pxx.pulses;
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[port].pxx.pcmValue = 0;
|
||||
#else
|
||||
modulePulsesData[port].pxx.rest = 18000;
|
||||
#endif
|
||||
modulePulsesData[port].pxx.pcmCrc = 0;
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
}
|
||||
|
||||
void pxxPutPcmHead(uint8_t port)
|
||||
{
|
||||
// send 7E, do not CRC
|
||||
// 01111110
|
||||
putPcmPart(0, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(1, port);
|
||||
putPcmPart(0, port);
|
||||
pxxPutPcmPart(port, 0);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 1);
|
||||
pxxPutPcmPart(port, 0);
|
||||
}
|
||||
|
||||
void putPcmPreamble(unsigned int port)
|
||||
void pxxPutPcmCrc(uint8_t port)
|
||||
{
|
||||
putPcmPart(0, port);
|
||||
putPcmPart(0, port);
|
||||
putPcmPart(0, port);
|
||||
putPcmPart(0, port);
|
||||
uint16_t pulseValue = modulePulsesData[port].pxx.pcmCrc;
|
||||
pxxPutPcmByte(port, pulseValue >> 8);
|
||||
pxxPutPcmByte(port, pulseValue);
|
||||
}
|
||||
|
||||
#if defined(PPM_PIN_UART)
|
||||
inline void initPcmArray(uint8_t port)
|
||||
{
|
||||
if (IS_UART_MODULE(port))
|
||||
uartInitPcmArray(port);
|
||||
else
|
||||
pxxInitPcmArray(port);
|
||||
}
|
||||
|
||||
inline void putPcmHead(uint8_t port)
|
||||
{
|
||||
if (IS_UART_MODULE(port))
|
||||
uartPutPcmHead(port);
|
||||
else
|
||||
pxxPutPcmHead(port);
|
||||
}
|
||||
|
||||
inline void putPcmByte(uint8_t port, uint8_t byte)
|
||||
{
|
||||
if (IS_UART_MODULE(port))
|
||||
uartPutPcmByte(port, byte);
|
||||
else
|
||||
pxxPutPcmByte(port, byte);
|
||||
}
|
||||
|
||||
inline void putPcmCrc(uint8_t port)
|
||||
{
|
||||
if (IS_UART_MODULE(port))
|
||||
uartPutPcmCrc(port);
|
||||
else
|
||||
pxxPutPcmCrc(port);
|
||||
}
|
||||
|
||||
inline void putPcmTail(uint8_t port)
|
||||
{
|
||||
if (!IS_UART_MODULE(port))
|
||||
pxxPutPcmTail(port);
|
||||
}
|
||||
#else
|
||||
inline void initPcmArray(uint8_t port)
|
||||
{
|
||||
pxxInitPcmArray(port);
|
||||
}
|
||||
|
||||
inline void putPcmHead(uint8_t port)
|
||||
{
|
||||
pxxPutPcmHead(port);
|
||||
}
|
||||
|
||||
inline void putPcmByte(uint8_t port, uint8_t byte)
|
||||
{
|
||||
pxxPutPcmByte(port, byte);
|
||||
}
|
||||
|
||||
inline void putPcmCrc(uint8_t port)
|
||||
{
|
||||
pxxPutPcmCrc(port);
|
||||
}
|
||||
|
||||
inline void putPcmTail(uint8_t port)
|
||||
{
|
||||
pxxPutPcmTail(port);
|
||||
}
|
||||
#endif
|
||||
|
||||
void setupPulsesPXX(unsigned int port)
|
||||
void setupPulsesPXX(uint8_t port)
|
||||
{
|
||||
uint16_t pulseValue=0, pulseValueLow=0;
|
||||
|
||||
modulePulsesData[port].pxx.ptr = modulePulsesData[port].pxx.pulses;
|
||||
modulePulsesData[port].pxx.pcmValue = 0 ;
|
||||
modulePulsesData[port].pxx.pcmCrc = 0;
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
|
||||
/* Preamble */
|
||||
putPcmPreamble(port);
|
||||
initPcmArray(port);
|
||||
|
||||
/* Sync */
|
||||
putPcmHead(port);
|
||||
|
||||
/* Rx Number */
|
||||
putPcmByte(g_model.header.modelId[port], port);
|
||||
putPcmByte(port, g_model.header.modelId[port]);
|
||||
|
||||
/* FLAG1 */
|
||||
uint8_t flag1 = (g_model.moduleData[port].rfProtocol << 6);
|
||||
@@ -226,10 +298,10 @@ void setupPulsesPXX(unsigned int port)
|
||||
}
|
||||
}
|
||||
|
||||
putPcmByte(flag1, port);
|
||||
putPcmByte(port, flag1);
|
||||
|
||||
/* FLAG2 */
|
||||
putPcmByte(0, port);
|
||||
putPcmByte(port, 0);
|
||||
|
||||
/* PPM */
|
||||
static uint8_t pass[NUM_MODULES] = { MODULES_INIT(0) };
|
||||
@@ -291,9 +363,9 @@ void setupPulsesPXX(unsigned int port)
|
||||
}
|
||||
|
||||
if (i & 1) {
|
||||
putPcmByte(pulseValueLow, port); // Low byte of channel
|
||||
putPcmByte(((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4), port); // 4 bits each from 2 channels
|
||||
putPcmByte(pulseValue >> 4, port); // High byte of channel
|
||||
putPcmByte(port, pulseValueLow); // Low byte of channel
|
||||
putPcmByte(port, ((pulseValueLow >> 8) & 0x0F) | (pulseValue << 4)); // 4 bits each from 2 channels
|
||||
putPcmByte(port, pulseValue >> 4); // High byte of channel
|
||||
}
|
||||
else {
|
||||
pulseValueLow = pulseValue;
|
||||
@@ -306,18 +378,16 @@ void setupPulsesPXX(unsigned int port)
|
||||
if (port == INTERNAL_MODULE) {
|
||||
antenna = g_model.moduleData[INTERNAL_MODULE].ppm.pulsePol;
|
||||
}
|
||||
putPcmByte (antenna, port);
|
||||
putPcmByte(port, antenna);
|
||||
#else
|
||||
putPcmByte(0, port);
|
||||
putPcmByte(port, 0);
|
||||
#endif
|
||||
|
||||
/* CRC16 */
|
||||
pulseValue = modulePulsesData[port].pxx.pcmCrc;
|
||||
putPcmByte(pulseValue >> 8, port);
|
||||
putPcmByte(pulseValue, port);
|
||||
/* CRC */
|
||||
putPcmCrc(port);
|
||||
|
||||
/* Sync */
|
||||
putPcmHead(port);
|
||||
|
||||
putPcmFlush(port);
|
||||
putPcmTail(port);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user