Some cleanning

This commit is contained in:
pascallanger 2016-09-20 18:27:09 +02:00
parent beb692a3c4
commit 73aab88109
5 changed files with 322 additions and 285 deletions

View File

@ -414,16 +414,23 @@ uint16_t ReadDsm()
#define DSM_WRITE_DELAY 1550 // Time after write to verify write complete
#define DSM_READ_DELAY 600 // Time before write to check read phase, and switch channels. Was 400 but 600 seems what the 328p needs to read a packet
uint16_t start;
#if defined DSM_TELEMETRY
uint8_t rx_phase;
uint8_t len;
#endif
switch(phase)
{
case DSM_BIND_WRITE:
if(bind_counter--==0)
#if defined DSM_TELEMETRY
phase=DSM_BIND_CHECK; //Check RX answer
#else
phase=DSM_CHANSEL; //Switch to normal mode
#endif
CYRF_WriteDataPacket(packet);
return 10000;
#if defined DSM_TELEMETRY
case DSM_BIND_CHECK:
CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84\xC9\x2C\x06\x93\x86\xB9\x9E", 16);
CYRF_SetTxRxMode(RX_EN); //Receive mode
@ -467,6 +474,7 @@ uint16_t ReadDsm()
CYRF_WriteRegister(CYRF_0F_XACT_CFG, 0x0C); // Read mode
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x83); // Prepare to receive
return 7000;
#endif
case DSM_CHANSEL:
BIND_DONE;
//Select channels and configure for writing data

View File

@ -182,7 +182,7 @@ struct PPM_Parameters
//*******************
// TX
#define SERIAL_TX_pin 1 // PD1
#define SERIAL_TX_pin 1 //PD1
#define SERIAL_TX_port PORTD
#define SERIAL_TX_ddr DDRD
#define SERIAL_TX_output SERIAL_TX_ddr |= _BV(SERIAL_TX_pin)
@ -201,12 +201,16 @@ struct PPM_Parameters
// Dial
#define MODE_DIAL1_pin 2
#define MODE_DIAL1_port PORTB
#define MODE_DIAL1_ipr PINB
#define MODE_DIAL2_pin 3
#define MODE_DIAL2_port PORTB
#define MODE_DIAL2_ipr PINB
#define MODE_DIAL3_pin 4
#define MODE_DIAL3_port PORTB
#define MODE_DIAL3_ipr PINB
#define MODE_DIAL4_pin 0
#define MODE_DIAL4_port PORTC
#define MODE_DIAL4_ipr PINC
// PPM
#define PPM_pin 3 //D3 = PD3
@ -223,7 +227,7 @@ struct PPM_Parameters
#else
#define SDI_on SDI_port |= _BV(SDI_pin)
#define SDI_off SDI_port &= ~_BV(SDI_pin)
#define SDI_1 (SDI_ipr & _BV(SDI_pin)) != 0x00
#define SDI_1 (SDI_ipr & _BV(SDI_pin))
#define SDI_0 (SDI_ipr & _BV(SDI_pin)) == 0x00
#endif
#define SDI_input SDI_ddr &= ~_BV(SDI_pin)
@ -234,10 +238,10 @@ struct PPM_Parameters
#define SDO_port PORTD
#define SDO_ipr PIND
#ifdef XMEGA
#define SDO_1 (SDO_port.IN & _BV(SDO_pin)) != 0x00
#define SDO_1 (SDO_port.IN & _BV(SDO_pin))
#define SDO_0 (SDO_port.IN & _BV(SDO_pin)) == 0x00
#else
#define SDO_1 (SDO_ipr & _BV(SDO_pin)) != 0x00
#define SDO_1 (SDO_ipr & _BV(SDO_pin))
#define SDO_0 (SDO_ipr & _BV(SDO_pin)) == 0x00
#endif
@ -245,7 +249,7 @@ struct PPM_Parameters
#define SCLK_port PORTD
#define SCLK_ddr DDRD
#ifdef XMEGA
#define SCLK_pin 7 //D7
#define SCLK_pin 7 //PD7
#define SCLK_on SCLK_port.OUTSET = _BV(SCLK_pin)
#define SCLK_off SCLK_port.OUTCLR = _BV(SCLK_pin)
#else
@ -283,7 +287,7 @@ struct PPM_Parameters
// CYRF6936
#ifdef XMEGA
#define CYRF_CSN_pin 4 //D4
#define CYRF_CSN_pin 4 //PD4
#define CYRF_CSN_port PORTD
#define CYRF_CSN_ddr DDRD
#define CYRF_CSN_on CYRF_CSN_port.OUTSET = _BV(CYRF_CSN_pin)
@ -335,7 +339,7 @@ struct PPM_Parameters
#define LED_off LED_port.OUTSET = _BV(LED_pin)
#define LED_toggle LED_port.OUTTGL = _BV(LED_pin)
#define LED_output LED_port.DIRSET = _BV(LED_pin)
#define IS_LED_on ( (LED_port.OUT & _BV(LED_pin)) != 0x00 )
#define IS_LED_on (LED_port.OUT & _BV(LED_pin))
#else
#define LED_pin 5 //D13 = PB5
#define LED_port PORTB
@ -344,7 +348,7 @@ struct PPM_Parameters
#define LED_off LED_port &= ~_BV(LED_pin)
#define LED_toggle LED_port ^= _BV(LED_pin)
#define LED_output LED_ddr |= _BV(LED_pin)
#define IS_LED_on ( (LED_port & _BV(LED_pin)) != 0x00 )
#define IS_LED_on (LED_port & _BV(LED_pin))
#endif
//BIND
@ -358,9 +362,9 @@ struct PPM_Parameters
#define BIND_ipr PINB
#define BIND_ddr DDRB
#define BIND_SET_INPUT BIND_ddr &= ~_BV(BIND_pin)
#define BIND_SET_OUTPUT BIND_ddr |= _BV(BIND_pin)
#define BIND_SET_PULLUP BIND_port |= _BV(BIND_pin)
#define IS_BIND_BUTTON_on ( (BIND_ipr & _BV(BIND_pin)) == 0x00 )
#define BIND_SET_OUTPUT BIND_ddr |= _BV(BIND_pin)
#endif
// Macros

