E010r5: added flip, led and calib channels

This commit is contained in:
Pascal Langer 2021-01-11 12:12:26 +01:00
parent 062fc05eac
commit 49f004e53f
10 changed files with 83 additions and 78 deletions

View File

@ -19,17 +19,6 @@
#define E010R5_FORCE_ID #define E010R5_FORCE_ID
static uint8_t __attribute__((unused)) E010R5_BR(uint8_t byte)
{
uint8_t result = 0;
for(uint8_t i=0;i<8;i++)
{
result = (result<<1) | (byte & 0x01);
byte >>= 1;
}
return result;
}
static void __attribute__((unused)) E010R5_build_data_packet() static void __attribute__((unused)) E010R5_build_data_packet()
{ {
uint8_t buf[16]; uint8_t buf[16];
@ -44,10 +33,13 @@ static void __attribute__((unused)) E010R5_build_data_packet()
buf[ 6] = 0x20; // Trim Elevator buf[ 6] = 0x20; // Trim Elevator
buf[ 7] = 0x20; // Trim Aileron buf[ 7] = 0x20; // Trim Aileron
buf[ 8] = 0x01 // Flags: high=0x01, low=0x00 buf[ 8] = 0x01 // Flags: high=0x01, low=0x00
| GET_FLAG(CH6_SW, 0x10) // headless=0x10 | GET_FLAG(CH5_SW, 0x04) // flip=0x04
| GET_FLAG(CH7_SW, 0x20); // one key return=0x20 | GET_FLAG(CH6_SW, 0x08) // led=0x08
| GET_FLAG(CH8_SW, 0x10) // headless=0x10
| GET_FLAG(CH9_SW, 0x20); // one key return=0x20
buf[ 9] = IS_BIND_IN_PROGRESS ? 0x80 : 0x00 // Flags: bind=0x80 buf[ 9] = IS_BIND_IN_PROGRESS ? 0x80 : 0x00 // Flags: bind=0x80
| GET_FLAG(CH5_SW, 0x01); // flip=0x01 | GET_FLAG(CH7_SW, 0x20) // calib=0x20
| GET_FLAG(CH10_SW, 0x01); // strange effect=0x01=long press on right button
buf[10] = rx_tx_addr[0]; buf[10] = rx_tx_addr[0];
buf[11] = rx_tx_addr[1]; buf[11] = rx_tx_addr[1];
buf[12] = rx_tx_addr[2]; buf[12] = rx_tx_addr[2];
@ -58,9 +50,9 @@ static void __attribute__((unused)) E010R5_build_data_packet()
//Add CRC //Add CRC
crc=0x00; crc=0x00;
for(uint8_t i=0;i<14;i++) for(uint8_t i=0;i<14;i++)
crc=crc16_update(crc,E010R5_BR(buf[i]),8); crc16_update(bit_reverse(buf[i]),8);
buf[14] = E010R5_BR(crc>>8); buf[14] = bit_reverse(crc>>8);
buf[15] = E010R5_BR(crc); buf[15] = bit_reverse(crc);
#if 0 #if 0
debug("B:"); debug("B:");
@ -96,7 +88,7 @@ static void __attribute__((unused)) E010R5_build_data_packet()
//CYRF wants LSB first //CYRF wants LSB first
for(uint8_t i=0;i<71;i++) for(uint8_t i=0;i<71;i++)
packet[i]=E010R5_BR(packet[i]); packet[i]=bit_reverse(packet[i]);
} }
const uint8_t PROGMEM E010R5_init_vals[][2] = { const uint8_t PROGMEM E010R5_init_vals[][2] = {
@ -109,7 +101,7 @@ const uint8_t PROGMEM E010R5_init_vals[][2] = {
{CYRF_1B_TX_OFFSET_LSB, 0x00}, // Tx frequency offset LSB {CYRF_1B_TX_OFFSET_LSB, 0x00}, // Tx frequency offset LSB
{CYRF_1C_TX_OFFSET_MSB, 0x00}, // Tx frequency offset MSB {CYRF_1C_TX_OFFSET_MSB, 0x00}, // Tx frequency offset MSB
{CYRF_0F_XACT_CFG, 0x24}, // Force End State, transaction end state = idle {CYRF_0F_XACT_CFG, 0x24}, // Force End State, transaction end state = idle
{CYRF_03_TX_CFG, 0x00 | 7}, // GFSK mode, PA = +4 dBm {CYRF_03_TX_CFG, 0x00}, // GFSK mode
{CYRF_12_DATA64_THOLD, 0x0a}, // 64 Chip Data PN Code Correlator Threshold = 10 {CYRF_12_DATA64_THOLD, 0x0a}, // 64 Chip Data PN Code Correlator Threshold = 10
{CYRF_0F_XACT_CFG, 0x04}, // Transaction End State = idle {CYRF_0F_XACT_CFG, 0x04}, // Transaction End State = idle
{CYRF_39_ANALOG_CTRL, 0x01}, // synth setting time for all channels is the same as for slow channels {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] = {
{CYRF_12_DATA64_THOLD, 0x0a}, //set pn correlation threshold {CYRF_12_DATA64_THOLD, 0x0a}, //set pn correlation threshold
{CYRF_10_FRAMING_CFG, 0x4a}, //set sop len and threshold {CYRF_10_FRAMING_CFG, 0x4a}, //set sop len and threshold
{CYRF_29_RX_ABORT, 0x0f}, //Clear RX abort? {CYRF_29_RX_ABORT, 0x0f}, //Clear RX abort?
{CYRF_03_TX_CFG, 0x00 | 4}, // GFSK mode, set power (0-7) {CYRF_03_TX_CFG, 0x00}, // GFSK mode
{CYRF_10_FRAMING_CFG, 0x4a}, // 0b11000000 //set sop len and threshold {CYRF_10_FRAMING_CFG, 0x4a}, // 0b11000000 //set sop len and threshold
{CYRF_1F_TX_OVERRIDE, 0x04}, //disable tx CRC {CYRF_1F_TX_OVERRIDE, 0x04}, //disable tx CRC
{CYRF_1E_RX_OVERRIDE, 0x14}, //disable rx crc {CYRF_1E_RX_OVERRIDE, 0x14}, //disable rx crc
@ -177,6 +169,7 @@ uint16_t ReadE010R5()
rf_ch_num = hopping_frequency[hopping_frequency_no]; rf_ch_num = hopping_frequency[hopping_frequency_no];
CYRF_ConfigRFChannel(rf_ch_num); CYRF_ConfigRFChannel(rf_ch_num);
debugln("%d",hopping_frequency[hopping_frequency_no]); debugln("%d",hopping_frequency[hopping_frequency_no]);
CYRF_SetPower(0x00);
packet_count = 0; packet_count = 0;
case 3: case 3:
E010R5_build_data_packet(); E010R5_build_data_packet();

View File

@ -115,7 +115,7 @@ static void __attribute__((unused)) E016HV2_send_packet()
uint8_t byte = (bit_reverse(packet[i])<<1) | (packet[i+1]&0x01); uint8_t byte = (bit_reverse(packet[i])<<1) | (packet[i+1]&0x01);
debug(" %02X",byte) debug(" %02X",byte)
CC2500_WriteReg(CC2500_3F_TXFIFO,byte); CC2500_WriteReg(CC2500_3F_TXFIFO,byte);
crc=crc16_update(crc, byte, 8); crc16_update(byte, 8);
} }
// crc // crc

View File

@ -58,11 +58,12 @@ static void __attribute__((unused)) ssv_pack_dpl(uint8_t addr[], uint8_t pid, ui
uint16_t val; uint16_t val;
} crc; } crc;
crc.val=0x3c18; crc=0x3c18;
for (i = 0; i < 7; ++i) for (i = 0; i < 7; ++i)
crc.val=crc16_update(crc.val,header[i],8); crc16_update(header[i],8);
for (i = 0; i < *len; ++i) for (i = 0; i < *len; ++i)
crc.val=crc16_update(crc.val,payload[i],8); crc16_update(payload[i],8);
crc.val=crc;
// encode payload and crc // encode payload and crc
// xor with this: // xor with this:

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_REVISION 1 #define VERSION_REVISION 1
#define VERSION_PATCH_LEVEL 98 #define VERSION_PATCH_LEVEL 99
//****************** //******************
// Protocols // Protocols

