Introduction of Banks for the switch protocol selection

This commit is contained in:
Pascal Langer
2018-01-30 12:02:45 +01:00
parent f4a4f67453
commit ab27ee50b0
12 changed files with 449 additions and 280 deletions

View File

@@ -38,7 +38,7 @@
#include "_Config.h"
//Personal config file
#if __has_include("_MyConfig.h") || defined(USE_MY_CONFIG)
#if defined(USE_MY_CONFIG)
#include "_MyConfig.h"
#endif
@@ -300,10 +300,10 @@ void setup()
SERIAL_TX_output;
// pullups
MODE_DIAL1_port |= _BV(MODE_DIAL1_pin);
MODE_DIAL2_port |= _BV(MODE_DIAL2_pin);
MODE_DIAL3_port |= _BV(MODE_DIAL3_pin);
MODE_DIAL4_port |= _BV(MODE_DIAL4_pin);
PROTO_DIAL1_port |= _BV(PROTO_DIAL1_pin);
PROTO_DIAL2_port |= _BV(PROTO_DIAL2_pin);
PROTO_DIAL3_port |= _BV(PROTO_DIAL3_pin);
PROTO_DIAL4_port |= _BV(PROTO_DIAL4_pin);
BIND_port |= _BV(BIND_pin);
// Timer1 config
@@ -357,13 +357,17 @@ void setup()
mode_select= 0x0F -(uint8_t)(((GPIOA->regs->IDR)>>4)&0x0F);
#else
mode_select =
((MODE_DIAL1_ipr & _BV(MODE_DIAL1_pin)) ? 0 : 1) +
((MODE_DIAL2_ipr & _BV(MODE_DIAL2_pin)) ? 0 : 2) +
((MODE_DIAL3_ipr & _BV(MODE_DIAL3_pin)) ? 0 : 4) +
((MODE_DIAL4_ipr & _BV(MODE_DIAL4_pin)) ? 0 : 8);
((PROTO_DIAL1_ipr & _BV(PROTO_DIAL1_pin)) ? 0 : 1) +
((PROTO_DIAL2_ipr & _BV(PROTO_DIAL2_pin)) ? 0 : 2) +
((PROTO_DIAL3_ipr & _BV(PROTO_DIAL3_pin)) ? 0 : 4) +
((PROTO_DIAL4_ipr & _BV(PROTO_DIAL4_pin)) ? 0 : 8);
#endif
//mode_select=1;
debugln("Mode switch reads as %d", mode_select);
debugln("Protocol selection switch reads as %d", mode_select);
#ifdef ENABLE_PPM
uint8_t bank=bank_switch();
#endif
// Set default channels' value
InitChannel();
@@ -373,7 +377,7 @@ void setup()
// Update LED
LED_off;
LED_output;
LED_output;
//Init RF modules
modules_reset();
@@ -396,47 +400,47 @@ void setup()
//Protocol and interrupts initialization
if(mode_select != MODE_SERIAL)
{ // PPM
mode_select--;
protocol = PPM_prot[mode_select].protocol;
uint8_t line=bank*14+mode_select-1;
protocol = PPM_prot[line].protocol;
cur_protocol[1] = protocol;
sub_protocol = PPM_prot[mode_select].sub_proto;
RX_num = PPM_prot[mode_select].rx_num;
sub_protocol = PPM_prot[line].sub_proto;
RX_num = PPM_prot[line].rx_num;
//Forced frequency tuning values for CC2500 protocols
#if defined(FORCE_FRSKYD_TUNING) && defined(FRSKYD_CC2500_INO)
if(protocol==MODE_FRSKYD)
if(protocol==PROTO_FRSKYD)
option = FORCE_FRSKYD_TUNING; // Use config-defined tuning value for FrSkyD
else
#endif
#if defined(FORCE_FRSKYV_TUNING) && defined(FRSKYV_CC2500_INO)
if(protocol==MODE_FRSKYV)
if(protocol==PROTO_FRSKYV)
option = FORCE_FRSKYV_TUNING; // Use config-defined tuning value for FrSkyV
else
#endif
#if defined(FORCE_FRSKYX_TUNING) && defined(FRSKYX_CC2500_INO)
if(protocol==MODE_FRSKYX)
if(protocol==PROTO_FRSKYX)
option = FORCE_FRSKYX_TUNING; // Use config-defined tuning value for FrSkyX
else
#endif
#if defined(FORCE_SFHSS_TUNING) && defined(SFHSS_CC2500_INO)
if (protocol==MODE_SFHSS)
if (protocol==PROTO_SFHSS)
option = FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS
else
#endif
#if defined(FORCE_CORONA_TUNING) && defined(CORONA_CC2500_INO)
if (protocol==MODE_CORONA)
if (protocol==PROTO_CORONA)
option = FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA
else
#endif
option = PPM_prot[mode_select].option; // Use radio-defined option value
option = PPM_prot[line].option; // Use radio-defined option value
if(PPM_prot[mode_select].power) POWER_FLAG_on;
if(PPM_prot[mode_select].autobind)
if(PPM_prot[line].power) POWER_FLAG_on;
if(PPM_prot[line].autobind)
{
AUTOBIND_FLAG_on;
BIND_IN_PROGRESS; // Force a bind at protocol startup
}
mode_select++;
line++;
protocol_init();
@@ -601,7 +605,7 @@ uint8_t Update_All()
update_led_status();
#if defined(TELEMETRY)
#if ( !( defined(MULTI_TELEMETRY) || defined(MULTI_STATUS) ) )
if( (protocol==MODE_FRSKYD) || (protocol==MODE_BAYANG) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) || (protocol==MODE_CABELL) )
if( (protocol==PROTO_FRSKYD) || (protocol==PROTO_BAYANG) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_FRSKYX) || (protocol==PROTO_DSM) || (protocol==PROTO_CABELL) )
#endif
TelemetryUpdate();
#endif
@@ -617,7 +621,7 @@ uint8_t Update_All()
BIND_CH_PREV_off;
//Request protocol to terminate bind
#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==PROTO_FRSKYD || protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYV)
BIND_DONE;
else
#endif
@@ -700,6 +704,88 @@ static void update_led_status(void)
}
}
#ifdef ENABLE_PPM
uint8_t bank_switch(void)
{
uint8_t bank=eeprom_read_byte((EE_ADDR)EEPROM_BANK_OFFSET);
if(bank>=NBR_BANKS)
{ // Wrong number of bank
eeprom_write_byte((EE_ADDR)EEPROM_BANK_OFFSET,0x00); // set bank to 0
bank=0;
}
debugln("Using bank %d", bank);
phase=3;
uint32_t check=millis();
blink=millis();
while(mode_select==15)
{ //loop here if the dial is on position 15 for user to select the bank
if(blink<millis())
{
switch(phase & 0x03)
{ // Flash bank number of times
case 0:
LED_on;
blink+=BLINK_BANK_TIME_HIGH;
phase++;
break;
case 1:
LED_off;
blink+=BLINK_BANK_TIME_LOW;
phase++;
break;
case 2:
if( (phase>>2) >= bank)
{
phase=0;
blink+=BLINK_BANK_REPEAT;
}
else
phase+=2;
break;
case 3:
LED_output;
LED_off;
blink+=BLINK_BANK_TIME_LOW;
phase=0;
break;
}
}
if(check<millis())
{
//Test bind button: for AVR it's shared with the LED so some work is needed to check it...
#ifndef STM32_BOARD
bool led=IS_LED_on;
BIND_SET_INPUT;
BIND_SET_PULLUP;
#endif
bool test_bind=IS_BIND_BUTTON_on;
#ifndef STM32_BOARD
if(led)
LED_on;
else
LED_off;
LED_output;
#endif
if( test_bind )
{ // Increase bank
LED_on;
bank++;
if(bank>=NBR_BANKS)
bank=0;
eeprom_write_byte((EE_ADDR)EEPROM_BANK_OFFSET,bank);
debugln("Using bank %d", bank);
phase=3;
blink+=BLINK_BANK_REPEAT;
check+=2*BLINK_BANK_REPEAT;
}
check+=1;
}
}
return bank;
}
#endif
inline void tx_pause()
{
#ifdef TELEMETRY
@@ -799,21 +885,21 @@ static void protocol_init()
{
#ifdef A7105_INSTALLED
#if defined(FLYSKY_A7105_INO)
case MODE_FLYSKY:
case PROTO_FLYSKY:
PE1_off; //antenna RF1
next_callback = initFlySky();
remote_callback = ReadFlySky;
break;
#endif
#if defined(AFHDS2A_A7105_INO)
case MODE_AFHDS2A:
case PROTO_AFHDS2A:
PE1_off; //antenna RF1
next_callback = initAFHDS2A();
remote_callback = ReadAFHDS2A;
break;
#endif
#if defined(HUBSAN_A7105_INO)
case MODE_HUBSAN:
case PROTO_HUBSAN:
PE1_off; //antenna RF1
if(IS_BIND_BUTTON_FLAG_on) random_id(EEPROM_ID_OFFSET,true); // Generate new ID if bind button is pressed.
next_callback = initHubsan();
@@ -823,7 +909,7 @@ static void protocol_init()
#endif
#ifdef CC2500_INSTALLED
#if defined(FRSKYD_CC2500_INO)
case MODE_FRSKYD:
case PROTO_FRSKYD:
PE1_off; //antenna RF2
PE2_on;
next_callback = initFrSky_2way();
@@ -831,7 +917,7 @@ static void protocol_init()
break;
#endif
#if defined(FRSKYV_CC2500_INO)
case MODE_FRSKYV:
case PROTO_FRSKYV:
PE1_off; //antenna RF2
PE2_on;
next_callback = initFRSKYV();
@@ -839,7 +925,7 @@ static void protocol_init()
break;
#endif
#if defined(FRSKYX_CC2500_INO)
case MODE_FRSKYX:
case PROTO_FRSKYX:
PE1_off; //antenna RF2
PE2_on;
next_callback = initFrSkyX();
@@ -847,7 +933,7 @@ static void protocol_init()
break;
#endif
#if defined(SFHSS_CC2500_INO)
case MODE_SFHSS:
case PROTO_SFHSS:
PE1_off; //antenna RF2
PE2_on;
next_callback = initSFHSS();
@@ -855,7 +941,7 @@ static void protocol_init()
break;
#endif
#if defined(CORONA_CC2500_INO)
case MODE_CORONA:
case PROTO_CORONA:
PE1_off; //antenna RF2
PE2_on;
next_callback = initCORONA();
@@ -865,25 +951,25 @@ static void protocol_init()
#endif
#ifdef CYRF6936_INSTALLED
#if defined(DSM_CYRF6936_INO)
case MODE_DSM:
case PROTO_DSM:
PE2_on; //antenna RF4
next_callback = initDsm();
remote_callback = ReadDsm;
break;
#endif
#if defined(DEVO_CYRF6936_INO)
case MODE_DEVO:
case PROTO_DEVO:
#ifdef ENABLE_PPM
if(mode_select) //PPM mode
{
if(IS_BIND_BUTTON_FLAG_on)
{
eeprom_write_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+mode_select),0x00); // reset to autobind mode for the current model
eeprom_write_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+RX_num),0x00); // reset to autobind mode for the current model
option=0;
}
else
{
option=eeprom_read_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+mode_select)); // load previous mode: autobind or fixed id
option=eeprom_read_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+RX_num)); // load previous mode: autobind or fixed id
if(option!=1) option=0; // if not fixed id mode then it should be autobind
}
}
@@ -894,18 +980,18 @@ static void protocol_init()
break;
#endif
#if defined(WK2x01_CYRF6936_INO)
case MODE_WK2x01:
case PROTO_WK2x01:
#ifdef ENABLE_PPM
if(mode_select) //PPM mode
{
if(IS_BIND_BUTTON_FLAG_on)
{
eeprom_write_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+mode_select),0x00); // reset to autobind mode for the current model
eeprom_write_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+RX_num),0x00); // reset to autobind mode for the current model
option=0;
}
else
{
option=eeprom_read_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+mode_select)); // load previous mode: autobind or fixed id
option=eeprom_read_byte((EE_ADDR)(MODELMODE_EEPROM_OFFSET+RX_num)); // load previous mode: autobind or fixed id
if(option!=1) option=0; // if not fixed id mode then it should be autobind
}
}
@@ -916,7 +1002,7 @@ static void protocol_init()
break;
#endif
#if defined(J6PRO_CYRF6936_INO)
case MODE_J6PRO:
case PROTO_J6PRO:
PE2_on; //antenna RF4
next_callback = initJ6Pro();
remote_callback = ReadJ6Pro;
@@ -925,141 +1011,141 @@ static void protocol_init()
#endif
#ifdef NRF24L01_INSTALLED
#if defined(HISKY_NRF24L01_INO)
case MODE_HISKY:
case PROTO_HISKY:
next_callback=initHiSky();
remote_callback = hisky_cb;
break;
#endif
#if defined(V2X2_NRF24L01_INO)
case MODE_V2X2:
case PROTO_V2X2:
next_callback = initV2x2();
remote_callback = ReadV2x2;
break;
#endif
#if defined(YD717_NRF24L01_INO)
case MODE_YD717:
case PROTO_YD717:
next_callback=initYD717();
remote_callback = yd717_callback;
break;
#endif
#if defined(KN_NRF24L01_INO)
case MODE_KN:
case PROTO_KN:
next_callback = initKN();
remote_callback = kn_callback;
break;
#endif
#if defined(SYMAX_NRF24L01_INO)
case MODE_SYMAX:
case PROTO_SYMAX:
next_callback = initSymax();
remote_callback = symax_callback;
break;
#endif
#if defined(SLT_NRF24L01_INO)
case MODE_SLT:
case PROTO_SLT:
next_callback=initSLT();
remote_callback = SLT_callback;
break;
#endif
#if defined(CX10_NRF24L01_INO)
case MODE_Q2X2:
case PROTO_Q2X2:
sub_protocol|=0x08; // Increase the number of sub_protocols for CX-10
case MODE_CX10:
case PROTO_CX10:
next_callback=initCX10();
remote_callback = CX10_callback;
break;
#endif
#if defined(CG023_NRF24L01_INO)
case MODE_CG023:
case PROTO_CG023:
next_callback=initCG023();
remote_callback = CG023_callback;
break;
#endif
#if defined(BAYANG_NRF24L01_INO)
case MODE_BAYANG:
case PROTO_BAYANG:
next_callback=initBAYANG();
remote_callback = BAYANG_callback;
break;
#endif
#if defined(ESKY_NRF24L01_INO)
case MODE_ESKY:
case PROTO_ESKY:
next_callback=initESKY();
remote_callback = ESKY_callback;
break;
#endif
#if defined(MT99XX_NRF24L01_INO)
case MODE_MT99XX:
case PROTO_MT99XX:
next_callback=initMT99XX();
remote_callback = MT99XX_callback;
break;
#endif
#if defined(MJXQ_NRF24L01_INO)
case MODE_MJXQ:
case PROTO_MJXQ:
next_callback=initMJXQ();
remote_callback = MJXQ_callback;
break;
#endif
#if defined(SHENQI_NRF24L01_INO)
case MODE_SHENQI:
case PROTO_SHENQI:
next_callback=initSHENQI();
remote_callback = SHENQI_callback;
break;
#endif
#if defined(FY326_NRF24L01_INO)
case MODE_FY326:
case PROTO_FY326:
next_callback=initFY326();
remote_callback = FY326_callback;
break;
#endif
#if defined(FQ777_NRF24L01_INO)
case MODE_FQ777:
case PROTO_FQ777:
next_callback=initFQ777();
remote_callback = FQ777_callback;
break;
#endif
#if defined(ASSAN_NRF24L01_INO)
case MODE_ASSAN:
case PROTO_ASSAN:
next_callback=initASSAN();
remote_callback = ASSAN_callback;
break;
#endif
#if defined(HONTAI_NRF24L01_INO)
case MODE_HONTAI:
case PROTO_HONTAI:
next_callback=initHONTAI();
remote_callback = HONTAI_callback;
break;
#endif
#if defined(Q303_NRF24L01_INO)
case MODE_Q303:
case PROTO_Q303:
next_callback=initQ303();
remote_callback = Q303_callback;
break;
#endif
#if defined(GW008_NRF24L01_INO)
case MODE_GW008:
case PROTO_GW008:
next_callback=initGW008();
remote_callback = GW008_callback;
break;
#endif
#if defined(DM002_NRF24L01_INO)
case MODE_DM002:
case PROTO_DM002:
next_callback=initDM002();
remote_callback = DM002_callback;
break;
#endif
#if defined(CABELL_NRF24L01_INO)
case MODE_CABELL:
case PROTO_CABELL:
next_callback=initCABELL();
remote_callback = CABELL_callback;
break;
#endif
#if defined(ESKY150_NRF24L01_INO)
case MODE_ESKY150:
case PROTO_ESKY150:
next_callback=initESKY150();
remote_callback = ESKY150_callback;
break;
#endif
#if defined(H8_3D_NRF24L01_INO)
case MODE_H8_3D:
case PROTO_H8_3D:
next_callback=initH8_3D();
remote_callback = H8_3D_callback;
break;
@@ -1114,27 +1200,27 @@ void update_serial_data()
//Forced frequency tuning values for CC2500 protocols
#if defined(FORCE_FRSKYD_TUNING) && defined(FRSKYD_CC2500_INO)
if(protocol==MODE_FRSKYD)
if(protocol==PROTO_FRSKYD)
option=FORCE_FRSKYD_TUNING; // Use config-defined tuning value for FrSkyD
else
#endif
#if defined(FORCE_FRSKYV_TUNING) && defined(FRSKYV_CC2500_INO)
if(protocol==MODE_FRSKYV)
if(protocol==PROTO_FRSKYV)
option=FORCE_FRSKYV_TUNING; // Use config-defined tuning value for FrSkyV
else
#endif
#if defined(FORCE_FRSKYX_TUNING) && defined(FRSKYX_CC2500_INO)
if(protocol==MODE_FRSKYX)
if(protocol==PROTO_FRSKYX)
option=FORCE_FRSKYX_TUNING; // Use config-defined tuning value for FrSkyX
else
#endif
#if defined(FORCE_SFHSS_TUNING) && defined(SFHSS_CC2500_INO)
if (protocol==MODE_SFHSS)
if (protocol==PROTO_SFHSS)
option=FORCE_SFHSS_TUNING; // Use config-defined tuning value for SFHSS
else
#endif
#if defined(FORCE_CORONA_TUNING) && defined(CORONA_CC2500_INO)
if (protocol==MODE_CORONA)
if (protocol==PROTO_CORONA)
option=FORCE_CORONA_TUNING; // Use config-defined tuning value for CORONA
else
#endif
@@ -1175,7 +1261,7 @@ void update_serial_data()
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(protocol==MODE_FRSKYD || protocol==MODE_FRSKYX || protocol==MODE_FRSKYV)
if(protocol==PROTO_FRSKYD || protocol==PROTO_FRSKYX || protocol==PROTO_FRSKYV)
BIND_DONE;
else
#endif
@@ -1441,11 +1527,11 @@ void pollBoot()
#if defined(TELEMETRY)
void PPM_Telemetry_serial_init()
{
if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_AFHDS2A) || (protocol==MODE_BAYANG) || (protocol==MODE_CABELL) )
if( (protocol==PROTO_FRSKYD) || (protocol==PROTO_HUBSAN) || (protocol==PROTO_AFHDS2A) || (protocol==PROTO_BAYANG) || (protocol==PROTO_CABELL) )
initTXSerial( SPEED_9600 ) ;
if(protocol==MODE_FRSKYX)
if(protocol==PROTO_FRSKYX)
initTXSerial( SPEED_57600 ) ;
if(protocol==MODE_DSM)
if(protocol==PROTO_DSM)
initTXSerial( SPEED_125K ) ;
}
#endif