View File

@ -30,10 +30,10 @@
#include "TX_Def.h"
#ifdef XMEGA
#undef ENABLE_PPM // Disable PPM for orange module
#undef A7105_INSTALLED // Disable A7105 for orange module
#undef CC2500_INSTALLED // Disable CC2500 for orange module
#undef NRF24L01_INSTALLED // Disable NRF for orange module
#undef ENABLE_PPM // Disable PPM for OrangeTX module
#undef A7105_INSTALLED // Disable A7105 for OrangeTX module
#undef CC2500_INSTALLED // Disable CC2500 for OrangeTX module
#undef NRF24L01_INSTALLED // Disable NRF for OrangeTX module
#endif
//Global constants/variables
@ -97,23 +97,6 @@ volatile uint16_t PPM_data[NUM_CHN];
//Random variable
volatile uint32_t gWDT_entropy=0;
#endif
// Serial variables
#ifdef INVERT_TELEMETRY
// enable bit bash for serial
#ifndef XMEGA
#define BASH_SERIAL 1
#endif
#define INVERT_SERIAL 1
#endif
#define BAUD 100000
#define RXBUFFER_SIZE 26
#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 discard_frame = 0;
//Serial protocol
uint8_t sub_protocol;
@ -123,16 +106,54 @@ uint8_t cur_protocol[3];
uint8_t prev_option;
uint8_t prev_power=0xFD; // unused power value
//Serial RX variables
#define BAUD 100000
#define RXBUFFER_SIZE 26
volatile uint8_t rx_buff[RXBUFFER_SIZE];
volatile uint8_t rx_ok_buff[RXBUFFER_SIZE];
volatile uint8_t discard_frame = 0;
//Make sure telemetry is selected correctly
#ifndef TELEMETRY
#undef INVERT_TELEMETRY
#undef DSM_TELEMETRY
#undef SPORT_TELEMETRY
#undef HUB_TELEMETRY
#else
#if not defined(CYRF6936_INSTALLED) || not defined(DSM_CYRF6936_INO)
#undef DSM_TELEMETRY
#endif
#if (not defined(CC2500_INSTALLED) || not defined(FRSKYD_CC2500_INO)) && (not defined(A7105_INSTALLED) || not defined(HUBSAN_A7105_INO))
#undef HUB_TELEMETRY
#endif
#if not defined(CC2500_INSTALLED) || not defined(FRSKYX_CC2500_INO)
#undef SPORT_TELEMETRY
#endif
#endif
#if not defined(DSM_TELEMETRY) && not defined(HUB_TELEMETRY) && not defined(SPORT_TELEMETRY)
#undef TELEMETRY
#undef INVERT_TELEMETRY
#endif
// Telemetry
#define MAX_PKT 27
uint8_t pkt[MAX_PKT];//telemetry receiving packets
#if defined(TELEMETRY)
#ifdef INVERT_TELEMETRY
// enable bit bash for serial
#ifndef XMEGA
#define BASH_SERIAL 1
#endif
#define INVERT_SERIAL 1
#endif
uint8_t pass = 0;
uint8_t pktt[MAX_PKT];//telemetry receiving packets
#ifndef BASH_SERIAL
#ifndef BASH_SERIAL
#define TXBUFFER_SIZE 32
volatile uint8_t tx_buff[TXBUFFER_SIZE];
volatile uint8_t tx_head=0;
volatile uint8_t tx_tail=0;
#endif // BASH_SERIAL
#endif // BASH_SERIAL
uint8_t v_lipo;
int16_t RSSI_dBm;
//const uint8_t RSSI_offset=72;//69 71.72 values db
@ -173,7 +194,7 @@ void setup()
#else
// General pinout
// all inputs
DDRB=DDRC=DDRD=0x00;
DDRB=0x00;DDRC=0x00;DDRD=0x00;
// outputs
SDI_output;
SCLK_output;
@ -192,7 +213,7 @@ void setup()
#endif
PE1_output;
PE2_output;
SERIAL_TX_output;
//SERIAL_TX_output;
// pullups
MODE_DIAL1_port |= _BV(MODE_DIAL1_pin);
@ -216,12 +237,12 @@ void setup()
#ifdef CC2500_INSTALLED
CC25_CSN_on;
#endif
#ifdef NRF24L01_INSTALLED
NRF_CSN_on;
#endif
#ifdef CYRF6936_INSTALLED
CYRF_CSN_on;
#endif
#ifdef NRF24L01_INSTALLED
NRF_CSN_on;
#endif
// Set SPI lines
SDI_on;
SCLK_off;
@ -246,12 +267,11 @@ void setup()
#ifndef ENABLE_PPM
mode_select = MODE_SERIAL ; // force serial mode
#else
mode_select=0x0F - ( ( (PINB>>2)&0x07 ) | ( (PINC<<3)&0x08) );//encoder dip switches 1,2,4,8=>B2,B3,B4,C0
/*mode_select = 0x0F - (
((MODE_DIAL1_port & MODE_DIAL1_pin) ? 1 : 0) +
((MODE_DIAL2_port & MODE_DIAL2_pin) ? 2 : 0) +
((MODE_DIAL3_port & MODE_DIAL3_pin) ? 4 : 0) +
((MODE_DIAL4_port & MODE_DIAL4_pin) ? 8 : 0));*/
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);
#endif
// Update LED
@ -407,7 +427,7 @@ void Update_All()
#endif //ENABLE_PPM
update_led_status();
#if defined(TELEMETRY)
if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
if((protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM) )
TelemetryUpdate();
#endif
}
@ -508,6 +528,7 @@ static void protocol_init()
switch(protocol) // Init the requested protocol
{
#ifdef A7105_INSTALLED
#if defined(FLYSKY_A7105_INO)
case MODE_FLYSKY:
PE1_off; //antenna RF1
@ -523,6 +544,8 @@ static void protocol_init()
remote_callback = ReadHubsan;
break;
#endif
#endif
#ifdef CC2500_INSTALLED
#if defined(FRSKYD_CC2500_INO)
case MODE_FRSKYD:
PE1_off; //antenna RF2
@ -555,6 +578,8 @@ static void protocol_init()
remote_callback = ReadSFHSS;
break;
#endif
#endif
#ifdef CYRF6936_INSTALLED
#if defined(DSM_CYRF6936_INO)
case MODE_DSM:
PE2_on; //antenna RF4
@ -592,6 +617,8 @@ static void protocol_init()
remote_callback = ReadJ6Pro;
break;
#endif
#endif
#ifdef NRF24L01_INSTALLED
#if defined(HISKY_NRF24L01_INO)
case MODE_HISKY:
next_callback=initHiSky();
@ -694,6 +721,7 @@ static void protocol_init()
remote_callback = HONTAI_callback;
break;
#endif
#endif
}
if(next_callback>32000)