View File

@ -112,7 +112,9 @@ uint8_t rf_ch_num;
uint8_t throttle, rudder, elevator, aileron; uint8_t throttle, rudder, elevator, aileron;
uint8_t flags; uint8_t flags;
uint16_t crc; uint16_t crc;
uint16_t crc16_polynomial;
uint8_t crc8; uint8_t crc8;
uint8_t crc8_polynomial;
uint16_t seed; uint16_t seed;
uint16_t failsafe_count; uint16_t failsafe_count;
uint16_t state; uint16_t state;
@ -1094,6 +1096,8 @@ static void protocol_init()
next_callback=0; // Default is immediate call back next_callback=0; // Default is immediate call back
LED_off; // Led off during protocol init LED_off; // Led off during protocol init
modules_reset(); // Reset all modules modules_reset(); // Reset all modules
crc16_polynomial = 0x1021; // Default CRC crc16_polynomial
crc8_polynomial = 0x31; // Default CRC crc8_polynomial
// reset telemetry // reset telemetry
#ifdef TELEMETRY #ifdef TELEMETRY
@ -2433,6 +2437,37 @@ static void __attribute__((unused)) calc_fh_channels(uint8_t num_ch)
} }
} }
static uint8_t __attribute__((unused)) bit_reverse(uint8_t b_in)
{
uint8_t b_out = 0;
for (uint8_t i = 0; i < 8; ++i)
{
b_out = (b_out << 1) | (b_in & 1);
b_in >>= 1;
}
return b_out;
}
static void __attribute__((unused)) crc16_update(uint8_t a, uint8_t bits)
{
crc ^= a << 8;
while(bits--)
if (crc & 0x8000)
crc = (crc << 1) ^ crc16_polynomial;
else
crc = crc << 1;
}
static void __attribute__((unused)) crc8_update(uint8_t byte)
{
crc8 = crc8 ^ byte;
for ( uint8_t j = 0; j < 8; j++ )
if ( crc8 & 0x80 )
crc8 = (crc8<<1) ^ crc8_polynomial;
else
crc8 <<= 1;
}
/**************************/ /**************************/
/**************************/ /**************************/
/** Interrupt routines **/ /** Interrupt routines **/

