mirror of
https://github.com/pascallanger/DIY-Multiprotocol-TX-Module.git
synced 2025-02-10 01:48:13 +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)
|
void A7105_WriteData(uint8_t len, uint8_t channel)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
CS_off;
|
A7105_CS_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]);
|
||||||
CS_on;
|
A7105_CS_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
|
||||||
CS_off;
|
A7105_CS_off;
|
||||||
SPI_Write(0x45);
|
SPI_Write(0x45);
|
||||||
for (i=0;i<16;i++)
|
for (i=0;i<16;i++)
|
||||||
packet[i]=A7105_Read();
|
packet[i]=A7105_Read();
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
void A7105_WriteReg(uint8_t address, uint8_t data) {
|
void A7105_WriteReg(uint8_t address, uint8_t data) {
|
||||||
CS_off;
|
A7105_CS_off;
|
||||||
SPI_Write(address);
|
SPI_Write(address);
|
||||||
NOP();
|
NOP();
|
||||||
SPI_Write(data);
|
SPI_Write(data);
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t A7105_ReadReg(uint8_t address) {
|
uint8_t A7105_ReadReg(uint8_t address) {
|
||||||
uint8_t result;
|
uint8_t result;
|
||||||
CS_off;
|
A7105_CS_off;
|
||||||
SPI_Write(address |=0x40); //bit 6 =1 for reading
|
SPI_Write(address |=0x40); //bit 6 =1 for reading
|
||||||
result = A7105_Read();
|
result = A7105_Read();
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,13 +110,13 @@ uint8_t A7105_Reset()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void A7105_WriteID(uint32_t ida) {
|
void A7105_WriteID(uint32_t ida) {
|
||||||
CS_off;
|
A7105_CS_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
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -162,9 +162,9 @@ void A7105_SetPower()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void A7105_Strobe(uint8_t address) {
|
void A7105_Strobe(uint8_t address) {
|
||||||
CS_off;
|
A7105_CS_off;
|
||||||
SPI_Write(address);
|
SPI_Write(address);
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t PROGMEM HUBSAN_A7105_regs[] = {
|
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"
|
#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)
|
static void __attribute__((unused)) frsky2way_init(uint8_t bind)
|
||||||
{
|
{
|
||||||
// Configure cc2500 for tx mode
|
// Configure cc2500 for tx mode
|
||||||
CC2500_Reset();
|
|
||||||
//
|
//
|
||||||
for(uint8_t i=0;i<36;i++)
|
for(uint8_t i=0;i<36;i++)
|
||||||
{
|
{
|
||||||
@ -144,7 +127,7 @@ uint16_t initFrSky_2way()
|
|||||||
if(IS_AUTOBIND_FLAG_on)
|
if(IS_AUTOBIND_FLAG_on)
|
||||||
{
|
{
|
||||||
frsky2way_init(1);
|
frsky2way_init(1);
|
||||||
state = FRSKY_BIND;//
|
state = FRSKY_BIND;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,8 @@ enum PROTOCOLS
|
|||||||
MODE_SFHSS = 21, // =>CC2500
|
MODE_SFHSS = 21, // =>CC2500
|
||||||
MODE_J6PRO = 22, // =>CYRF6936
|
MODE_J6PRO = 22, // =>CYRF6936
|
||||||
MODE_FQ777 = 23, // =>NRF24L01
|
MODE_FQ777 = 23, // =>NRF24L01
|
||||||
MODE_ASSAN = 24 // =>NRF24L01
|
MODE_ASSAN = 24, // =>NRF24L01
|
||||||
|
MODE_FRSKY1 = 25 // =>CC2500
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Flysky
|
enum Flysky
|
||||||
@ -148,21 +149,22 @@ struct PPM_Parameters
|
|||||||
//*******************
|
//*******************
|
||||||
//*** Pinouts ***
|
//*** Pinouts ***
|
||||||
//*******************
|
//*******************
|
||||||
#define LED_pin 13 //Promini original led on B5
|
#define LED_pin 5 //D13 = PB5
|
||||||
#define PPM_pin 3 //PPM-D3
|
#define BIND_pin 5 //D13 = PB5
|
||||||
|
#define PPM_pin 3 //D3 = PD3
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define SDI_pin 6 //SDIO-D6
|
#define SDI_pin 6 //SDIO-D6
|
||||||
#else
|
#else
|
||||||
#define SDI_pin 5 //SDIO-D5
|
#define SDI_pin 5 //D5 = PD5
|
||||||
#endif
|
#endif
|
||||||
#define SCLK_pin 4 //SCK-D4
|
#define SCLK_pin 4 //D4 = PD4
|
||||||
#define CS_pin 2 //CS-D2
|
#define A7105_CS_pin 2 //D2 = PD2
|
||||||
#define SDO_pin 6 //D6
|
#define SDO_pin 6 //D6 = PD6
|
||||||
#define CC25_CSN_pin 7
|
#define CC25_CSN_pin 7 //D7 = PD7
|
||||||
#define NRF_CSN_pin 8
|
#define NRF_CSN_pin 0 //D8 = PB0
|
||||||
#define CYRF_CSN_pin 9
|
#define CYRF_CSN_pin 1 //D9 = PB1
|
||||||
#define CTRL1 1 //C1 (A1)
|
#define CTRL1_pin 1 //A1 = PC1
|
||||||
#define CTRL2 2 //C2 (A2)
|
#define CTRL2_pin 2 //A2 = PC2
|
||||||
//
|
//
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define CTRL1_on
|
#define CTRL1_on
|
||||||
@ -177,11 +179,11 @@ struct PPM_Parameters
|
|||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define CS_on PORTD.OUTSET = _BV(4) //D4
|
#define A7105_CS_on PORTD.OUTSET = _BV(4) //D4
|
||||||
#define CS_off PORTD.OUTCLR = _BV(4) //D4
|
#define A7105_CS_off PORTD.OUTCLR = _BV(4) //D4
|
||||||
#else
|
#else
|
||||||
#define CS_on PORTD |= _BV(2) //D2
|
#define A7105_CS_on PORTD |= _BV(2) //D2
|
||||||
#define CS_off PORTD &= ~_BV(2) //D2
|
#define A7105_CS_off PORTD &= ~_BV(2) //D2
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
@ -201,11 +203,11 @@ struct PPM_Parameters
|
|||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define SDI_1 (PORTD.IN & (1<<SDI_pin)) == (1<<SDI_pin) //D5
|
#define SDI_1 (PORTD.IN & _BV(SDI_pin)) == _BV(SDI_pin) //D5
|
||||||
#define SDI_0 (PORTD.IN & (1<<SDI_pin)) == 0x00 //D5
|
#define SDI_0 (PORTD.IN & _BV(SDI_pin)) == 0x00 //D5
|
||||||
#else
|
#else
|
||||||
#define SDI_1 (PIND & (1<<SDI_pin)) == (1<<SDI_pin) //D5
|
#define SDI_1 (PIND & _BV(SDI_pin)) == _BV(SDI_pin) //D5
|
||||||
#define SDI_0 (PIND & (1<<SDI_pin)) == 0x00 //D5
|
#define SDI_0 (PIND & _BV(SDI_pin)) == 0x00 //D5
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#define SDI_SET_INPUT DDRD &= ~_BV(5) //D5
|
#define SDI_SET_INPUT DDRD &= ~_BV(5) //D5
|
||||||
@ -230,19 +232,21 @@ struct PPM_Parameters
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define CYRF_CSN_on PORTD.OUTSET = _BV(4)
|
#define CYRF_CSN_on PORTD.OUTSET = _BV(4)
|
||||||
#define CYRF_CSN_off PORTD.OUTCLR = _BV(4)
|
#define CYRF_CSN_off PORTD.OUTCLR = _BV(4)
|
||||||
|
#define CYRF_RST 0
|
||||||
#else
|
#else
|
||||||
#define CYRF_CSN_on PORTB |= _BV(1) //D9
|
#define CYRF_CSN_on PORTB |= _BV(1) //D9
|
||||||
#define CYRF_CSN_off PORTB &= ~_BV(1) //D9
|
#define CYRF_CSN_off PORTB &= ~_BV(1) //D9
|
||||||
#define CYRF_RST_HI PORTC |= _BV(5) //A5
|
#define CYRF_RST_HI PORTC |= _BV(5) //A5
|
||||||
#define CYRF_RST_LO PORTC &= ~_BV(5) //A5
|
#define CYRF_RST_LO PORTC &= ~_BV(5) //A5
|
||||||
|
#define CYRF_RST 5
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
#define SDO_1 (PORTD.IN & (1<<SDO_pin)) == (1<<SDO_pin) //D6
|
#define SDO_1 (PORTD.IN & _BV(SDO_pin)) == _BV(SDO_pin) //D6
|
||||||
#define SDO_0 (PORTD.IN & (1<<SDO_pin)) == 0x00 //D6
|
#define SDO_0 (PORTD.IN & _BV(SDO_pin)) == 0x00 //D6
|
||||||
#else
|
#else
|
||||||
#define SDO_1 (PIND & (1<<SDO_pin)) == (1<<SDO_pin) //D6
|
#define SDO_1 (PIND & _BV(SDO_pin)) == _BV(SDO_pin) //D6
|
||||||
#define SDO_0 (PIND & (1<<SDO_pin)) == 0x00 //D6
|
#define SDO_0 (PIND & _BV(SDO_pin)) == 0x00 //D6
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -510,6 +514,7 @@ Serial: 100000 Baud 8e2 _ xxxx xxxx p --
|
|||||||
J6PRO 22
|
J6PRO 22
|
||||||
FQ777 23
|
FQ777 23
|
||||||
ASSAN 24
|
ASSAN 24
|
||||||
|
FRSKY1 25
|
||||||
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
|
||||||
|
@ -64,6 +64,8 @@ uint8_t rf_ch_num;
|
|||||||
uint8_t throttle, rudder, elevator, aileron;
|
uint8_t throttle, rudder, elevator, aileron;
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
uint16_t crc;
|
uint16_t crc;
|
||||||
|
uint8_t crc8;
|
||||||
|
uint16_t seed;
|
||||||
//
|
//
|
||||||
uint16_t state;
|
uint16_t state;
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
@ -148,16 +150,15 @@ void setup()
|
|||||||
PORTE.OUTCLR = 0x01 ;
|
PORTE.OUTCLR = 0x01 ;
|
||||||
#else
|
#else
|
||||||
// General pinout
|
// General pinout
|
||||||
DDRD = (1<<CS_pin)|(1<<SDI_pin)|(1<<SCLK_pin)|(1<<CS_pin)|(1<< CC25_CSN_pin);
|
DDRD = _BV(A7105_CS_pin)|_BV(SDI_pin)|_BV(SCLK_pin)|_BV( CC25_CSN_pin);//pin output
|
||||||
DDRC = (1<<CTRL1)|(1<<CTRL2); //output
|
DDRC = _BV(CTRL1_pin)|_BV(CTRL2_pin)|_BV(CYRF_RST); //pin output
|
||||||
//DDRC |= (1<<5);//RST pin A5(C5) CYRF output
|
DDRB = _BV(NRF_CSN_pin)|_BV(CYRF_CSN_pin); //pin output
|
||||||
DDRB = _BV(0)|_BV(1);
|
PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(BIND_pin); //pullup on dial (D10=PB2,D11=PB3,D12=PB4) and bind button
|
||||||
PORTB = _BV(2)|_BV(3)|_BV(4)|_BV(5);//pullup 10,11,12 and bind button
|
PORTC = _BV(0); //pullup on dial (A0=PC0)
|
||||||
PORTC = _BV(0);//A0 high pullup
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set Chip selects
|
// Set Chip selects
|
||||||
CS_on;
|
A7105_CS_on;
|
||||||
CC25_CSN_on;
|
CC25_CSN_on;
|
||||||
NRF_CSN_on;
|
NRF_CSN_on;
|
||||||
CYRF_CSN_on;
|
CYRF_CSN_on;
|
||||||
@ -237,8 +238,8 @@ void setup()
|
|||||||
|
|
||||||
#ifndef XMEGA
|
#ifndef XMEGA
|
||||||
//Configure PPM interrupt
|
//Configure PPM interrupt
|
||||||
EICRA |=(1<<ISC11); // The rising edge of INT1 pin D3 generates an interrupt request
|
EICRA |=_BV(ISC11); // The rising edge of INT1 pin D3 generates an interrupt request
|
||||||
EIMSK |= (1<<INT1); // INT1 interrupt enable
|
EIMSK |= _BV(INT1); // INT1 interrupt enable
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TELEMETRY)
|
#if defined(TELEMETRY)
|
||||||
@ -285,14 +286,14 @@ void loop()
|
|||||||
else
|
else
|
||||||
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait before callback
|
while((TCC1.INTFLAGS & TC1_CCAIF_bm) == 0); // wait before callback
|
||||||
#else
|
#else
|
||||||
if( (TIFR1 & (1<<OCF1A)) != 0)
|
if( (TIFR1 & _BV(OCF1A)) != 0)
|
||||||
{
|
{
|
||||||
cli(); // Disable global int due to RW of 16 bits registers
|
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.
|
OCR1A=TCNT1; // Callback should already have been called... Use "now" as new sync point.
|
||||||
sei(); // Enable global int
|
sei(); // Enable global int
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
while((TIFR1 & (1<<OCF1A)) == 0); // Wait before callback
|
while((TIFR1 & _BV(OCF1A)) == 0); // Wait before callback
|
||||||
#endif
|
#endif
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -318,12 +319,12 @@ void loop()
|
|||||||
#else
|
#else
|
||||||
cli(); // Disable global int due to RW of 16 bits registers
|
cli(); // Disable global int due to RW of 16 bits registers
|
||||||
OCR1A += 2000*2 ; // set compare A for callback
|
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
|
sei(); // enable global int
|
||||||
Update_All();
|
Update_All();
|
||||||
if(IS_CHANGE_PROTOCOL_FLAG_on)
|
if(IS_CHANGE_PROTOCOL_FLAG_on)
|
||||||
break; // Protocol has been changed
|
break; // Protocol has been changed
|
||||||
while((TIFR1 & (1<<OCF1A)) == 0); // wait 2ms...
|
while((TIFR1 & _BV(OCF1A)) == 0); // wait 2ms...
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
// at this point we have a maximum of 4ms in next_callback
|
// at this point we have a maximum of 4ms in next_callback
|
||||||
@ -337,7 +338,7 @@ void loop()
|
|||||||
#else
|
#else
|
||||||
cli(); // Disable global int due to RW of 16 bits registers
|
cli(); // Disable global int due to RW of 16 bits registers
|
||||||
OCR1A+= next_callback ; // set compare A for callback
|
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
|
diff=OCR1A-TCNT1; // compare timer and comparator
|
||||||
sei(); // enable global int
|
sei(); // enable global int
|
||||||
#endif
|
#endif
|
||||||
@ -434,7 +435,7 @@ inline void tx_pause()
|
|||||||
USARTC0.CTRLA &= ~0x03 ; // Pause telemetry by disabling transmitter interrupt
|
USARTC0.CTRLA &= ~0x03 ; // Pause telemetry by disabling transmitter interrupt
|
||||||
#else
|
#else
|
||||||
#ifndef BASH_SERIAL
|
#ifndef BASH_SERIAL
|
||||||
UCSR0B &= ~(1<<UDRIE0); // Pause telemetry by disabling transmitter interrupt
|
UCSR0B &= ~_BV(UDRIE0); // Pause telemetry by disabling transmitter interrupt
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -447,7 +448,7 @@ inline void tx_resume()
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt
|
USARTC0.CTRLA = (USARTC0.CTRLA & 0xFC) | 0x01 ; // Resume telemetry by enabling transmitter interrupt
|
||||||
#else
|
#else
|
||||||
UCSR0B |= (1<<UDRIE0); // Resume telemetry by enabling transmitter interrupt
|
UCSR0B |= _BV(UDRIE0); // Resume telemetry by enabling transmitter interrupt
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -505,6 +506,14 @@ static void protocol_init()
|
|||||||
remote_callback = ReadFrSky_2way;
|
remote_callback = ReadFrSky_2way;
|
||||||
break;
|
break;
|
||||||
#endif
|
#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)
|
#if defined(FRSKYX_CC2500_INO)
|
||||||
case MODE_FRSKYX:
|
case MODE_FRSKYX:
|
||||||
CTRL1_off; //antenna RF2
|
CTRL1_off; //antenna RF2
|
||||||
@ -670,7 +679,7 @@ static void protocol_init()
|
|||||||
#else
|
#else
|
||||||
OCR1A=TCNT1+next_callback*2; // set compare A for callback
|
OCR1A=TCNT1+next_callback*2; // set compare A for callback
|
||||||
sei(); // enable global int
|
sei(); // enable global int
|
||||||
TIFR1=(1<<OCF1A); // clear compare A flag
|
TIFR1=_BV(OCF1A); // clear compare A flag
|
||||||
#endif
|
#endif
|
||||||
BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change
|
BIND_BUTTON_FLAG_off; // do not bind/reset id anymore even if protocol change
|
||||||
}
|
}
|
||||||
@ -728,7 +737,7 @@ void update_serial_data()
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
cli();
|
cli();
|
||||||
#else
|
#else
|
||||||
UCSR0B &= ~(1<<RXCIE0); // RX interrupt disable
|
UCSR0B &= ~_BV(RXCIE0); // RX interrupt disable
|
||||||
#endif
|
#endif
|
||||||
if(IS_RX_MISSED_BUFF_on) // If the buffer is still valid
|
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
|
{ memcpy((void*)rx_ok_buff,(const void*)rx_buff,RXBUFFER_SIZE);// Duplicate the buffer
|
||||||
@ -738,7 +747,7 @@ void update_serial_data()
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
sei();
|
sei();
|
||||||
#else
|
#else
|
||||||
UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable
|
UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -847,11 +856,11 @@ void Mprotocol_serial_init()
|
|||||||
UBRR0L = UBRRL_VALUE;
|
UBRR0L = UBRRL_VALUE;
|
||||||
UCSR0A = 0 ; // Clear X2 bit
|
UCSR0A = 0 ; // Clear X2 bit
|
||||||
//Set frame format to 8 data bits, even parity, 2 stop bits
|
//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
|
while ( UCSR0A & (1 << RXC0) )//flush receive buffer
|
||||||
UDR0;
|
UDR0;
|
||||||
//enable reception and RC complete interrupt
|
//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
|
#ifdef DEBUG_TX
|
||||||
TX_SET_OUTPUT;
|
TX_SET_OUTPUT;
|
||||||
#else
|
#else
|
||||||
@ -1104,7 +1113,7 @@ ISR(USART_RX_vect)
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error
|
if((USARTC0.STATUS & 0x1C)==0) // Check frame error, data overrun and parity error
|
||||||
#else
|
#else
|
||||||
UCSR0B &= ~(1<<RXCIE0) ; // RX interrupt disable
|
UCSR0B &= ~_BV(RXCIE0) ; // RX interrupt disable
|
||||||
sei() ;
|
sei() ;
|
||||||
if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error
|
if((UCSR0A&0x1C)==0) // Check frame error, data overrun and parity error
|
||||||
#endif
|
#endif
|
||||||
@ -1126,8 +1135,8 @@ ISR(USART_RX_vect)
|
|||||||
TCC1.INTCTRLB = (TCC1.INTCTRLB & 0xF3) | 0x04 ; // enable interrupt on compare B match
|
TCC1.INTCTRLB = (TCC1.INTCTRLB & 0xF3) | 0x04 ; // enable interrupt on compare B match
|
||||||
#else
|
#else
|
||||||
OCR1B=TCNT1+6500L; // Full message should be received within timer of 3250us
|
OCR1B=TCNT1+6500L; // Full message should be received within timer of 3250us
|
||||||
TIFR1=(1<<OCF1B); // clear OCR1B match flag
|
TIFR1=_BV(OCF1B); // clear OCR1B match flag
|
||||||
TIMSK1 |=(1<<OCIE1B); // enable interrupt on compare B match
|
TIMSK1 |=_BV(OCIE1B); // enable interrupt on compare B match
|
||||||
#endif
|
#endif
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
@ -1167,14 +1176,14 @@ ISR(USART_RX_vect)
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
||||||
#else
|
#else
|
||||||
TIMSK1 &=~(1<<OCIE1B); // Disable interrupt on compare B match
|
TIMSK1 &=~_BV(OCIE1B); // Disable interrupt on compare B match
|
||||||
#endif
|
#endif
|
||||||
TX_RX_PAUSE_off;
|
TX_RX_PAUSE_off;
|
||||||
tx_resume();
|
tx_resume();
|
||||||
}
|
}
|
||||||
#ifndef XMEGA
|
#ifndef XMEGA
|
||||||
cli() ;
|
cli() ;
|
||||||
UCSR0B |= (1<<RXCIE0) ; // RX interrupt enable
|
UCSR0B |= _BV(RXCIE0) ; // RX interrupt enable
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,7 +1199,7 @@ ISR(TIMER1_COMPB_vect, ISR_NOBLOCK )
|
|||||||
#ifdef XMEGA
|
#ifdef XMEGA
|
||||||
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
TCC1.INTCTRLB &=0xF3; // Disable interrupt on compare B match
|
||||||
#else
|
#else
|
||||||
TIMSK1 &=~(1<<OCIE1B); // Disable interrupt on compare B match
|
TIMSK1 &=~_BV(OCIE1B); // Disable interrupt on compare B match
|
||||||
#endif
|
#endif
|
||||||
tx_resume();
|
tx_resume();
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef CC2500_INSTALLED
|
#ifdef CC2500_INSTALLED
|
||||||
#define FRSKY_CC2500_INO
|
#define FRSKY_CC2500_INO
|
||||||
|
#define FRSKY1_CC2500_INO
|
||||||
#define FRSKYX_CC2500_INO
|
#define FRSKYX_CC2500_INO
|
||||||
#define SFHSS_CC2500_INO
|
#define SFHSS_CC2500_INO
|
||||||
#endif
|
#endif
|
||||||
@ -238,6 +239,8 @@ const PPM_Parameters PPM_prot[15]= {
|
|||||||
NONE
|
NONE
|
||||||
MODE_ASSAN
|
MODE_ASSAN
|
||||||
NONE
|
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...
|
// 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