mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-04 17:48:11 +00:00
FrSky 1way protocol + cosmetic
This commit is contained in:
parent
eabfd8b5c4
commit
7b65233699
@ -23,12 +23,12 @@
|
||||
void A7105_WriteData(uint8_t len, uint8_t channel)
|
||||
{
|
||||
uint8_t i;
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(A7105_RST_WRPTR);
|
||||
SPI_Write(0x05);
|
||||
for (i = 0; i < len; i++)
|
||||
SPI_Write(packet[i]);
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
A7105_WriteReg(0x0F, channel);
|
||||
A7105_Strobe(A7105_TX);
|
||||
}
|
||||
@ -36,27 +36,27 @@ void A7105_WriteData(uint8_t len, uint8_t channel)
|
||||
void A7105_ReadData() {
|
||||
uint8_t i;
|
||||
A7105_Strobe(0xF0); //A7105_RST_RDPTR
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(0x45);
|
||||
for (i=0;i<16;i++)
|
||||
packet[i]=A7105_Read();
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
}
|
||||
|
||||
void A7105_WriteReg(uint8_t address, uint8_t data) {
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(address);
|
||||
NOP();
|
||||
SPI_Write(data);
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
}
|
||||
|
||||
uint8_t A7105_ReadReg(uint8_t address) {
|
||||
uint8_t result;
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(address |=0x40); //bit 6 =1 for reading
|
||||
result = A7105_Read();
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
return(result);
|
||||
}
|
||||
|
||||
@ -110,13 +110,13 @@ uint8_t A7105_Reset()
|
||||
}
|
||||
|
||||
void A7105_WriteID(uint32_t ida) {
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(0x06);//ex id=0x5475c52a ;txid3txid2txid1txid0
|
||||
SPI_Write((ida>>24)&0xff);//53
|
||||
SPI_Write((ida>>16)&0xff);//75
|
||||
SPI_Write((ida>>8)&0xff);//c5
|
||||
SPI_Write((ida>>0)&0xff);//2a
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -162,9 +162,9 @@ void A7105_SetPower()
|
||||
}
|
||||
|
||||
void A7105_Strobe(uint8_t address) {
|
||||
CS_off;
|
||||
A7105_CS_off;
|
||||
SPI_Write(address);
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
}
|
||||
|
||||
const uint8_t PROGMEM HUBSAN_A7105_regs[] = {
|
||||
|
185
Multiprotocol/FrSky1_cc2500.ino
Normal file
185
Multiprotocol/FrSky1_cc2500.ino
Normal file
@ -0,0 +1,185 @@
|
||||
/*
|
||||
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
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#if defined(FRSKY1_CC2500_INO)
|
||||
|
||||
#include "iface_cc2500.h"
|
||||
|
||||
static void __attribute__((unused)) FRSKY1_init()
|
||||
{
|
||||
CC2500_WriteReg(CC2500_17_MCSM1, 0x0c);
|
||||
CC2500_WriteReg(CC2500_18_MCSM0, 0x18);
|
||||
CC2500_WriteReg(CC2500_06_PKTLEN, 0xff);
|
||||
CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x04);
|
||||
CC2500_WriteReg(CC2500_08_PKTCTRL0, 0x05);
|
||||
CC2500_WriteReg(CC2500_3E_PATABLE, 0xfe);
|
||||
CC2500_WriteReg(CC2500_0B_FSCTRL1, 0x08);
|
||||
CC2500_WriteReg(CC2500_0C_FSCTRL0, option);
|
||||
CC2500_WriteReg(CC2500_0D_FREQ2, 0x5c);
|
||||
CC2500_WriteReg(CC2500_0E_FREQ1, 0x58);
|
||||
CC2500_WriteReg(CC2500_0F_FREQ0, 0x9d);
|
||||
CC2500_WriteReg(CC2500_10_MDMCFG4, 0xaa);
|
||||
CC2500_WriteReg(CC2500_11_MDMCFG3, 0x10);
|
||||
CC2500_WriteReg(CC2500_12_MDMCFG2, 0x93);
|
||||
CC2500_WriteReg(CC2500_13_MDMCFG1, 0x23);
|
||||
CC2500_WriteReg(CC2500_14_MDMCFG0, 0x7a);
|
||||
CC2500_WriteReg(CC2500_15_DEVIATN, 0x41);
|
||||
for(uint8_t i=19;i<36;i++)
|
||||
{
|
||||
uint8_t reg=pgm_read_byte_near(&cc2500_conf[i][0]);
|
||||
uint8_t val=pgm_read_byte_near(&cc2500_conf[i][1]);
|
||||
CC2500_WriteReg(reg,val);
|
||||
}
|
||||
|
||||
CC2500_SetTxRxMode(TX_EN);
|
||||
CC2500_SetPower();
|
||||
|
||||
CC2500_Strobe(CC2500_SIDLE); // Go to idle...
|
||||
prev_option = option ;
|
||||
}
|
||||
|
||||
static uint8_t __attribute__((unused)) FRSKY1_crc8(uint8_t result, uint8_t *data, uint8_t len, uint8_t polynomial)
|
||||
{
|
||||
for(uint8_t i = 0; i < len; i++)
|
||||
{
|
||||
result = result ^ data[i];
|
||||
for(uint8_t j = 0; j < 8; j++)
|
||||
if(result & 0x80)
|
||||
result = (result << 1) ^ polynomial;
|
||||
else
|
||||
result = result << 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint8_t __attribute__((unused)) FRSKY1_crc8_le(uint8_t init, u8 *data, uint8_t len)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
result = (result << 1) | (init & 0x01);
|
||||
init >>= 1;
|
||||
}
|
||||
return FRSKY1_crc8(result,data,len,0x83);
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) FRSKY1_build_bind_packet()
|
||||
{
|
||||
//0e 03 01 57 12 00 06 0b 10 15 1a 00 00 00 61
|
||||
packet[0] = 0x0e; //Length
|
||||
packet[1] = 0x03; //Packet type
|
||||
packet[2] = 0x01; //Packet type
|
||||
packet[3] = rx_tx_addr[3];
|
||||
packet[4] = rx_tx_addr[2];
|
||||
packet[5] = ((state - FRSKY_BIND) % 10) * 5;
|
||||
packet[6] = packet[5] * 5 + 6;
|
||||
packet[7] = packet[5] * 5 + 11;
|
||||
packet[8] = packet[5] * 5 + 16;
|
||||
packet[9] = packet[5] * 5 + 21;
|
||||
packet[10] = packet[5] * 5 + 26;
|
||||
packet[11] = 0x00;
|
||||
packet[12] = 0x00;
|
||||
packet[13] = 0x00;
|
||||
packet[14] = FRSKY1_crc8(0x93, packet, 14, 0x07);
|
||||
}
|
||||
|
||||
static uint8_t __attribute__((unused)) FRSKY1_calc_channel()
|
||||
{
|
||||
uint32_t temp=seed;
|
||||
temp = (temp * 0xaa) % 0x7673;
|
||||
seed = temp;
|
||||
return (seed & 0xff) % 0x32;
|
||||
}
|
||||
|
||||
static void __attribute__((unused)) FRSKY1_build_data_packet()
|
||||
{
|
||||
packet[0] = 0x0e;
|
||||
packet[1] = rx_tx_addr[3];
|
||||
packet[2] = rx_tx_addr[2];
|
||||
packet[3] = seed & 0xff;
|
||||
packet[4] = seed >> 8;
|
||||
if (state == FRSKY_DATA1 || state == FRSKY_DATA3)
|
||||
packet[5] = 0x0f;
|
||||
else
|
||||
if(state == FRSKY_DATA2 || state == FRSKY_DATA4)
|
||||
packet[5] = 0xf0;
|
||||
else
|
||||
packet[5] = 0x00;
|
||||
uint8_t idx = 0; //= (state == FRSKY_DATA1) ? 4 : 0;
|
||||
for(uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
uint16_t value = convert_channel_frsky(i+idx);
|
||||
packet[2*i + 6] = value & 0xff;
|
||||
packet[2*i + 7] = value >> 8;
|
||||
}
|
||||
packet[14] = FRSKY1_crc8(crc8, packet, 14, 0x07);
|
||||
}
|
||||
|
||||
static uint16_t ReadFRSKY1()
|
||||
{
|
||||
if (state < FRSKY_BIND_DONE)
|
||||
{
|
||||
FRSKY1_build_bind_packet();
|
||||
CC2500_Strobe(CC2500_SIDLE);
|
||||
CC2500_WriteReg(CC2500_0A_CHANNR, 0x00);
|
||||
CC2500_WriteData(packet, packet[0]+1);
|
||||
state++;
|
||||
return 53460;
|
||||
}
|
||||
if (state == FRSKY_BIND_DONE)
|
||||
{
|
||||
state++;
|
||||
BIND_DONE;
|
||||
}
|
||||
if (state >= FRSKY_DATA1)
|
||||
{
|
||||
CC2500_Strobe(CC2500_SIDLE);
|
||||
if (option != prev_option)
|
||||
{
|
||||
CC2500_WriteReg(CC2500_0C_FSCTRL0, option);
|
||||
prev_option=option;
|
||||
}
|
||||
uint8_t chan = FRSKY1_calc_channel();
|
||||
CC2500_WriteReg(CC2500_0A_CHANNR, chan * 5 + 6);
|
||||
FRSKY1_build_data_packet();
|
||||
|
||||
CC2500_WriteData(packet, packet[0]+1);
|
||||
if (state == FRSKY_DATA5)
|
||||
{
|
||||
CC2500_SetPower();
|
||||
state = FRSKY_DATA1;
|
||||
}
|
||||
else
|
||||
state++;
|
||||
return 9006;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t initFRSKY1()
|
||||
{
|
||||
//u8 data[2] = {(fixed_id >> 8) & 0xff, fixed_id & 0xff};
|
||||
crc8 = FRSKY1_crc8_le(0x6b, rx_tx_addr+2, 2); // Use rx_tx_addr[2] and rx_tx_addr[3] since we want to use RX_Num
|
||||
FRSKY1_init();
|
||||
seed = 1;
|
||||
if(IS_AUTOBIND_FLAG_on)
|
||||
state = FRSKY_BIND;
|
||||
else
|
||||
state = FRSKY_DATA1;
|
||||
return 10000;
|
||||
}
|
||||
|
||||
#endif
|
@ -17,26 +17,9 @@
|
||||
|
||||
#include "iface_cc2500.h"
|
||||
|
||||
//##########Variables########
|
||||
//uint32_t state;
|
||||
//uint8_t len;
|
||||
|
||||
/*
|
||||
enum {
|
||||
FRSKY_BIND = 0,
|
||||
FRSKY_BIND_DONE = 1000,
|
||||
FRSKY_DATA1,
|
||||
FRSKY_DATA2,
|
||||
FRSKY_DATA3,
|
||||
FRSKY_DATA4,
|
||||
FRSKY_DATA5
|
||||
};
|
||||
*/
|
||||
|
||||
static void __attribute__((unused)) frsky2way_init(uint8_t bind)
|
||||
{
|
||||
// Configure cc2500 for tx mode
|
||||
CC2500_Reset();
|
||||
//
|
||||
for(uint8_t i=0;i<36;i++)
|
||||
{
|
||||
@ -142,9 +125,9 @@ static void __attribute__((unused)) frsky2way_data_frame()
|
||||
uint16_t initFrSky_2way()
|
||||
{
|
||||
if(IS_AUTOBIND_FLAG_on)
|
||||
{
|
||||
{
|
||||
frsky2way_init(1);
|
||||
state = FRSKY_BIND;//
|
||||
state = FRSKY_BIND;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -52,7 +52,8 @@ enum PROTOCOLS
|
||||
MODE_SFHSS = 21, // =>CC2500
|
||||
MODE_J6PRO = 22, // =>CYRF6936
|
||||
MODE_FQ777 = 23, // =>NRF24L01
|
||||
MODE_ASSAN = 24 // =>NRF24L01
|
||||
MODE_ASSAN = 24, // =>NRF24L01
|
||||
MODE_FRSKY1 = 25 // =>CC2500
|
||||
};
|
||||
|
||||
enum Flysky
|
||||
@ -148,21 +149,22 @@ struct PPM_Parameters
|
||||
//*******************
|
||||
//*** Pinouts ***
|
||||
//*******************
|
||||
#define LED_pin 13 //Promini original led on B5
|
||||
#define PPM_pin 3 //PPM-D3
|
||||
#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
|
||||
#define SDI_pin 6 //SDIO-D6
|
||||
#else
|
||||
#define SDI_pin 5 //SDIO-D5
|
||||
#define SDI_pin 5 //D5 = PD5
|
||||
#endif
|
||||
#define SCLK_pin 4 //SCK-D4
|
||||
#define CS_pin 2 //CS-D2
|
||||
#define SDO_pin 6 //D6
|
||||
#define CC25_CSN_pin 7
|
||||
#define NRF_CSN_pin 8
|
||||
#define CYRF_CSN_pin 9
|
||||
#define CTRL1 1 //C1 (A1)
|
||||
#define CTRL2 2 //C2 (A2)
|
||||
#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
|
||||
@ -177,39 +179,39 @@ struct PPM_Parameters
|
||||
#endif
|
||||
//
|
||||
#ifdef XMEGA
|
||||
#define CS_on PORTD.OUTSET = _BV(4) //D4
|
||||
#define CS_off PORTD.OUTCLR = _BV(4) //D4
|
||||
#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
|
||||
#define A7105_CS_on PORTD |= _BV(2) //D2
|
||||
#define A7105_CS_off PORTD &= ~_BV(2) //D2
|
||||
#endif
|
||||
//
|
||||
#ifdef XMEGA
|
||||
#define SCK_on PORTD.OUTSET = _BV(7) //D7
|
||||
#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
|
||||
#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_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
|
||||
#define SDI_on PORTD |= _BV(5) //D5
|
||||
#define SDI_off PORTD &= ~_BV(5) //D5
|
||||
#endif
|
||||
//
|
||||
#ifdef XMEGA
|
||||
#define SDI_1 (PORTD.IN & (1<<SDI_pin)) == (1<<SDI_pin) //D5
|
||||
#define SDI_0 (PORTD.IN & (1<<SDI_pin)) == 0x00 //D5
|
||||
#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 & (1<<SDI_pin)) == (1<<SDI_pin) //D5
|
||||
#define SDI_0 (PIND & (1<<SDI_pin)) == 0x00 //D5
|
||||
#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
|
||||
#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
|
||||
@ -230,19 +232,21 @@ struct PPM_Parameters
|
||||
#ifdef XMEGA
|
||||
#define CYRF_CSN_on PORTD.OUTSET = _BV(4)
|
||||
#define CYRF_CSN_off PORTD.OUTCLR = _BV(4)
|
||||
#define CYRF_RST 0
|
||||
#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 5
|
||||
#endif
|
||||
//
|
||||
#ifdef XMEGA
|
||||
#define SDO_1 (PORTD.IN & (1<<SDO_pin)) == (1<<SDO_pin) //D6
|
||||
#define SDO_0 (PORTD.IN & (1<<SDO_pin)) == 0x00 //D6
|
||||
#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 & (1<<SDO_pin)) == (1<<SDO_pin) //D6
|
||||
#define SDO_0 (PIND & (1<<SDO_pin)) == 0x00 //D6
|
||||
#define SDO_1 (PIND & _BV(SDO_pin)) == _BV(SDO_pin) //D6
|
||||
#define SDO_0 (PIND & _BV(SDO_pin)) == 0x00 //D6
|
||||
#endif
|
||||
//
|
||||
//
|
||||
@ -510,6 +514,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
||||
J6PRO 22
|
||||
FQ777 23
|
||||
ASSAN 24
|
||||
FRSKY1 25
|
||||
BindBit=> 0x80 1=Bind/0=No
|
||||
AutoBindBit=> 0x40 1=Yes /0=No
|
||||
RangeCheck=> 0x20 1=Yes /0=No
|
||||
|
@ -64,6 +64,8 @@ uint8_t rf_ch_num;
|
||||
uint8_t throttle, rudder, elevator, aileron;
|
||||
uint8_t flags;
|
||||
uint16_t crc;
|
||||
uint8_t crc8;
|
||||
uint16_t seed;
|
||||
//
|
||||
uint16_t state;
|
||||
uint8_t len;
|
||||
@ -148,16 +150,15 @@ void setup()
|
||||
PORTE.OUTCLR = 0x01 ;
|
||||
#else
|
||||
// General pinout
|
||||
DDRD = (1<<CS_pin)|(1<<SDI_pin)|(1<<SCLK_pin)|(1<<CS_pin)|(1<< CC25_CSN_pin);
|
||||
DDRC = (1<<CTRL1)|(1<<CTRL2); //output
|
||||
//DDRC |= (1<<5);//RST pin A5(C5) CYRF output
|
||||
DDRB = _BV(0)|_BV(1);
|
||||
PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(5);//pullup 10,11,12 and bind button
|
||||
PORTC = _BV(0);//A0 high pullup
|
||||
DDRD = _BV(A7105_CS_pin)|_BV(SDI_pin)|_BV(SCLK_pin)|_BV( CC25_CSN_pin);//pin output
|
||||
DDRC = _BV(CTRL1_pin)|_BV(CTRL2_pin)|_BV(CYRF_RST); //pin output
|
||||
DDRB = _BV(NRF_CSN_pin)|_BV(CYRF_CSN_pin); //pin output
|
||||
PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(BIND_pin); //pullup on dial (D10=PB2,D11=PB3,D12=PB4) and bind button
|
||||
PORTC = _BV(0); //pullup on dial (A0=PC0)
|
||||
#endif
|
||||
|
||||
// Set Chip selects
|
||||
CS_on;
|
||||
A7105_CS_on;
|
||||
CC25_CSN_on;
|
||||
NRF_CSN_on;
|
||||
CYRF_CSN_on;
|
||||
@ -237,8 +238,8 @@ void setup()
|
||||
|
||||
#ifndef XMEGA
|
||||
//Configure PPM interrupt
|
||||
EICRA |=(1<<ISC11); // The rising edge of INT1 pin D3 generates an interrupt request
|
||||
EIMSK |= (1<<INT1); // INT1 interrupt enable
|
||||
EICRA |=_BV(ISC11); // The rising edge of INT1 pin D3 generates an interrupt request
|
||||
EIMSK |= _BV(INT1); // INT1 interrupt enable
|
||||
#endif
|
||||
|
||||
#if defined(TELEMETRY)
|
||||
@ -285,14 +286,14 @@ void loop()
|
||||
else
|
||||
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait before callback
|
||||
#else
|
||||
if( (TIFR1 & (1<<OCF1A)) != 0)
|
||||
if( (TIFR1 & _BV(OCF1A)) != 0)
|
||||
{
|
||||
cli(); // Disable global int due to RW of 16 bits registers
|
||||
OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point.
|
||||
sei(); // Enable global int
|
||||
}
|
||||
else
|
||||
while((TIFR1 & (1<<OCF1A)) == 0); // Wait before callback
|
||||
while((TIFR1 & _BV(OCF1A)) == 0); // Wait before callback
|
||||
#endif
|
||||
do
|
||||
{
|
||||
@ -318,12 +319,12 @@ void loop()
|
||||
#else
|
||||
cli(); // Disable global int due to RW of 16 bits registers
|
||||
OCR1A += 2000*2 ; // set compare A for callback
|
||||
TIFR1=(1<<OCF1A); // clear compare A=callback flag
|
||||
TIFR1=_BV(OCF1A); // clear compare A=callback flag
|
||||
sei(); // enable global int
|
||||
Update_All();
|
||||
if(IS_CHANGE_PROTOCOL_FLAG_on)
|
||||
break; // Protocol has been changed
|
||||
while((TIFR1 & (1<<OCF1A)) == 0); // wait 2ms...
|
||||
while((TIFR1 & _BV(OCF1A)) == 0); // wait 2ms...
|
||||
#endif
|
||||
}
|
||||
// at this point we have a maximum of 4ms in next_callback
|
||||
@ -337,7 +338,7 @@ void loop()
|
||||
#else
|
||||
cli(); // Disable global int due to RW of 16 bits registers
|
||||
OCR1A+= next_callback ; // set compare A for callback
|
||||
TIFR1=(1<<OCF1A); // clear compare A=callback flag
|
||||
TIFR1=_BV(OCF1A); // clear compare A=callback flag
|
||||
diff=OCR1A-TCNT1; // compare timer and comparator
|
||||
sei(); // enable global int
|
||||
#endif
|
||||
@ -434,7 +435,7 @@ inline void tx_pause()
|
||||
USARTC0.CTRLA &= ~0x03 ; // Pause telemetry by disabling transmitter interrupt
|
||||
#else
|
||||
#ifndef BASH_SERIAL
|
||||
UCSR0B &= ~(1<<UDRIE0); // Pause telemetry by disabling transmitter interrupt
|
||||
UCSR0B &= ~_BV(UDRIE0); // Pause telemetry by disabling transmitter interrupt
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@ -447,7 +448,7 @@ inline void tx_resume()
|
||||
#ifdef XMEGA
|
||||
USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt
|
||||
#else
|
||||
UCSR0B |= (1<<UDRIE0); // Resume telemetry by enabling transmitter interrupt
|
||||
UCSR0B |= _BV(UDRIE0); // Resume telemetry by enabling transmitter interrupt
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@ -505,6 +506,14 @@ static void protocol_init()
|
||||
remote_callback = ReadFrSky_2way;
|
||||
break;
|
||||
#endif
|
||||
#if defined(FRSKY1_CC2500_INO)
|
||||
case MODE_FRSKY1:
|
||||
CTRL1_off; //antenna RF2
|
||||
CTRL2_on;
|
||||
next_callback = initFRSKY1();
|
||||
remote_callback = ReadFRSKY1;
|
||||
break;
|
||||
#endif
|
||||
#if defined(FRSKYX_CC2500_INO)
|
||||
case MODE_FRSKYX:
|
||||
CTRL1_off; //antenna RF2
|
||||
@ -670,7 +679,7 @@ static void protocol_init()
|
||||
#else
|
||||
OCR1A=TCNT1+next_callback*2; // set compare A for callback
|
||||
sei(); // enable global int
|
||||
TIFR1=(1<<OCF1A); // clear compare A flag
|
||||
TIFR1=_BV(OCF1A); // clear compare A flag
|
||||
#endif
|
||||
BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change
|
||||
}
|
||||
@ -728,7 +737,7 @@ void update_serial_data()
|
||||
#ifdef XMEGA
|
||||
cli();
|
||||
#else
|
||||
UCSR0B &= ~(1<<RXCIE0); // RX interrupt disable
|
||||
UCSR0B &= ~_BV(RXCIE0); // RX interrupt disable
|
||||
#endif
|
||||
if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid
|
||||
{ memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer
|
||||
@ -738,7 +747,7 @@ void update_serial_data()
|
||||
#ifdef XMEGA
|
||||
sei();
|
||||
#else
|
||||
UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable
|
||||
UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -847,11 +856,11 @@ void Mprotocol_serial_init()
|
||||
UBRR0L = UBRRL_VALUE;
|
||||
UCSR0A = 0 ; // Clear X2 bit
|
||||
//Set frame format to 8 data bits, even parity, 2 stop bits
|
||||
UCSR0C = (1<<UPM01)|(1<<USBS0)|(1<<UCSZ01)|(1<<UCSZ00);
|
||||
UCSR0C = _BV(UPM01)|_BV(USBS0)|_BV(UCSZ01)|_BV(UCSZ00);
|
||||
while ( UCSR0A & (1 << RXC0) )//flush receive buffer
|
||||
UDR0;
|
||||
//enable reception and RC complete interrupt
|
||||
UCSR0B = (1<<RXEN0)|(1<<RXCIE0);//rx enable and interrupt
|
||||
UCSR0B = _BV(RXEN0)|_BV(RXCIE0);//rx enable and interrupt
|
||||
#ifdef DEBUG_TX
|
||||
TX_SET_OUTPUT;
|
||||
#else
|
||||
@ -1104,7 +1113,7 @@ ISR(USART_RX_vect)
|
||||
#ifdef XMEGA
|
||||
if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error
|
||||
#else
|
||||
UCSR0B &= ~(1<<RXCIE0) ; // RX interrupt disable
|
||||
UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable
|
||||
sei() ;
|
||||
if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error
|
||||
#endif
|
||||
@ -1126,8 +1135,8 @@ ISR(USART_RX_vect)
|
||||
TCC1.INTCTRLB = (TCC1.INTCTRLB & 0xF3) | 0x04 ; // enable interrupt on compare B match
|
||||
#else
|
||||
OCR1B=TCNT1+6500L; // Full message should be received within timer of 3250us
|
||||
TIFR1=(1<<OCF1B); // clear OCR1B match flag
|
||||
TIMSK1 |=(1<<OCIE1B); // enable interrupt on compare B match
|
||||
TIFR1=_BV(OCF1B); // clear OCR1B match flag
|
||||
TIMSK1 |=_BV(OCIE1B); // enable interrupt on compare B match
|
||||
#endif
|
||||
idx++;
|
||||
}
|
||||
@ -1167,14 +1176,14 @@ ISR(USART_RX_vect)
|
||||
#ifdef XMEGA
|
||||
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
||||
#else
|
||||
TIMSK1 &=~(1<<OCIE1B); // Disable interrupt on compare B match
|
||||
TIMSK1 &=~_BV(OCIE1B); // Disable interrupt on compare B match
|
||||
#endif
|
||||
TX_RX_PAUSE_off;
|
||||
tx_resume();
|
||||
}
|
||||
#ifndef XMEGA
|
||||
cli() ;
|
||||
UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable
|
||||
UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1190,7 +1199,7 @@ ISR(TIMER1_COMPB_vect, ISR_NOBLOCK )
|
||||
#ifdef XMEGA
|
||||
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
||||
#else
|
||||
TIMSK1 &=~(1<<OCIE1B); // Disable interrupt on compare B match
|
||||
TIMSK1 &=~_BV(OCIE1B); // Disable interrupt on compare B match
|
||||
#endif
|
||||
tx_resume();
|
||||
}
|
||||
|
@ -50,6 +50,7 @@
|
||||
#endif
|
||||
#ifdef CC2500_INSTALLED
|
||||
#define FRSKY_CC2500_INO
|
||||
#define FRSKY1_CC2500_INO
|
||||
#define FRSKYX_CC2500_INO
|
||||
#define SFHSS_CC2500_INO
|
||||
#endif
|
||||
@ -238,6 +239,8 @@ const PPM_Parameters PPM_prot[15]= {
|
||||
NONE
|
||||
MODE_ASSAN
|
||||
NONE
|
||||
MODE_FRSKY1
|
||||
NONE
|
||||
*/
|
||||
|
||||
// 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...
|
||||
|
Loading…
x
Reference in New Issue
Block a user