View File

@ -62,7 +62,7 @@ static void __attribute__((unused)) NCC_Crypt_Packet()
for(uint8_t i=0; i< NCC_TX_PACKET_LEN-2; i++) for(uint8_t i=0; i< NCC_TX_PACKET_LEN-2; i++)
{ {
packet[i]^=NCC_xor[i]; packet[i]^=NCC_xor[i];
crc=crc16_update(crc, packet[i], 8); crc16_update(packet[i], 8);
} }
crc^=0x60DE; crc^=0x60DE;
packet[NCC_TX_PACKET_LEN-2]=crc>>8; packet[NCC_TX_PACKET_LEN-2]=crc>>8;
@ -74,7 +74,7 @@ static boolean __attribute__((unused)) NCC_Decrypt_Packet()
debug("RX: "); debug("RX: ");
for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++) for(uint8_t i=0; i< NCC_RX_PACKET_LEN-2; i++)
{ {
crc=crc16_update(crc, packet[i], 8); crc=crc16_update( packet[i], 8);
packet[i]^=NCC_xor[i]; packet[i]^=NCC_xor[i];
debug("%02X ",packet[i]); debug("%02X ",packet[i]);
} }

View File

@ -300,29 +300,6 @@ const uint16_t xn297_crc_xorout_enhanced[] = {
0xABFC, 0xE68E, 0x0DE7, 0x28A2, 0x1965 }; 0xABFC, 0xE68E, 0x0DE7, 0x28A2, 0x1965 };
#endif #endif
static uint8_t bit_reverse(uint8_t b_in)
{
uint8_t b_out = 0;
for (uint8_t i = 0; i < 8; ++i)
{
b_out = (b_out << 1) | (b_in & 1);
b_in >>= 1;
}
return b_out;
}
static const uint16_t polynomial = 0x1021;
static uint16_t crc16_update(uint16_t crc, uint8_t a, uint8_t bits)
{
crc ^= a << 8;
while(bits--)
if (crc & 0x8000)
crc = (crc << 1) ^ polynomial;
else
crc = crc << 1;
return crc;
}
void XN297_SetTXAddr(const uint8_t* addr, uint8_t len) void XN297_SetTXAddr(const uint8_t* addr, uint8_t len)
{ {
if (len > 5) len = 5; if (len > 5) len = 5;
@ -403,7 +380,7 @@ void XN297_WritePayload(uint8_t* msg, uint8_t len)
uint8_t offset = xn297_addr_len < 4 ? 1 : 0; uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
uint16_t crc = 0xb5d2; uint16_t crc = 0xb5d2;
for (uint8_t i = offset; i < last; ++i) for (uint8_t i = offset; i < last; ++i)
crc = crc16_update(crc, buf[i], 8); crc16_update( buf[i], 8);
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]); crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]);
else else
@ -468,8 +445,8 @@ void XN297_WriteEnhancedPayload(uint8_t* msg, uint8_t len, uint8_t noack)
uint8_t offset = xn297_addr_len < 4 ? 1 : 0; uint8_t offset = xn297_addr_len < 4 ? 1 : 0;
uint16_t crc = 0xb5d2; uint16_t crc = 0xb5d2;
for (uint8_t i = offset; i < last; ++i) for (uint8_t i = offset; i < last; ++i)
crc = crc16_update(crc, packet[i], 8); crc16_update( packet[i], 8);
crc = crc16_update(crc, packet[last] & 0xc0, 2); crc16_update( packet[last] & 0xc0, 2);
if (xn297_scramble_enabled) if (xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]); crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
//else //else
@ -512,11 +489,11 @@ boolean XN297_ReadPayload(uint8_t* msg, uint8_t len)
uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1]; uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1];
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
b_in ^= xn297_scramble[i]; b_in ^= xn297_scramble[i];
crc = crc16_update(crc, b_in, 8); crc16_update( b_in, 8);
} }
//process payload //process payload
for (uint8_t i = 0; i < len; ++i) for (uint8_t i = 0; i < len; ++i)
crc = crc16_update(crc, buf[i], 8); crc16_update( buf[i], 8);
//xorout //xorout
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]); 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)
uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1]; uint8_t b_in=xn297_rx_addr[xn297_addr_len-i-1];
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
b_in ^= xn297_scramble[i]; b_in ^= xn297_scramble[i];
crc = crc16_update(crc, b_in, 8); crc16_update( b_in, 8);
} }
//process payload //process payload
for (uint8_t i = 0; i < len+1; ++i) for (uint8_t i = 0; i < len+1; ++i)
crc = crc16_update(crc, buffer[i], 8); crc16_update( buffer[i], 8);
crc = crc16_update(crc, buffer[len+1] & 0xc0, 2); crc16_update( buffer[len+1] & 0xc0, 2);
//xorout //xorout
if (xn297_scramble_enabled) if (xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]); crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
@ -606,9 +583,10 @@ void HS6200_SetTXAddr(const uint8_t* addr, uint8_t len)
NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t*)"\xaa\xaa\xaa\xaa\xaa", 5); NRF24L01_WriteRegisterMulti(NRF24L01_10_TX_ADDR, (uint8_t*)"\xaa\xaa\xaa\xaa\xaa", 5);
// precompute address crc // precompute address crc
hs6200_crc_init = 0xffff; crc = 0xffff;
for(int i=0; i<len; i++) for(int i=0; i<len; i++)
hs6200_crc_init = crc16_update(hs6200_crc_init, addr[len-1-i], 8); crc16_update(addr[len-1-i], 8);
hs6200_crc_init=crc;
memcpy(hs6200_tx_addr, addr, len); memcpy(hs6200_tx_addr, addr, len);
hs6200_address_length = len; hs6200_address_length = len;
} }
@ -616,14 +594,14 @@ void HS6200_SetTXAddr(const uint8_t* addr, uint8_t len)
static uint16_t hs6200_calc_crc(uint8_t* msg, uint8_t len) static uint16_t hs6200_calc_crc(uint8_t* msg, uint8_t len)
{ {
uint8_t pos; uint8_t pos;
uint16_t crc = hs6200_crc_init;
crc = hs6200_crc_init;
// pcf + payload // pcf + payload
for(pos=0; pos < len-1; pos++) for(pos=0; pos < len-1; pos++)
crc = crc16_update(crc, msg[pos], 8); crc16_update(msg[pos], 8);
// last byte (1 bit only) // last byte (1 bit only)
if(len > 0) if(len > 0)
crc = crc16_update(crc, msg[pos+1], 1); crc16_update(msg[pos+1], 1);
return crc; return crc;
} }
@ -817,14 +795,14 @@ uint8_t LT8900_ReadPayload(uint8_t* msg, uint8_t len)
//Check len //Check len
if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN)) if(LT8900_Flags&_BV(LT8900_PACKET_LENGTH_EN))
{ {
crc=crc16_update(crc,buffer[pos],8); crc16_update(buffer[pos],8);
if(bit_reverse(len)!=buffer[pos++]) if(bit_reverse(len)!=buffer[pos++])
return 0; // wrong len... return 0; // wrong len...
} }
//Decode message //Decode message
for(i=0;i<len;i++) for(i=0;i<len;i++)
{ {
crc=crc16_update(crc,buffer[pos],8); crc16_update(buffer[pos],8);
msg[i]=bit_reverse(buffer[pos++]); msg[i]=bit_reverse(buffer[pos++]);
} }
//Check CRC //Check CRC
@ -846,14 +824,14 @@ void LT8900_WritePayload(uint8_t* msg, uint8_t len)
{ {
tmp=bit_reverse(len); tmp=bit_reverse(len);
buffer[pos++]=tmp; buffer[pos++]=tmp;
crc=crc16_update(crc,tmp,8); crc16_update(tmp,8);
} }
//Add payload //Add payload
for(i=0;i<len;i++) for(i=0;i<len;i++)
{ {
tmp=bit_reverse(msg[i]); tmp=bit_reverse(msg[i]);
buffer[pos++]=tmp; buffer[pos++]=tmp;
crc=crc16_update(crc,tmp,8); crc16_update(tmp,8);
} }
//Add CRC //Add CRC
if(LT8900_Flags&_BV(LT8900_CRC_ON)) if(LT8900_Flags&_BV(LT8900_CRC_ON))

