@@ -35,7 +35,38 @@ uint8_t dsm2BindTimer = DSM2_BIND_TIMEOUT;
|
||||
|
||||
#define BITLEN_DSM2 (8*2) //125000 Baud => 8uS per bit
|
||||
|
||||
#if !defined(PPM_PIN_SERIAL)
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
void putDsm2SerialBit(uint8_t bit)
|
||||
{
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte >>= 1;
|
||||
if (bit & 1) {
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte |= 0x80;
|
||||
}
|
||||
if (++modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount >= 8) {
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sendByteDsm2(uint8_t b) // max 10changes 0 10 10 10 10 1
|
||||
{
|
||||
putDsm2SerialBit(0); // Start bit
|
||||
for (uint8_t i=0; i<8; i++) { // 8 data Bits
|
||||
putDsm2SerialBit(b & 1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
putDsm2SerialBit(1); // Stop bit
|
||||
putDsm2SerialBit(1); // Stop bit
|
||||
}
|
||||
|
||||
void putDsm2Flush()
|
||||
{
|
||||
for (int i=0; i<16; i++) {
|
||||
putDsm2SerialBit(1); // 16 extra stop bits
|
||||
}
|
||||
}
|
||||
#else
|
||||
void _send_1(uint8_t v)
|
||||
{
|
||||
if (modulePulsesData[EXTERNAL_MODULE].dsm2.index & 1)
|
||||
@@ -74,37 +105,6 @@ void putDsm2Flush()
|
||||
else
|
||||
*(modulePulsesData[EXTERNAL_MODULE].dsm2.ptr - 1) = modulePulsesData[EXTERNAL_MODULE].dsm2.rest;
|
||||
}
|
||||
#else
|
||||
void putDsm2SerialBit(uint8_t bit)
|
||||
{
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte >>= 1;
|
||||
if (bit & 1) {
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte |= 0x80;
|
||||
}
|
||||
if (++modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount >= 8) {
|
||||
*modulePulsesData[EXTERNAL_MODULE].dsm2.ptr++ = modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sendByteDsm2(uint8_t b) // max 10changes 0 10 10 10 10 1
|
||||
{
|
||||
putDsm2SerialBit(0); // Start bit
|
||||
for (uint8_t i=0; i<8; i++) { // 8 data Bits
|
||||
putDsm2SerialBit(b & 1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
putDsm2SerialBit(1); // Stop bit
|
||||
putDsm2SerialBit(1); // Stop bit
|
||||
}
|
||||
|
||||
void putDsm2Flush()
|
||||
{
|
||||
for (int i=0; i<16; i++) {
|
||||
putDsm2SerialBit(1); // 16 extra stop bits
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// This is the data stream to send, prepare after 19.5 mS
|
||||
@@ -119,7 +119,7 @@ void setupPulsesDSM2(uint8_t port)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
#else
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = 0;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = 44000;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = DSM2_PERIOD * 2000;
|
||||
#endif
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
|
||||
@@ -24,15 +24,12 @@
|
||||
// see https://github.com/pascallanger/DIY-Multiprotocol-TX-Module
|
||||
// file Multiprotocol/multiprotocol.h
|
||||
|
||||
|
||||
|
||||
#define MULTI_SEND_BIND (1 << 7)
|
||||
#define MULTI_SEND_RANGECHECK (1 << 5)
|
||||
#define MULTI_SEND_AUTOBIND (1 << 6)
|
||||
|
||||
|
||||
#define MULTI_CHANS 16
|
||||
#define MULTI_CHAN_BITS 11
|
||||
#define MULTI_CHANS 16
|
||||
#define MULTI_CHAN_BITS 11
|
||||
|
||||
static void sendFrameProtocolHeader(uint8_t port, bool failsafe);
|
||||
|
||||
@@ -40,15 +37,15 @@ void sendChannels(uint8_t port);
|
||||
|
||||
static void sendSetupFrame()
|
||||
{
|
||||
|
||||
// Old multi firmware will mark config messsages as invalid frame and throw them away
|
||||
sendByteSbus('M');
|
||||
sendByteSbus('P');
|
||||
sendByteSbus(0x80); // Module Configuration
|
||||
sendByteSbus(1); // 1 byte data
|
||||
uint8_t config = 0x1 | 0x2; // inversion + multi_telemetry
|
||||
sendByteSbus(0x80); // Module Configuration
|
||||
sendByteSbus(1); // 1 byte data
|
||||
uint8_t config = 0x01 | 0x02; // inversion + multi_telemetry
|
||||
#if !defined(PPM_PIN_SERIAL)
|
||||
config |= 0x04; //input synchronsisation
|
||||
// TODO why PPM_PIN_SERIAL would change MULTI protocol?
|
||||
config |= 0x04; // input synchronsisation
|
||||
#endif
|
||||
|
||||
sendByteSbus(config);
|
||||
@@ -68,7 +65,6 @@ static void sendFailsafeChannels(uint8_t port)
|
||||
if (g_model.moduleData[port].failsafeMode == FAILSAFE_NOPULSES)
|
||||
failsafeValue = FAILSAFE_CHANNEL_NOPULSE;
|
||||
|
||||
|
||||
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
|
||||
pulseValue = 0;
|
||||
}
|
||||
@@ -87,13 +83,13 @@ static void sendFailsafeChannels(uint8_t port)
|
||||
bits >>= 8;
|
||||
bitsavailable -= 8;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void setupPulsesMultimodule(uint8_t port)
|
||||
{
|
||||
static int counter=0;
|
||||
static int counter = 0;
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
|
||||
@@ -136,7 +136,7 @@ void setupPulses(uint8_t port)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
disable_dsm2(port);
|
||||
disable_serial(port);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -150,7 +150,7 @@ void setupPulses(uint8_t port)
|
||||
case PROTO_MULTIMODULE:
|
||||
#endif
|
||||
case PROTO_SBUS:
|
||||
disable_sbusOut(port);
|
||||
disable_serial(port);
|
||||
break;
|
||||
|
||||
case PROTO_PPM:
|
||||
@@ -168,11 +168,12 @@ void setupPulses(uint8_t port)
|
||||
switch (required_protocol) {
|
||||
case PROTO_PXX:
|
||||
setupPulsesPXX(port);
|
||||
scheduleNextMixerCalculation(port, MODULES_TIMER_PXX_PERIOD);
|
||||
scheduleNextMixerCalculation(port, PXX_PERIOD);
|
||||
break;
|
||||
|
||||
case PROTO_SBUS:
|
||||
setupPulsesSbus(port);
|
||||
scheduleNextMixerCalculation(port, (45+g_model.moduleData[port].sbus.refreshRate)/2);
|
||||
scheduleNextMixerCalculation(port, SBUS_PERIOD);
|
||||
break;
|
||||
|
||||
#if defined(DSM2)
|
||||
@@ -180,7 +181,7 @@ void setupPulses(uint8_t port)
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
setupPulsesDSM2(port);
|
||||
scheduleNextMixerCalculation(port, 11);
|
||||
scheduleNextMixerCalculation(port, DSM2_PERIOD);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -203,14 +204,14 @@ void setupPulses(uint8_t port)
|
||||
}
|
||||
sportSendBuffer(crossfire, len);
|
||||
}
|
||||
scheduleNextMixerCalculation(port, CROSSFIRE_FRAME_PERIOD);
|
||||
scheduleNextMixerCalculation(port, CROSSFIRE_PERIOD);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
setupPulsesMultimodule(port);
|
||||
scheduleNextMixerCalculation(port, 4);
|
||||
scheduleNextMixerCalculation(port, MULTIMODULE_PERIOD);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -219,7 +220,7 @@ void setupPulses(uint8_t port)
|
||||
case PROTO_NONE:
|
||||
#endif
|
||||
setupPulsesPPMModule(port);
|
||||
scheduleNextMixerCalculation(port, (45+g_model.moduleData[port].ppm.frameLength)/2);
|
||||
scheduleNextMixerCalculation(port, PPM_PERIOD(port));
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -236,7 +237,7 @@ void setupPulses(uint8_t port)
|
||||
case PROTO_DSM2_LP45:
|
||||
case PROTO_DSM2_DSM2:
|
||||
case PROTO_DSM2_DSMX:
|
||||
init_dsm2(port);
|
||||
init_serial(port, DSM2_BAUDRATE, DSM2_PERIOD * 2000);
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -248,11 +249,13 @@ void setupPulses(uint8_t port)
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
case PROTO_MULTIMODULE:
|
||||
#endif
|
||||
case PROTO_SBUS:
|
||||
init_sbusOut(port);
|
||||
init_serial(port, MULTIMODULE_BAUDRATE, MULTIMODULE_PERIOD * 2000);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case PROTO_SBUS:
|
||||
init_serial(port, SBUS_BAUDRATE, SBUS_PERIOD_HALF_US);
|
||||
break;
|
||||
|
||||
case PROTO_PPM:
|
||||
init_ppm(port);
|
||||
|
||||
@@ -47,13 +47,15 @@ template<class T> struct PpmPulsesData {
|
||||
#if defined(PXX_FREQUENCY_HIGH)
|
||||
#define EXTMODULE_USART_PXX_BAUDRATE 420000
|
||||
#define INTMODULE_USART_PXX_BAUDRATE 450000
|
||||
#define MODULES_TIMER_PXX_PERIOD 4 // 4ms
|
||||
#define PXX_PERIOD 4/*ms*/
|
||||
#else
|
||||
#define EXTMODULE_USART_PXX_BAUDRATE 115200
|
||||
#define INTMODULE_USART_PXX_BAUDRATE 115200
|
||||
#define MODULES_TIMER_PXX_PERIOD 9 // 9ms
|
||||
#define PXX_PERIOD 9/*ms*/
|
||||
#endif
|
||||
|
||||
#define PXX_PERIOD_HALF_US (PXX_PERIOD * 2000)
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PACK(struct PxxSerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
@@ -64,7 +66,9 @@ PACK(struct PxxSerialPulsesData {
|
||||
uint16_t serialByte;
|
||||
uint16_t serialBitCount;
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PACK(struct Dsm2SerialPulsesData {
|
||||
uint8_t pulses[64];
|
||||
uint8_t * ptr;
|
||||
@@ -72,6 +76,14 @@ PACK(struct Dsm2SerialPulsesData {
|
||||
uint8_t serialBitCount;
|
||||
uint16_t _alignment;
|
||||
});
|
||||
#else
|
||||
#define MAX_PULSES_TRANSITIONS 300
|
||||
PACK(struct Dsm2TimerPulsesData {
|
||||
pulse_duration_t pulses[MAX_PULSES_TRANSITIONS];
|
||||
pulse_duration_t * ptr;
|
||||
uint16_t rest;
|
||||
uint8_t index;
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
|
||||
@@ -83,9 +95,17 @@ PACK(struct PxxUartPulsesData {
|
||||
});
|
||||
#endif
|
||||
|
||||
#define MULTIMODULE_BAUDRATE 100000
|
||||
#if defined(INTMODULE_PULSES) || defined(EXTMODULE_PULSES)
|
||||
#define PPM_PERIOD_HALF_US(module) ((g_model.moduleData[module].ppm.frameLength * 5 + 225) * 200) /*half us*/
|
||||
#define PPM_PERIOD(module) (PPM_PERIOD_HALF_US(module) / 2000) /*ms*/
|
||||
#define DSM2_BAUDRATE 125000
|
||||
#define DSM2_PERIOD 22 /*ms*/
|
||||
#define SBUS_BAUDRATE 100000
|
||||
#define SBUS_PERIOD_HALF_US ((g_model.moduleData[EXTERNAL_MODULE].sbus.refreshRate * 5 + 225) * 200) /*half us*/
|
||||
#define SBUS_PERIOD (SBUS_PERIOD_HALF_US / 2000) /*ms*/
|
||||
#define MULTIMODULE_BAUDRATE 100000
|
||||
#define MULTIMODULE_PERIOD 7 /*ms*/
|
||||
|
||||
#if !defined(EXTMODULE_USART) || !defined(EXTMODULE_USART)
|
||||
/* 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 */
|
||||
@@ -103,15 +123,6 @@ PACK(struct PxxTimerPulsesData {
|
||||
uint16_t pcmCrc;
|
||||
uint32_t pcmOnesCount;
|
||||
});
|
||||
|
||||
#define MAX_PULSES_TRANSITIONS 300
|
||||
|
||||
PACK(struct Dsm2TimerPulsesData {
|
||||
pulse_duration_t pulses[MAX_PULSES_TRANSITIONS];
|
||||
pulse_duration_t * ptr;
|
||||
uint16_t rest;
|
||||
uint8_t index;
|
||||
});
|
||||
#endif
|
||||
|
||||
#define CROSSFIRE_FRAME_MAXLEN 64
|
||||
@@ -121,17 +132,21 @@ PACK(struct CrossfirePulsesData {
|
||||
});
|
||||
|
||||
union ModulePulsesData {
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PxxSerialPulsesData pxx;
|
||||
Dsm2SerialPulsesData dsm2;
|
||||
#endif
|
||||
#if defined(INTMODULE_PULSES) || defined(EXTMODULE_PULSES)
|
||||
PxxTimerPulsesData pxx;
|
||||
Dsm2TimerPulsesData dsm2;
|
||||
#endif
|
||||
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
|
||||
PxxUartPulsesData pxx_uart;
|
||||
#endif
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
PxxSerialPulsesData pxx;
|
||||
#elif !defined(INTMODULE_USART) || !defined(EXTMODULE_USART)
|
||||
PxxTimerPulsesData pxx;
|
||||
#endif
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
Dsm2SerialPulsesData dsm2;
|
||||
#else
|
||||
Dsm2TimerPulsesData dsm2;
|
||||
#endif
|
||||
|
||||
PpmPulsesData<pulse_duration_t> ppm;
|
||||
CrossfirePulsesData crossfire;
|
||||
} __ALIGNED;
|
||||
|
||||
@@ -106,6 +106,8 @@ void uartPutPcmCrc(uint8_t port)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(INTMODULE_USART) || !defined(EXTMODULE_USART)
|
||||
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
void pxxPutPcmSerialBit(uint8_t port, uint8_t bit)
|
||||
{
|
||||
@@ -180,7 +182,7 @@ void pxxInitPcmArray(uint8_t port)
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[port].pxx.pcmValue = 0;
|
||||
#else
|
||||
modulePulsesData[port].pxx.rest = 18000;
|
||||
modulePulsesData[port].pxx.rest = PXX_PERIOD_HALF_US;
|
||||
#endif
|
||||
|
||||
modulePulsesData[port].pxx.pcmOnesCount = 0;
|
||||
@@ -211,6 +213,15 @@ void pxxPutPcmCrc(uint8_t port)
|
||||
pxxPutPcmByte(port, pulseValue >> 8);
|
||||
pxxPutPcmByte(port, pulseValue);
|
||||
}
|
||||
#else
|
||||
// those functions should not be used, a link error will occur if wrong
|
||||
void pxxInitPcmArray(uint8_t port);
|
||||
void pxxInitPcmCrc(uint8_t port);
|
||||
void pxxPutPcmByte(uint8_t port, uint8_t byte);
|
||||
void pxxPutPcmHead(uint8_t port);
|
||||
void pxxPutPcmTail(uint8_t port);
|
||||
void pxxPutPcmCrc(uint8_t port);
|
||||
#endif
|
||||
|
||||
#if defined(INTMODULE_USART) || defined(EXTMODULE_USART)
|
||||
inline void initPcmArray(uint8_t port)
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "opentx.h"
|
||||
|
||||
|
||||
#define BITLEN_SBUS (10*2) //100000 Baud => 10uS per bit
|
||||
#define BITLEN_SBUS (10*2) // 100000 Baud => 10uS per bit
|
||||
|
||||
|
||||
/* The protocol reuse some the DSM2 definitions where they are identical */
|
||||
@@ -84,8 +84,6 @@ void sendByteSbus(uint8_t b) //max 11 changes 0 10 10 10 10 P 1
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#define SBUS_NORMAL_CHANS 16
|
||||
#define SBUS_CHAN_BITS 11
|
||||
|
||||
@@ -100,27 +98,27 @@ void sendByteSbus(uint8_t b) //max 11 changes 0 10 10 10 10 P 1
|
||||
|
||||
#define SBUS_CHAN_CENTER 992
|
||||
|
||||
inline int getChannelValue(uint8_t port, int channel) {
|
||||
inline int getChannelValue(uint8_t port, int channel)
|
||||
{
|
||||
int ch = g_model.moduleData[port].channelsStart+channel;
|
||||
// We will ignore 17 and 18th if that brings us over the limit
|
||||
if (ch > 31)
|
||||
return 0;
|
||||
return channelOutputs[ch] + 2*PPM_CH_CENTER(ch) - 2*PPM_CENTER;
|
||||
return channelOutputs[ch] + 2 * PPM_CH_CENTER(ch) - 2*PPM_CENTER;
|
||||
}
|
||||
|
||||
void setupPulsesSbus(uint8_t port)
|
||||
{
|
||||
#if defined(PPM_PIN_SERIAL)
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialByte = 0;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.serialBitCount = 0;
|
||||
#else
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = (g_model.moduleData[EXTERNAL_MODULE].sbus.refreshRate * 5 + 225)*200 ;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.rest = SBUS_PERIOD_HALF_US;
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.index = 0;
|
||||
#endif
|
||||
|
||||
modulePulsesData[EXTERNAL_MODULE].dsm2.ptr = modulePulsesData[EXTERNAL_MODULE].dsm2.pulses;
|
||||
|
||||
|
||||
// Sync Byte
|
||||
sendByteSbus(SBUS_FRAME_BEGIN_BYTE);
|
||||
|
||||
@@ -140,7 +138,8 @@ void setupPulsesSbus(uint8_t port)
|
||||
bitsavailable -= 8;
|
||||
}
|
||||
}
|
||||
// Flags
|
||||
|
||||
// flags
|
||||
uint8_t flags=0;
|
||||
if (getChannelValue(port, 16) > 0)
|
||||
flags |=SBUS_FLAG_CHANNEL_17;
|
||||
@@ -149,7 +148,7 @@ void setupPulsesSbus(uint8_t port)
|
||||
|
||||
sendByteSbus(flags);
|
||||
|
||||
// Last byte, always 0x0
|
||||
// last byte, always 0x0
|
||||
sendByteSbus(0x0);
|
||||
|
||||
putDsm2Flush();
|
||||
|
||||
Reference in New Issue
Block a user