Skip to content

Commit 49f004e

Browse files
author
Pascal Langer
committed
E010r5: added flip, led and calib channels
1 parent 062fc05 commit 49f004e

File tree

10 files changed

+83
-78
lines changed

10 files changed

+83
-78
lines changed

Multiprotocol/E010R5_cyrf6936.ino

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@
1919

2020
#define E010R5_FORCE_ID
2121

22-
static uint8_t __attribute__((unused)) E010R5_BR(uint8_t byte)
23-
{
24-
uint8_t result = 0;
25-
for(uint8_t i=0;i<8;i++)
26-
{
27-
result = (result<<1) | (byte & 0x01);
28-
byte >>= 1;
29-
}
30-
return result;
31-
}
32-
3322
static void __attribute__((unused)) E010R5_build_data_packet()
3423
{
3524
uint8_t buf[16];
@@ -44,10 +33,13 @@ static void __attribute__((unused)) E010R5_build_data_packet()
4433
buf[ 6] = 0x20; // Trim Elevator
4534
buf[ 7] = 0x20; // Trim Aileron
4635
buf[ 8] = 0x01 // Flags: high=0x01, low=0x00
47-
| GET_FLAG(CH6_SW, 0x10) // headless=0x10
48-
| GET_FLAG(CH7_SW, 0x20); // one key return=0x20
36+
| GET_FLAG(CH5_SW, 0x04) // flip=0x04
37+
| GET_FLAG(CH6_SW, 0x08) // led=0x08
38+
| GET_FLAG(CH8_SW, 0x10) // headless=0x10
39+
| GET_FLAG(CH9_SW, 0x20); // one key return=0x20
4940
buf[ 9] = IS_BIND_IN_PROGRESS ? 0x80 : 0x00 // Flags: bind=0x80
50-
| GET_FLAG(CH5_SW, 0x01); // flip=0x01
41+
| GET_FLAG(CH7_SW, 0x20) // calib=0x20
42+
| GET_FLAG(CH10_SW, 0x01); // strange effect=0x01=long press on right button
5143
buf[10] = rx_tx_addr[0];
5244
buf[11] = rx_tx_addr[1];
5345
buf[12] = rx_tx_addr[2];
@@ -58,9 +50,9 @@ static void __attribute__((unused)) E010R5_build_data_packet()
5850
//Add CRC
5951
crc=0x00;
6052
for(uint8_t i=0;i<14;i++)
61-
crc=crc16_update(crc,E010R5_BR(buf[i]),8);
62-
buf[14] = E010R5_BR(crc>>8);
63-
buf[15] = E010R5_BR(crc);
53+
crc16_update(bit_reverse(buf[i]),8);
54+
buf[14] = bit_reverse(crc>>8);
55+
buf[15] = bit_reverse(crc);
6456

6557
#if 0
6658
debug("B:");
@@ -96,7 +88,7 @@ static void __attribute__((unused)) E010R5_build_data_packet()
9688

9789
//CYRF wants LSB first
9890
for(uint8_t i=0;i<71;i++)
99-
packet[i]=E010R5_BR(packet[i]);
91+
packet[i]=bit_reverse(packet[i]);
10092
}
10193

