New Corona protocol and autobind bug fix

This commit is contained in:
Pascal Langer 2018-01-03 13:04:58 +01:00
parent d70d8f62a4
commit 70db505dd9
38 changed files with 366 additions and 77 deletions

View File

@ -145,7 +145,7 @@ static void A7105_SetPower_Value(int power)
void A7105_SetPower() void A7105_SetPower()
{ {
uint8_t power=A7105_BIND_POWER; uint8_t power=A7105_BIND_POWER;
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
#ifdef A7105_ENABLE_LOW_POWER #ifdef A7105_ENABLE_LOW_POWER
power=IS_POWER_FLAG_on?A7105_HIGH_POWER:A7105_LOW_POWER; power=IS_POWER_FLAG_on?A7105_HIGH_POWER:A7105_LOW_POWER;
#else #else

View File

@ -350,7 +350,7 @@ uint16_t initAFHDS2A()
AFHDS2A_calc_channels(); AFHDS2A_calc_channels();
packet_count = 0; packet_count = 0;
bind_phase = 0; bind_phase = 0;
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
phase = AFHDS2A_BIND1; phase = AFHDS2A_BIND1;
else else
{ {

View File

@ -175,7 +175,7 @@ uint16_t initASSAN()
ASSAN_init(); ASSAN_init();
hopping_frequency_no = 0; hopping_frequency_no = 0;
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
phase=ASSAN_BIND0; phase=ASSAN_BIND0;
else else
phase=ASSAN_DATA0; phase=ASSAN_DATA0;

View File

@ -247,7 +247,7 @@ static void __attribute__((unused)) BAYANG_init()
uint16_t BAYANG_callback() uint16_t BAYANG_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
{ {
if(packet_count==0) if(packet_count==0)
BAYANG_send_packet(0); BAYANG_send_packet(0);

View File

@ -332,7 +332,7 @@ static void __attribute__((unused)) CABELL_setAddress()
// Serial.print("NORM ID: ");Serial.print((uint32_t)(CABELL_normal_addr>>32)); Serial.print(" ");Serial.println((uint32_t)((CABELL_normal_addr<<32)>>32)); // Serial.print("NORM ID: ");Serial.print((uint32_t)(CABELL_normal_addr>>32)); Serial.print(" ");Serial.println((uint32_t)((CABELL_normal_addr<<32)>>32));
if (IS_BIND_DONE_on) if (IS_BIND_DONE)
{ {
CABELL_addr = (((uint64_t)rx_tx_addr[0]) << 32) + CABELL_addr = (((uint64_t)rx_tx_addr[0]) << 32) +
(((uint64_t)rx_tx_addr[1]) << 24) + (((uint64_t)rx_tx_addr[1]) << 24) +
@ -386,7 +386,7 @@ static void CABELL_SetPower() // This over-ride the standard Set Power to all
// Note that on many modules max power may actually be worse than the normal high power setting // Note that on many modules max power may actually be worse than the normal high power setting
// test and only use max if it helps the range // test and only use max if it helps the range
{ {
if(IS_BIND_DONE_on && !IS_RANGE_FLAG_on && ((option & CABELL_OPTION_MASK_MAX_POWER_OVERRIDE) != 0)) if(IS_BIND_DONE && !IS_RANGE_FLAG_on && ((option & CABELL_OPTION_MASK_MAX_POWER_OVERRIDE) != 0))
{ // If we are not in range or bind mode and power setting override is in effect, then set max power, else standard power logic { // If we are not in range or bind mode and power setting override is in effect, then set max power, else standard power logic
if(prev_power != NRF_POWER_3) // prev_power is global variable for NRF24L01; NRF_POWER_3 is max power if(prev_power != NRF_POWER_3) // prev_power is global variable for NRF24L01; NRF_POWER_3 is max power
{ {
@ -403,7 +403,7 @@ static void CABELL_SetPower() // This over-ride the standard Set Power to all
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
uint16_t CABELL_callback() uint16_t CABELL_callback()
{ {
if (IS_BIND_DONE_on) if (IS_BIND_DONE)
{ {
CABELL_send_packet(0); // packet_period is set/adjusted in CABELL_send_packet CABELL_send_packet(0); // packet_period is set/adjusted in CABELL_send_packet
return packet_period; return packet_period;
@ -424,7 +424,7 @@ uint16_t CABELL_callback()
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
uint16_t initCABELL(void) uint16_t initCABELL(void)
{ {
if (IS_BIND_DONE_on) if (IS_BIND_DONE)
bind_counter = 0; bind_counter = 0;
else else
bind_counter = CABELL_BIND_COUNT; bind_counter = CABELL_BIND_COUNT;

View File

@ -144,7 +144,7 @@ static void CC2500_SetPower_Value(uint8_t power)
void CC2500_SetPower() void CC2500_SetPower()
{ {
uint8_t power=CC2500_BIND_POWER; uint8_t power=CC2500_BIND_POWER;
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
#ifdef CC2500_ENABLE_LOW_POWER #ifdef CC2500_ENABLE_LOW_POWER
power=IS_POWER_FLAG_on?CC2500_HIGH_POWER:CC2500_LOW_POWER; power=IS_POWER_FLAG_on?CC2500_HIGH_POWER:CC2500_LOW_POWER;
#else #else

View File

@ -137,7 +137,7 @@ static void __attribute__((unused)) CG023_init()
uint16_t CG023_callback() uint16_t CG023_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
CG023_send_packet(0); CG023_send_packet(0);
else else
{ {

View File

@ -136,7 +136,7 @@ static void CYRF_SetPower_Value(uint8_t power)
void CYRF_SetPower(uint8_t val) void CYRF_SetPower(uint8_t val)
{ {
uint8_t power=CYRF_BIND_POWER; uint8_t power=CYRF_BIND_POWER;
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
#ifdef CYRF6936_ENABLE_LOW_POWER #ifdef CYRF6936_ENABLE_LOW_POWER
power=IS_POWER_FLAG_on?CYRF_HIGH_POWER:CYRF_LOW_POWER; power=IS_POWER_FLAG_on?CYRF_HIGH_POWER:CYRF_LOW_POWER;
#else #else

View File

@ -0,0 +1,230 @@
/*
This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Multiprotocol 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.
You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(CORONA_CC2500_INO)
#include "iface_cc2500.h"
//#define CORONA_FORCE_ID
#define CORONA_RF_NUM_CHANNELS 3
#define CORONA_ADDRESS_LENGTH 4
#define CORONA_BIND_CHANNEL_V1 0xD1
#define CORONA_BIND_CHANNEL_V2 0xB8
#define CORONA_COARSE 0x00
const PROGMEM uint8_t CORONA_init_values[] = {
/* 00 */ 0x29, 0x2E, 0x06, 0x07, 0xD3, 0x91, 0xFF, 0x04,
/* 08 */ 0x05, 0x00, CORONA_BIND_CHANNEL_V1, 0x06, 0x00, 0x5C, 0x4E, 0xC4 + CORONA_COARSE,
/* 10 */ 0x5B, 0xF8, 0x03, 0x23, 0xF8, 0x47, 0x07, 0x30,
/* 18 */ 0x18, 0x16, 0x6C, 0x43, 0x40, 0x91, 0x87, 0x6B,
/* 20 */ 0xF8, 0x56, 0x10, 0xA9, 0x0A, 0x00, 0x11, 0x41,
/* 28 */ 0x00, 0x59, 0x7F, 0x3F, 0x81, 0x35, 0x0B
};
static void __attribute__((unused)) CORONA_rf_init()
{
CC2500_Strobe(CC2500_SIDLE);
for (uint8_t i = 0; i <= 0x2E; ++i)
CC2500_WriteReg(i, pgm_read_byte_near(&CORONA_init_values[i]));
if(sub_protocol!=COR_V1)
{
CC2500_WriteReg(CC2500_0A_CHANNR, CORONA_BIND_CHANNEL_V2);
CC2500_WriteReg(CC2500_0E_FREQ1, 0x80);
CC2500_WriteReg(CC2500_0F_FREQ0, 0x00 + CORONA_COARSE);
CC2500_WriteReg(CC2500_15_DEVIATN, 0x50);
CC2500_WriteReg(CC2500_17_MCSM1, 0x00);
CC2500_WriteReg(CC2500_1B_AGCCTRL2, 0x67);
CC2500_WriteReg(CC2500_1C_AGCCTRL1, 0xFB);
CC2500_WriteReg(CC2500_1D_AGCCTRL0, 0xDC);
}
prev_option = option;
CC2500_WriteReg(CC2500_0C_FSCTRL0, option);
//not sure what they are doing to the PATABLE since basically only the first byte is used and it's only 8 bytes long. So I think they end up filling the PATABLE fully with 0xFF
CC2500_WriteRegisterMulti(CC2500_3E_PATABLE,(const uint8_t *)"\x08\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", 13);
CC2500_SetTxRxMode(TX_EN);
CC2500_SetPower();
}
// Generate id and hopping freq
static void __attribute__((unused)) CORONA_init()
{
#ifdef CORONA_FORCE_ID
// Example of ID and channels taken from dumps
if(sub_protocol==COR_V1)
{
memcpy((void *)rx_tx_addr,(void *)"\x1F\xFE\x6C\x35",CORONA_ADDRESS_LENGTH);
memcpy((void *)hopping_frequency,(void *)"\x17\x0D\x03\x49",CORONA_RF_NUM_CHANNELS+1);
}
else
{
memcpy((void *)rx_tx_addr,(void *)"\xFE\xFE\x02\xFB",CORONA_ADDRESS_LENGTH);
memcpy((void *)hopping_frequency,(void *)"\x14\x3D\x35",CORONA_RF_NUM_CHANNELS);
}
#else
// From dumps channels are anything between 0x00 and 0xC5 on V1.
// But 0x00 and 0xB8 should be avoided on V2 since they are used for bind.
// Below code make sure channels are between 0x02 and 0xA0, spaced with a minimum of 2 and not ordered (RX only use the 1st channel unless there is an issue).
uint8_t order=rx_tx_addr[3]&0x03;
for(uint8_t i=0; i<CORONA_RF_NUM_CHANNELS+1; i++)
hopping_frequency[i^order]=2+rx_tx_addr[3-i]%39+(i<<5)+(i<<3);
// ID looks random but on the 15 V1 dumps they all show the same odd/even rule
if(rx_tx_addr[3]&0x01)
{ // If [3] is odd then [0] is odd and [2] is even
rx_tx_addr[0]|=0x01;
rx_tx_addr[2]&=0xFE;
}
else
{ // If [3] is even then [0] is even and [2] is odd
rx_tx_addr[0]&=0xFE;
rx_tx_addr[2]|=0x01;
}
rx_tx_addr[1]=0xFE; // Always FE in the dumps of V1 and V2
#endif
}
// 8 Channels with direct values from PPM
static void __attribute__((unused)) CORONA_send_packet()
{
if(IS_BIND_DONE)
{
if(state==0 || sub_protocol==COR_V1)
{ // Build standard packet
packet[0] = 0x10; // 17 bytes to follow
//Channels
memset(packet+9, 0x00, 4);
for(uint8_t i=0; i<8; i++)
{ // Channel values are packed
packet[i+1] = Servo_data[i];
packet[9 + (i>>1)] |= (i&0x01)?(Servo_data[i]>>4)&0xF0:(Servo_data[i]>>8)&0x0F;
}
//TX ID
for(uint8_t i=0; i<CORONA_ADDRESS_LENGTH; i++)
packet[i+13] = rx_tx_addr[i];
packet[17] = 0x00;
// Tune frequency if it has been changed
if ( prev_option != option )
{
CC2500_WriteReg(CC2500_0C_FSCTRL0, option);
prev_option = option ;
}
// Packet period is based on hopping
switch(hopping_frequency_no)
{
case 0:
packet_period=sub_protocol==COR_V1?4991:4248;
break;
case 1:
packet_period=sub_protocol==COR_V1?4991:4345;
break;
case 2:
packet_period=sub_protocol==COR_V1?12520:13468;
if(sub_protocol!=COR_V1)
packet[17] = 0x03;
break;
}
// Set channel
CC2500_WriteReg(CC2500_0A_CHANNR, hopping_frequency[hopping_frequency_no]);
hopping_frequency_no++;
hopping_frequency_no%=CORONA_RF_NUM_CHANNELS;
// Update power
CC2500_SetPower();
}
else
{ // Send identifier packet for 2.65sec. This is how the RX learns the hopping table after a bind. Why it's not part of the bind like V1 is a mistery...
state--;
packet[0]=0x07; // 8 bytes to follow
// Send hopping freq
for(uint8_t i=0; i<CORONA_RF_NUM_CHANNELS; i++)
packet[i+1]=hopping_frequency[i];
// Send TX ID
for(uint8_t i=0; i<CORONA_ADDRESS_LENGTH; i++)
packet[i+4]=rx_tx_addr[i];
packet[8]=0;
packet_period=6647;
// Set channel
CC2500_WriteReg(CC2500_0A_CHANNR, 0x00);
}
}
else
{ // Build bind packets
if(sub_protocol==COR_V1)
{ // V1
if(bind_counter&1)
{ // Send TX ID
packet[0]=0x04; // 5 bytes to follow
for(uint8_t i=0; i<CORONA_ADDRESS_LENGTH; i++)
packet[i+1]=rx_tx_addr[i];
packet[5]=0xCD; // Unknown but seems to be always the same value for V1
packet_period=3689;
}
else
{ // Send hopping freq
packet[0]=0x03; // 4 bytes to follow
for(uint8_t i=0; i<CORONA_RF_NUM_CHANNELS+1; i++)
packet[i+1]=hopping_frequency[i];
// Not sure what the last byte (+1) is for now since only the first 3 channels are used...
packet_period=3438;
}
}
else
{ // V2
packet[0]=0x04; // 5 bytes to follow
for(uint8_t i=0; i<CORONA_ADDRESS_LENGTH; i++)
packet[i+1]=rx_tx_addr[i];
packet[5]=0x00; // Unknown but seems to be always the same value for V2
packet_period=26791;
}
}
// Send packet
CC2500_WriteData(packet, packet[0]+2);
}
uint16_t ReadCORONA()
{
if(IS_BIND_IN_PROGRESS)
{
bind_counter--;
if (bind_counter == 0)
BIND_DONE;
}
CORONA_send_packet();
return packet_period;
}
uint16_t initCORONA()
{
if(sub_protocol==COR_V1)
bind_counter=700; // Stay in bind mode for 5s
else
bind_counter=187; // Stay in bind mode for 5s
state=400; // Used by V2 to send RF channels + ID for 2.65s at startup
hopping_frequency_no=0;
CORONA_init();
CORONA_rf_init();
return 10000;
}
#endif

View File

@ -112,7 +112,7 @@ static void __attribute__((unused)) DM002_init()
uint16_t DM002_callback() uint16_t DM002_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
DM002_send_packet(0); DM002_send_packet(0);
else else
{ {

View File

@ -566,9 +566,8 @@ uint16_t initDsm()
// //
DSM_update_channels(); DSM_update_channels();
// //
if(IS_AUTOBIND_FLAG_on ) if(IS_BIND_IN_PROGRESS)
{ {
BIND_IN_PROGRESS;
DSM_initialize_bind_phase(); DSM_initialize_bind_phase();
phase = DSM_BIND_WRITE; phase = DSM_BIND_WRITE;
bind_counter=DSM_BIND_COUNT; bind_counter=DSM_BIND_COUNT;

View File

@ -57,7 +57,7 @@ static void __attribute__((unused)) DEVO_add_pkt_suffix()
{ {
uint8_t bind_state; uint8_t bind_state;
#ifdef ENABLE_PPM #ifdef ENABLE_PPM
if(mode_select && option==0 && IS_BIND_DONE_on) //PPM mode and option not already set and bind is finished if(mode_select && option==0 && IS_BIND_DONE) //PPM mode and option not already set and bind is finished
{ {
BIND_SET_INPUT; BIND_SET_INPUT;
BIND_SET_PULLUP; // set pullup BIND_SET_PULLUP; // set pullup
@ -69,7 +69,7 @@ static void __attribute__((unused)) DEVO_add_pkt_suffix()
BIND_SET_OUTPUT; BIND_SET_OUTPUT;
} }
#endif //ENABLE_PPM #endif //ENABLE_PPM
if(prev_option!=option && IS_BIND_DONE_on) if(prev_option!=option && IS_BIND_DONE)
{ {
MProtocol_id = RX_num + MProtocol_id_master; MProtocol_id = RX_num + MProtocol_id_master;
bind_counter=DEVO_BIND_COUNT; bind_counter=DEVO_BIND_COUNT;

View File

@ -150,7 +150,7 @@ uint8_t ESKY150_convert_2bit_channel(uint8_t num)
uint16_t ESKY150_callback() uint16_t ESKY150_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
ESKY150_send_packet(); ESKY150_send_packet();
else else
{ {
@ -169,7 +169,7 @@ uint16_t ESKY150_callback()
uint16_t initESKY150(void) uint16_t initESKY150(void)
{ {
ESKY150_init(); ESKY150_init();
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
{ {
bind_counter=3000; bind_counter=3000;
ESKY150_bind_init(); ESKY150_bind_init();

View File

@ -138,7 +138,7 @@ static void __attribute__((unused)) ESKY_send_packet(uint8_t bind)
uint16_t ESKY_callback() uint16_t ESKY_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
{ {
if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED) if (packet_sent && NRF24L01_packet_ack() != PKT_ACKED)
return ESKY_PACKET_CHKTIME; return ESKY_PACKET_CHKTIME;
@ -162,7 +162,7 @@ uint16_t initESKY(void)
{ {
bind_counter = ESKY_BIND_COUNT; bind_counter = ESKY_BIND_COUNT;
rx_tx_addr[3] = 0xBB; rx_tx_addr[3] = 0xBB;
ESKY_init(IS_AUTOBIND_FLAG_on); ESKY_init(IS_BIND_IN_PROGRESS);
ESKY_init2(); ESKY_init2();
return 50000; return 50000;
} }

View File

@ -234,7 +234,7 @@ uint16_t initFlySky()
} }
hopping_frequency_no=0; hopping_frequency_no=0;
packet_count=0; packet_count=0;
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
bind_counter = FLYSKY_BIND_COUNT; bind_counter = FLYSKY_BIND_COUNT;
else else
bind_counter = 0; bind_counter = 0;

View File

@ -100,7 +100,7 @@ uint16_t initFrSky_2way()
#if defined TELEMETRY #if defined TELEMETRY
init_frskyd_link_telemetry(); init_frskyd_link_telemetry();
#endif #endif
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
{ {
frsky2way_init(1); frsky2way_init(1);
state = FRSKY_BIND; state = FRSKY_BIND;
@ -122,7 +122,7 @@ uint16_t ReadFrSky_2way()
CC2500_WriteReg(CC2500_23_FSCAL3, 0x89); CC2500_WriteReg(CC2500_23_FSCAL3, 0x89);
CC2500_Strobe(CC2500_SFRX);//0x3A CC2500_Strobe(CC2500_SFRX);//0x3A
CC2500_WriteData(packet, packet[0]+1); CC2500_WriteData(packet, packet[0]+1);
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
state = FRSKY_BIND_DONE; state = FRSKY_BIND_DONE;
else else
state++; state++;

View File

@ -115,7 +115,7 @@ static void __attribute__((unused)) FRSKYV_build_data_packet()
uint16_t ReadFRSKYV() uint16_t ReadFRSKYV()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
{ // Normal operation { // Normal operation
uint8_t chan = FRSKYV_calc_channel(); uint8_t chan = FRSKYV_calc_channel();
CC2500_Strobe(CC2500_SIDLE); CC2500_Strobe(CC2500_SIDLE);

View File

@ -243,7 +243,7 @@ uint16_t ReadFrSkyX()
frskyX_build_bind_packet(); frskyX_build_bind_packet();
CC2500_Strobe(CC2500_SIDLE); CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteData(packet, packet[0]+1); CC2500_WriteData(packet, packet[0]+1);
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
state = FRSKY_BIND_DONE; state = FRSKY_BIND_DONE;
else else
state++; state++;
@ -334,7 +334,7 @@ uint16_t initFrSkyX()
//************************ //************************
frskyX_init(); frskyX_init();
// //
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
{ {
state = FRSKY_BIND; state = FRSKY_BIND;
frskyX_initialize_data(1); frskyX_initialize_data(1);

View File

@ -176,7 +176,7 @@ static void __attribute__((unused)) H8_3D_init()
uint16_t H8_3D_callback() uint16_t H8_3D_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
H8_3D_send_packet(0); H8_3D_send_packet(0);
else else
{ {

View File

@ -253,7 +253,7 @@ uint16_t initHiSky()
hopping_frequency_no = 0; hopping_frequency_no = 0;
binding_idx = 0; binding_idx = 0;
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
bind_counter = HISKY_BIND_COUNT; bind_counter = HISKY_BIND_COUNT;
else else
bind_counter = 0; bind_counter = 0;

View File

@ -428,7 +428,7 @@ uint16_t initHubsan()
channel = allowed_ch[MProtocol_id % sizeof(allowed_ch)]; channel = allowed_ch[MProtocol_id % sizeof(allowed_ch)];
hubsan_id_data=ID_NORMAL; hubsan_id_data=ID_NORMAL;
if(IS_AUTOBIND_FLAG_on || sub_protocol==H107) if(IS_BIND_IN_PROGRESS || sub_protocol==H107)
{ {
BIND_IN_PROGRESS; // autobind protocol BIND_IN_PROGRESS; // autobind protocol
phase = BIND_1; phase = BIND_1;

View File

@ -227,7 +227,7 @@ uint16_t initJ6Pro()
{ {
j6pro_cyrf_init(); j6pro_cyrf_init();
if(IS_AUTOBIND_FLAG_on) if(IS_BIND_IN_PROGRESS)
phase = J6PRO_BIND; phase = J6PRO_BIND;
else else
phase = J6PRO_CHANSEL; phase = J6PRO_CHANSEL;

View File

@ -287,7 +287,7 @@ uint16_t initKN()
packet_count = KN_FX_PACKET_SEND_COUNT; packet_count = KN_FX_PACKET_SEND_COUNT;
} }
kn_init(); kn_init();
phase = IS_AUTOBIND_FLAG_on ? KN_PHASE_PRE_BIND : KN_PHASE_PRE_SEND; phase = IS_BIND_IN_PROGRESS ? KN_PHASE_PRE_BIND : KN_PHASE_PRE_SEND;
return KN_INIT_WAIT_MS; return KN_INIT_WAIT_MS;
} }

View File

@ -299,7 +299,7 @@ static void __attribute__((unused)) MJXQ_initialize_txid()
uint16_t MJXQ_callback() uint16_t MJXQ_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
MJXQ_send_packet(0); MJXQ_send_packet(0);
else else
{ {

View File

@ -221,7 +221,7 @@ static void __attribute__((unused)) MT99XX_initialize_txid()
uint16_t MT99XX_callback() uint16_t MT99XX_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
MT99XX_send_packet(); MT99XX_send_packet();
else else
{ {

View File

@ -34,3 +34,5 @@
34,CABELL,CAB_V3,C_TELEM,-,-,-,-,F_SAFE,UNBIND 34,CABELL,CAB_V3,C_TELEM,-,-,-,-,F_SAFE,UNBIND
35,ESKY150 35,ESKY150
36,H8_3D,H8_3D,H20H,H20Mini,H30Mini 36,H8_3D,H8_3D,H20H,H20Mini,H30Mini
37,CORONA,COR_V1,COR_V2

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_REVISION 0 #define VERSION_REVISION 0
#define VERSION_PATCH_LEVEL 0 #define VERSION_PATCH_LEVEL 4
//****************** //******************
// Protocols // Protocols
//****************** //******************
@ -62,6 +62,7 @@ enum PROTOCOLS
MODE_CABELL = 34, // =>NRF24L01 MODE_CABELL = 34, // =>NRF24L01
MODE_ESKY150 = 35, // =>NRF24L01 MODE_ESKY150 = 35, // =>NRF24L01
MODE_H8_3D = 36, // =>NRF24L01 MODE_H8_3D = 36, // =>NRF24L01
MODE_CORONA = 37, // =>CC2500
}; };
enum Flysky enum Flysky
@ -219,6 +220,11 @@ enum H8_3D
H20MINI = 2, H20MINI = 2,
H30MINI = 3, H30MINI = 3,
}; };
enum CORONA
{
COR_V1 = 0,
COR_V2 = 1,
};
#define NONE 0 #define NONE 0
#define P_HIGH 1 #define P_HIGH 1
@ -287,7 +293,8 @@ enum MultiPacketTypes
//Bind flag //Bind flag
#define BIND_IN_PROGRESS protocol_flags &= ~_BV(7) #define BIND_IN_PROGRESS protocol_flags &= ~_BV(7)
#define BIND_DONE protocol_flags |= _BV(7) #define BIND_DONE protocol_flags |= _BV(7)
#define IS_BIND_DONE_on ( ( protocol_flags & _BV(7) ) !=0 ) #define IS_BIND_DONE ( ( protocol_flags & _BV(7) ) !=0 )
#define IS_BIND_IN_PROGRESS ( ( protocol_flags & _BV(7) ) ==0 )
// //
#define FAILSAFE_VALUES_off protocol_flags2 &= ~_BV(0) #define FAILSAFE_VALUES_off protocol_flags2 &= ~_BV(0)
#define FAILSAFE_VALUES_on protocol_flags2 |= _BV(0) #define FAILSAFE_VALUES_on protocol_flags2 |= _BV(0)
@ -540,6 +547,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
CABELL 34 CABELL 34
ESKY150 35 ESKY150 35
H8_3D 36 H8_3D 36
CORONA 37
BindBit=> 0x80 1=Bind/0=No BindBit=> 0x80 1=Bind/0=No
AutoBindBit=> 0x40 1=Yes /0=No AutoBindBit=> 0x40 1=Yes /0=No
RangeCheck=> 0x20 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No
@ -656,6 +664,9 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
H20H 1 H20H 1
H20MINI 2 H20MINI 2
H30MINI 3 H30MINI 3
sub_protocol==CORONA
COR_V1 0
COR_V2 1
Power value => 0x80 0=High/1=Low Power value => 0x80 0=High/1=Low
Stream[3] = option_protocol; Stream[3] = option_protocol;

View File

@ -338,7 +338,12 @@ void setup()
// Read status of bind button // Read status of bind button
if( IS_BIND_BUTTON_on ) if( IS_BIND_BUTTON_on )
BIND_BUTTON_FLAG_on; // If bind button pressed save the status for protocol id reset under hubsan {
BIND_BUTTON_FLAG_on; // If bind button pressed save the status
BIND_IN_PROGRESS; // Request bind
}
else
BIND_DONE;
// Read status of mode select binary switch // Read status of mode select binary switch
// after this mode_select will be one of {0000, 0001, ..., 1111} // after this mode_select will be one of {0000, 0001, ..., 1111}
@ -414,11 +419,20 @@ void setup()
if (protocol==MODE_SFHSS) if (protocol==MODE_SFHSS)
option = FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS option = FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS
else else
#endif
#if defined(FORCE_CORONA_TUNING) && defined(CORONA_CC2500_INO)
if (protocol==MODE_CORONA)
option = FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA
else
#endif #endif
option = PPM_prot[mode_select].option; // Use radio-defined option value option = PPM_prot[mode_select].option; // Use radio-defined option value
if(PPM_prot[mode_select].power) POWER_FLAG_on; if(PPM_prot[mode_select].power) POWER_FLAG_on;
if(PPM_prot[mode_select].autobind) AUTOBIND_FLAG_on; if(PPM_prot[mode_select].autobind)
{
AUTOBIND_FLAG_on;
BIND_IN_PROGRESS; // Force a bind at protocol startup
}
mode_select++; mode_select++;
servo_max_100=PPM_MAX_100; servo_min_100=PPM_MIN_100; servo_max_100=PPM_MAX_100; servo_min_100=PPM_MIN_100;
servo_max_125=PPM_MAX_125; servo_min_125=PPM_MIN_125; servo_max_125=PPM_MAX_125; servo_min_125=PPM_MIN_125;
@ -594,12 +608,14 @@ uint8_t Update_All()
#ifdef ENABLE_BIND_CH #ifdef ENABLE_BIND_CH
if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && Servo_data[BIND_CH-1]>PPM_MAX_COMMAND && Servo_data[THROTTLE]<(servo_min_100+25)) if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && Servo_data[BIND_CH-1]>PPM_MAX_COMMAND && Servo_data[THROTTLE]<(servo_min_100+25))
{ // Autobind is on and BIND_CH went up and Throttle is low { // Autobind is on and BIND_CH went up and Throttle is low
CHANGE_PROTOCOL_FLAG_on; //reload protocol to rebind CHANGE_PROTOCOL_FLAG_on; //reload protocol
BIND_IN_PROGRESS; //enable bind
BIND_CH_PREV_on; BIND_CH_PREV_on;
} }
if(IS_BIND_CH_PREV_on && Servo_data[BIND_CH-1]<PPM_MIN_COMMAND) if(IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_on && Servo_data[BIND_CH-1]<PPM_MIN_COMMAND)
{ { // Autobind is on and BIND_CH went down
BIND_CH_PREV_off; BIND_CH_PREV_off;
//Request protocol to terminate bind
#if defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKYV_CC2500_INO) #if defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKYV_CC2500_INO)
if(protocol==MODE_FRSKYD || protocol==MODE_FRSKYX || protocol==MODE_FRSKYV) if(protocol==MODE_FRSKYD || protocol==MODE_FRSKYX || protocol==MODE_FRSKYV)
BIND_DONE; BIND_DONE;
@ -674,7 +690,7 @@ static void update_led_status(void)
} }
else else
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
LED_off; //bind completed force led on LED_off; //bind completed force led on
blink+=BLINK_BIND_TIME; //blink fastly during binding blink+=BLINK_BIND_TIME; //blink fastly during binding
} }
@ -773,13 +789,6 @@ static void protocol_init()
blink=millis(); blink=millis();
if(IS_BIND_BUTTON_FLAG_on)
AUTOBIND_FLAG_on;
if(IS_AUTOBIND_FLAG_on)
BIND_IN_PROGRESS; // Indicates bind in progress for blinking bind led
else
BIND_DONE;
PE1_on; //NRF24L01 antenna RF3 by default PE1_on; //NRF24L01 antenna RF3 by default
PE2_off; //NRF24L01 antenna RF3 by default PE2_off; //NRF24L01 antenna RF3 by default
@ -842,6 +851,14 @@ static void protocol_init()
remote_callback = ReadSFHSS; remote_callback = ReadSFHSS;
break; break;
#endif #endif
#if defined(CORONA_CC2500_INO)
case MODE_CORONA:
PE1_off; //antenna RF2
PE2_on;
next_callback = initCORONA();
remote_callback = ReadCORONA;
break;
#endif
#endif #endif
#ifdef CYRF6936_INSTALLED #ifdef CYRF6936_INSTALLED
#if defined(DSM_CYRF6936_INO) #if defined(DSM_CYRF6936_INO)
@ -1050,8 +1067,8 @@ static void protocol_init()
} }
#if defined(WAIT_FOR_BIND) && defined(ENABLE_BIND_CH) #if defined(WAIT_FOR_BIND) && defined(ENABLE_BIND_CH)
if( IS_AUTOBIND_FLAG_on && ! ( IS_BIND_CH_PREV_on || IS_BIND_BUTTON_FLAG_on || (cur_protocol[1]&0x80)!=0 ) ) if( IS_AUTOBIND_FLAG_on && IS_BIND_CH_PREV_off && (cur_protocol[1]&0x80)==0 && mode_select == MODE_SERIAL)
{ { // Autobind is active but no bind requested by either BIND_CH or BIND. But do not wait if in PPM mode...
WAIT_BIND_on; WAIT_BIND_on;
return; return;
} }
@ -1084,7 +1101,7 @@ void update_serial_data()
RANGE_FLAG_on; RANGE_FLAG_on;
else else
RANGE_FLAG_off; RANGE_FLAG_off;
if(rx_ok_buff[1]&0xC0) //check autobind(0x40) & bind(0x80) together if(rx_ok_buff[1]&0x40) //check autobind
AUTOBIND_FLAG_on; AUTOBIND_FLAG_on;
else else
AUTOBIND_FLAG_off; AUTOBIND_FLAG_off;
@ -1113,13 +1130,18 @@ void update_serial_data()
if (protocol==MODE_SFHSS) if (protocol==MODE_SFHSS)
option=FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS option=FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS
else else
#endif
#if defined(FORCE_CORONA_TUNING) && defined(CORONA_CC2500_INO)
if (protocol==MODE_CORONA)
option=FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA
else
#endif #endif
option=rx_ok_buff[3]; // Use radio-defined option value option=rx_ok_buff[3]; // Use radio-defined option value
#ifdef FAILSAFE_ENABLE #ifdef FAILSAFE_ENABLE
bool failsafe=false; bool failsafe=false;
if(rx_ok_buff[0]&0x02) if(rx_ok_buff[0]&0x02)
{ //packet contains failsafe instead of channels { // Packet contains failsafe instead of channels
failsafe=true; failsafe=true;
rx_ok_buff[0]&=0xFD; //remove the failsafe flag rx_ok_buff[0]&=0xFD; //remove the failsafe flag
FAILSAFE_VALUES_on; //failsafe data has been received FAILSAFE_VALUES_on; //failsafe data has been received
@ -1129,6 +1151,10 @@ void update_serial_data()
{ // New model has been selected { // New model has been selected
CHANGE_PROTOCOL_FLAG_on; //change protocol CHANGE_PROTOCOL_FLAG_on; //change protocol
WAIT_BIND_off; WAIT_BIND_off;
if(IS_AUTOBIND_FLAG_on)
BIND_IN_PROGRESS; //launch bind right away if in autobind mode
else
BIND_DONE;
protocol=(rx_ok_buff[0]==0x55?0:32) + (rx_ok_buff[1]&0x1F); //protocol no (0-63) bits 4-6 of buff[1] and bit 0 of buf[0] protocol=(rx_ok_buff[0]==0x55?0:32) + (rx_ok_buff[1]&0x1F); //protocol no (0-63) bits 4-6 of buff[1] and bit 0 of buf[0]
sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6 sub_protocol=(rx_ok_buff[2]>>4)& 0x07; //subprotocol no (0-7) bits 4-6
RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0---3 RX_num=rx_ok_buff[2]& 0x0F; // rx_num bits 0---3
@ -1136,10 +1162,13 @@ void update_serial_data()
} }
else else
if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set if( ((rx_ok_buff[1]&0x80)!=0) && ((cur_protocol[1]&0x80)==0) ) // Bind flag has been set
CHANGE_PROTOCOL_FLAG_on; //restart protocol with bind { // Restart protocol with bind
CHANGE_PROTOCOL_FLAG_on;
BIND_IN_PROGRESS;
}
else else
if( ((rx_ok_buff[1]&0x80)==0) && ((cur_protocol[1]&0x80)!=0) ) // Bind flag has been reset if( ((rx_ok_buff[1]&0x80)==0) && ((cur_protocol[1]&0x80)!=0) ) // Bind flag has been reset
{ { // Request protocol to end bind
#if defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKYV_CC2500_INO) #if defined(FRSKYD_CC2500_INO) || defined(FRSKYX_CC2500_INO) || defined(FRSKYV_CC2500_INO)
if(protocol==MODE_FRSKYD || protocol==MODE_FRSKYX || protocol==MODE_FRSKYV) if(protocol==MODE_FRSKYD || protocol==MODE_FRSKYX || protocol==MODE_FRSKYV)
BIND_DONE; BIND_DONE;

View File

@ -161,7 +161,7 @@ void NRF24L01_SetBitrate(uint8_t bitrate)
void NRF24L01_SetPower() void NRF24L01_SetPower()
{ {
uint8_t power=NRF_BIND_POWER; uint8_t power=NRF_BIND_POWER;
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
#ifdef NRF24L01_ENABLE_LOW_POWER #ifdef NRF24L01_ENABLE_LOW_POWER
power=IS_POWER_FLAG_on?NRF_HIGH_POWER:NRF_LOW_POWER; power=IS_POWER_FLAG_on?NRF_HIGH_POWER:NRF_LOW_POWER;
#else #else

View File

@ -354,7 +354,7 @@ static void __attribute__((unused)) Q303_initialize_txid()
uint16_t Q303_callback() uint16_t Q303_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
Q303_send_packet(0); Q303_send_packet(0);
else else
{ {

View File

@ -90,7 +90,7 @@ void SHENQI_send_packet()
uint16_t SHENQI_callback() uint16_t SHENQI_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
SHENQI_send_packet(); SHENQI_send_packet();
else else
{ {

View File

@ -17,6 +17,10 @@
/********************/ /********************/
#ifdef STM32_BOARD #ifdef STM32_BOARD
#ifdef DEBUG_SERIAL
// #define DEBUG_SPI
#endif
SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port SPIClass SPI_2(2); //Create an instance of the SPI Class called SPI_2 that uses the 2nd SPI Port
void initSPI2() void initSPI2()
@ -35,6 +39,9 @@ void initSPI2()
void SPI_Write(uint8_t command) void SPI_Write(uint8_t command)
{//working OK {//working OK
SPI2_BASE->DR = command; //Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag). SPI2_BASE->DR = command; //Write the first data item to be transmitted into the SPI_DR register (this clears the TXE flag).
#ifdef DEBUG_SPI
debug("%02X ",command);
#endif
while (!(SPI2_BASE->SR & SPI_SR_RXNE)); while (!(SPI2_BASE->SR & SPI_SR_RXNE));
command = SPI2_BASE->DR; // ... and read the last received data. command = SPI2_BASE->DR; // ... and read the last received data.
} }

View File

@ -107,7 +107,7 @@ static void multi_send_status()
if (IS_WAIT_BIND_on) if (IS_WAIT_BIND_on)
flags |= 0x10; flags |= 0x10;
else else
if (!IS_BIND_DONE_on) if (IS_BIND_IN_PROGRESS)
flags |= 0x08; flags |= 0x08;
#ifdef FAILSAFE_ENABLE #ifdef FAILSAFE_ENABLE
//Is failsafe supported? //Is failsafe supported?
@ -1052,7 +1052,6 @@ void TelemetryUpdate()
#endif #endif
if(USART3_BASE->SR & USART_SR_TXE) if(USART3_BASE->SR & USART_SR_TXE)
{ {
USART3_BASE->SR &= ~USART_SR_TXE;
#endif #endif
if(tx_head!=tx_tail) if(tx_head!=tx_tail)
{ {

View File

@ -275,7 +275,7 @@ uint16_t initV2x2()
{ {
v202_init(); v202_init();
// //
if (IS_AUTOBIND_FLAG_on) if (IS_BIND_IN_PROGRESS)
{ {
bind_counter = V2X2_BIND_COUNT; bind_counter = V2X2_BIND_COUNT;
phase = V202_INIT2; phase = V202_INIT2;

View File

@ -81,6 +81,11 @@
#error "The SFHSS forced frequency tuning value is outside of the range -127..127." #error "The SFHSS forced frequency tuning value is outside of the range -127..127."
#endif #endif
#endif #endif
#ifdef FORCE_CORONA_TUNING
#if ( FORCE_CORONA_TUNING < -127 ) || ( FORCE_CORONA_TUNING > 127 )
#error "The CORONA forced frequency tuning value is outside of the range -127..127."
#endif
#endif
//Change/Force configuration if OrangeTX //Change/Force configuration if OrangeTX
#ifdef ORANGE_TX #ifdef ORANGE_TX
@ -113,6 +118,7 @@
#undef FRSKYV_CC2500_INO #undef FRSKYV_CC2500_INO
#undef FRSKYX_CC2500_INO #undef FRSKYX_CC2500_INO
#undef SFHSS_CC2500_INO #undef SFHSS_CC2500_INO
#undef CORONA_CC2500_INO
#endif #endif
#ifndef NRF24L01_INSTALLED #ifndef NRF24L01_INSTALLED
#undef BAYANG_NRF24L01_INO #undef BAYANG_NRF24L01_INO

View File

@ -288,7 +288,7 @@ static void __attribute__((unused)) WK_build_beacon_pkt_2801()
uint8_t bind_state; uint8_t bind_state;
#ifdef ENABLE_PPM #ifdef ENABLE_PPM
if(mode_select && option==0 && IS_BIND_DONE_on) //PPM mode and option not already set and bind is finished if(mode_select && option==0 && IS_BIND_DONE) //PPM mode and option not already set and bind is finished
{ {
BIND_SET_INPUT; BIND_SET_INPUT;
BIND_SET_PULLUP; // set pullup BIND_SET_PULLUP; // set pullup
@ -300,7 +300,7 @@ static void __attribute__((unused)) WK_build_beacon_pkt_2801()
BIND_SET_OUTPUT; BIND_SET_OUTPUT;
} }
#endif //ENABLE_PPM #endif //ENABLE_PPM
if(prev_option!=option && IS_BIND_DONE_on) if(prev_option!=option && IS_BIND_DONE)
{ {
set_rx_tx_addr(MProtocol_id); set_rx_tx_addr(MProtocol_id);
rx_tx_addr[2]=rx_tx_addr[3]<<4; // Make use of RX_Num rx_tx_addr[2]=rx_tx_addr[3]<<4; // Make use of RX_Num

View File

@ -154,7 +154,7 @@ static void __attribute__((unused)) yd717_init()
uint16_t yd717_callback() uint16_t yd717_callback()
{ {
if(IS_BIND_DONE_on) if(IS_BIND_DONE)
yd717_send_packet(0); yd717_send_packet(0);
else else
{ {

View File

@ -133,6 +133,7 @@
#define FRSKYD_CC2500_INO #define FRSKYD_CC2500_INO
#define FRSKYX_CC2500_INO #define FRSKYX_CC2500_INO
#define SFHSS_CC2500_INO #define SFHSS_CC2500_INO
#define CORONA_CC2500_INO
//The protocols below need a NRF24L01 to be installed //The protocols below need a NRF24L01 to be installed
#define BAYANG_NRF24L01_INO #define BAYANG_NRF24L01_INO
@ -159,6 +160,7 @@
#define ESKY150_NRF24L01_INO #define ESKY150_NRF24L01_INO
#define H8_3D_NRF24L01_INO #define H8_3D_NRF24L01_INO
/**************************/ /**************************/
/*** FAILSAFE SETTINGS ***/ /*** FAILSAFE SETTINGS ***/
/**************************/ /**************************/
@ -192,6 +194,7 @@
//#define FORCE_FRSKYV_TUNING 0 //#define FORCE_FRSKYV_TUNING 0
//#define FORCE_FRSKYX_TUNING 0 //#define FORCE_FRSKYX_TUNING 0
//#define FORCE_SFHSS_TUNING 0 //#define FORCE_SFHSS_TUNING 0
//#define FORCE_CORONA_TUNING 0
/**************************/ /**************************/
/*** TELEMETRY SETTINGS ***/ /*** TELEMETRY SETTINGS ***/
@ -437,6 +440,9 @@ const PPM_Parameters PPM_prot[15]= {
H20H H20H
H20 Mini H20 Mini
H30 Mini H30 Mini
MODE_CORONA
COR_V1
COR_V2
*/ */
// RX_Num is used for model match. Using RX_Num values different for each receiver will prevent starting a model with the false config loaded... // RX_Num is used for model match. Using RX_Num values different for each receiver will prevent starting a model with the false config loaded...