From 7438545a161b02dcf967cfde37b53c8cbab47e12 Mon Sep 17 00:00:00 2001 From: pascallanger Date: Mon, 15 Aug 2016 11:52:43 +0200 Subject: [PATCH] Invert serial, optimization and SFHSS --- Multiprotocol/A7105_SPI.ino | 6 +- Multiprotocol/CC2500_SPI.ino | 6 +- Multiprotocol/CYRF6936_SPI.ino | 6 +- Multiprotocol/DSM2_cyrf6936.ino | 8 +- Multiprotocol/Devo_cyrf6936.ino | 96 ++++--- Multiprotocol/FlySky_a7105.ino | 7 +- Multiprotocol/FrSkyX_cc2500.ino | 13 +- Multiprotocol/Multiprotocol.h | 4 + Multiprotocol/Multiprotocol.ino | 126 ++++----- Multiprotocol/NRF24l01_SPI.ino | 6 +- Multiprotocol/SFHSS_cc2500.ino | 39 +-- Multiprotocol/Symax_nrf24l01.ino | 2 +- Multiprotocol/Telemetry.ino | 444 ++++++++++++++++++++++++++++--- Multiprotocol/_Config.h | 25 +- 14 files changed, 611 insertions(+), 177 deletions(-) diff --git a/Multiprotocol/A7105_SPI.ino b/Multiprotocol/A7105_SPI.ino index 15c0b56..6582876 100644 --- a/Multiprotocol/A7105_SPI.ino +++ b/Multiprotocol/A7105_SPI.ino @@ -155,7 +155,11 @@ void A7105_SetPower() power=IS_POWER_FLAG_on?A7105_HIGH_POWER:A7105_LOW_POWER; if(IS_RANGE_FLAG_on) power=A7105_RANGE_POWER; - A7105_WriteReg(0x28, power); + if(prev_power != power) + { + A7105_WriteReg(0x28, power); + prev_power=power; + } } void A7105_Strobe(uint8_t address) { diff --git a/Multiprotocol/CC2500_SPI.ino b/Multiprotocol/CC2500_SPI.ino index 67ea66c..410d8e3 100644 --- a/Multiprotocol/CC2500_SPI.ino +++ b/Multiprotocol/CC2500_SPI.ino @@ -125,7 +125,11 @@ void CC2500_SetPower() power=IS_POWER_FLAG_on?CC2500_HIGH_POWER:CC2500_LOW_POWER; if(IS_RANGE_FLAG_on) power=CC2500_RANGE_POWER; - CC2500_WriteReg(CC2500_3E_PATABLE, power); + if(prev_power != power) + { + CC2500_WriteReg(CC2500_3E_PATABLE, power); + prev_power=power; + } } void CC2500_SetTxRxMode(uint8_t mode) diff --git a/Multiprotocol/CYRF6936_SPI.ino b/Multiprotocol/CYRF6936_SPI.ino index 51a9b08..3699e9e 100644 --- a/Multiprotocol/CYRF6936_SPI.ino +++ b/Multiprotocol/CYRF6936_SPI.ino @@ -128,7 +128,11 @@ void CYRF_SetPower(uint8_t val) power=IS_POWER_FLAG_on?CYRF_HIGH_POWER:CYRF_LOW_POWER; if(IS_RANGE_FLAG_on) power=CYRF_RANGE_POWER; - CYRF_WriteRegister(CYRF_03_TX_CFG, val | power); + if(prev_power != power) + { + CYRF_WriteRegister(CYRF_03_TX_CFG, val | power); + prev_power=power; + } } /* diff --git a/Multiprotocol/DSM2_cyrf6936.ino b/Multiprotocol/DSM2_cyrf6936.ino index b51279a..429dd60 100644 --- a/Multiprotocol/DSM2_cyrf6936.ino +++ b/Multiprotocol/DSM2_cyrf6936.ino @@ -416,7 +416,7 @@ uint16_t ReadDsm2() #define DSM_CH1_CH2_DELAY 4010 // Time between write of channel 1 and channel 2 #define DSM_WRITE_DELAY 1550 // Time after write to verify write complete #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 - uint32_t start; + uint16_t start; switch(cyrf_state) { @@ -458,7 +458,7 @@ uint16_t ReadDsm2() case DSM2_CH1_CHECK_A: case DSM2_CH1_CHECK_B: start=micros(); - while (micros()-start < 500) // Wait max 500µs + while ((uint16_t)micros()-start < 500) // Wait max 500µs if(CYRF_ReadRegister(CYRF_04_TX_IRQ_STATUS) & 0x02) break; set_sop_data_crc(); @@ -467,7 +467,7 @@ uint16_t ReadDsm2() case DSM2_CH2_CHECK_A: case DSM2_CH2_CHECK_B: start=micros(); - while (micros()-start < 500) // Wait max 500µs + 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) @@ -501,7 +501,7 @@ uint16_t ReadDsm2() //Force end read state CYRF_WriteRegister(CYRF_0F_XACT_CFG, (CYRF_ReadRegister(CYRF_0F_XACT_CFG) | 0x20)); // Force end state start=micros(); - while (micros()-start < 100) // Wait max 100 µs + 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; diff --git a/Multiprotocol/Devo_cyrf6936.ino b/Multiprotocol/Devo_cyrf6936.ino index e569cb9..e7b446a 100644 --- a/Multiprotocol/Devo_cyrf6936.ino +++ b/Multiprotocol/Devo_cyrf6936.ino @@ -116,24 +116,28 @@ static void __attribute__((unused)) build_beacon_pkt(uint8_t upper) add_pkt_suffix(); } +#define FORCE_INDIRECT(ptr) __asm__ __volatile__ ("" : "=e" (ptr) : "0" (ptr)) + static void __attribute__((unused)) build_bind_pkt() { - packet[0] = (DEVO_NUM_CHANNELS << 4) | 0x0a; - packet[1] = bind_counter & 0xff; - packet[2] = (bind_counter >> 8); - packet[3] = *hopping_frequency_ptr; - packet[4] = *(hopping_frequency_ptr + 1); - packet[5] = *(hopping_frequency_ptr + 2); - packet[6] = cyrfmfg_id[0]; - packet[7] = cyrfmfg_id[1]; - packet[8] = cyrfmfg_id[2]; - packet[9] = cyrfmfg_id[3]; + uint8_t *p = packet ; + FORCE_INDIRECT(p) ; + p[0] = (DEVO_NUM_CHANNELS << 4) | 0x0a; + p[1] = bind_counter & 0xff; + p[2] = (bind_counter >> 8); + p[3] = *hopping_frequency_ptr; + p[4] = *(hopping_frequency_ptr + 1); + p[5] = *(hopping_frequency_ptr + 2); + p[6] = cyrfmfg_id[0]; + p[7] = cyrfmfg_id[1]; + p[8] = cyrfmfg_id[2]; + p[9] = cyrfmfg_id[3]; add_pkt_suffix(); //The fixed-id portion is scrambled in the bind packet //I assume it is ignored - packet[13] ^= cyrfmfg_id[0]; - packet[14] ^= cyrfmfg_id[1]; - packet[15] ^= cyrfmfg_id[2]; + p[13] ^= cyrfmfg_id[0]; + p[14] ^= cyrfmfg_id[1]; + p[15] ^= cyrfmfg_id[2]; } static void __attribute__((unused)) build_data_pkt() @@ -174,31 +178,57 @@ static void __attribute__((unused)) cyrf_set_bound_sop_code() CYRF_SetPower(0x08); } +const uint8_t PROGMEM devo_init_vals[][2] = { + {CYRF_06_RX_CFG, 0x4A }, + {CYRF_0B_PWR_CTRL, 0x00 }, + {CYRF_0D_IO_CFG, 0x04 }, + {CYRF_0E_GPIO_CTRL, 0x20 }, + {CYRF_10_FRAMING_CFG, 0xA4 }, + {CYRF_11_DATA32_THOLD, 0x05 }, + {CYRF_12_DATA64_THOLD, 0x0E }, + {CYRF_1B_TX_OFFSET_LSB, 0x55 }, + {CYRF_1C_TX_OFFSET_MSB, 0x05 }, + {CYRF_32_AUTO_CAL_TIME, 0x3C }, + {CYRF_35_AUTOCAL_OFFSET, 0x14 }, + {CYRF_39_ANALOG_CTRL, 0x01 }, + {CYRF_1E_RX_OVERRIDE, 0x10 }, + {CYRF_1F_TX_OVERRIDE, 0x00 }, + {CYRF_01_TX_LENGTH, 0x10 }, + {CYRF_0C_XTAL_CTRL, 0xC0 }, + {CYRF_0F_XACT_CFG, 0x10 }, + {CYRF_27_CLK_OVERRIDE, 0x02 }, + {CYRF_28_CLK_EN, 0x02 }, + {CYRF_0F_XACT_CFG, 0x28 } +}; + static void __attribute__((unused)) cyrf_init() { /* Initialise CYRF chip */ CYRF_WriteRegister(CYRF_1D_MODE_OVERRIDE, 0x39); CYRF_SetPower(0x08); - CYRF_WriteRegister(CYRF_06_RX_CFG, 0x4A); - CYRF_WriteRegister(CYRF_0B_PWR_CTRL, 0x00); - CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); - CYRF_WriteRegister(CYRF_0E_GPIO_CTRL, 0x20); - CYRF_WriteRegister(CYRF_10_FRAMING_CFG, 0xA4); - CYRF_WriteRegister(CYRF_11_DATA32_THOLD, 0x05); - CYRF_WriteRegister(CYRF_12_DATA64_THOLD, 0x0E); - CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, 0x55); - CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, 0x05); - CYRF_WriteRegister(CYRF_32_AUTO_CAL_TIME, 0x3C); - CYRF_WriteRegister(CYRF_35_AUTOCAL_OFFSET, 0x14); - CYRF_WriteRegister(CYRF_39_ANALOG_CTRL, 0x01); - CYRF_WriteRegister(CYRF_1E_RX_OVERRIDE, 0x10); - CYRF_WriteRegister(CYRF_1F_TX_OVERRIDE, 0x00); - CYRF_WriteRegister(CYRF_01_TX_LENGTH, 0x10); - CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); - CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x10); - CYRF_WriteRegister(CYRF_27_CLK_OVERRIDE, 0x02); - CYRF_WriteRegister(CYRF_28_CLK_EN, 0x02); - CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x28); + for(uint8_t i = 0; i < sizeof(devo_init_vals) / 2; i++) + CYRF_WriteRegister(pgm_read_byte( &devo_init_vals[i][0]), pgm_read_byte( &devo_init_vals[i][1]) ); + +// CYRF_WriteRegister(CYRF_06_RX_CFG, 0x4A); +// CYRF_WriteRegister(CYRF_0B_PWR_CTRL, 0x00); +// CYRF_WriteRegister(CYRF_0D_IO_CFG, 0x04); +// CYRF_WriteRegister(CYRF_0E_GPIO_CTRL, 0x20); +// CYRF_WriteRegister(CYRF_10_FRAMING_CFG, 0xA4); +// CYRF_WriteRegister(CYRF_11_DATA32_THOLD, 0x05); +// CYRF_WriteRegister(CYRF_12_DATA64_THOLD, 0x0E); +// CYRF_WriteRegister(CYRF_1B_TX_OFFSET_LSB, 0x55); +// CYRF_WriteRegister(CYRF_1C_TX_OFFSET_MSB, 0x05); +// CYRF_WriteRegister(CYRF_32_AUTO_CAL_TIME, 0x3C); +// CYRF_WriteRegister(CYRF_35_AUTOCAL_OFFSET, 0x14); +// CYRF_WriteRegister(CYRF_39_ANALOG_CTRL, 0x01); +// CYRF_WriteRegister(CYRF_1E_RX_OVERRIDE, 0x10); +// CYRF_WriteRegister(CYRF_1F_TX_OVERRIDE, 0x00); +// CYRF_WriteRegister(CYRF_01_TX_LENGTH, 0x10); +// CYRF_WriteRegister(CYRF_0C_XTAL_CTRL, 0xC0); +// CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x10); +// CYRF_WriteRegister(CYRF_27_CLK_OVERRIDE, 0x02); +// CYRF_WriteRegister(CYRF_28_CLK_EN, 0x02); +// CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x28); } static void __attribute__((unused)) set_radio_channels() diff --git a/Multiprotocol/FlySky_a7105.ino b/Multiprotocol/FlySky_a7105.ino index 92f723d..a7f4033 100644 --- a/Multiprotocol/FlySky_a7105.ino +++ b/Multiprotocol/FlySky_a7105.ino @@ -54,10 +54,11 @@ uint8_t chanrow; uint8_t chancol; uint8_t chanoffset; +const uint8_t PROGMEM V912_X17_SEQ[10] = { 0x14, 0x31, 0x40, 0x49, 0x49, // sometime first byte is 0x15 ? + 0x49, 0x49, 0x49, 0x49, 0x49, }; + static void __attribute__((unused)) flysky_apply_extension_flags() { - const uint8_t V912_X17_SEQ[10] = { 0x14, 0x31, 0x40, 0x49, 0x49, // sometime first byte is 0x15 ? - 0x49, 0x49, 0x49, 0x49, 0x49, }; static uint8_t seq_counter; switch(sub_protocol) { @@ -115,7 +116,7 @@ static void __attribute__((unused)) flysky_apply_extension_flags() packet[14] |= FLAG_V912_TOPBTN; packet[15] = 0x27; // [15] and [16] apparently hold an analog channel with a value lower than 1000 packet[16] = 0x03; // maybe it's there for a pitch channel for a CP copter ? - packet[17] = V912_X17_SEQ[seq_counter]; // not sure what [17] & [18] are for + packet[17] = pgm_read_byte( &V912_X17_SEQ[seq_counter] ) ; // not sure what [17] & [18] are for if(seq_counter == 0) // V912 Rx does not even read those bytes... [17-20] packet[18] = 0x02; else diff --git a/Multiprotocol/FrSkyX_cc2500.ino b/Multiprotocol/FrSkyX_cc2500.ino index ed40f28..d631821 100644 --- a/Multiprotocol/FrSkyX_cc2500.ino +++ b/Multiprotocol/FrSkyX_cc2500.ino @@ -89,6 +89,7 @@ static void __attribute__((unused)) frskyX_init() } CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x04); + prev_option = option ; CC2500_WriteReg(CC2500_0C_FSCTRL0, option); CC2500_Strobe(CC2500_SIDLE); // @@ -124,9 +125,12 @@ static void __attribute__((unused)) initialize_data(uint8_t adr) const uint16_t PROGMEM CRC_Short[]={ 0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7 }; -static uint16_t __attribute__((unused)) CRCTable(uint8_t val) +static uint16_t CRCTable(uint8_t val) { - return pgm_read_word(&CRC_Short[val&0x0F]) ^ (0x1081 * (val>>4)); + uint16_t word ; + word = pgm_read_word(&CRC_Short[val&0x0F]) ; + val /= 16 ; + return word ^ (0x1081 * val) ; } static uint16_t __attribute__((unused)) crc_x(uint8_t *data, uint8_t len) { @@ -253,6 +257,11 @@ uint16_t ReadFrSkyX() state++; break; case FRSKY_DATA1: + if ( prev_option != option ) + { + CC2500_WriteReg(CC2500_0C_FSCTRL0,option); // Frequency offset hack + prev_option = option ; + } LED_ON; CC2500_SetTxRxMode(TX_EN); set_start(channr); diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h index f89b7ef..f9ffdbb 100644 --- a/Multiprotocol/Multiprotocol.h +++ b/Multiprotocol/Multiprotocol.h @@ -439,6 +439,10 @@ enum { PKT_TIMEOUT }; +// baudrate defines for serial +#define SPEED_100K 0 +#define SPEED_9600 1 + //**************************************** //*** MULTI protocol serial definition *** //**************************************** diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 8e0416a..882541a 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -36,6 +36,8 @@ uint32_t Model_fixed_id=0; uint32_t fixed_id; uint8_t cyrfmfg_id[6];//for dsm2 and devo uint32_t blink=0; +uint8_t prev_option; +uint8_t prev_power=0xFD; // unused power value // uint16_t counter; uint8_t channel; @@ -85,11 +87,19 @@ uint8_t protocol_flags=0,protocol_flags2=0; volatile uint16_t PPM_data[NUM_CHN]; // Serial variables +#ifdef INVERT_TELEMETRY +// enable bit bash for serial + #define BASH_SERIAL 1 + #define INVERT_SERIAL 1 +#endif +#define BAUD 100000 #define RXBUFFER_SIZE 25 -#define TXBUFFER_SIZE 20 +#define TXBUFFER_SIZE 32 volatile uint8_t rx_buff[RXBUFFER_SIZE]; volatile uint8_t rx_ok_buff[RXBUFFER_SIZE]; +#ifndef BASH_SERIAL volatile uint8_t tx_buff[TXBUFFER_SIZE]; +#endif volatile uint8_t idx = 0; //Serial protocol @@ -112,8 +122,10 @@ uint8_t pkt[MAX_PKT];//telemetry receiving packets #define HUB_TELEMETRY #endif uint8_t pktt[MAX_PKT];//telemetry receiving packets +#ifndef BASH_SERIAL volatile uint8_t tx_head=0; volatile uint8_t tx_tail=0; +#endif // BASH_SERIAL uint8_t v_lipo; int16_t RSSI_dBm; //const uint8_t RSSI_offset=72;//69 71.72 values db @@ -283,9 +295,11 @@ void loop() { for(uint8_t i=0;i4000) { // start to wait here as much as we can... next_callback=next_callback-2000; - cli(); // disable global int #ifdef XMEGA + cli(); // disable global int TCC1.CCA +=2000*2; // set compare A for callback TCC1.INTFLAGS = TC1_CCAIF_bm ; // clear compare A=callback flag sei(); // enable global int while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait 2ms... #else - OCR1A+=2000*2; // set compare A for callback + uint16_t temp ; + temp = OCR1A + 2000*2 ; + cli(); // disable global int + OCR1A = temp ; // set compare A for callback TIFR1=(1<=TXBUFFER_SIZE) - tx_head=0; - tx_buff[tx_head]=data; -#ifdef XMEGA - USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; -#else - UCSR0B |= (1<>1; - if(aPPM_MAX) a=PPM_MAX; - PPM_data[chan]=a; + uint16_t temp = Cur_TCNT1>>1; + if(tempPPM_MAX) temp=PPM_MAX; + PPM_data[chan]=temp; if(chan++>=NUM_CHN) chan=-1; // don't accept any new channels } @@ -1041,6 +1033,10 @@ ISR(USART_RX_vect) #ifdef XMEGA if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error #else + + UCSR0B &= ~(1<=TXBUFFER_SIZE)//head - tx_tail=0; -#ifdef XMEGA - USARTC0.DATA = tx_buff[tx_tail] ; -#else - UDR0=tx_buff[tx_tail]; -#endif - } - if (tx_tail == tx_head) -#ifdef XMEGA - USARTC0.CTRLA &= ~0x03 ; -#else - UCSR0B &= ~(1<= FRSKY_SPORT_PACKET_SIZE) {//8 bytes no crc - sport = 1;//ok to send + if ( sport ) + { + // overrun! + } + else + { + uint8_t i ; + for ( i = 0 ; i < FRSKY_SPORT_PACKET_SIZE ; i += 1 ) + { + pktx1[i] = pktx[i] ; // Double buffer + } + sport = 1;//ok to send + } pass = 0;//reset } } @@ -362,7 +395,62 @@ void proces_sport_data(uint8_t data) #endif void frskyUpdate() -{ +{ +#if defined SPORT_TELEMETRY + if ((cur_protocol[0]&0x1F)==MODE_FRSKYX) + { // FrSkyX + if(telemetry_link) + { + if(pktt[4] & 0x80) + rssi=pktt[4] & 0x7F ; + else + RxBt = (pktt[4]<<1) + 1 ; + for (uint8_t i=0; i < pktt[6]; i++) + proces_sport_data(pktt[7+i]); + telemetry_link=0; + } + } +#endif + + // check for space in tx buffer + +#ifdef BASH_SERIAL + uint8_t h ; + uint8_t t ; + h = SerialControl.head ; + t = SerialControl.tail ; + if ( h >= t ) + { + t += 64 - h ; + } + else + { + t -= h ; + } + if ( t < 32 ) + { + return ; + } + +#else + uint8_t h ; + uint8_t t ; + h = tx_head ; + t = tx_tail ; + if ( h >= t ) + { + t += TXBUFFER_SIZE - h ; + } + else + { + t -= h ; + } + if ( t < 16 ) + { + return ; + } +#endif + #if defined DSM_TELEMETRY if(telemetry_link && (cur_protocol[0]&0x1F) == MODE_DSM2 ) { // DSM2 @@ -387,24 +475,318 @@ void frskyUpdate() #if defined SPORT_TELEMETRY if ((cur_protocol[0]&0x1F)==MODE_FRSKYX) { // FrSkyX - if(telemetry_link) - { - if(pktt[4]>0x36) - rssi=pktt[4]>>1; - else - RxBt=pktt[4]; - for (uint8_t i=0; i < pktt[6]; i++) - proces_sport_data(pktt[7+i]); - telemetry_link=0; - } uint32_t now = micros(); if ((now - last) > SPORT_TIME) { sportSendFrame(); - last = now; + last += SPORT_TIME ; } } #endif } -#endif \ No newline at end of file + +/**************************/ +/**************************/ +/** Serial TX routines **/ +/**************************/ +/**************************/ + +#ifndef BASH_SERIAL +// Routines for normal serial output +void Serial_write(uint8_t data) +{ + cli(); // disable global int + if(++tx_head>=TXBUFFER_SIZE) + tx_head=0; + tx_buff[tx_head]=data; +#ifdef XMEGA + USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; +#else + UCSR0B |= (1<=TXBUFFER_SIZE)//head + tx_tail=0; +#ifdef XMEGA + USARTC0.DATA = tx_buff[tx_tail] ; +#else + UDR0=tx_buff[tx_tail]; +#endif + } + if (tx_tail == tx_head) +#ifdef XMEGA + USARTC0.CTRLA &= ~0x03 ; +#else + UCSR0B &= ~(1<>= 7 ; // Top bit + if ( SerialControl.speed == SPEED_100K ) + { +#ifdef INVERT_SERIAL + byteLo |= 0x02 ; // Parity bit +#else + byteLo |= 0xFC ; // Stop bits +#endif + // calc parity + temp = byte ; + temp >>= 4 ; + temp = byte ^ temp ; + temp1 = temp ; + temp1 >>= 2 ; + temp = temp ^ temp1 ; + temp1 = temp ; + temp1 <<= 1 ; + temp ^= temp1 ; + temp &= 0x02 ; +#ifdef INVERT_SERIAL + byteLo ^= temp ; +#else + byteLo |= temp ; +#endif + } + else + { + byteLo |= 0xFE ; // Stop bit + } + byte <<= 1 ; +#ifdef INVERT_SERIAL + byte |= 1 ; // Start bit +#endif + uint8_t next = (SerialControl.head + 2) & 0x3f ; + if ( next != SerialControl.tail ) + { + SerialControl.data[SerialControl.head] = byte ; + SerialControl.data[SerialControl.head+1] = byteLo ; + SerialControl.head = next ; + } + cli() ; + if ( SerialControl.busy == 0 ) + { + sei() ; + // Start the transmission here +#ifdef INVERT_SERIAL + GPIOR2 = 0 ; +#else + GPIOR2 = 0x01 ; +#endif + if ( SerialControl.speed == SPEED_100K ) + { + GPIOR1 = 1 ; + OCR0B = TCNT0 + 40 ; + OCR0A = OCR0B + 210 ; + TIFR0 = (1<>= 1 + GPIOR0 = byte ; + if ( --GPIOR1 == 0 ) + { + TIMSK0 &= ~(1<>= 1 + GPIOR2 = byte ; + if ( --GPIOR1 == 0 ) + { + // prepare next byte and allow for 2 stop bits + struct t_serial_bash *ptr = &SerialControl ; + if ( ptr->head != ptr->tail ) + { + GPIOR0 = ptr->data[ptr->tail] ; + GPIOR2 = ptr->data[ptr->tail+1] ; + ptr->tail = ( ptr->tail + 2 ) & 0x3F ; + GPIOR1 = 8 ; + OCR0A = OCR0B + 40 ; + OCR0B = OCR0A + 8 * 20 ; + TIMSK0 |= (1< 2 ) + { + byte = GPIOR0 ; + } + else + { + byte = GPIOR2 ; + } + if ( byte & 0x01 ) + { + PORTD |= 0x02 ; + } + else + { + PORTD &= ~0x02 ; + } + byte /= 2 ; // Generates shorter code than byte >>= 1 + if ( GPIOR1 > 2 ) + { + GPIOR0 = byte ; + } + else + { + GPIOR2 = byte ; + } + if ( --GPIOR1 == 0 ) + { + // prepare next byte + struct t_serial_bash *ptr = &SerialControl ; + if ( ptr->head != ptr->tail ) + { + GPIOR0 = ptr->data[ptr->tail] ; + GPIOR2 = ptr->data[ptr->tail+1] ; + ptr->tail = ( ptr->tail + 2 ) & 0x3F ; + GPIOR1 = 10 ; + } + else + { + SerialControl.busy = 0 ; + TIMSK0 &= ~(1<2012µs) //#define TX_ER9X_TAER //ER9X TAER (988<->2012µs) @@ -22,6 +25,9 @@ //#define TX_SPEKTRUM //Spektrum TAER (1100<->1900µs) //#define TX_HISKY //HISKY AETR (1100<->1900µs) +/****************************/ +/*** PROTOCOLS TO INCLUDE ***/ +/****************************/ //Comment if a module is not installed #define A7105_INSTALLED #define CYRF6936_INSTALLED @@ -61,9 +67,15 @@ #define FQ777_NRF24L01_INO #endif +/**************************/ +/*** TELEMETRY SETTINGS ***/ +/**************************/ //Uncomment to enable telemetry #define TELEMETRY +//Uncomment to invert the telemetry serial signal, this is usefull for OpenTX on Taranis as an example +//#define INVERT_TELEMETRY 1 + //Comment to disable a specific telemetry #if defined(TELEMETRY) #if defined DSM2_CYRF6936_INO @@ -77,6 +89,9 @@ #endif #endif +/********************/ +/*** PPM SETTINGS ***/ +/********************/ //Update this table to set which protocol and all associated settings are called for the corresponding dial number const PPM_Parameters PPM_prot[15]= { // Dial Protocol Sub protocol RX_Num Power Auto Bind Option @@ -180,9 +195,9 @@ Auto Bind AUTOBIND or NO_AUTOBIND Option value between 0 and 255. 0xD7 or 0x00 for Frsky fine tuning. */ -//****************** -//TX definitions with timing endpoints and channels order - +/*******************/ +/*** TX SETTINGS ***/ +/*******************/ // Turnigy PPM and channels #if defined(TX_ER9X_AETR) #define PPM_MAX 2140 // 125% @@ -301,7 +316,3 @@ enum chan_order{ #define PPM_MIN_COMMAND 1250 #define PPM_SWITCH 1550 #define PPM_MAX_COMMAND 1750 - -//Uncoment the desired serial speed -#define BAUD 100000 -//#define BAUD 125000