#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);
}