View File

@ -126,7 +126,6 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le
uint8_t buf[32]; uint8_t buf[32];
uint8_t last = 0; uint8_t last = 0;
uint8_t i; uint8_t i;
static const uint16_t initial = 0xb5d2;
// address // address
for (i = 0; i < xn297_addr_len; ++i) for (i = 0; i < xn297_addr_len; ++i)
@ -147,9 +146,9 @@ static void __attribute__((unused)) XN297L_WritePayload(uint8_t* msg, uint8_t le
} }
// crc // crc
uint16_t crc = initial; uint16_t crc = 0xb5d2;
for (uint8_t i = 0; i < last; ++i) for (uint8_t i = 0; i < last; ++i)
crc = crc16_update(crc, buf[i], 8); crc16_update( buf[i], 8);
if(xn297_scramble_enabled) if(xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]); crc ^= pgm_read_word(&xn297_crc_xorout_scrambled[xn297_addr_len - 3 + len]);
else else
@ -230,8 +229,8 @@ static void __attribute__((unused)) XN297L_WriteEnhancedPayload(uint8_t* msg, ui
{ {
uint16_t crc = 0xb5d2; uint16_t crc = 0xb5d2;
for (uint8_t i = 0; i < last; ++i) for (uint8_t i = 0; i < last; ++i)
crc = crc16_update(crc, buf[i], 8); crc16_update( buf[i], 8);
crc = crc16_update(crc, buf[last] & 0xc0, 2); crc16_update( buf[last] & 0xc0, 2);
if (xn297_scramble_enabled) if (xn297_scramble_enabled)
crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]); crc ^= pgm_read_word(&xn297_crc_xorout_scrambled_enhanced[xn297_addr_len-3+len]);
//else //else
@ -399,7 +398,7 @@ static void __attribute__((unused)) NRF250K_WritePayload(uint8_t* msg, uint8_t l
// crc // crc
uint16_t crc = 0xffff; uint16_t crc = 0xffff;
for (uint8_t i = 1; i < last; ++i) for (uint8_t i = 1; i < last; ++i)
crc = crc16_update(crc, buf[i], 8); crc16_update( buf[i], 8);
buf[last++] = crc >> 8; buf[last++] = crc >> 8;
buf[last++] = crc & 0xff; buf[last++] = crc & 0xff;
buf[last++] = 0; buf[last++] = 0;

View File

@ -312,7 +312,6 @@
#undef XK_NRF24L01_INO #undef XK_NRF24L01_INO
#undef YD717_NRF24L01_INO #undef YD717_NRF24L01_INO
#undef ZSX_NRF24L01_INO #undef ZSX_NRF24L01_INO
#undef E010R5_CYRF6936_INO // Use both CYRF and NRF code
#endif #endif
#if not defined(STM32_BOARD) #if not defined(STM32_BOARD)
#undef SX1276_INSTALLED #undef SX1276_INSTALLED

View File

@ -837,11 +837,11 @@ A|E|T|R|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12
## E010R5 - *81* ## E010R5 - *81*
Models: E010 R5 red boards, JJRC H36 Models: E010 R5 red boards, JJRC H36
**Only 1 ID available** **Only 1 ID available**. More IDs can be added if you send me your "unused" original TX.
CH1|CH2|CH3|CH4|CH5|CH6|CH7 CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10
---|---|---|---|---|---|--- ---|---|---|---|---|---|---|---|---|---
A|E|T|R|FLIP|HEADLESS|RTH A|E|T|R|FLIP|LED|CALIB|HEADLESS|RTH|UNK
## J6Pro - *22* ## J6Pro - *22*