10294
const uint8_t PROGMEM E010R5_init_vals[][2] = {
@@ -109,7 +101,7 @@ const uint8_t PROGMEM E010R5_init_vals[][2] = {
109101
{CYRF_1B_TX_OFFSET_LSB, 0x00}, // Tx frequency offset LSB
110102
{CYRF_1C_TX_OFFSET_MSB, 0x00}, // Tx frequency offset MSB
111103
{CYRF_0F_XACT_CFG, 0x24}, // Force End State, transaction end state = idle
112-
{CYRF_03_TX_CFG, 0x00 | 7}, // GFSK mode, PA = +4 dBm
104+
{CYRF_03_TX_CFG, 0x00}, // GFSK mode
113105
{CYRF_12_DATA64_THOLD, 0x0a}, // 64 Chip Data PN Code Correlator Threshold = 10
114106
{CYRF_0F_XACT_CFG, 0x04}, // Transaction End State = idle
115107
{CYRF_39_ANALOG_CTRL, 0x01}, // synth setting time for all channels is the same as for slow channels
@@ -118,7 +110,7 @@ const uint8_t PROGMEM E010R5_init_vals[][2] = {
118110
{CYRF_12_DATA64_THOLD, 0x0a}, //set pn correlation threshold
119111
{CYRF_10_FRAMING_CFG, 0x4a}, //set sop len and threshold
120112
{CYRF_29_RX_ABORT, 0x0f}, //Clear RX abort?
121-
{CYRF_03_TX_CFG, 0x00 | 4}, // GFSK mode, set power (0-7)
113+
{CYRF_03_TX_CFG, 0x00}, // GFSK mode
122114
{CYRF_10_FRAMING_CFG, 0x4a}, // 0b11000000 //set sop len and threshold
123115
{CYRF_1F_TX_OVERRIDE, 0x04}, //disable tx CRC
124116
{CYRF_1E_RX_OVERRIDE, 0x14}, //disable rx crc
@@ -177,6 +169,7 @@ uint16_t ReadE010R5()
177169
rf_ch_num = hopping_frequency[hopping_frequency_no];
178170
CYRF_ConfigRFChannel(rf_ch_num);
179171
debugln("%d",hopping_frequency[hopping_frequency_no]);
172+
CYRF_SetPower(0x00);
180173
packet_count = 0;
181174
case 3:
182175
E010R5_build_data_packet();

Multiprotocol/E016HV2_cc2500.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static void __attribute__((unused)) E016HV2_send_packet()
115115
uint8_t byte = (bit_reverse(packet[i])<<1) | (packet[i+1]&0x01);
116116
debug(" %02X",byte)
117117
CC2500_WriteReg(CC2500_3F_TXFIFO,byte);
118-
crc=crc16_update(crc, byte, 8);
118+
crc16_update(byte, 8);
119119
}
120120

121121
// crc

Multiprotocol/FQ777_nrf24l01.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ static void __attribute__((unused)) ssv_pack_dpl(uint8_t addr[], uint8_t pid, ui
5858
uint16_t val;
5959
} crc;
6060

61-
crc.val=0x3c18;
61+
crc=0x3c18;
6262
for (i = 0; i < 7; ++i)
63-
crc.val=crc16_update(crc.val,header[i],8);
63+
crc16_update(header[i],8);
6464
for (i = 0; i < *len; ++i)
65-
crc.val=crc16_update(crc.val,payload[i],8);
65+
crc16_update(payload[i],8);
66+
crc.val=crc;
6667

6768
// encode payload and crc
6869
// xor with this:

Multiprotocol/Multiprotocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 3
2121
#define VERSION_REVISION 1
22-
#define VERSION_PATCH_LEVEL 98
22+
#define VERSION_PATCH_LEVEL 99
2323

2424
//******************
2525
// Protocols

Multiprotocol/Multiprotocol.ino

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ uint8_t rf_ch_num;
112112
uint8_t throttle, rudder, elevator, aileron;
113113
uint8_t flags;
114114
uint16_t crc;
115+
uint16_t crc16_polynomial;
115116
uint8_t crc8;
117+
uint8_t crc8_polynomial;
116118
uint16_t seed;
117119
uint16_t failsafe_count;
118120
uint16_t state;
@@ -1094,6 +1096,8 @@ static void protocol_init()
10941096
next_callback=0; // Default is immediate call back
10951097
LED_off; // Led off during protocol init
10961098
modules_reset(); // Reset all modules
1099+
crc16_polynomial = 0x1021; // Default CRC crc16_polynomial
1100+
crc8_polynomial = 0x31; // Default CRC crc8_polynomial
10971101

10981102
// reset telemetry
10991103
#ifdef TELEMETRY
@@ -2433,6 +2437,37 @@ static void __attribute__((unused)) calc_fh_channels(uint8_t num_ch)
24332437
}
24342438
}
24352439

2440+
static uint8_t __attribute__((unused)) bit_reverse(uint8_t b_in)
2441+
{
2442+
uint8_t b_out = 0;
2443+
for (uint8_t i = 0; i < 8; ++i)
2444+
{
2445+
b_out = (b_out << 1) | (b_in & 1);
2446+
b_in >>= 1;
2447+
}
2448+
return b_out;
2449+
}
2450+
2451+
static void __attribute__((unused)) crc16_update(uint8_t a, uint8_t bits)
2452+
{
2453+
crc ^= a << 8;
2454+
while(bits--)
2455+
if (crc & 0x8000)
2456+
crc = (crc << 1) ^ crc16_polynomial;
2457+
else
2458+
crc = crc << 1;
2459+
}
2460+
2461+
static void __attribute__((unused)) crc8_update(uint8_t byte)
2462+
{
2463+
crc8 = crc8 ^ byte;
2464+
for ( uint8_t j = 0; j < 8; j++ )
2465+
if ( crc8 & 0x80 )
2466+
crc8 = (crc8<<1) ^ crc8_polynomial;
2467+
else
2468+
crc8 <<= 1;
2469+
}
2470+
24362471
/**************************/
24372472
/**************************/
24382473
/** Interrupt routines **/

