#2894 - Crossfire (inverted serial) sent on S.PORT pin in the module bay (ported from master f7044a20ec)

16 channels sent every 2.5ms now @ 200KBauds with CRC
This commit is contained in:
Damjan Adamic
2015-12-20 17:10:32 +01:00
parent e8983250ca
commit 91e80d446a
31 changed files with 435 additions and 92 deletions
+62
View File
@@ -0,0 +1,62 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "../opentx.h"
#define CROSSFIRE_START_BYTE 0x0F
#define CROSSFIRE_CH_CENTER 0x3E0
#define CROSSFIRE_CH_BITS 11
// Range for pulses (channels output) is [-1024:+1024]
void createCrossfireFrame(uint8_t * frame, int16_t * pulses)
{
uint8_t * buf = frame;
*buf++ = CROSSFIRE_START_BYTE;
uint32_t bits = 0;
uint8_t bitsavailable = 0;
for (int i=0; i<NUM_TRAINER; i++) {
bits |= (CROSSFIRE_CH_CENTER + (((pulses[i]) * 4) / 5)) << bitsavailable;
bitsavailable += CROSSFIRE_CH_BITS;
while (bitsavailable >= 8) {
*buf++ = bits;
bits >>= 8;
bitsavailable -= 8;
}
}
*buf++ = 0;
*buf++ = crc16(frame, 24);
}
+27
View File
@@ -98,6 +98,11 @@ void setupPulses(unsigned int port)
}
}
break;
#endif
#if defined(PCBTARANIS) && defined(CROSSFIRE)
case MODULE_TYPE_CROSSFIRE:
required_protocol = PROTO_CROSSFIRE;
break;
#endif
default:
required_protocol = PROTO_NONE;
@@ -129,6 +134,11 @@ void setupPulses(unsigned int port)
case PROTO_DSM2_DSMX:
disable_dsm2(port);
break;
#endif
#if defined(CROSSFIRE)
case PROTO_CROSSFIRE:
disable_crossfire(port);
break;
#endif
case PROTO_PPM:
disable_ppm(port);
@@ -150,10 +160,16 @@ void setupPulses(unsigned int port)
case PROTO_DSM2_DSMX:
init_dsm2(port);
break;
#endif
#if defined(CROSSFIRE)
case PROTO_CROSSFIRE:
init_crossfire(port);
break;
#endif
case PROTO_PPM:
init_ppm(port);
break;
default:
init_no_pulses(port);
break;
@@ -171,6 +187,17 @@ void setupPulses(unsigned int port)
case PROTO_DSM2_DSMX:
setupPulsesDSM2(port);
break;
#endif
#if defined(CROSSFIRE)
case PROTO_CROSSFIRE:
{
if (telemetryProtocol == PROTOCOL_PULSES_CROSSFIRE) {
uint8_t * crossfire = modulePulsesData[port].crossfire.pulses;
createCrossfireFrame(crossfire, &channelOutputs[g_model.moduleData[port].channelsStart]);
sportSendBuffer(crossfire, CROSSFIRE_FRAME_LEN);
}
break;
}
#endif
case PROTO_PPM:
setupPulsesPPM(port);
+9
View File
@@ -84,10 +84,17 @@ PACK(struct Dsm2PulsesData {
});
#endif
#define CROSSFIRE_BAUDRATE 200000
#define CROSSFIRE_FRAME_LEN 25
PACK(struct CrossfirePulsesData {
uint8_t pulses[CROSSFIRE_FRAME_LEN];
});
union ModulePulsesData {
PxxPulsesData pxx;
Dsm2PulsesData dsm2;
PpmPulsesData ppm;
CrossfirePulsesData crossfire;
};
union TrainerPulsesData {
@@ -102,6 +109,8 @@ void setupPulsesDSM2(unsigned int port);
void setupPulsesPXX(unsigned int port);
void setupPulsesPPM(unsigned int port);
void createCrossfireFrame(uint8_t * frame, int16_t * pulses);
#if defined(HUBSAN)
void Hubsan_Init();
#endif