This commit is contained in:
midelic 2016-09-23 23:46:48 +03:00 committed by GitHub
parent 6c3ef981e2
commit a0074adcb2
7 changed files with 777 additions and 858 deletions

View File

@ -23,12 +23,12 @@
void A7105_WriteData(uint8_t len, uint8_t channel) void A7105_WriteData(uint8_t len, uint8_t channel)
{ {
uint8_t i; uint8_t i;
A7105_CS_off; A7105_CSN_off;
spi_write(A7105_RST_WRPTR); spi_write(A7105_RST_WRPTR);
spi_write(0x05); spi_write(0x05);
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
spi_write(packet[i]); spi_write(packet[i]);
A7105_CS_on; A7105_CSN_on;
A7105_WriteReg(0x0F, channel); A7105_WriteReg(0x0F, channel);
A7105_Strobe(A7105_TX); A7105_Strobe(A7105_TX);
} }
@ -36,27 +36,27 @@ void A7105_WriteData(uint8_t len, uint8_t channel)
void A7105_ReadData() { void A7105_ReadData() {
uint8_t i; uint8_t i;
A7105_Strobe(0xF0); //A7105_RST_RDPTR A7105_Strobe(0xF0); //A7105_RST_RDPTR
A7105_CS_off; A7105_CSN_off;
spi_write(0x45); spi_write(0x45);
for (i=0;i<16;i++) for (i=0;i<16;i++)
packet[i]=spi_Read(); packet[i]=spi_Read();
A7105_CS_on; A7105_CSN_on;
} }
void A7105_WriteReg(uint8_t address, uint8_t data) { void A7105_WriteReg(uint8_t address, uint8_t data) {
A7105_CS_off; A7105_CSN_off;
spi_write(address); spi_write(address);
NOP(); NOP();
spi_write(data); spi_write(data);
A7105_CS_on; A7105_CSN_on;
} }
uint8_t A7105_ReadReg(uint8_t address) { uint8_t A7105_ReadReg(uint8_t address) {
uint8_t result; uint8_t result;
A7105_CS_off; A7105_CSN_off;
spi_write(address |=0x40); //bit 6 =1 for reading spi_write(address |=0x40); //bit 6 =1 for reading
result = spi_Read(); result = spi_Read();
A7105_CS_on; A7105_CSN_on;
return(result); return(result);
} }
@ -93,13 +93,13 @@ uint8_t A7105_Reset()
} }
void A7105_WriteID(uint32_t ida) { void A7105_WriteID(uint32_t ida) {
A7105_CS_off; A7105_CSN_off;
spi_write(0x06);//ex id=0x5475c52a ;txid3txid2txid1txid0 spi_write(0x06);//ex id=0x5475c52a ;txid3txid2txid1txid0
spi_write((ida>>24)&0xff);//53 spi_write((ida>>24)&0xff);//53
spi_write((ida>>16)&0xff);//75 spi_write((ida>>16)&0xff);//75
spi_write((ida>>8)&0xff);//c5 spi_write((ida>>8)&0xff);//c5
spi_write((ida>>0)&0xff);//2a spi_write((ida>>0)&0xff);//2a
A7105_CS_on; A7105_CSN_on;
} }
/* /*
@ -145,9 +145,9 @@ void A7105_SetPower()
} }
void A7105_Strobe(uint8_t address) { void A7105_Strobe(uint8_t address) {
A7105_CS_off; A7105_CSN_off;
spi_write(address); spi_write(address);
A7105_CS_on; A7105_CSN_on;
} }
const uint8_t PROGMEM HUBSAN_A7105_regs[] = { const uint8_t PROGMEM HUBSAN_A7105_regs[] = {

View File

@ -15,7 +15,7 @@
// Check selected board type // Check selected board type
#ifndef XMEGA #ifndef XMEGA
#if not defined(ARDUINO_AVR_PRO) && not defined(ARDUINO_AVR_MINI) #if not defined(ARDUINO_AVR_PRO) && not defined(ARDUINO_AVR_MINI) && not defined(ARDUINO_AVR_NANO)
#error You must select the board type "Arduino Pro or Pro Mini" or "Arduino Mini" #error You must select the board type "Arduino Pro or Pro Mini" or "Arduino Mini"
#endif #endif
#if F_CPU != 16000000L || not defined(__AVR_ATmega328P__) #if F_CPU != 16000000L || not defined(__AVR_ATmega328P__)
@ -55,7 +55,7 @@ enum PROTOCOLS
MODE_ASSAN = 24, // =>NRF24L01 MODE_ASSAN = 24, // =>NRF24L01
MODE_FRSKYV = 25, // =>CC2500 MODE_FRSKYV = 25, // =>CC2500
MODE_HONTAI = 26, // =>NRF24L01 MODE_HONTAI = 26, // =>NRF24L01
MODE_OPENLRS = 27 // =>OpenLRS hardware MODE_OPENLRS = 27, // =>OpenLRS hardware
}; };
enum Flysky enum Flysky
@ -70,10 +70,13 @@ enum Hisky
Hisky = 0, Hisky = 0,
HK310 = 1 HK310 = 1
}; };
enum DSM2 enum DSM
{ {
DSM2 = 0, DSM2_22 = 0,
DSMX = 1 DSM2_11 = 1,
DSMX_22 = 2,
DSMX_11 = 3,
DSM_AUTO = 4
}; };
enum YD717 enum YD717
{ {
@ -125,7 +128,6 @@ enum MJXQ
H26D = 3, H26D = 3,
E010 = 4 E010 = 4
}; };
enum FRSKYX enum FRSKYX
{ {
CH_16 = 0, CH_16 = 0,
@ -146,22 +148,29 @@ enum HONTAI
struct PPM_Parameters struct PPM_Parameters
{ {
uint8_t protocol : 5; uint8_t protocol : 6;
uint8_t sub_proto : 3; uint8_t sub_proto : 3;
uint8_t rx_num : 4; uint8_t rx_num : 4;
uint8_t power : 1; uint8_t power : 1;
uint8_t autobind : 1; uint8_t autobind : 1;
uint8_t option; uint8_t option;
}; };
// Macros
#define NOP() __asm__ __volatile__("nop")
//*******************
//*** Timer ***
//*******************
#ifdef XMEGA #ifdef XMEGA
#define TIFR1 TCC1.INTFLAGS #define TIFR1 TCC1.INTFLAGS
#define OCF1A_bm TC1_CCAIF_bm #define OCF1A_bm TC1_CCAIF_bm
#define OCR1A TCC1.CCA #define OCR1A TCC1.CCA
#define TCNT1 TCC1.CNT #define TCNT1 TCC1.CNT
#define USARTC0.DATA UDR0 #define UDR0 USARTC0.DATA
#define OCF1B_bm TC1_CCBIF_bm #define OCF1B_bm TC1_CCBIF_bm
#define OCR1B TCC1.CCB #define OCR1B TCC1.CCB
#define TCC1.INTCTRLB TIMSK1 #define TIMSK1 TCC1.INTCTRLB
#define SET_TIMSK1_OCIE1B TIMSK1 = (TIMSK1 & 0xF3) | 0x04 #define SET_TIMSK1_OCIE1B TIMSK1 = (TIMSK1 & 0xF3) | 0x04
#define CLR_TIMSK1_OCIE1B TIMSK1 &= 0xF3 #define CLR_TIMSK1_OCIE1B TIMSK1 &= 0xF3
#else #else
@ -170,157 +179,10 @@ struct PPM_Parameters
#define SET_TIMSK1_OCIE1B TIMSK1 |= _BV(OCIE1B) #define SET_TIMSK1_OCIE1B TIMSK1 |= _BV(OCIE1B)
#define CLR_TIMSK1_OCIE1B TIMSK1 &=~_BV(OCIE1B) #define CLR_TIMSK1_OCIE1B TIMSK1 &=~_BV(OCIE1B)
#endif #endif
//*******************
//*** Pinouts ***
//*******************
#define LED_pin 5 //D13 = PB5
#define BIND_pin 5 //D13 = PB5
#define PPM_pin 3 //D3 = PD3
#ifdef XMEGA
#define SDI_pin 6 //SDIO-D6
#else
#define SDI_pin 5 //D5 = PD5
#endif
#define SCLK_pin 4 //D4 = PD4
#define A7105_CS_pin 2 //D2 = PD2
#define SDO_pin 6 //D6 = PD6
#define CC25_CSN_pin 7 //D7 = PD7
#define NRF_CSN_pin 0 //D8 = PB0
#define CYRF_CSN_pin 1 //D9 = PB1
#define CTRL1_pin 1 //A1 = PC1
#define CTRL2_pin 2 //A2 = PC2
//
#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 A7105_CS_on PORTD.OUTSET = _BV(4) //D4
#define A7105_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 & _BV(SDI_pin)) == _BV(SDI_pin) //D5
#define SDI_0 (PORTD.IN & _BV(SDI_pin)) == 0x00 //D5
#else
#define SDI_1 (PIND & _BV(SDI_pin)) == _BV(SDI_pin) //D5
#define SDI_0 (PIND & _BV(SDI_pin)) == 0x00 //D5
#endif
//
#define SDI_SET_INPUT DDRD &= ~_BV(5) //D5
#define SDI_SET_OUTPUT DDRD |= _BV(5) //D5
//
#ifdef XMEGA
#define CC25_CSN_on PORTD.OUTSET = _BV(7) //D7
#define CC25_CSN_off PORTD.OUTCLR = _BV(7) //D7
#else
#define CC25_CSN_on PORTD |= _BV(7) //D7
#define CC25_CSN_off PORTD &= ~_BV(7) //D7
#endif
//
#ifdef XMEGA
#define NRF_CSN_on
#define NRF_CSN_off
#define NRF_CE_on
#define NRF_CE_off
#else
#define NRF_CSN_on PORTB |= _BV(0) //D8
#define NRF_CSN_off PORTB &= ~_BV(0) //D8
#define NRF_CE_on
#define NRF_CE_off
#endif
//
#ifdef XMEGA
#define CYRF_CSN_on PORTD.OUTSET = _BV(4)
#define CYRF_CSN_off PORTD.OUTCLR = _BV(4)
#else
#define CYRF_CSN_on PORTB |= _BV(1) //D9
#define CYRF_CSN_off PORTB &= ~_BV(1) //D9
#define CYRF_RST_HI PORTC |= _BV(5) //A5
#define CYRF_RST_LO PORTC &= ~_BV(5) //A5
#define CYRF_RST_pin 5
#endif
//
#ifdef XMEGA
#define SDO_1 (PORTD.IN & _BV(SDO_pin)) == _BV(SDO_pin) //D6
#define SDO_0 (PORTD.IN & _BV(SDO_pin)) == 0x00 //D6
#else
#define SDO_1 (PIND & _BV(SDO_pin)) == _BV(SDO_pin) //D6
#define SDO_0 (PIND & _BV(SDO_pin)) == 0x00 //D6
#endif
//
//
// LED //***************
#ifdef XMEGA //*** Flags ***
#define LED_ON PORTD.OUTCLR = _BV(1) //***************
#define LED_OFF PORTD.OUTSET = _BV(1)
#define LED_TOGGLE PORTD.OUTTGL = _BV(1)
#define LED_SET_OUTPUT PORTD.DIRSET = _BV(1)
#define IS_LED_on ( (PORTD.OUT & _BV(1)) != 0x00 )
#else
#define LED_ON PORTB |= _BV(5)
#define LED_OFF PORTB &= ~_BV(5)
#define LED_TOGGLE PORTB ^= _BV(5)
#define LED_SET_OUTPUT DDRB |= _BV(5)
#define IS_LED_on ( (PORTB & _BV(5)) != 0x00 )
#endif
//BIND
#ifdef XMEGA
#define IS_BIND_BUTTON_on ( (PORTD.IN & _BV(2)) == 0x00 )
#else
#define BIND_SET_INPUT DDRB &= ~_BV(5)
#define BIND_SET_PULLUP PORTB |= _BV(5)
#define IS_BIND_BUTTON_on ( (PINB & _BV(5)) == 0x00 )
#define BIND_SET_OUTPUT DDRB |= _BV(5)
#endif
// TX
#ifdef DEBUG_TX
#define TX_ON PORTD |= _BV(1)
#define TX_OFF PORTD &= ~_BV(1)
#define TX_TOGGLE PORTD ^= _BV(1)
#define TX_SET_OUTPUT DDRD |= _BV(1)
#else
#define TX_ON
#define TX_OFF
#define TX_TOGGLE
#define TX_SET_OUTPUT
#endif
// Macros
#define NOP() __asm__ __volatile__("nop")
#define BV(bit) (1 << bit)
//Serial flags definition
#define RX_FLAG_on protocol_flags |= _BV(0) #define RX_FLAG_on protocol_flags |= _BV(0)
#define RX_FLAG_off protocol_flags &= ~_BV(0) #define RX_FLAG_off protocol_flags &= ~_BV(0)
#define IS_RX_FLAG_on ( ( protocol_flags & _BV(0) ) !=0 ) #define IS_RX_FLAG_on ( ( protocol_flags & _BV(0) ) !=0 )
@ -344,45 +206,47 @@ struct PPM_Parameters
#define BIND_BUTTON_FLAG_on protocol_flags |= _BV(5) #define BIND_BUTTON_FLAG_on protocol_flags |= _BV(5)
#define BIND_BUTTON_FLAG_off protocol_flags &= ~_BV(5) #define BIND_BUTTON_FLAG_off protocol_flags &= ~_BV(5)
#define IS_BIND_BUTTON_FLAG_on ( ( protocol_flags & _BV(5) ) !=0 ) #define IS_BIND_BUTTON_FLAG_on ( ( protocol_flags & _BV(5) ) !=0 )
//PPM RX OK //PPM RX OK
#define PPM_FLAG_off protocol_flags &= ~_BV(6) #define PPM_FLAG_off protocol_flags &= ~_BV(6)
#define PPM_FLAG_on protocol_flags |= _BV(6) #define PPM_FLAG_on protocol_flags |= _BV(6)
#define IS_PPM_FLAG_on ( ( protocol_flags & _BV(6) ) !=0 ) #define IS_PPM_FLAG_on ( ( protocol_flags & _BV(6) ) !=0 )
//Bind flag
//Bind flag for blinking
#define BIND_IN_PROGRESS protocol_flags &= ~_BV(7) #define BIND_IN_PROGRESS protocol_flags &= ~_BV(7)
#define BIND_DONE protocol_flags |= _BV(7) #define BIND_DONE protocol_flags |= _BV(7)
#define IS_BIND_DONE_on ( ( protocol_flags & _BV(7) ) !=0 ) #define IS_BIND_DONE_on ( ( protocol_flags & _BV(7) ) !=0 )
//
#define BAD_PROTO_off protocol_flags2 &= ~_BV(0) #define BAD_PROTO_off protocol_flags2 &= ~_BV(0)
#define BAD_PROTO_on protocol_flags2 |= _BV(0) #define BAD_PROTO_on protocol_flags2 |= _BV(0)
#define IS_BAD_PROTO_on ( ( protocol_flags2 & _BV(0) ) !=0 ) #define IS_BAD_PROTO_on ( ( protocol_flags2 & _BV(0) ) !=0 )
//
#define RX_DONOTUPDTAE_off protocol_flags2 &= ~_BV(1) #define RX_DONOTUPDTAE_off protocol_flags2 &= ~_BV(1)
#define RX_DONOTUPDTAE_on protocol_flags2 |= _BV(1) #define RX_DONOTUPDTAE_on protocol_flags2 |= _BV(1)
#define IS_RX_DONOTUPDTAE_on ( ( protocol_flags2 & _BV(1) ) !=0 ) #define IS_RX_DONOTUPDTAE_on ( ( protocol_flags2 & _BV(1) ) !=0 )
//
#define RX_MISSED_BUFF_off protocol_flags2 &= ~_BV(2) #define RX_MISSED_BUFF_off protocol_flags2 &= ~_BV(2)
#define RX_MISSED_BUFF_on protocol_flags2 |= _BV(2) #define RX_MISSED_BUFF_on protocol_flags2 |= _BV(2)
#define IS_RX_MISSED_BUFF_on ( ( protocol_flags2 & _BV(2) ) !=0 ) #define IS_RX_MISSED_BUFF_on ( ( protocol_flags2 & _BV(2) ) !=0 )
//TX Pause
#define TX_MAIN_PAUSE_off protocol_flags2 &= ~_BV(3) #define TX_MAIN_PAUSE_off protocol_flags2 &= ~_BV(3)
#define TX_MAIN_PAUSE_on protocol_flags2 |= _BV(3) #define TX_MAIN_PAUSE_on protocol_flags2 |= _BV(3)
#define IS_TX_MAIN_PAUSE_on ( ( protocol_flags2 & _BV(3) ) !=0 ) #define IS_TX_MAIN_PAUSE_on ( ( protocol_flags2 & _BV(3) ) !=0 )
#define TX_RX_PAUSE_off protocol_flags2 &= ~_BV(4) #define TX_RX_PAUSE_off protocol_flags2 &= ~_BV(4)
#define TX_RX_PAUSE_on protocol_flags2 |= _BV(4) #define TX_RX_PAUSE_on protocol_flags2 |= _BV(4)
#define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 ) #define IS_TX_RX_PAUSE_on ( ( protocol_flags2 & _BV(4) ) !=0 )
#define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 )
//********************
//*** Blink timing ***
//********************
#define BLINK_BIND_TIME 100 #define BLINK_BIND_TIME 100
#define BLINK_SERIAL_TIME 500 #define BLINK_SERIAL_TIME 500
#define BLINK_BAD_PROTO_TIME_LOW 1000 #define BLINK_BAD_PROTO_TIME_LOW 1000
#define BLINK_BAD_PROTO_TIME_HIGH 50 #define BLINK_BAD_PROTO_TIME_HIGH 50
//AUX flags definition //*******************
//*** AUX flags ***
//*******************
#define GET_FLAG(ch, mask) ( ch ? mask : 0)
#define Servo_AUX1 Servo_AUX & _BV(0) #define Servo_AUX1 Servo_AUX & _BV(0)
#define Servo_AUX2 Servo_AUX & _BV(1) #define Servo_AUX2 Servo_AUX & _BV(1)
#define Servo_AUX3 Servo_AUX & _BV(2) #define Servo_AUX3 Servo_AUX & _BV(2)
@ -392,8 +256,6 @@ struct PPM_Parameters
#define Servo_AUX7 Servo_AUX & _BV(6) #define Servo_AUX7 Servo_AUX & _BV(6)
#define Servo_AUX8 Servo_AUX & _BV(7) #define Servo_AUX8 Servo_AUX & _BV(7)
#define GET_FLAG(ch, mask) ( ch ? mask : 0)
//************************ //************************
//*** Power settings *** //*** Power settings ***
//************************ //************************
@ -484,7 +346,7 @@ enum CYRF_POWER
#define CYRF_HIGH_POWER CYRF_POWER_7 #define CYRF_HIGH_POWER CYRF_POWER_7
#define CYRF_LOW_POWER CYRF_POWER_3 #define CYRF_LOW_POWER CYRF_POWER_3
#define CYRF_RANGE_POWER CYRF_POWER_1 // 1/30 of the full power distance #define CYRF_RANGE_POWER CYRF_POWER_1 // 1/30 of the full power distance
#define CYRF_BIND_POWER CYRF_POWER_1 #define CYRF_BIND_POWER CYRF_POWER_0
enum TXRX_State { enum TXRX_State {
TXRX_OFF, TXRX_OFF,
@ -502,6 +364,8 @@ enum {
// baudrate defines for serial // baudrate defines for serial
#define SPEED_100K 0 #define SPEED_100K 0
#define SPEED_9600 1 #define SPEED_9600 1
#define SPEED_57600 2
#define SPEED_125K 3
//**************************************** //****************************************
//*** MULTI protocol serial definition *** //*** MULTI protocol serial definition ***
@ -512,17 +376,18 @@ enum {
************************** **************************
Serial: 100000 Baud 8e2 _ xxxx xxxx p -- Serial: 100000 Baud 8e2 _ xxxx xxxx p --
Total of 26 bytes Total of 26 bytes
Stream[0] = 0x55 Stream[0] = 0x55 sub_protocol values are 0..31
Stream[0] = 0x54 sub_protocol values are 32..63
header header
Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit; Stream[1] = sub_protocol|BindBit|RangeCheckBit|AutoBindBit;
sub_protocol is 0..31 (bits 0..4) sub_protocol is 0..31 (bits 0..4), value should be added with 32 if Stream[0] = 0x54
=> Reserved 0 => Reserved 0
Flysky 1 Flysky 1
Hubsan 2 Hubsan 2
Frsky 3 FrskyD 3
Hisky 4 Hisky 4
V2x2 5 V2x2 5
DSM2 6 DSM 6
Devo 7 Devo 7
YD717 8 YD717 8
KN 9 KN 9
@ -541,7 +406,9 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
J6PRO 22 J6PRO 22
FQ777 23 FQ777 23
ASSAN 24 ASSAN 24
FRSKY1 25 FrskyV 25
HONTAI 26
OpenLRS 27
BindBit=> 0x80 1=Bind/0=No BindBit=> 0x80 1=Bind/0=No
AutoBindBit=> 0x40 1=Yes /0=No AutoBindBit=> 0x40 1=Yes /0=No
RangeCheck=> 0x20 1=Yes /0=No RangeCheck=> 0x20 1=Yes /0=No
@ -556,9 +423,11 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
sub_protocol==Hisky sub_protocol==Hisky
Hisky 0 Hisky 0
HK310 1 HK310 1
sub_protocol==DSM2 sub_protocol==DSM
DSM2 0 DSM2_22 0
DSMX 1 DSM2_11 1
DSMX_22 2
DSMX_11 3
sub_protocol==YD717 sub_protocol==YD717
YD717 0 YD717 0
SKYWLKR 1 SKYWLKR 1
@ -598,6 +467,10 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
sub_protocol==FRSKYX sub_protocol==FRSKYX
CH_16 0 CH_16 0
CH_8 1 CH_8 1
sub_protocol==HONTAI
FORMAT_HONTAI 0
FORMAT_JJRCX1 1
FORMAT_X5C1 2
Power value => 0x80 0=High/1=Low Power value => 0x80 0=High/1=Low
Stream[3] = option_protocol; Stream[3] = option_protocol;
option_protocol value is -127..127 option_protocol value is -127..127
@ -610,4 +483,3 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
2047 +125% 2047 +125%
Channels bits are concatenated to fit in 22 bytes like in SBUS protocol Channels bits are concatenated to fit in 22 bytes like in SBUS protocol
*/ */

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ enum PROTOCOLS
MODE_FRSKYD = 3, // =>CC2500 MODE_FRSKYD = 3, // =>CC2500
MODE_HISKY = 4, // =>NRF24L01 MODE_HISKY = 4, // =>NRF24L01
MODE_V2X2 = 5, // =>NRF24L01 MODE_V2X2 = 5, // =>NRF24L01
MODE_DSM2 = 6, // =>CYRF6936 MODE_DSM = 6, // =>CYRF6936
MODE_DEVO = 7, // =>CYRF6936 MODE_DEVO = 7, // =>CYRF6936
MODE_YD717 = 8, // =>NRF24L01 MODE_YD717 = 8, // =>NRF24L01
MODE_KN = 9, // =>NRF24L01 MODE_KN = 9, // =>NRF24L01
@ -61,9 +61,12 @@ enum Hisky
Hisky = 0, Hisky = 0,
HK310 = 1 HK310 = 1
}; };
enum DSM2{ enum DSM{
DSM2 = 0, DSM2_22 = 0,
DSMX = 1 DSM2_11 = 1,
DSMX_22 = 2,
DSMX_11 = 3,
DSM_AUTO = 4
}; };
enum YD717 enum YD717
{ {
@ -177,7 +180,7 @@ struct PPM_Parameters
#define CC25_CSN_pin PB6//CC2500 #define CC25_CSN_pin PB6//CC2500
#define NRF_CSN_pin PB7//NRF24L01 #define NRF_CSN_pin PB7//NRF24L01
#define CYRF_RST_pin PB8//CYRF RESET #define CYRF_RST_pin PB8//CYRF RESET
#define A7105_CS_pin PB9//A7105 #define A7105_CSN_pin PB9//A7105
#define CYRF_CSN_pin PB12//CYRF CSN #define CYRF_CSN_pin PB12//CYRF CSN
//SPI pins //SPI pins
#define SCK_pin PB13//SCK #define SCK_pin PB13//SCK
@ -187,18 +190,18 @@ struct PPM_Parameters
#define TX_INV_pin PB3 #define TX_INV_pin PB3
#define RX_INV_pin PB1 #define RX_INV_pin PB1
// //
#define CTRL1_on digitalWrite(CTRL1,HIGH) #define PE1_on digitalWrite(CTRL1,HIGH)
#define CTRL1_off digitalWrite(CTRL1,LOW) #define PE1_off digitalWrite(CTRL1,LOW)
// //
#define CTRL2_on digitalWrite(CTRL2,HIGH) #define PE2_on digitalWrite(CTRL2,HIGH)
#define CTRL2_off digitalWrite(CTRL2,LOW) #define PE2_off digitalWrite(CTRL2,LOW)
#define RS_HI digitalWrite(CYRF_RST_pin,HIGH) //reset pin cyrf #define RS_HI digitalWrite(CYRF_RST_pin,HIGH) //reset pin cyrf
#define RS_LO digitalWrite(CYRF_RST_pin,LOW) #define RS_LO digitalWrite(CYRF_RST_pin,LOW)
#define A7105_CS_on digitalWrite(CS_pin,HIGH) #define A7105_CSN_on digitalWrite(A7105_CSN_pin,HIGH)
#define A7105_CS_off digitalWrite(CS_pin,LOW) #define A7105_CSN_off digitalWrite(A7105_CSN_pin,LOW)
#define NRF_CE_on #define NRF_CE_on
#define NRF_CE_off #define NRF_CE_off
@ -233,9 +236,9 @@ struct PPM_Parameters
#define RX_INV_on digitalWrite(RX_INV_pin,HIGH) #define RX_INV_on digitalWrite(RX_INV_pin,HIGH)
#define RX_INV_off digitalWrite(RX_INV_pin,LOW) #define RX_INV_off digitalWrite(RX_INV_pin,LOW)
#define LED_ON digitalWrite(LED_pin,HIGH) #define LED_on digitalWrite(LED_pin,HIGH)
#define LED_OFF digitalWrite(LED_pin,LOW) #define LED_off digitalWrite(LED_pin,LOW)
#define LED_TOGGLE digitalWrite(LED_pin ,!digitalRead(LED_pin)) #define LED_toggle digitalWrite(LED_pin ,!digitalRead(LED_pin))
#define LED_SET_OUTPUT pinMode(LED_pin,OUTPUT) #define LED_SET_OUTPUT pinMode(LED_pin,OUTPUT)
#define IS_LED_on ( digitalRead(LED_pin)==HIGH) #define IS_LED_on ( digitalRead(LED_pin)==HIGH)
@ -310,7 +313,7 @@ struct PPM_Parameters
#define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 ) #define IS_TX_PAUSE_on ( ( protocol_flags2 & (_BV(4)|_BV(3)) ) !=0 )
#define IS_BIND_BUTTON_on (digitalRead(BIND_pin)==0x00) #define IS_BIND_BUTTON_on (digitalRead(BIND_pin)==LOW)
#define BIND_SET_INPUT pinMode(BIND_pin,INPUT) #define BIND_SET_INPUT pinMode(BIND_pin,INPUT)
#define BIND_SET_PULLUP digitalWrite(BIND_pin,HIGH) #define BIND_SET_PULLUP digitalWrite(BIND_pin,HIGH)

View File

@ -78,6 +78,11 @@ void SPI_SET_UNIDIRECTIONAL()
#else #else
#ifdef XMEGA
#define XNOP() NOP()
#else
#define XNOP()
#endif
void spi_write(uint8_t command) void spi_write(uint8_t command)
{ {
uint8_t n=8; uint8_t n=8;

View File

@ -1,22 +1,34 @@
//************************************* /*
// FrSky Telemetry serial code * This project is free software: you can redistribute it and/or modify
// By Midelic on RCGroups * it under the terms of the GNU General Public License as published by
//************************************* the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Multiprotocol is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
//**************************
// Telemetry serial code *
//**************************
#if defined TELEMETRY #if defined TELEMETRY
#if defined SPORT_TELEMETRY #if defined SPORT_TELEMETRY
#define SPORT_TIME 12000 #define SPORT_TIME 12000
#define FRSKY_SPORT_PACKET_SIZE 8 #define FRSKY_SPORT_PACKET_SIZE 8
uint32_t last = 0; uint32_t last = 0;
uint8_t sport_counter=0; uint8_t sport_counter=0;
uint8_t RxBt = 0; uint8_t RxBt = 0;
uint8_t rssi; uint8_t rssi;
uint8_t sport = 0; uint8_t sport = 0;
#endif #endif
#if defined HUB_TELEMETRY #if defined HUB_TELEMETRY
#define USER_MAX_BYTES 6 #define USER_MAX_BYTES 6
uint8_t prev_index; uint8_t prev_index;
#endif #endif
#define START_STOP 0x7e #define START_STOP 0x7e
@ -28,10 +40,8 @@ uint8_t pktx1[MAX_PKTX];//second buffer for sport
uint8_t idxt; uint8_t idxt;
uint8_t frame[18]; uint8_t frame[18];
#ifdef BASH_SERIAL #ifdef BASH_SERIAL
// For bit-bashed serial output // For bit-bashed serial output
struct t_serial_bash struct t_serial_bash
{ {
uint8_t head ; uint8_t head ;
@ -42,13 +52,12 @@ struct t_serial_bash
} SerialControl ; } SerialControl ;
#endif #endif
#if defined DSM_TELEMETRY #if defined DSM_TELEMETRY
void DSM2_frame() void DSM_frame()
{ {
Serial_write(0xAA); // Start Serial_write(0xAA); // Telemetry packet
for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data for (uint8_t i = 0; i < 17; i++) // RSSI value followed by 16 bytes of telemetry data
Serial_write(pkt[i]); Serial_write(pkt[i]);
} }
#endif #endif
@ -72,9 +81,9 @@ void compute_RSSIdbm()
RSSI_dBm = (((uint16_t)(pktt[len-2])*18)>>4); RSSI_dBm = (((uint16_t)(pktt[len-2])*18)>>4);
if(pktt[len-2] >=128) if(pktt[len-2] >=128)
RSSI_dBm -= 164; RSSI_dBm -= 164;
else else
RSSI_dBm += 130; RSSI_dBm += 130;
} }
void frsky_check_telemetry(uint8_t *pkt,uint8_t len) void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
@ -82,13 +91,13 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
if(pkt[1] == rx_tx_addr[3] && pkt[2] == rx_tx_addr[2] && len ==(pkt[0] + 3)) if(pkt[1] == rx_tx_addr[3] && pkt[2] == rx_tx_addr[2] && len ==(pkt[0] + 3))
{ {
for (uint8_t i=3;i<len;i++) for (uint8_t i=3;i<len;i++)
pktt[i]=pkt[i]; pktt[i]=pkt[i];
telemetry_link=1; telemetry_link=1;
if(pktt[6]) if(pktt[6])
telemetry_counter=(telemetry_counter+1)%32; telemetry_counter=(telemetry_counter+1)%32;
// //
#if defined FRSKYX_CC2500_INO #if defined SPORT_TELEMETRY && defined FRSKYX_CC2500_INO
if ((cur_protocol[0]&0x1F)==MODE_FRSKYX) if (protocol==MODE_FRSKYX)
{ {
if ((pktt[5] >> 4 & 0x0f) == 0x08) if ((pktt[5] >> 4 & 0x0f) == 0x08)
{ {
@ -99,9 +108,9 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
else else
{ {
if ((pktt[5] >> 4 & 0x03) == (seq_last_rcvd + 1) % 4) if ((pktt[5] >> 4 & 0x03) == (seq_last_rcvd + 1) % 4)
seq_last_rcvd = (seq_last_rcvd + 1) % 4; seq_last_rcvd = (seq_last_rcvd + 1) % 4;
else else
pass=0;//reset if sequence wrong pass=0;//reset if sequence wrong
} }
} }
#endif #endif
@ -111,7 +120,7 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
void frsky_link_frame() void frsky_link_frame()
{ {
frame[0] = 0xFE; frame[0] = 0xFE;
if ((cur_protocol[0]&0x1F)==MODE_FRSKYD) if (protocol==MODE_FRSKYD)
{ {
compute_RSSIdbm(); compute_RSSIdbm();
frame[1] = pktt[3]; frame[1] = pktt[3];
@ -120,13 +129,13 @@ void frsky_link_frame()
frame[4] = (uint8_t)RSSI_dBm; frame[4] = (uint8_t)RSSI_dBm;
} }
else else
if ((cur_protocol[0]&0x1F)==MODE_HUBSAN) if (protocol==MODE_HUBSAN)
{ {
frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V frame[1] = v_lipo*2; //v_lipo; common 0x2A=42/10=4.2V
frame[2] = frame[1]; frame[2] = frame[1];
frame[3] = 0x00; frame[3] = 0x00;
frame[4] = (uint8_t)RSSI_dBm; frame[4] = (uint8_t)RSSI_dBm;
} }
frame[5] = frame[6] = frame[7] = frame[8] = 0; frame[5] = frame[6] = frame[7] = frame[8] = 0;
frskySendStuffed(); frskySendStuffed();
} }
@ -142,58 +151,58 @@ void frsky_user_frame()
frame[2] = pktt[7]; frame[2] = pktt[7];
switch(pass) switch(pass)
{ {
case 0: case 0:
indexx=pktt[6]; indexx=pktt[6];
for(i=0;i<indexx;i++) for(i=0;i<indexx;i++)
{ {
pktx[i]=pktt[j++]; pktx[i]=pktt[j++];
} }
pass=1; pass=1;
case 1: case 1:
idxt=indexx; idxt=indexx;
prev_index = indexx; prev_index = indexx;
if(idxt<USER_MAX_BYTES) if(idxt<USER_MAX_BYTES)
{ {
for(i=0;i<idxt;i++) for(i=0;i<idxt;i++)
frame[i+3]=pktx[i]; frame[i+3]=pktx[i];
pktt[6]=0;
pass=0;
}
else
{
idxt = USER_MAX_BYTES;
for(i=0;i<idxt;i++)
frame[i+3]=pktx[i];
pass=2;
}
break;
case 2:
idxt = prev_index - idxt;
prev_index=0;
if(idxt<=(MAX_PKTX-USER_MAX_BYTES)) //10-6=4
for(i=0;i<idxt;i++)
frame[i+3]=pktx[USER_MAX_BYTES+i];
pass=0;
pktt[6]=0; pktt[6]=0;
break; pass=0;
default: }
break; else
{
idxt = USER_MAX_BYTES;
for(i=0;i<idxt;i++)
frame[i+3]=pktx[i];
pass=2;
}
break;
case 2:
idxt = prev_index - idxt;
prev_index=0;
if(idxt<=(MAX_PKTX-USER_MAX_BYTES)) //10-6=4
for(i=0;i<idxt;i++)
frame[i+3]=pktx[USER_MAX_BYTES+i];
pass=0;
pktt[6]=0;
break;
default:
break;
} }
if(!idxt) if(!idxt)
return; return;
frame[1] = idxt; frame[1] = idxt;
frskySendStuffed(); frskySendStuffed();
} }
else else
pass=0; pass=0;
} }
#endif #endif
/* /*
HuB RX packets. HuB RX packets.
pkt[6]|(counter++)|00 01 02 03 04 05 06 07 08 09 pkt[6]|(counter++)|00 01 02 03 04 05 06 07 08 09
%32 %32
01 08 5E 28 12 00 5E 5E 3A 06 00 5E 01 08 5E 28 12 00 5E 5E 3A 06 00 5E
0A 09 28 12 00 5E 5E 3A 06 00 5E 5E 0A 09 28 12 00 5E 5E 3A 06 00 5E 5E
09 0A 3B 09 00 5E 5E 06 36 7D 5E 5E 09 0A 3B 09 00 5E 5E 06 36 7D 5E 5E
@ -262,7 +271,7 @@ void sportSend(uint8_t *p)
for (uint8_t i = 1; i < 9; i++) for (uint8_t i = 1; i < 9; i++)
{ {
if (i == 8) if (i == 8)
p[i] = 0xff - crc_s; p[i] = 0xff - crc_s;
if ((p[i] == START_STOP) || (p[i] == BYTESTUFF)) if ((p[i] == START_STOP) || (p[i] == BYTESTUFF))
{ {
@ -270,7 +279,7 @@ void sportSend(uint8_t *p)
Serial_write(STUFF_MASK ^ p[i]); Serial_write(STUFF_MASK ^ p[i]);
} }
else else
Serial_write(p[i]); Serial_write(p[i]);
if (i>0) if (i>0)
{ {
@ -300,29 +309,36 @@ void sportSendFrame()
} }
switch (sport_counter) switch (sport_counter)
{ {
case 2: // RSSI case 0:
frame[2] = 0x01; frame[2] = 0x05;
frame[3] = 0xf1; frame[3] = 0xf1;
frame[4] = rssi; frame[4] = 0x02 ;//dummy values if swr 20230f00
frame[5] = 0x23;
frame[6] = 0x0F;
break;
case 2: // RSSI
frame[2] = 0x01;
frame[3] = 0xf1;
frame[4] = rssi;
break;
case 4: //BATT
frame[2] = 0x04;
frame[3] = 0xf1;
frame[4] = RxBt;//a1;
break;
default:
if(sport)
{
for (i=0;i<FRSKY_SPORT_PACKET_SIZE;i++)
frame[i]=pktx1[i];
sport=0;
break; break;
case 4: //BATT }
frame[2] = 0x04; else
frame[3] = 0xf1; {
frame[4] = RxBt;//a1; sportIdle();
break; return;
default: }
if(sport)
{
for (i=0;i<FRSKY_SPORT_PACKET_SIZE;i++)
frame[i]=pktx1[i];
sport=0;
break;
}
else
{
sportIdle();
return;
}
} }
sportSend(frame); sportSend(frame);
} }
@ -331,31 +347,37 @@ void proces_sport_data(uint8_t data)
{ {
switch (pass) switch (pass)
{ {
case 0: case 0:
if (data == START_STOP) if (data == START_STOP)
{//waiting for 0x7e {//waiting for 0x7e
idxt = 0; idxt = 0;
pass = 1; pass = 1;
} }
break; break;
case 1: case 1:
if(data == BYTESTUFF)//if they are stuffed if (data == START_STOP) // Happens if missed packet
pass=2; {//waiting for 0x7e
else idxt = 0;
if (idxt < MAX_PKTX) pass = 1;
pktx[idxt++] = data;
break;
case 2:
if (idxt < MAX_PKTX)
pktx[idxt++] = data ^ STUFF_MASK; //unstuff bytes
pass=1;
break; break;
}
if(data == BYTESTUFF)//if they are stuffed
pass=2;
else
if (idxt < MAX_PKTX)
pktx[idxt++] = data;
break;
case 2:
if (idxt < MAX_PKTX)
pktx[idxt++] = data ^ STUFF_MASK; //unstuff bytes
pass=1;
break;
} // end switch } // end switch
if (idxt >= FRSKY_SPORT_PACKET_SIZE) if (idxt >= FRSKY_SPORT_PACKET_SIZE)
{//8 bytes no crc {//8 bytes no crc
if ( sport ) if ( sport )
{ {
// overrun! do nothing // overrun!
} }
else else
{ {
@ -375,12 +397,12 @@ void proces_sport_data(uint8_t data)
void TelemetryUpdate() void TelemetryUpdate()
{ {
#if defined SPORT_TELEMETRY #if defined SPORT_TELEMETRY
if ((cur_protocol[0]&0x1F)==MODE_FRSKYX) if (protocol==MODE_FRSKYX)
{ // FrSkyX { // FrSkyX
if(telemetry_link) if(telemetry_link)
{ {
if(pktt[4] & 0x80) if(pktt[4] & 0x80)
rssi=pktt[4] & 0x7F ; rssi=pktt[4] & 0x7F ;
else else
RxBt = (pktt[4]<<1) + 1 ; RxBt = (pktt[4]<<1) + 1 ;
for (uint8_t i=0; i < pktt[6]; i++) for (uint8_t i=0; i < pktt[6]; i++)
@ -400,6 +422,8 @@ void TelemetryUpdate()
} }
#endif #endif
// check for space in tx buffer
#ifdef BASH_SERIAL #ifdef BASH_SERIAL
uint8_t h ; uint8_t h ;
uint8_t t ; uint8_t t ;
@ -418,7 +442,7 @@ void TelemetryUpdate()
return ; return ;
} }
#else #else
uint8_t h ; uint8_t h ;
uint8_t t ; uint8_t t ;
h = tx_head ; h = tx_head ;
@ -435,24 +459,24 @@ void TelemetryUpdate()
{ {
return ; return ;
} }
#endif #endif
#if defined DSM_TELEMETRY #if defined DSM_TELEMETRY
if(telemetry_link && (cur_protocol[0]&0x1F) == MODE_DSM2 ) if(telemetry_link && protocol == MODE_DSM )
{ // DSM2 { // DSM
DSM2_frame(); DSM_frame();
telemetry_link=0; telemetry_link=0;
return; return;
} }
#endif #endif
if(telemetry_link && (cur_protocol[0]&0x1F) != MODE_FRSKYX ) if(telemetry_link && protocol != MODE_FRSKYX )
{ // FrSky + Hubsan { // FrSky + Hubsan
frsky_link_frame(); frsky_link_frame();
telemetry_link=0; telemetry_link=0;
return; return;
} }
#if defined HUB_TELEMETRY #if defined HUB_TELEMETRY
if(!telemetry_link && (cur_protocol[0]&0x1F) == MODE_FRSKYD) if(!telemetry_link && protocol == MODE_FRSKYD)
{ // FrSky { // FrSky
frsky_user_frame(); frsky_user_frame();
return; return;
@ -471,7 +495,6 @@ void TelemetryUpdate()
/**************************/ /**************************/
/**************************/ /**************************/
#ifndef BASH_SERIAL #ifndef BASH_SERIAL
// Routines for normal serial output // Routines for normal serial output
void Serial_write(uint8_t data) void Serial_write(uint8_t data)
@ -479,86 +502,131 @@ void Serial_write(uint8_t data)
uint8_t nextHead ; uint8_t nextHead ;
nextHead = tx_head + 1 ; nextHead = tx_head + 1 ;
if ( nextHead >= TXBUFFER_SIZE ) if ( nextHead >= TXBUFFER_SIZE )
nextHead = 0 ; nextHead = 0 ;
tx_buff[nextHead]=data; tx_buff[nextHead]=data;
tx_head = nextHead ; tx_head = nextHead ;
tx_resume(); tx_resume();
} }
// Speed is 0 for 100K and 1 for 9600
void initTXSerial( uint8_t speed) void initTXSerial( uint8_t speed)
{ {
#ifdef ENABLE_PPM
if(speed==SPEED_9600) if(speed==SPEED_9600)
{ // 9600 { // 9600
#ifdef XMEGA #ifdef XMEGA
USARTC0.BAUDCTRLA = 207 ; USARTC0.BAUDCTRLA = 207 ;
USARTC0.BAUDCTRLB = 0 ; USARTC0.BAUDCTRLB = 0 ;
USARTC0.CTRLB = 0x18 ; USARTC0.CTRLB = 0x18 ;
USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ; USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ;
USARTC0.CTRLC = 0x03 ; USARTC0.CTRLC = 0x03 ;
} #else
#else #ifdef STM32_board
#ifdef STM32_board Serial2.begin(9600);//USART3
Serial2.begin(9600);//USART3
USART3_BASE->CR1 &= ~ USART_CR1_RE;//disable RX leave TX enabled USART3_BASE->CR1 &= ~ USART_CR1_RE;//disable RX leave TX enabled
} #else
#else
//9600 bauds //9600 bauds
UBRR0H = 0x00; UBRR0H = 0x00;
UBRR0L = 0x67; UBRR0L = 0x67;
UCSR0A = 0 ; // Clear X2 bit UCSR0A = 0 ; // Clear X2 bit
//Set frame format to 8 data bits, none, 1 stop bit //Set frame format to 8 data bits, none, 1 stop bit
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00); UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
#endif
#endif
} }
else if(speed==SPEED_57600)
{ // 57600
#ifdef XMEGA
/*USARTC0.BAUDCTRLA = 207 ;
USARTC0.BAUDCTRLB = 0 ;
USARTC0.CTRLB = 0x18 ;
USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ;
USARTC0.CTRLC = 0x03 ;*/
#else
#ifdef STM32_board
Serial2.begin(57600);//USART3
USART3_BASE->CR1 &= ~ USART_CR1_RE;//disable RX leave TX enabled
#else
//57600 bauds
UBRR0H = 0x00;
UBRR0L = 0x22;
UCSR0A = 0x02 ; // Set X2 bit
//Set frame format to 8 data bits, none, 1 stop bit
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
#endif
#endif
}
else if(speed==SPEED_125K)
{ // 125000
#ifdef XMEGA
/*USARTC0.BAUDCTRLA = 207 ;
USARTC0.BAUDCTRLB = 0 ;
USARTC0.CTRLB = 0x18 ;
USARTC0.CTRLA = (USARTC0.CTRLA & 0xCF) | 0x10 ;
USARTC0.CTRLC = 0x03 ;*/
#else
#ifdef STM32_board
Serial2.begin(125000);//USART3
USART3_BASE->CR1 &= ~ USART_CR1_RE;//disable RX leave TX enabled
#else
//125000 bauds
UBRR0H = 0x00;
UBRR0L = 0x07;
UCSR0A = 0x00 ; // Clear X2 bit
//Set frame format to 8 data bits, none, 1 stop bit
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
#endif
#endif
}
#endif
#ifndef XMEGA
#ifndef STM32_board
UCSR0B |= (1<<TXEN0);//tx enable UCSR0B |= (1<<TXEN0);//tx enable
#endif #endif
#endif #endif
} }
//Serial TX //Serial TX
#ifdef XMEGA #ifdef XMEGA
ISR(USARTC0_DRE_vect) ISR(USARTC0_DRE_vect)
#else #else
#if defined STM32_board #if defined STM32_board
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
void __irq_usart3() void __irq_usart3()
#else #else
ISR(USART_UDRE_vect) ISR(USART_UDRE_vect)
#endif #endif
#endif #endif
{ // Transmit interrupt { // Transmit interrupt
#if defined STM32_board #if defined STM32_board
if(USART3_BASE->SR & USART_SR_TXE) { if(USART3_BASE->SR & USART_SR_TXE) {
#endif #endif
if(tx_head!=tx_tail) if(tx_head!=tx_tail)
{ {
if(++tx_tail>=TXBUFFER_SIZE)//head if(++tx_tail>=TXBUFFER_SIZE)//head
tx_tail=0; tx_tail=0;
#if defined STM32_board #if defined STM32_board
USART3_BASE->DR=tx_buff[tx_tail];//clears TXE bit USART3_BASE->DR=tx_buff[tx_tail];//clears TXE bit
#else #else
UDR0=tx_buff[tx_tail]; UDR0=tx_buff[tx_tail];
#endif #endif
} }
if (tx_tail == tx_head) if (tx_tail == tx_head)
#if defined STM32_board #if defined STM32_board
USART3_BASE->CR1 &= ~USART_CR1_TXEIE;//disable interrupt USART3_BASE->CR1 &= ~USART_CR1_TXEIE;//disable interrupt
} }
#else #else
tx_pause(); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt tx_pause(); // Check if all data is transmitted . if yes disable transmitter UDRE interrupt
#endif #endif
} }
#if defined STM32_board #if defined STM32_board
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif
#endif #endif
@ -572,11 +640,10 @@ void initTXSerial( uint8_t speed)
{ {
TIMSK0 = 0 ; // Stop all timer 0 interrupts TIMSK0 = 0 ; // Stop all timer 0 interrupts
#ifdef INVERT_SERIAL #ifdef INVERT_SERIAL
PORTD &= ~2 ; SERIAL_TX_off;
#else #else
PORTD |= 2 ; SERIAL_TX_on;
#endif #endif
DDRD |= 2 ; // TxD pin is an output
UCSR0B &= ~(1<<TXEN0) ; UCSR0B &= ~(1<<TXEN0) ;
SerialControl.speed = speed ; SerialControl.speed = speed ;
@ -612,7 +679,7 @@ void Serial_write( uint8_t byte )
#else #else
byteLo |= 0xFC ; // Stop bits byteLo |= 0xFC ; // Stop bits
#endif #endif
// calc parity // calc parity
temp = byte ; temp = byte ;
temp >>= 4 ; temp >>= 4 ;
temp = byte ^ temp ; temp = byte ^ temp ;
@ -637,13 +704,19 @@ void Serial_write( uint8_t byte )
#ifdef INVERT_SERIAL #ifdef INVERT_SERIAL
byte |= 1 ; // Start bit byte |= 1 ; // Start bit
#endif #endif
uint8_t next = (SerialControl.head + 2) & 0x3f ; uint8_t next = (SerialControl.head + 2) & 0x3f ;
if ( next != SerialControl.tail ) if ( next != SerialControl.tail )
{ {
SerialControl.data[SerialControl.head] = byte ; SerialControl.data[SerialControl.head] = byte ;
SerialControl.data[SerialControl.head+1] = byteLo ; SerialControl.data[SerialControl.head+1] = byteLo ;
SerialControl.head = next ; SerialControl.head = next ;
} }
if(!IS_TX_PAUSE_on)
tx_resume();
}
void resumeBashSerial()
{
cli() ; cli() ;
if ( SerialControl.busy == 0 ) if ( SerialControl.busy == 0 )
{ {
@ -684,13 +757,9 @@ ISR(TIMER0_COMPA_vect)
uint8_t byte ; uint8_t byte ;
byte = GPIOR0 ; byte = GPIOR0 ;
if ( byte & 0x01 ) if ( byte & 0x01 )
{ SERIAL_TX_on;
PORTD |= 0x02 ;
}
else else
{ SERIAL_TX_off;
PORTD &= ~0x02 ;
}
byte /= 2 ; // Generates shorter code than byte >>= 1 byte /= 2 ; // Generates shorter code than byte >>= 1
GPIOR0 = byte ; GPIOR0 = byte ;
if ( --GPIOR1 == 0 ) if ( --GPIOR1 == 0 )
@ -709,34 +778,38 @@ ISR(TIMER0_COMPB_vect)
uint8_t byte ; uint8_t byte ;
byte = GPIOR2 ; byte = GPIOR2 ;
if ( byte & 0x01 ) if ( byte & 0x01 )
{ SERIAL_TX_on;
PORTD |= 0x02 ;
}
else else
{ SERIAL_TX_off;
PORTD &= ~0x02 ;
}
byte /= 2 ; // Generates shorter code than byte >>= 1 byte /= 2 ; // Generates shorter code than byte >>= 1
GPIOR2 = byte ; GPIOR2 = byte ;
if ( --GPIOR1 == 0 ) if ( --GPIOR1 == 0 )
{ {
// prepare next byte and allow for 2 stop bits if ( IS_TX_PAUSE_on )
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<<OCIE0A) ;
}
else
{ {
SerialControl.busy = 0 ; SerialControl.busy = 0 ;
TIMSK0 &= ~(1<<OCIE0B) ; TIMSK0 &= ~(1<<OCIE0B) ;
} }
else
{
// 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<<OCIE0A) ;
}
else
{
SerialControl.busy = 0 ;
TIMSK0 &= ~(1<<OCIE0B) ;
}
}
} }
else else
{ {
@ -756,13 +829,9 @@ ISR(TIMER0_OVF_vect)
byte = GPIOR2 ; byte = GPIOR2 ;
} }
if ( byte & 0x01 ) if ( byte & 0x01 )
{ SERIAL_TX_on;
PORTD |= 0x02 ;
}
else else
{ SERIAL_TX_off;
PORTD &= ~0x02 ;
}
byte /= 2 ; // Generates shorter code than byte >>= 1 byte /= 2 ; // Generates shorter code than byte >>= 1
if ( GPIOR1 > 2 ) if ( GPIOR1 > 2 )
{ {

View File

@ -1,37 +1,19 @@
/* /*
This project is free software: you can redistribute it and/or modify This project is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Multiprotocol is distributed in the hope that it will be useful, Multiprotocol is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>. along with Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/ */
/**Board selection**/
#define STM32_board
//#define XMEGA
/*******************/
#ifdef STM32_board
#undef __cplusplus
#include "Multiprotocol_STM32.h"
#include <EEPROM.h>
#include <libmaple/usart.h>
#include <libmaple/timer.h>
#include <SPI.h>
#else
#include <avr/eeprom.h>
#include <util/delay.h>
#include "Multiprotocol.h"
#endif
/** Multiprotocol module configuration file ***/ /** Multiprotocol module configuration file ***/
@ -48,59 +30,58 @@
#define CC2500_INSTALLED #define CC2500_INSTALLED
#define NFR24L01_INSTALLED #define NFR24L01_INSTALLED
//Comment a protocol to exclude it from compilation //The protocols below need an A7105 to be installed
#ifdef A7105_INSTALLED #define FLYSKY_A7105_INO
#define FLYSKY_A7105_INO #define HUBSAN_A7105_INO
#define HUBSAN_A7105_INO
#endif //The protocols below need a CYRF6936 to be installed
#ifdef CYRF6936_INSTALLED #define DEVO_CYRF6936_INO
#define DEVO_CYRF6936_INO #define DSM2_CYRF6936_INO
#define DSM2_CYRF6936_INO #define J6PRO_CYRF6936_INO
#define J6PRO_CYRF6936_INO
#endif //The protocols below need a CC2500 to be installed
#ifdef CC2500_INSTALLED #define FRSKYD_CC2500_INO
#define FRSKYD_CC2500_INO #define FRSKYV_CC2500_INO
#define FRSKYV_CC2500_INO #define FRSKYX_CC2500_INO
#define FRSKYX_CC2500_INO #define SFHSS_CC2500_INO
#define SFHSS_CC2500_INO
#endif //The protocols below need a NRF24L01 to be installed
#ifdef NFR24L01_INSTALLED #define BAYANG_NRF24L01_INO
#define BAYANG_NRF24L01_INO #define CG023_NRF24L01_INO
#define CG023_NRF24L01_INO #define CX10_NRF24L01_INO
#define CX10_NRF24L01_INO #define ESKY_NRF24L01_INO
#define ESKY_NRF24L01_INO #define HISKY_NRF24L01_INO
#define HISKY_NRF24L01_INO #define KN_NRF24L01_INO
#define KN_NRF24L01_INO #define SLT_NRF24L01_INO
#define SLT_NRF24L01_INO #define SYMAX_NRF24L01_INO
#define SYMAX_NRF24L01_INO #define V2X2_NRF24L01_INO
#define V2X2_NRF24L01_INO #define YD717_NRF24L01_INO
#define YD717_NRF24L01_INO #define MT99XX_NRF24L01_INO
#define MT99XX_NRF24L01_INO #define MJXQ_NRF24L01_INO
#define MJXQ_NRF24L01_INO #define SHENQI_NRF24L01_INO
#define SHENQI_NRF24L01_INO #define FY326_NRF24L01_INO
#define FY326_NRF24L01_INO #define FQ777_NRF24L01_INO
#define FQ777_NRF24L01_INO #define ASSAN_NRF24L01_INO
#define ASSAN_NRF24L01_INO #define HONTAI_NRF24L01_INO
#endif
/**************************/
/*** TELEMETRY SETTINGS ***/
/**************************/
//In this section you can configure the telemetry.
//Uncomment to enable telemetry //Uncomment to enable telemetry
#define TELEMETRY #define TELEMETRY
//Uncomment to invert the polarity of the telemetry serial signal. //Uncomment to invert the polarity of the telemetry serial signal.
//For ER9X and ERSKY9X it must be commented. For OpenTX it must be uncommented. //For ER9X and ERSKY9X it must be commented. For OpenTX it must be uncommented.
//#define INVERT_TELEMETRY 1 //#define INVERT_TELEMETRY
//Comment to disable a specific telemetry //Comment to disable a specific telemetry
#if defined(TELEMETRY) #define DSM_TELEMETRY
#if defined DSM2_CYRF6936_INO #define SPORT_TELEMETRY
#define DSM_TELEMETRY #define HUB_TELEMETRY
#endif
#if defined FRSKYX_CC2500_INO
#define SPORT_TELEMETRY
#endif
#if defined FRSKYD_CC2500_INO
#define HUB_TELEMETRY
#endif
#endif
/****************************/ /****************************/
@ -125,10 +106,11 @@
//It is important for the module to know the endpoints of your radio. //It is important for the module to know the endpoints of your radio.
//Below are some standard transmitters already preconfigured. //Below are some standard transmitters already preconfigured.
//Uncomment only the one which matches your transmitter. //Uncomment only the one which matches your transmitter.
#define TX_ER9X //ER9X/ERSKY9X/OpenTX ( 988<->2012µs) #define TX_ER9X //ER9X/ERSKY9X/OpenTX ( 988<->2012µs)
//#define TX_DEVO7 //DEVO (1120<->1920µs) //#define TX_DEVO7 //DEVO (1120<->1920µs)
//#define TX_SPEKTRUM //Spektrum (1100<->1900µs) //#define TX_SPEKTRUM //Spektrum (1100<->1900µs)
//#define TX_HISKY //HISKY (1100<->1900µs) //#define TX_HISKY //HISKY (1100<->1900µs)
//#define TX_MPX //Multiplex MC2020 (1250<->1950µs)
//#define TX_CUSTOM //Custom //#define TX_CUSTOM //Custom
// The lines below are used to set the end points in microseconds (µs) if you have selected TX_CUSTOM. // The lines below are used to set the end points in microseconds (µs) if you have selected TX_CUSTOM.
@ -138,10 +120,10 @@
// - 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. // - 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 // - 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) #if defined(TX_CUSTOM)
#define PPM_MAX_100 1900 // 100% #define PPM_MAX_100 1900 // 100%
#define PPM_MIN_100 1100 // 100% #define PPM_MIN_100 1100 // 100%
#define PPM_MAX_125 2000 // 125% #define PPM_MAX_125 2000 // 125%
#define PPM_MIN_125 1000 // 125% #define PPM_MIN_125 1000 // 125%
#endif #endif
/* /*
@ -157,22 +139,22 @@ struct PPM_Parameters
*/ */
//Update this table to set which protocol and all associated settings are called for the corresponding dial number //Update this table to set which protocol and all associated settings are called for the corresponding dial number
const PPM_Parameters PPM_prot[15]= { const PPM_Parameters PPM_prot[15]= {
// Dial Protocol Sub protocol RX_Num Power Auto Bind Option // Dial Protocol Sub protocol RX_Num Power Auto Bind Option
/* 1 */ {MODE_FLYSKY, Flysky , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 1 */ {MODE_FLYSKY, Flysky , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 2 */ {MODE_HUBSAN, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 2 */ {MODE_HUBSAN, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 3 */ {MODE_FRSKYD, 0 , 0 , P_HIGH , NO_AUTOBIND , 40 }, // D7 fine tuning /* 3 */ {MODE_FRSKYD, 0 , 0 , P_HIGH , NO_AUTOBIND , 40 }, // option=fine freq tuning
/* 4 */ {MODE_HISKY , Hisky , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 4 */ {MODE_HISKY , Hisky , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 5 */ {MODE_V2X2 , 0 , 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_DSM , DSM2_22 , 0 , P_HIGH , NO_AUTOBIND , 6 }, // option=number of channels
/* 7 */ {MODE_DEVO , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 7 */ {MODE_DEVO , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 8 */ {MODE_YD717 , YD717 , 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 }, /* 9 */ {MODE_KN , WLTOYS , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 10 */ {MODE_SYMAX , SYMAX , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 10 */ {MODE_SYMAX , SYMAX , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 11 */ {MODE_SLT , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 11 */ {MODE_SLT , 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 12 */ {MODE_CX10 , CX10_BLUE , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 12 */ {MODE_CX10 , CX10_BLUE , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 13 */ {MODE_CG023 , CG023 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 13 */ {MODE_CG023 , CG023 , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 14 */ {MODE_BAYANG, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 }, /* 14 */ {MODE_BAYANG, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 15 */ {MODE_SYMAX , SYMAX5C , 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:
MODE_FLYSKY MODE_FLYSKY
@ -182,16 +164,18 @@ const PPM_Parameters PPM_prot[15]= {
V912 V912
MODE_HUBSAN MODE_HUBSAN
NONE NONE
MODE_FRSKY MODE_FRSKYD
NONE NONE
MODE_HISKY MODE_HISKY
Hisky Hisky
HK310 HK310
MODE_V2X2 MODE_V2X2
NONE NONE
MODE_DSM2 MODE_DSM
DSM2 DSM2_22
DSMX DSM2_11
DSMX_22
DSMX_11
MODE_DEVO MODE_DEVO
NONE NONE
MODE_YD717 MODE_YD717
@ -232,21 +216,32 @@ const PPM_Parameters PPM_prot[15]= {
MT99 MT99
H7 H7
YZ YZ
LS
MODE_MJXQ MODE_MJXQ
WLH08 WLH08
X600 X600
X800 X800
H26D H26D
E010
MODE_SHENQI MODE_SHENQI
NONE NONE
MODE_FY326 MODE_FY326
NONE NONE
MODE_SFHSS MODE_SFHSS
NONE NONE
MODE_J6PRO
NONE
MODE_FQ777 MODE_FQ777
NONE NONE
MODE_ASSAN MODE_ASSAN
NONE NONE
MODE_FRSKYV
NONE
MODE_HONTAI
FORMAT_HONTAI
FORMAT_JJRCX1
FORMAT_X5C1
RX_Num value between 0 and 15 RX_Num value between 0 and 15