Multiprotocol/NCC1701_nrf24l01.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void __attribute__((unused)) NCC_Crypt_Packet()
6262
for(uint8_t i=0; i< NCC_TX_PACKET_LEN-2; i++)
6363
{
6464
packet[i]^=NCC_xor[i];
65-
crc=crc16_update(crc, packet[i], 8);
65+
crc16_update(packet[i], 8);
6666
}
6767
crc^=0x60DE;
6868
packet[NCC_TX_PACKET_LEN-2]=crc>>8;
@@ -74,7 +74,7 @@ static boolean __attribute__((unused)) NCC_Decrypt_Packet()
7474
debug("RX: ");
7575
for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++)
7676
{
77-
crc=crc16_update(crc, packet[i], 8);
77+
crc=crc16_update( packet[i], 8);
7878
packet[i]^=NCC_xor[i];
7979
debug("%02X ",packet[i]);
8080
}

Multiprotocol/NRF24l01_SPI.ino

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -300,29 +300,6 @@ const uint16_t xn297_crc_xorout_enhanced[] = {
300300
0xABFC, 0xE68E, 0x0DE7, 0x28A2, 0x1965 };
301301
#endif
302302

303-
static uint8_t bit_reverse(uint8_t b_in)
304-
{
305-
uint8_t b_out = 0;
306-
for (uint8_t i = 0; i < 8; ++i)
307-
{
308-
b_out = (b_out << 1) | (b_in & 1);
309-
b_in >>= 1;
310-
}
311-
return b_out;
312-
}
313-
314-
static const uint16_t polynomial = 0x1021;
315-
static uint16_t crc16_update(uint16_t crc, uint8_t a, uint8_t bits)
316-
{
317-
crc ^= a << 8;
318-
while(bits--)
319-
if (crc & 0x8000)
320-
crc = (crc << 1) ^ polynomial;
321-
else
322-
crc = crc << 1;
323-
return crc;
324-
}
325-
326303
void XN297_SetTXAddr(const uint8_t* addr, uint8_t len)
327304
{
328305
if (len > 5) len = 5;
@@ -403,7 +380,7 @@ void XN297_WritePayload(uint8_t* msg, uint8_t len)
403380
uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
404381
uint16_t crc = 0xb5d2;
405382
for (uint8_t i = offset; i < last; ++i)
406-
crc = crc16_update(crc, buf[i], 8);
383+
crc16_update( buf[i], 8);
407384
if(xn297_scramble_enabled)
408385
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]);
409386
else
@@ -468,8 +445,8 @@ void XN297_WriteEnhancedPayload(uint8_t* msg, uint8_t len, uint8_t noack)
468445
uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
469446
uint16_t crc = 0xb5d2;
470447
for (uint8_t i = offset; i < last; ++i)
471-
crc = crc16_update(crc, packet[i], 8);
472-
crc = crc16_update(crc, packet[last] & 0xc0, 2);
448+
crc16_update( packet[i], 8);
449+
crc16_update( packet[last] & 0xc0, 2);
473450
if (xn297_scramble_enabled)
474451
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
475452
//else
@@ -512,11 +489,11 @@ boolean XN297_ReadPayload(uint8_t* msg, uint8_t len)
512489
uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1];
513490
if(xn297_scramble_enabled)
514491
b_in ^= xn297_scramble[i];
515-
crc = crc16_update(crc, b_in, 8);
492+
crc16_update( b_in, 8);
516493
}
517494
//process payload
518495
for (uint8_t i = 0; i < len; ++i)
519-
crc = crc16_update(crc, buf[i], 8);
496+
crc16_update( buf[i], 8);
520497
//xorout
521498
if(xn297_scramble_enabled)
522499
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]);
@@ -559,12 +536,12 @@ uint8_t XN297_ReadEnhancedPayload(uint8_t* msg, uint8_t len)
559536
uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1];
560537
if(xn297_scramble_enabled)
561538
b_in ^= xn297_scramble[i];
562-
crc = crc16_update(crc, b_in, 8);
539+
crc16_update( b_in, 8);
563540
}
564541
//process payload
565542
for (uint8_t i = 0; i < len+1; ++i)
566-
crc = crc16_update(crc, buffer[i], 8);
567-
crc = crc16_update(crc, buffer[len+1] & 0xc0, 2);
543+
crc16_update( buffer[i], 8);
544+
crc16_update( buffer[len+1] & 0xc0, 2);
568545
//xorout
569546
if (xn297_scramble_enabled)
570547
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
@@ -606,24 +583,25 @@ void HS6200_SetTXAddr(const uint8_t* addr, uint8_t len)
606583
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t*)"\xaa\xaa\xaa\xaa\xaa", 5);
607584

