diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino index 6d0378a..6233227 100644 --- a/Multiprotocol/Multiprotocol.ino +++ b/Multiprotocol/Multiprotocol.ino @@ -39,6 +39,7 @@ #include #include "_Config.h" +#include "TX_Def.h" //Multiprotocol module configuration file //Global constants/variables @@ -59,6 +60,9 @@ uint8_t packet[40]; uint16_t Servo_data[NUM_CHN]; uint8_t Servo_AUX; +#ifndef STM32_board +uint16_t servo_max_100,servo_min_100,servo_max_125,servo_min_125; +#endif // Protocol variables uint8_t cyrfmfg_id[6];//for dsm2 and devo uint8_t rx_tx_addr[5]; @@ -122,18 +126,20 @@ uint8_t option; uint8_t cur_protocol[2]; uint8_t prev_protocol=0; +#ifdef STM32_board void PPM_decode(); void ISR_COMPB(); - +#endif // Telemetry #define MAX_PKT 27 uint8_t pkt[MAX_PKT];//telemetry receiving packets #if defined(TELEMETRY) - #ifndef BASH_SERIAL + uint8_t pass = 0; + 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 pktt[MAX_PKT];//telemetry receiving packets uint8_t v_lipo; int16_t RSSI_dBm; uint8_t telemetry_link=0; @@ -161,7 +167,7 @@ void setup() for ( uint8_t count = 0 ; count < 20 ; count += 1 ) asm("nop") ; PORTE.OUTCLR = 0x01 ; - #else + #else // General pinout #if defined STM32_board pinMode(CS_pin,OUTPUT); @@ -181,7 +187,7 @@ void setup() TX_INV_off; RX_INV_off; #endif - #endif + #endif //pinMode(SDI_pin,OUTPUT); //pinMode(SCK_pin,OUTPUT);//spi pins initialized with spi init //pinMode(SDO_pin,INPUT); @@ -191,7 +197,7 @@ void setup() pinMode(S2_pin,INPUT_PULLUP); pinMode(S3_pin,INPUT_PULLUP); pinMode(S4_pin,INPUT_PULLUP); - #else + #else DDRD = (1<B2,B3,B4,C0 mode_select = MODE_SERIAL ; - #else + #else #if defined STM32_board mode_select= 0x0F -(uint8_t)(((GPIOA->regs->IDR)>>4)&0x0F); - #else + #else mode_select=0x0F - ( ( (PINB>>2)&0x07 ) | ( (PINC<<3)&0x08) );//encoder dip switches 1,2,4,8=>B2,B3,B4,C0 #endif #endif @@ -277,22 +287,15 @@ void setup() LED_SET_OUTPUT; // Read or create protocol id MProtocol_id_master=random_id(10,false); - initSPI2(); - //Init RF modules - #ifdef CC2500_INSTALLED - CC2500_Reset(); - #endif - #ifdef A7105_INSTALLED - A7105_Reset(); - #endif - #ifdef CYRF6936_INSTALLED - CYRF_Reset(); - #endif - #ifdef NFR24L01_INSTALLED - NRF24L01_Reset(); - #endif + + #ifdef STM32_board + initSPI2(); + #endif + //Init RF modules + modules_reset(); //LED_ON; //Protocol and interrupts initialization +#ifdef ENABLE_PPM if(mode_select != MODE_SERIAL) { // PPM mode_select--; @@ -304,6 +307,10 @@ 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(); @@ -314,7 +321,7 @@ void setup() EIMSK |= (1<>dec)&0x7FF)*5)/8+860; //value range 860<->2140 -125%<->+125% } RX_DONOTUPDTAE_off; - } -while(IS_RX_MISSED_BUFF_on); // We've just processed an old frame... + +#ifdef XMEGA + cli(); + #else + #ifdef STM32_board + //here code fro RX intrurpt disable + USART3_BASE->CR1 &= ~ USART_CR1_RXIE;//disable + #else + UCSR0B &= ~(1<CR1 |= USART_CR1_RXIE;//disable + #else + UCSR0B |= (1<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(aPPM_MAX) a=PPM_MAX; - PPM_data[chan]=a; - if(chan++>=NUM_CHN) - chan=-1; // don't accept any new channels + 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 XMEGA ISR(USARTC0_RXC_vect) @@ -1157,7 +1201,6 @@ void init() #endif #endif { - idx++; #ifdef XMEGA TCC1.CCB = TCC1.CNT+(6500L) ; // Full message should be received within timer of 3250us TCC1.INTFLAGS = TC1_CCBIF_bm ; // clear OCR1B match flag @@ -1175,6 +1218,7 @@ void init() TIMSK1 |=(1<RXBUFFER_SIZE) { // A full frame has been received - #ifdef XMEGA - TCC1.INTCTRLB &=0xF3; // disable interrupt on compare B match - #else - #if defined STM32_board - detachInterrupt(2);//disable interrupt on ch2 - #else - TIMSK1 &=~(1<