From 061c97caca66fc8293b9bdf0bd7f7214f767df5e Mon Sep 17 00:00:00 2001 From: pascallanger Date: Wed, 24 Aug 2016 14:52:47 +0200 Subject: [PATCH] New _Config.h file, MJXQ fix, 16 bit regs --- Multiprotocol/A7105_SPI.ino | 5 +- Multiprotocol/ASSAN_nrf24l01.ino | 6 +- Multiprotocol/DSM2_cyrf6936.ino | 45 +++-- Multiprotocol/Devo_cyrf6936.ino | 2 +- Multiprotocol/FrSkyX_cc2500.ino | 2 +- Multiprotocol/Hisky_nrf24l01.ino | 2 +- Multiprotocol/MJXQ_nrf24l01.ino | 35 ++-- Multiprotocol/Multiprotocol.h | 287 +++++++++++++++---------------- Multiprotocol/Multiprotocol.ino | 69 ++++---- Multiprotocol/SFHSS_cc2500.ino | 2 +- Multiprotocol/TX_Def.h | 255 +++++++++++++++++++++++++++ Multiprotocol/Telemetry.ino | 3 +- Multiprotocol/_Config.h | 220 ++++++++--------------- 13 files changed, 563 insertions(+), 370 deletions(-) create mode 100644 Multiprotocol/TX_Def.h diff --git a/Multiprotocol/A7105_SPI.ino b/Multiprotocol/A7105_SPI.ino index af4cbcb..30c022b 100644 --- a/Multiprotocol/A7105_SPI.ino +++ b/Multiprotocol/A7105_SPI.ino @@ -62,10 +62,9 @@ uint8_t A7105_ReadReg(uint8_t address) { uint8_t A7105_Read(void) { - uint8_t result; - uint8_t i; + uint8_t result=0; SDI_SET_INPUT; - for(i=0;i<8;i++) + for(uint8_t i=0;i<8;i++) { result=result<<1; if(SDI_1) ///if SDIO =1 diff --git a/Multiprotocol/ASSAN_nrf24l01.ino b/Multiprotocol/ASSAN_nrf24l01.ino index 4bbf348..3356e2f 100644 --- a/Multiprotocol/ASSAN_nrf24l01.ino +++ b/Multiprotocol/ASSAN_nrf24l01.ino @@ -74,17 +74,17 @@ uint16_t ASSAN_callback() NRF24L01_SetTxRxMode(RX_EN); phase++; case ASSAN_BIND1: - //Wait for RX to send the frames + //Wait for receiver to send the frames if( NRF24L01_ReadReg(NRF24L01_07_STATUS) & BV(NRF24L01_07_RX_DR)) { //Something has been received NRF24L01_ReadPayload(packet, ASSAN_PACKET_SIZE); if(packet[19]==0x13) - { //Last packet received + { //Last frame received phase++; //Switch to TX NRF24L01_SetTxRxMode(TXRX_OFF); NRF24L01_SetTxRxMode(TX_EN); - //Prepare packet + //Prepare bind packet memset(packet,0x05,ASSAN_PACKET_SIZE-5); packet[15]=0x99; for(uint8_t i=0;i<4;i++) diff --git a/Multiprotocol/DSM2_cyrf6936.ino b/Multiprotocol/DSM2_cyrf6936.ino index 9ab5ead..85f8029 100644 --- a/Multiprotocol/DSM2_cyrf6936.ino +++ b/Multiprotocol/DSM2_cyrf6936.ino @@ -108,7 +108,6 @@ static void __attribute__((unused)) read_code(uint8_t *buf, uint8_t row, uint8_t // uint8_t sop_col; uint8_t data_col; -uint16_t cyrf_state; uint8_t binding; static void __attribute__((unused)) build_bind_packet() @@ -146,7 +145,7 @@ static void __attribute__((unused)) build_bind_packet() static uint8_t __attribute__((unused)) PROTOCOL_SticksMoved(uint8_t init) { -#define STICK_MOVEMENT 15*(PPM_MAX-PPM_MIN)/100 // defines when the bind dialog should be interrupted (stick movement STICK_MOVEMENT %) +#define STICK_MOVEMENT 15*(servo_max_125-servo_min_125)/100 // defines when the bind dialog should be interrupted (stick movement STICK_MOVEMENT %) static uint16_t ele_start, ail_start; uint16_t ele = Servo_data[ELEVATOR];//CHAN_ReadInput(MIXER_MapChannel(INP_ELEVATOR)); uint16_t ail = Servo_data[AILERON];//CHAN_ReadInput(MIXER_MapChannel(INP_AILERON)); @@ -263,7 +262,7 @@ static void __attribute__((unused)) build_data_packet(uint8_t upper)// value=Servo_data[AUX8]; break; } - value=map(value,PPM_MIN,PPM_MAX,0,max-1); + value=map(value,servo_min_125,servo_max_125,0,max-1); } value |= (upper && i == 0 ? 0x8000 : 0) | (idx << bits); } @@ -416,12 +415,12 @@ uint16_t ReadDsm2() #define DSM_READ_DELAY 600 // Time before write to check read state, and switch channels. Was 400 but 500 seems what the 328p needs to read a packet uint16_t start; - switch(cyrf_state) + switch(state) { default: //Binding - cyrf_state++; - if(cyrf_state & 1) + state++; + if(state & 1) { //Send packet on even states //Note state has already incremented, so this is actually 'even' state @@ -441,17 +440,17 @@ uint16_t ReadDsm2() cyrf_configdata(); CYRF_SetTxRxMode(TX_EN); hopping_frequency_no = 0; - cyrf_state = DSM2_CH1_WRITE_A; // in fact cyrf_state++ + state = DSM2_CH1_WRITE_A; // in fact state++ set_sop_data_crc(); return 10000; case DSM2_CH1_WRITE_A: case DSM2_CH1_WRITE_B: case DSM2_CH2_WRITE_A: case DSM2_CH2_WRITE_B: - build_data_packet(cyrf_state == DSM2_CH1_WRITE_B);// build lower or upper channels + build_data_packet(state == DSM2_CH1_WRITE_B);// build lower or upper channels CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS); // clear IRQ flags CYRF_WriteDataPacket(packet); - cyrf_state++; // change from WRITE to CHECK mode + state++; // change from WRITE to CHECK mode return DSM_WRITE_DELAY; case DSM2_CH1_CHECK_A: case DSM2_CH1_CHECK_B: @@ -460,7 +459,7 @@ uint16_t ReadDsm2() if(CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS) & 0x02) break; set_sop_data_crc(); - cyrf_state++; // change from CH1_CHECK to CH2_WRITE + state++; // change from CH1_CHECK to CH2_WRITE return DSM_CH1_CH2_DELAY - DSM_WRITE_DELAY; case DSM2_CH2_CHECK_A: case DSM2_CH2_CHECK_B: @@ -468,10 +467,10 @@ uint16_t ReadDsm2() while ((uint16_t)micros()-start < 500) // Wait max 500µs if(CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS) & 0x02) break; - if (cyrf_state == DSM2_CH2_CHECK_A) + if (state == DSM2_CH2_CHECK_A) CYRF_SetPower(0x28); //Keep transmit power in sync #if defined DSM_TELEMETRY - cyrf_state++; // change from CH2_CHECK to CH2_READ + state++; // change from CH2_CHECK to CH2_READ if(option<=3 || option>7) { // disable telemetry for option between 4 and 7 ie 4,5,6,7 channels @11ms since it does not work... CYRF_SetTxRxMode(RX_EN); //Receive mode @@ -494,7 +493,7 @@ uint16_t ReadDsm2() pkt[0]=CYRF_ReadRegister(CYRF_13_RSSI)&0x1F; // store RSSI of the received telemetry signal telemetry_link=1; } - if (cyrf_state == DSM2_CH2_READ_A && option <= 3) // normal 22ms mode if option<=3 ie 4,5,6,7 channels @22ms + if (state == DSM2_CH2_READ_A && option <= 3) // normal 22ms mode if option<=3 ie 4,5,6,7 channels @22ms { //Force end read state CYRF_WriteRegister(CYRF_0F_XACT_CFG, (CYRF_ReadRegister(CYRF_0F_XACT_CFG) | 0x20)); // Force end state @@ -502,35 +501,35 @@ uint16_t ReadDsm2() while ((uint16_t)micros()-start < 100) // Wait max 100 µs if((CYRF_ReadRegister(CYRF_0F_XACT_CFG) & 0x20) == 0) break; - cyrf_state = DSM2_CH2_READ_B; + state = DSM2_CH2_READ_B; CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x87); //0x80??? //Prepare to receive return 11000; } - if (cyrf_state == DSM2_CH2_READ_A && option>7) - cyrf_state = DSM2_CH1_WRITE_B; //Transmit upper + if (state == DSM2_CH2_READ_A && option>7) + state = DSM2_CH1_WRITE_B; //Transmit upper else - cyrf_state = DSM2_CH1_WRITE_A; //Force 11ms if option>3 ie 4,5,6,7 channels @11ms + state = DSM2_CH1_WRITE_A; //Force 11ms if option>3 ie 4,5,6,7 channels @11ms CYRF_SetTxRxMode(TX_EN); //Write mode set_sop_data_crc(); return DSM_READ_DELAY; #else // No telemetry set_sop_data_crc(); - if (cyrf_state == DSM2_CH2_CHECK_A) + if (state == DSM2_CH2_CHECK_A) { if(option < 8) { - cyrf_state = DSM2_CH1_WRITE_A; // change from CH2_CHECK_A to CH1_WRITE_A (ie no upper) + state = DSM2_CH1_WRITE_A; // change from CH2_CHECK_A to CH1_WRITE_A (ie no upper) if(option>3) return 11000 - DSM_CH1_CH2_DELAY - DSM_WRITE_DELAY ; // force 11ms if option>3 ie 4,5,6,7 channels @11ms else return 22000 - DSM_CH1_CH2_DELAY - DSM_WRITE_DELAY ; // normal 22ms mode if option<=3 ie 4,5,6,7 channels @22ms } else - cyrf_state = DSM2_CH1_WRITE_B; // change from CH2_CHECK_A to CH1_WRITE_A (to transmit upper) + state = DSM2_CH1_WRITE_B; // change from CH2_CHECK_A to CH1_WRITE_A (to transmit upper) } else - cyrf_state = DSM2_CH1_WRITE_A; // change from CH2_CHECK_B to CH1_WRITE_A (upper already transmitted so transmit lower) + state = DSM2_CH1_WRITE_A; // change from CH2_CHECK_B to CH1_WRITE_A (upper already transmitted so transmit lower) return 11000 - DSM_CH1_CH2_DELAY - DSM_WRITE_DELAY; #endif } @@ -581,14 +580,14 @@ uint16_t initDsm2() // if(IS_AUTOBIND_FLAG_on) { - cyrf_state = DSM2_BIND; + state = DSM2_BIND; PROTOCOL_SticksMoved(1); //Initialize Stick position initialize_bind_state(); binding = 1; } else { - cyrf_state = DSM2_CHANSEL;// + state = DSM2_CHANSEL;// binding = 0; } return 10000; diff --git a/Multiprotocol/Devo_cyrf6936.ino b/Multiprotocol/Devo_cyrf6936.ino index eee0231..e535095 100644 --- a/Multiprotocol/Devo_cyrf6936.ino +++ b/Multiprotocol/Devo_cyrf6936.ino @@ -148,7 +148,7 @@ static void __attribute__((unused)) build_data_pkt() for (i = 0; i < 4; i++) { // - int16_t value= map(Servo_data[ch_idx * 4 + i],PPM_MIN,PPM_MAX,-1600,1600);//range -1600...+1600 + int16_t value= map(Servo_data[ch_idx * 4 + i],servo_min_125,servo_max_125,-1600,1600);//range -1600...+1600 //s32 value = (s32)Channels[ch_idx * 4 + i] * 0x640 / CHAN_MAX_VALUE;//10000 if(value < 0) { diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index d631821..452f23f 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -145,7 +145,7 @@ static uint16_t __attribute__((unused)) crc_x(uint8_t *data, uint8_t len) static uint16_t __attribute__((unused)) scaleForPXX( uint8_t i ) { //mapped 860,2140(125%) range to 64,1984(PXX values); - return (uint16_t)(((Servo_data[i]-PPM_MIN)*3)>>1)+64; + return (uint16_t)(((Servo_data[i]-servo_min_125)*3)>>1)+64; } static void __attribute__((unused)) frskyX_build_bind_packet() diff --git a/Multiprotocol/Hisky_nrf24l01.ino b/Multiprotocol/Hisky_nrf24l01.ino index 36c35b8..ddf935b 100644 --- a/Multiprotocol/Hisky_nrf24l01.ino +++ b/Multiprotocol/Hisky_nrf24l01.ino @@ -122,7 +122,7 @@ static void __attribute__((unused)) build_ch_data() uint8_t i,j; for (i = 0; i< 8; i++) { j=CH_AETR[i]; - temp=map(limit_channel_100(j),PPM_MIN_100,PPM_MAX_100,0,1000); + temp=map(limit_channel_100(j),servo_min_100,servo_max_100,0,1000); if (j == THROTTLE) // It is clear that hisky's throttle stick is made reversely, so I adjust it here on purpose temp = 1000 -temp; if (j == AUX3) diff --git a/Multiprotocol/MJXQ_nrf24l01.ino b/Multiprotocol/MJXQ_nrf24l01.ino index 484e798..e57cdf6 100644 --- a/Multiprotocol/MJXQ_nrf24l01.ino +++ b/Multiprotocol/MJXQ_nrf24l01.ino @@ -26,6 +26,17 @@ #define MJXQ_RF_NUM_CHANNELS 4 #define MJXQ_ADDRESS_LENGTH 5 +// haven't figured out txid<-->rf channel mapping for MJX models +const uint8_t PROGMEM MJXQ_map_rfchan[][4] = { + {0x0A, 0x46, 0x3A, 0x42}, + {0x0A, 0x3C, 0x36, 0x3F}, + {0x0A, 0x43, 0x36, 0x3F} }; +const uint8_t PROGMEM MJXQ_map_txid[][3] = { + {0xF8, 0x4F, 0x1C}, + {0xC8, 0x6E, 0x02}, + {0x48, 0x6A, 0x40} }; + + #define MJXQ_PAN_TILT_COUNT 16 // for H26D - match stock tx timing #define MJXQ_PAN_DOWN 0x08 #define MJXQ_PAN_UP 0x04 @@ -39,14 +50,14 @@ static uint8_t __attribute__((unused)) MJXQ_pan_tilt_value() packet_count++; if(packet_count & MJXQ_PAN_TILT_COUNT) { - if(Servo_AUX8) + if(Servo_data[AUX8]>PPM_MAX_COMMAND) pan=MJXQ_PAN_UP; if(Servo_data[AUX8]PPM_MIN_COMMAND) - pan=MJXQ_TILT_UP; + if(Servo_data[AUX9]>PPM_MAX_COMMAND) + pan+=MJXQ_TILT_UP; if(Servo_data[AUX9]rf channel mapping for MJX models - static const uint8_t rf_map[][4] = { - {0x0A, 0x46, 0x3A, 0x42}, - {0x0A, 0x3C, 0x36, 0x3F}, - {0x0A, 0x43, 0x36, 0x3F} }; if (sub_protocol == H26D) memcpy(hopping_frequency, "\x32\x3e\x42\x4e", MJXQ_RF_NUM_CHANNELS); else if (sub_protocol == WLH08) - memcpy(hopping_frequency, rf_map[rx_tx_addr[0]%3], MJXQ_RF_NUM_CHANNELS); + for(uint8_t i=0;irf channel mapping for MJX models - static const uint8_t tx_map[][3]={ - {0xF8, 0x4F, 0x1C}, - {0xC8, 0x6E, 0x02}, - {0x48, 0x6A, 0x40} }; if (sub_protocol == WLH08) rx_tx_addr[0]&=0xF8; // txid must be multiple of 8 else - memcpy(rx_tx_addr,tx_map[rx_tx_addr[0]%3],3); + for(uint8_t i=0;i<3;i++) + rx_tx_addr[i]=pgm_read_byte_near( &MJXQ_map_txid[rx_tx_addr[4]%3][i] ); } uint16_t MJXQ_callback() diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index b54affa..4e30d40 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -28,83 +28,84 @@ //****************** enum PROTOCOLS { - MODE_SERIAL = 0, // Serial commands - MODE_FLYSKY = 1, // =>A7105 - MODE_HUBSAN = 2, // =>A7105 - MODE_FRSKY = 3, // =>CC2500 - MODE_HISKY = 4, // =>NRF24L01 - MODE_V2X2 = 5, // =>NRF24L01 - MODE_DSM2 = 6, // =>CYRF6936 - MODE_DEVO =7, // =>CYRF6936 - MODE_YD717 = 8, // =>NRF24L01 - MODE_KN = 9, // =>NRF24L01 - MODE_SYMAX = 10, // =>NRF24L01 - MODE_SLT = 11, // =>NRF24L01 - MODE_CX10 = 12, // =>NRF24L01 - MODE_CG023 = 13, // =>NRF24L01 - MODE_BAYANG = 14, // =>NRF24L01 - MODE_FRSKYX = 15, // =>CC2500 - MODE_ESKY = 16, // =>NRF24L01 - MODE_MT99XX=17, // =>NRF24L01 - MODE_MJXQ=18, // =>NRF24L01 - MODE_SHENQI=19, // =>NRF24L01 - MODE_FY326=20, // =>NRF24L01 - MODE_SFHSS=21, // =>CC2500 - MODE_J6PRO=22, // =>CYRF6936 - MODE_FQ777=23, // =>NRF24L01 - MODE_ASSAN=24 // =>NRF24L01 + MODE_SERIAL = 0, // Serial commands + MODE_FLYSKY = 1, // =>A7105 + MODE_HUBSAN = 2, // =>A7105 + MODE_FRSKY = 3, // =>CC2500 + MODE_HISKY = 4, // =>NRF24L01 + MODE_V2X2 = 5, // =>NRF24L01 + MODE_DSM2 = 6, // =>CYRF6936 + MODE_DEVO = 7, // =>CYRF6936 + MODE_YD717 = 8, // =>NRF24L01 + MODE_KN = 9, // =>NRF24L01 + MODE_SYMAX = 10, // =>NRF24L01 + MODE_SLT = 11, // =>NRF24L01 + MODE_CX10 = 12, // =>NRF24L01 + MODE_CG023 = 13, // =>NRF24L01 + MODE_BAYANG = 14, // =>NRF24L01 + MODE_FRSKYX = 15, // =>CC2500 + MODE_ESKY = 16, // =>NRF24L01 + MODE_MT99XX = 17, // =>NRF24L01 + MODE_MJXQ = 18, // =>NRF24L01 + MODE_SHENQI = 19, // =>NRF24L01 + MODE_FY326 = 20, // =>NRF24L01 + MODE_SFHSS = 21, // =>CC2500 + MODE_J6PRO = 22, // =>CYRF6936 + MODE_FQ777 = 23, // =>NRF24L01 + MODE_ASSAN = 24 // =>NRF24L01 }; enum Flysky { - Flysky=0, - V9X9=1, - V6X6=2, - V912=3 + Flysky = 0, + V9X9 = 1, + V6X6 = 2, + V912 = 3 }; enum Hisky { - Hisky=0, - HK310=1 + Hisky = 0, + HK310 = 1 }; -enum DSM2{ - DSM2=0, - DSMX=1 +enum DSM2 +{ + DSM2 = 0, + DSMX = 1 }; enum YD717 { - YD717=0, - SKYWLKR=1, - SYMAX4=2, - XINXUN=3, - NIHUI=4 + YD717 = 0, + SKYWLKR = 1, + SYMAX4 = 2, + XINXUN = 3, + NIHUI = 4 }; enum KN { - WLTOYS=0, - FEILUN=1 + WLTOYS = 0, + FEILUN = 1 }; enum SYMAX { - SYMAX=0, - SYMAX5C=1 + SYMAX = 0, + SYMAX5C = 1 }; enum CX10 { - CX10_GREEN = 0, - CX10_BLUE=1, // also compatible with CX10-A, CX12 - DM007=2, - Q282=3, - JC3015_1=4, - JC3015_2=5, - MK33041=6, - Q242=7 + CX10_GREEN = 0, + CX10_BLUE = 1, // also compatible with CX10-A, CX12 + DM007 = 2, + Q282 = 3, + JC3015_1 = 4, + JC3015_2 = 5, + MK33041 = 6, + Q242 = 7 }; enum CG023 { - CG023 = 0, - YD829 = 1, - H8_3D = 2 + CG023 = 0, + YD829 = 1, + H8_3D = 2 }; enum MT99XX { @@ -146,126 +147,118 @@ struct PPM_Parameters //******************* //*** Pinouts *** //******************* -//#define BIND_pin 13 -#define LED_pin 13 //Promini original led on B5 -// -#define PPM_pin 3 //PPM -D3 +#define LED_pin 13 //Promini original led on B5 +#define PPM_pin 3 //PPM-D3 #ifdef XMEGA -#define SDI_pin 6 //SDIO-D6 + #define SDI_pin 6 //SDIO-D6 #else -#define SDI_pin 5 //SDIO-D5 + #define SDI_pin 5 //SDIO-D5 #endif -#define SCLK_pin 4 //SCK-D4 -#define CS_pin 2 //CS-D2 -#define SDO_pin 6 //D6 -// -#define CTRL1 1 //C1 (A1) -#define CTRL2 2 //C2 (A2) -// -#ifdef XMEGA -#define CTRL1_on -#define CTRL1_off -// -#define CTRL2_on -#define CTRL2_off -#else -#define CTRL1_on PORTC |= _BV(1) -#define CTRL1_off PORTC &= ~_BV(1) -// -#define CTRL2_on PORTC |= _BV(2) -#define CTRL2_off PORTC &= ~_BV(2) -#endif -// -#ifdef XMEGA -#define CS_on PORTD.OUTSET = _BV(4) //D4 -#define CS_off PORTD.OUTCLR = _BV(4) //D4 -#else -#define CS_on PORTD |= _BV(2) //D2 -#define CS_off PORTD &= ~_BV(2) //D2 -#endif -// -#ifdef XMEGA -#define SCK_on PORTD.OUTSET = _BV(7) //D7 -#define SCK_off PORTD.OUTCLR = _BV(7) //D7 -#else -#define SCK_on PORTD |= _BV(4) //D4 -#define SCK_off PORTD &= ~_BV(4) //D4 -#endif -// -#ifdef XMEGA -#define SDI_on PORTD.OUTSET = _BV(5) //D5 -#define SDI_off PORTD.OUTCLR = _BV(5) //D5 -#else -#define SDI_on PORTD |= _BV(5) //D5 -#define SDI_off PORTD &= ~_BV(5) //D5 -#endif - -#ifdef XMEGA -#define SDI_1 (PORTD.IN & (1<>2)&0x07 ) | ( (PINC<<3)&0x08) );//encoder dip switches 1,2,4,8=>B2,B3,B4,C0 #endif -//********************************** -//mode_select=1; // here to test PPM -//********************************** // Update LED LED_OFF; @@ -242,6 +243,7 @@ void setup() NRF24L01_Reset(); #endif +#ifdef ENABLE_PPM //Protocol and interrupts initialization if(mode_select != MODE_SERIAL) { // PPM @@ -254,6 +256,8 @@ void setup() if(PPM_prot[mode_select].power) POWER_FLAG_on; if(PPM_prot[mode_select].autobind) AUTOBIND_FLAG_on; mode_select++; + servo_max_100=PPM_MAX_100; servo_min_100=PPM_MIN_100; + servo_max_125=PPM_MAX_125; servo_min_125=PPM_MIN_125; protocol_init(); @@ -268,17 +272,23 @@ void setup() #endif } else +#endif //ENABLE_PPM { // Serial +#ifdef ENABLE_SERIAL cur_protocol[0]=0; cur_protocol[1]=0; prev_protocol=0; + servo_max_100=SERIAL_MAX_100; servo_min_100=SERIAL_MIN_100; + servo_max_125=SERIAL_MAX_125; servo_min_125=SERIAL_MIN_125; Mprotocol_serial_init(); // Configure serial and enable RX interrupt +#endif //ENABLE_SERIAL } } // Main void loop() { +#ifdef ENABLE_SERIAL if(mode_select==MODE_SERIAL && IS_RX_FLAG_on) // Serial mode and something has been received { update_serial_data(); // Update protocol and data @@ -291,6 +301,8 @@ void loop() CHANGE_PROTOCOL_FLAG_off; //done } } +#endif //ENABLE_SERIAL +#ifdef ENABLE_PPM if(mode_select!=MODE_SERIAL && IS_PPM_FLAG_on) // PPM mode and a full frame has been received { for(uint8_t i=0;iPPM_MAX_125) temp_ppm=PPM_MAX_125; Servo_data[i]= temp_ppm ; } update_aux_flags(); PPM_FLAG_off; // wait for next frame before update } +#endif //ENABLE_PPM update_led_status(); #if defined(TELEMETRY) if( ((cur_protocol[0]&0x1F)==MODE_FRSKY) || ((cur_protocol[0]&0x1F)==MODE_HUBSAN) || ((cur_protocol[0]&0x1F)==MODE_FRSKYX) || ((cur_protocol[0]&0x1F)==MODE_DSM2) ) @@ -362,10 +377,8 @@ static void CheckTimer(uint16_t (*cb)(void)) #else if( (TIFR1 & (1<32000) { // next_callback should not be more than 32767 so we will wait here... - uint16_t temp=next_callback>>10-2; + uint16_t temp=(next_callback>>10)-2; delayMilliseconds(temp); next_callback-=temp<<10; // between 2-3ms left at this stage } @@ -612,7 +623,7 @@ static void protocol_init() BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change } -static void update_serial_data() +void update_serial_data() { if(rx_ok_buff[0]&0x20) //check range RANGE_FLAG_on; @@ -660,7 +671,7 @@ static void update_serial_data() RX_FLAG_off; //data has been processed } -static void module_reset() +void module_reset() { if(remote_callback) { // previous protocol loaded @@ -703,13 +714,13 @@ int16_t map( int16_t x, int16_t in_min, int16_t in_max, int16_t out_min, int16_t // Channel value is converted to 8bit values full scale uint8_t convert_channel_8b(uint8_t num) { - return (uint8_t) (map(limit_channel_100(num),PPM_MIN_100,PPM_MAX_100,0,255)); + return (uint8_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,0,255)); } // Channel value is converted to 8bit values to provided values scale uint8_t convert_channel_8b_scale(uint8_t num,uint8_t min,uint8_t max) { - return (uint8_t) (map(limit_channel_100(num),PPM_MIN_100,PPM_MAX_100,min,max)); + return (uint8_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,min,max)); } // Channel value is converted sign + magnitude 8bit values @@ -723,7 +734,7 @@ uint8_t convert_channel_s8b(uint8_t num) // Channel value is converted to 10bit values uint16_t convert_channel_10b(uint8_t num) { - return (uint16_t) (map(limit_channel_100(num),PPM_MIN_100,PPM_MAX_100,1,1023)); + return (uint16_t) (map(limit_channel_100(num),servo_min_100,servo_max_100,1,1023)); } // Channel value is multiplied by 1.5 @@ -743,15 +754,15 @@ void convert_channel_HK310(uint8_t num, uint8_t *low, uint8_t *high) // Channel value is limited to PPM_100 uint16_t limit_channel_100(uint8_t ch) { - if(Servo_data[ch]>PPM_MAX_100) - return PPM_MAX_100; + if(Servo_data[ch]>servo_max_100) + return servo_max_100; else - if (Servo_data[ch]>1; - if(tempPPM_MAX) temp=PPM_MAX; - PPM_data[chan]=temp; + PPM_data[chan]= Cur_TCNT1>>1;; if(chan++>=NUM_CHN) chan=-1; // don't accept any new channels } Prev_TCNT1+=Cur_TCNT1; } +#endif //ENABLE_PPM //Serial RX +#ifdef ENABLE_SERIAL #ifdef XMEGA ISR(USARTC0_RXC_vect) #else @@ -1071,8 +1083,7 @@ ISR(USART_RX_vect) #endif if(!IS_RX_FLAG_on) { //Good frame received and main has finished with previous buffer - uint8_t i ; - for(i=0;i0 && pktt[6]<=10) {//only valid hub frames diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h index 52f8cc9..eb075a1 100644 --- a/Multiprotocol/_Config.h +++ b/Multiprotocol/_Config.h @@ -13,28 +13,32 @@ along with Multiprotocol. If not, see . */ +/**********************************************/ /** Multiprotocol module configuration file ***/ +/**********************************************/ /*******************/ /*** TX SETTINGS ***/ /*******************/ -//Uncomment your TX type -#define TX_ER9X_AETR //ER9X AETR (988<->2012µs) -//#define TX_ER9X_TAER //ER9X TAER (988<->2012µs) -//#define TX_DEVO7 //DEVO7 EATR (1120<->1920µs) -//#define TX_SPEKTRUM //Spektrum TAER (1100<->1900µs) -//#define TX_HISKY //HISKY AETR (1100<->1900µs) +//Modify the channel order based on your TX: AETR, TAER, RETA... +//For example a JR/Spektrum radio is TAER. Default is AETR. +#define AETR + /****************************/ /*** PROTOCOLS TO INCLUDE ***/ /****************************/ -//Comment if a module is not installed +//In this section select the protocols you want to be accessible when using the module. +//All the protocols will not fit in the module so you need to pick and choose. + +//There are 4 RF components supported. If one of them is not installed you must comment it using "//". +//This is also a quick way to reduce the number of protocols and save Flash space. #define A7105_INSTALLED #define CYRF6936_INSTALLED #define CC2500_INSTALLED #define NFR24L01_INSTALLED -//Comment a protocol to exclude it from compilation +//Bellow is the list of all available protocols. Comment the protocols you are not using with "//" to save Flash space. #ifdef A7105_INSTALLED #define FLYSKY_A7105_INO #define HUBSAN_A7105_INO @@ -68,16 +72,20 @@ #define ASSAN_NRF24L01_INO #endif + /**************************/ /*** TELEMETRY SETTINGS ***/ /**************************/ -//Uncomment to enable telemetry +//In this section you can configure the telemetry. + +//If you do not plan using the telemetry comment this global setting using "//" and skip to the next section. #define TELEMETRY -//Uncomment to invert the telemetry serial signal, this is usefull for OpenTX on Taranis as an example +//Uncomment to invert the polarity of the telemetry serial signal. +//For ER9X and ERSKY9X it must be commented. For OpenTX it must be uncommented. //#define INVERT_TELEMETRY 1 -//Comment to disable a specific telemetry +//Comment a line to disable a protocol telemetry #if defined(TELEMETRY) #if defined DSM2_CYRF6936_INO #define DSM_TELEMETRY @@ -90,18 +98,59 @@ #endif #endif -/********************/ -/*** PPM SETTINGS ***/ -/********************/ -//Update this table to set which protocol and all associated settings are called for the corresponding dial number + +/****************************/ +/*** SERIAL MODE SETTINGS ***/ +/****************************/ +//In this section you can configure the serial mode. +//The serial mode enables full editing of all the parameters in the GUI of the radio. +//This is available natively for ER9X and ERSKY9X. It is available for OpenTX on Taranis with a special version. + +//If you do not plan to use the Serial mode comment this line using "//" to save Flash space +#define ENABLE_SERIAL + + +/*************************/ +/*** PPM MODE SETTINGS ***/ +/*************************/ +//In this section you can configure all details about PPM. +//If you do not plan to use the PPM mode comment this line using "//" to save Flash space, you don't need to configure anything below in this case +#define ENABLE_PPM + +/*** TX END POINTS ***/ +//It is important for the module to know the endpoints of your radio. +//Below are some standard transmitters already preconfigured. +//Uncomment only the one which matches your transmitter. +#define TX_ER9X //ER9X/ERSKY9X/OpenTX ( 988<->2012µs) +//#define TX_DEVO7 //DEVO (1120<->1920µs) +//#define TX_SPEKTRUM //Spektrum (1100<->1900µs) +//#define TX_HISKY //HISKY (1100<->1900µs) +//#define TX_CUSTOM //Custom + +// The lines below are used to set the end points in microseconds (µs) if you have selected TX_CUSTOM. +// A few things to considered: +// - If you put too big values compared to your TX you won't be able to reach the extremes which is bad for throttle as an example +// - If you put too low values you won't be able to use your full stick range, it will be maxed out before reaching the end +// - Centered stick value is usually 1500. It should match the middle between MIN and MAX, ie Center=(MAX-MIN)/2+MIN. If your TX is not centered you can adjust the value MIN or MAX. +// - 100% is the value when the model is by default, 125% is the value when you extend the servo travel which is only used by some protocols +#if defined(TX_CUSTOM) + #define PPM_MAX_100 1900 // 100% + #define PPM_MIN_100 1100 // 100% + #define PPM_MAX_125 2000 // 125% + #define PPM_MIN_125 1000 // 125% +#endif + +//The table below indicates which protocol to run when a specific position on the dial has been selected. +//All fields and values are explained below. Everything is configurable from here like in the Serial mode. +//Example: You can associate multiple times the same protocol to different dial positions to take advantage of the model match (RX_Num) const PPM_Parameters PPM_prot[15]= { // Dial Protocol Sub protocol RX_Num Power Auto Bind Option /* 1 */ {MODE_FLYSKY, Flysky , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 2 */ {MODE_HUBSAN, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, -/* 3 */ {MODE_FRSKY , 0 , 0 , P_HIGH , NO_AUTOBIND , 0xD7 }, // D7 fine tuning +/* 3 */ {MODE_FRSKY , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, // option=fine freq tuning /* 4 */ {MODE_HISKY , Hisky , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 5 */ {MODE_V2X2 , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, -/* 6 */ {MODE_DSM2 , DSM2 , 0 , P_HIGH , NO_AUTOBIND , 6 }, // 6 channels @ 11ms +/* 6 */ {MODE_DSM2 , DSM2 , 0 , P_HIGH , NO_AUTOBIND , 2 }, // option=2=6 channels @ 22ms /* 7 */ {MODE_DEVO , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 8 */ {MODE_YD717 , YD717 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 9 */ {MODE_KN , WLTOYS , 0 , P_HIGH , NO_AUTOBIND , 0 }, @@ -112,7 +161,7 @@ const PPM_Parameters PPM_prot[15]= { /* 14 */ {MODE_BAYANG, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 15 */ {MODE_SYMAX , SYMAX5C , 0 , P_HIGH , NO_AUTOBIND , 0 } }; -/* Available protocols and associated sub protocols: +/* Available protocols and associated sub protocols to pick and choose from MODE_FLYSKY Flysky V9X9 @@ -188,134 +237,17 @@ const PPM_Parameters PPM_prot[15]= { NONE MODE_ASSAN NONE - -RX_Num value between 0 and 15 - -Power P_HIGH or P_LOW - -Auto Bind AUTOBIND or NO_AUTOBIND - -Option value between 0 and 255. 0xD7 or 0x00 for Frsky fine tuning. */ -/*******************/ -/*** TX SETTINGS ***/ -/*******************/ -// Turnigy PPM and channels -#if defined(TX_ER9X_AETR) -#define PPM_MAX 2140 // 125% -#define PPM_MIN 860 // 125% -#define PPM_MAX_100 2012 // 100% -#define PPM_MIN_100 988 // 100% -enum chan_order{ - AILERON =0, - ELEVATOR, - THROTTLE, - RUDDER, - AUX1, - AUX2, - AUX3, - AUX4, - AUX5, - AUX6, - AUX7, - AUX8, - AUX9 -}; -#endif +// 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 value is between 0 and 15. -// Turnigy PPM and channels -#if defined(TX_ER9X_TAER) -#define PPM_MAX 2140 // 125% -#define PPM_MIN 860 // 125% -#define PPM_MAX_100 2012 // 100% -#define PPM_MIN_100 988 // 100% -enum chan_order{ - THROTTLE =0, - AILERON, - ELEVATOR, - RUDDER, - AUX1, - AUX2, - AUX3, - AUX4, - AUX5, - AUX6, - AUX7, - AUX8, - AUX9 -}; -#endif +// Power P_HIGH or P_LOW: High or low power setting for the transmission. +// For indoor P_LOW is more than enough. -// Devo PPM and channels -#if defined(TX_DEVO7) -#define PPM_MAX 2100 // 125% -#define PPM_MIN 900 // 125% -#define PPM_MAX_100 1920 // 100% -#define PPM_MIN_100 1120 // 100% -enum chan_order{ - ELEVATOR=0, - AILERON, - THROTTLE, - RUDDER, - AUX1, - AUX2, - AUX3, - AUX4, - AUX5, - AUX6, - AUX7, - AUX8, - AUX9 -}; -#endif +// Auto Bind AUTOBIND or NO_AUTOBIND +// For protocols which does not require binding at each power up (like Flysky, FrSky...), you might still want a bind to be initiated each time you power up the TX. +// As an exxample, it's usefull for the WLTOYS F929/F939/F949/F959 (all using the Flysky protocol) which requires a bind at each power up. -// SPEKTRUM PPM and channels -#if defined(TX_SPEKTRUM) -#define PPM_MAX 2000 // 125% -#define PPM_MIN 1000 // 125% -#define PPM_MAX_100 1900 // 100% -#define PPM_MIN_100 1100 // 100% -enum chan_order{ - THROTTLE=0, - AILERON, - ELEVATOR, - RUDDER, - AUX1, - AUX2, - AUX3, - AUX4, - AUX5, - AUX6, - AUX7, - AUX8, - AUX9 -}; -#endif - -// HISKY -#if defined(TX_HISKY) -#define PPM_MAX 2000 // 125% -#define PPM_MIN 1000 // 125% -#define PPM_MAX_100 1900 // 100% -#define PPM_MIN_100 1100 // 100% -enum chan_order{ - AILERON =0, - ELEVATOR, - THROTTLE, - RUDDER, - AUX1, - AUX2, - AUX3, - AUX4, - AUX5, - AUX6, - AUX7, - AUX8, - AUX9 -}; -#endif - -#define PPM_MIN_COMMAND 1250 -#define PPM_SWITCH 1550 -#define PPM_MAX_COMMAND 1750 +// Option: the value is between -127 and +127. +// The option value is only valid for some protocols, read this page for more information: https://github.com/pascallanger/DIY-Multiprotocol-TX-Module/blob/master/Protocols_Details.md \ No newline at end of file