608585
// precompute address crc
609-
hs6200_crc_init = 0xffff;
586+
crc = 0xffff;
610587
for(int i=0; i<len; i++)
611-
hs6200_crc_init = crc16_update(hs6200_crc_init, addr[len-1-i], 8);
588+
crc16_update(addr[len-1-i], 8);
589+
hs6200_crc_init=crc;
612590
memcpy(hs6200_tx_addr, addr, len);
613591
hs6200_address_length = len;
614592
}
615593

616594
static uint16_t hs6200_calc_crc(uint8_t* msg, uint8_t len)
617595
{
618596
uint8_t pos;
619-
uint16_t crc = hs6200_crc_init;
620597

598+
crc = hs6200_crc_init;
621599
// pcf + payload
622600
for(pos=0; pos < len-1; pos++)
623-
crc = crc16_update(crc, msg[pos], 8);
601+
crc16_update(msg[pos], 8);
624602
// last byte (1 bit only)
625603
if(len > 0)
626-
crc = crc16_update(crc, msg[pos+1], 1);
604+
crc16_update(msg[pos+1], 1);
627605
return crc;
628606
}
629607

@@ -817,14 +795,14 @@ uint8_t LT8900_ReadPayload(uint8_t* msg, uint8_t len)
817795
//Check len
818796
if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN))
819797
{
820-
crc=crc16_update(crc,buffer[pos],8);
798+
crc16_update(buffer[pos],8);
821799
if(bit_reverse(len)!=buffer[pos++])
822800
return 0; // wrong len...
823801
}
824802
//Decode message
825803
for(i=0;i<len;i++)
826804
{
827-
crc=crc16_update(crc,buffer[pos],8);
805+
crc16_update(buffer[pos],8);
828806
msg[i]=bit_reverse(buffer[pos++]);
829807
}
830808
//Check CRC
@@ -846,14 +824,14 @@ void LT8900_WritePayload(uint8_t* msg, uint8_t len)
846824
{
847825
tmp=bit_reverse(len);
848826
buffer[pos++]=tmp;
849-
crc=crc16_update(crc,tmp,8);
827+
crc16_update(tmp,8);
850828
}
851829
//Add payload
852830
for(i=0;i<len;i++)
853831
{
854832
tmp=bit_reverse(msg[i]);
855833
buffer[pos++]=tmp;
856-
crc=crc16_update(crc,tmp,8);
834+
crc16_update(tmp,8);
857835
}
858836
//Add CRC
859837
if(LT8900_Flags&_BV(LT8900_CRC_ON))

Multiprotocol/NRF250K_EMU.ino

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le
126126
uint8_t buf[32];
127127
uint8_t last = 0;
128128
uint8_t i;
129-
static const uint16_t initial = 0xb5d2;
130129

131130
// address
132131
for (i = 0; i < xn297_addr_len; ++i)
@@ -147,9 +146,9 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le
147146
}
148147

149148
// crc
150-
uint16_t crc = initial;
149+
uint16_t crc = 0xb5d2;
151150
for (uint8_t i = 0; i < last; ++i)
152-
crc = crc16_update(crc, buf[i], 8);
151+
crc16_update( buf[i], 8);
153152
if(xn297_scramble_enabled)
154153
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]);
155154
else
@@ -230,8 +229,8 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui
230229
{
231230
uint16_t crc = 0xb5d2;
232231
for (uint8_t i = 0; i < last; ++i)
233-
crc = crc16_update(crc, buf[i], 8);
234-
crc = crc16_update(crc, buf[last] & 0xc0, 2);
232+
crc16_update( buf[i], 8);
233+
crc16_update( buf[last] & 0xc0, 2);
235234
if (xn297_scramble_enabled)
236235
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
237236
//else
@@ -399,7 +398,7 @@ static void __attribute__((unused)) NRF250K_WritePayload(uint8_t* msg, uint8_t l
399398
// crc
400399
uint16_t crc = 0xffff;
401400
for (uint8_t i = 1; i < last; ++i)
402-
crc = crc16_update(crc, buf[i], 8);
401+
crc16_update( buf[i], 8);
403402
buf[last++] = crc >> 8;
404403
buf[last++] = crc & 0xff;
405404
buf[last++] = 0;

Multiprotocol/Validate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,6 @@
312312
#undef XK_NRF24L01_INO
313313
#undef YD717_NRF24L01_INO
314314
#undef ZSX_NRF24L01_INO
315-
#undef E010R5_CYRF6936_INO // Use both CYRF and NRF code
316315
#endif
317316
#if not defined(STM32_BOARD)
318317
#undef SX1276_INSTALLED

0 commit comments

Comments
 (0)