View File

@ -116,7 +116,7 @@ uint16_t initSHENQI()
SHENQI_init();
hopping_frequency_no = 0;
packet_count=0;
packet_period=100;
packet_period=500;
return 1000;
}

View File

@ -25,54 +25,59 @@
#define AETR
/****************************/
/*** PROTOCOLS TO INCLUDE ***/
/****************************/
//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.
/**************************/
/*** RF CHIPS INSTALLED ***/
/**************************/
//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.
//If a chip is not installed all associated protocols are disabled.
//4-in-1 modules have all RF chips installed
//!!!If a RF chip is present it MUST be marked as installed!!! or weird things will happen you have been warned.
#define A7105_INSTALLED
#define CYRF6936_INSTALLED
#define CC2500_INSTALLED
#define NRF24L01_INSTALLED
//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
#endif
#ifdef CYRF6936_INSTALLED
#define DEVO_CYRF6936_INO
#define DSM_CYRF6936_INO
#define J6PRO_CYRF6936_INO
#endif
#ifdef CC2500_INSTALLED
#define FRSKYD_CC2500_INO
#define FRSKYV_CC2500_INO
#define FRSKYX_CC2500_INO
#define SFHSS_CC2500_INO
#endif
#ifdef NRF24L01_INSTALLED
#define BAYANG_NRF24L01_INO
#define CG023_NRF24L01_INO
#define CX10_NRF24L01_INO
#define ESKY_NRF24L01_INO
#define HISKY_NRF24L01_INO
#define KN_NRF24L01_INO
#define SLT_NRF24L01_INO
#define SYMAX_NRF24L01_INO
#define V2X2_NRF24L01_INO
#define YD717_NRF24L01_INO
#define MT99XX_NRF24L01_INO
#define MJXQ_NRF24L01_INO
#define SHENQI_NRF24L01_INO
#define FY326_NRF24L01_INO
#define FQ777_NRF24L01_INO
#define ASSAN_NRF24L01_INO
#define HONTAI_NRF24L01_INO
#endif
/****************************/
/*** PROTOCOLS TO INCLUDE ***/
/****************************/
//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.
//Comment the protocols you are not using with "//" to save Flash space.
//The protocols below need an A7105 to be installed
#define FLYSKY_A7105_INO
#define HUBSAN_A7105_INO
//The protocols below need a CYRF6936 to be installed
#define DEVO_CYRF6936_INO
#define DSM_CYRF6936_INO
#define J6PRO_CYRF6936_INO
//The protocols below need a CC2500 to be installed
#define FRSKYD_CC2500_INO
#define FRSKYV_CC2500_INO
#define FRSKYX_CC2500_INO
#define SFHSS_CC2500_INO
//The protocols below need a NRF24L01 to be installed
#define BAYANG_NRF24L01_INO
#define CG023_NRF24L01_INO
#define CX10_NRF24L01_INO
#define ESKY_NRF24L01_INO
#define HISKY_NRF24L01_INO
#define KN_NRF24L01_INO
#define SLT_NRF24L01_INO
#define SYMAX_NRF24L01_INO
#define V2X2_NRF24L01_INO
#define YD717_NRF24L01_INO
#define MT99XX_NRF24L01_INO
#define MJXQ_NRF24L01_INO
#define SHENQI_NRF24L01_INO
#define FY326_NRF24L01_INO
#define FQ777_NRF24L01_INO
#define ASSAN_NRF24L01_INO
#define HONTAI_NRF24L01_INO
/**************************/
@ -85,20 +90,12 @@
//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
//#define INVERT_TELEMETRY
//Comment a line to disable a protocol telemetry
#if defined(TELEMETRY)
#if defined DSM_CYRF6936_INO
#define DSM_TELEMETRY
#endif
#if defined FRSKYX_CC2500_INO
#define SPORT_TELEMETRY
#endif
#if defined FRSKYD_CC2500_INO
#define HUB_TELEMETRY
#endif
#endif
#define DSM_TELEMETRY
#define SPORT_TELEMETRY
#define HUB_TELEMETRY
/****************************/
@ -152,7 +149,7 @@ const PPM_Parameters PPM_prot[15]= {
/* 3 */ {MODE_FRSKYD, 0 , 0 , P_HIGH , NO_AUTOBIND , 40 }, // 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_DSM , DSM2_22 , 0 , P_HIGH , NO_AUTOBIND , 6 }, // option=6 channels @ 22ms
/* 6 */ {MODE_DSM , DSM2_22 , 0 , P_HIGH , NO_AUTOBIND , 6 }, // option=number of channels
/* 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 },