diff --git a/Multiprotocol/FrSkyV_cc2500.ino b/Multiprotocol/FrSkyV_cc2500.ino
index df948a7..2c7248e 100644
--- a/Multiprotocol/FrSkyV_cc2500.ino
+++ b/Multiprotocol/FrSkyV_cc2500.ino
@@ -3,20 +3,29 @@
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 .
*/
-#if defined(FRSKY1_CC2500_INO)
+#if defined(FRSKYV_CC2500_INO)
+
+#define FRSKYV_BIND_COUNT 200
+
+enum {
+ FRSKYV_DATA1=0,
+ FRSKYV_DATA2,
+ FRSKYV_DATA3,
+ FRSKYV_DATA4,
+ FRSKYV_DATA5
+};
+
#include "iface_cc2500.h"
-const PROGMEM uint8_t FRSKY1_cc2500_conf[][2]={
+const PROGMEM uint8_t FRSKYV_cc2500_conf[][2]={
{ CC2500_17_MCSM1, 0x0c },
{ CC2500_18_MCSM0, 0x18 },
{ CC2500_06_PKTLEN, 0xff },
@@ -36,12 +45,12 @@ const PROGMEM uint8_t FRSKY1_cc2500_conf[][2]={
{ CC2500_15_DEVIATN, 0x41 }
};
-static void __attribute__((unused)) FRSKY1_init()
+static void __attribute__((unused)) FRSKYV_init()
{
for(uint8_t i=0;i<17;i++)
{
- uint8_t reg=pgm_read_byte_near(&FRSKY1_cc2500_conf[i][0]);
- uint8_t val=pgm_read_byte_near(&FRSKY1_cc2500_conf[i][1]);
+ uint8_t reg=pgm_read_byte_near(&FRSKYV_cc2500_conf[i][0]);
+ uint8_t val=pgm_read_byte_near(&FRSKYV_cc2500_conf[i][1]);
if(reg==CC2500_0C_FSCTRL0)
val=option;
CC2500_WriteReg(reg,val);
@@ -60,33 +69,37 @@ static void __attribute__((unused)) FRSKY1_init()
CC2500_Strobe(CC2500_SIDLE); // Go to idle...
}
-static uint8_t __attribute__((unused)) FRSKY1_crc8(uint8_t result, uint8_t *data, uint8_t len, uint8_t polynomial)
+static uint8_t __attribute__((unused)) FRSKYV_crc8(uint8_t result, uint8_t *data, uint8_t len)
{
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;
+ result = (result << 1) ^ 0x07;
else
result = result << 1;
}
return result;
}
-static uint8_t __attribute__((unused)) FRSKY1_crc8_le(uint8_t init, uint8_t *data, uint8_t len)
+static uint8_t __attribute__((unused)) FRSKYV_crc8_le(uint8_t *data, uint8_t len)
{
- uint8_t result = 0;
+ uint8_t result = 0xD6;
- for(uint8_t i = 0; i < 8; i++)
+ for(uint8_t i = 0; i < len; i++)
{
- result = (result << 1) | (init & 0x01);
- init >>= 1;
+ result = result ^ data[i];
+ for(uint8_t j = 0; j < 8; j++)
+ if(result & 0x01)
+ result = (result >> 1) ^ 0x83;
+ else
+ result = result >> 1;
}
- return FRSKY1_crc8(result,data,len,0x83);
+ return result;
}
-static void __attribute__((unused)) FRSKY1_build_bind_packet()
+static void __attribute__((unused)) FRSKYV_build_bind_packet()
{
//0e 03 01 57 12 00 06 0b 10 15 1a 00 00 00 61
packet[0] = 0x0e; //Length
@@ -94,7 +107,7 @@ static void __attribute__((unused)) FRSKY1_build_bind_packet()
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[5] = (binding_idx % 10) * 5;
packet[6] = packet[5] * 5 + 6;
packet[7] = packet[5] * 5 + 11;
packet[8] = packet[5] * 5 + 16;
@@ -103,10 +116,10 @@ static void __attribute__((unused)) FRSKY1_build_bind_packet()
packet[11] = 0x00;
packet[12] = 0x00;
packet[13] = 0x00;
- packet[14] = FRSKY1_crc8(0x93, packet, 14, 0x07);
+ packet[14] = FRSKYV_crc8(0x93, packet, 14);
}
-static uint8_t __attribute__((unused)) FRSKY1_calc_channel()
+static uint8_t __attribute__((unused)) FRSKYV_calc_channel()
{
uint32_t temp=seed;
temp = (temp * 0xaa) % 0x7673;
@@ -114,81 +127,80 @@ static uint8_t __attribute__((unused)) FRSKY1_calc_channel()
return (seed & 0xff) % 0x32;
}
-static void __attribute__((unused)) FRSKY1_build_data_packet()
+static void __attribute__((unused)) FRSKYV_build_data_packet()
{
+ uint8_t idx = 0; // transmit lower channels
+
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)
+ if (phase == FRSKYV_DATA1 || phase == FRSKYV_DATA3)
packet[5] = 0x0f;
else
- if(state == FRSKY_DATA2 || state == FRSKY_DATA4)
+ if(phase == FRSKYV_DATA2 || phase == FRSKYV_DATA4)
+ {
packet[5] = 0xf0;
+ idx=4; // transmit upper channels
+ }
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);
+ packet[14] = FRSKYV_crc8(crc8, packet, 14);
}
-static uint16_t ReadFRSKY1()
+uint16_t ReadFRSKYV()
{
- 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)
- {
+ if(IS_BIND_DONE_on)
+ { // Normal operation
+ uint8_t chan = FRSKYV_calc_channel();
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();
+ FRSKYV_build_data_packet();
- CC2500_WriteData(packet, packet[0]+1);
- if (state == FRSKY_DATA5)
+ if (phase == FRSKYV_DATA5)
{
CC2500_SetPower();
- state = FRSKY_DATA1;
+ phase = FRSKYV_DATA1;
}
else
- state++;
+ phase++;
+
+ CC2500_WriteData(packet, packet[0]+1);
return 9006;
}
- return 0;
+ // Bind mode
+ FRSKYV_build_bind_packet();
+ CC2500_Strobe(CC2500_SIDLE);
+ CC2500_WriteReg(CC2500_0A_CHANNR, 0x00);
+ CC2500_WriteData(packet, packet[0]+1);
+ binding_idx++;
+ if(binding_idx>=FRSKYV_BIND_COUNT)
+ BIND_DONE;
+ return 53460;
}
-uint16_t initFRSKY1()
+uint16_t initFRSKYV()
{
- //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();
+ //ID is 15 bits. Using rx_tx_addr[2] and rx_tx_addr[3] since we want to use RX_Num for model match
+ rx_tx_addr[2]&=0x7F;
+ crc8 = FRSKYV_crc8_le(rx_tx_addr+2, 2);
+
+ FRSKYV_init();
seed = 1;
- if(IS_AUTOBIND_FLAG_on)
- state = FRSKY_BIND;
- else
- state = FRSKY_DATA1;
+ binding_idx=0;
+ phase = FRSKYV_DATA1;
return 10000;
}
diff --git a/Multiprotocol/Multiprotocol.h b/Multiprotocol/Multiprotocol.h
index 2ec2492..b9be5ae 100644
--- a/Multiprotocol/Multiprotocol.h
+++ b/Multiprotocol/Multiprotocol.h
@@ -31,7 +31,7 @@ enum PROTOCOLS
MODE_SERIAL = 0, // Serial commands
MODE_FLYSKY = 1, // =>A7105
MODE_HUBSAN = 2, // =>A7105
- MODE_FRSKY = 3, // =>CC2500
+ MODE_FRSKYD = 3, // =>CC2500
MODE_HISKY = 4, // =>NRF24L01
MODE_V2X2 = 5, // =>NRF24L01
MODE_DSM2 = 6, // =>CYRF6936
@@ -53,7 +53,7 @@ enum PROTOCOLS
MODE_J6PRO = 22, // =>CYRF6936
MODE_FQ777 = 23, // =>NRF24L01
MODE_ASSAN = 24, // =>NRF24L01
- MODE_FRSKY1 = 25 // =>CC2500
+ MODE_FRSKYV = 25 // =>CC2500
};
enum Flysky
diff --git a/Multiprotocol/Multiprotocol.ino b/Multiprotocol/Multiprotocol.ino
index 47ee684..0cdfd8c 100644
--- a/Multiprotocol/Multiprotocol.ino
+++ b/Multiprotocol/Multiprotocol.ino
@@ -444,7 +444,7 @@ void Update_All()
update_led_status();
#if defined(TELEMETRY)
uint8_t protocol=cur_protocol[0]&0x1F;
- if( (protocol==MODE_FRSKY) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM2) )
+ if( (protocol==MODE_FRSKYD) || (protocol==MODE_HUBSAN) || (protocol==MODE_FRSKYX) || (protocol==MODE_DSM2) )
TelemetryUpdate();
#endif
}
@@ -583,7 +583,7 @@ static void protocol_init()
break;
#endif
#if defined(FRSKY_CC2500_INO)
- case MODE_FRSKY:
+ case MODE_FRSKYD:
CTRL1_off; //antenna RF2
CTRL2_on;
next_callback = initFrSky_2way();
@@ -591,11 +591,11 @@ static void protocol_init()
break;
#endif
#if defined(FRSKY1_CC2500_INO)
- case MODE_FRSKY1:
+ case MODE_FRSKYV:
CTRL1_off; //antenna RF2
CTRL2_on;
- next_callback = initFRSKY1();
- remote_callback = ReadFRSKY1;
+ next_callback = initFRSKYV();
+ remote_callback = ReadFRSKYV;
break;
#endif
#if defined(FRSKYX_CC2500_INO)
diff --git a/Multiprotocol/Multiprotocol_STM32.h b/Multiprotocol/Multiprotocol_STM32.h
index 522f661..b0d295c 100644
--- a/Multiprotocol/Multiprotocol_STM32.h
+++ b/Multiprotocol/Multiprotocol_STM32.h
@@ -22,7 +22,7 @@ enum PROTOCOLS
MODE_SERIAL = 0, // Serial commands
MODE_FLYSKY = 1, // =>A7105
MODE_HUBSAN = 2, // =>A7105
- MODE_FRSKY = 3, // =>CC2500
+ MODE_FRSKYD = 3, // =>CC2500
MODE_HISKY = 4, // =>NRF24L01
MODE_V2X2 = 5, // =>NRF24L01
MODE_DSM2 = 6, // =>CYRF6936
@@ -44,7 +44,7 @@ enum PROTOCOLS
MODE_J6PRO=22, // =>CYRF6936
MODE_FQ777=23, // =>NRF24L01
MODE_ASSAN=24, // =>NRF24L01
- MODE_FRSKY1 = 25 // =>CC2500
+ MODE_FRSKYV = 25 // =>CC2500
};
enum Flysky
@@ -145,6 +145,8 @@ struct PPM_Parameters
#define OCR1A TIMER2_BASE->CCR1
#define TCNT1 TIMER2_BASE->CNT
#define UDR0 USART2_BASE->DR
+#define TIFR1 TIMER2_BASE->SR
+#define OCF1A_bm TIMER_SR_CC1IF
#define UCSR0B USART2_BASE->CR1
#define RXCIE0 USART_CR1_RXNEIE_BIT
#define TXCIE0 USART_CR1_TXEIE_BIT
diff --git a/Multiprotocol/Multiprotocol_STM32.h.bak b/Multiprotocol/Multiprotocol_STM32.h.bak
index 4b9ac64..26966ce 100644
--- a/Multiprotocol/Multiprotocol_STM32.h.bak
+++ b/Multiprotocol/Multiprotocol_STM32.h.bak
@@ -22,7 +22,7 @@ enum PROTOCOLS
MODE_SERIAL = 0, // Serial commands
MODE_FLYSKY = 1, // =>A7105
MODE_HUBSAN = 2, // =>A7105
- MODE_FRSKY = 3, // =>CC2500
+ MODE_FRSKYD = 3, // =>CC2500
MODE_HISKY = 4, // =>NRF24L01
MODE_V2X2 = 5, // =>NRF24L01
MODE_DSM2 = 6, // =>CYRF6936
@@ -44,7 +44,7 @@ enum PROTOCOLS
MODE_J6PRO=22, // =>CYRF6936
MODE_FQ777=23, // =>NRF24L01
MODE_ASSAN=24, // =>NRF24L01
- MODE_FRSKY1 = 25 // =>CC2500
+ MODE_FRSKYV = 25 // =>CC2500
};
diff --git a/Multiprotocol/Telemetry.ino b/Multiprotocol/Telemetry.ino
index c8b83c4..2ad4e33 100644
--- a/Multiprotocol/Telemetry.ino
+++ b/Multiprotocol/Telemetry.ino
@@ -111,7 +111,7 @@ void frsky_check_telemetry(uint8_t *pkt,uint8_t len)
void frsky_link_frame()
{
frame[0] = 0xFE;
- if ((cur_protocol[0]&0x1F)==MODE_FRSKY)
+ if ((cur_protocol[0]&0x1F)==MODE_FRSKYD)
{
compute_RSSIdbm();
frame[1] = pktt[3];
@@ -452,7 +452,7 @@ void TelemetryUpdate()
return;
}
#if defined HUB_TELEMETRY
- if(!telemetry_link && (cur_protocol[0]&0x1F) == MODE_FRSKY)
+ if(!telemetry_link && (cur_protocol[0]&0x1F) == MODE_FRSKYD)
{ // FrSky
frsky_user_frame();
return;
diff --git a/Multiprotocol/_Config.h b/Multiprotocol/_Config.h
index 5bdb2e3..ce41782 100644
--- a/Multiprotocol/_Config.h
+++ b/Multiprotocol/_Config.h
@@ -20,7 +20,7 @@
//#define XMEGA
/*******************/
#ifdef STM32_board
-//#undef __cplusplus
+#undef __cplusplus
#include "Multiprotocol_STM32.h"
#include
#include
@@ -59,8 +59,8 @@
#define J6PRO_CYRF6936_INO
#endif
#ifdef CC2500_INSTALLED
- #define FRSKY_CC2500_INO
- #define FRSKY1_CC2500_INO
+ #define FRSKYD_CC2500_INO
+ #define FRSKYV_CC2500_INO
#define FRSKYX_CC2500_INO
#define SFHSS_CC2500_INO
#endif
@@ -97,7 +97,7 @@
#if defined FRSKYX_CC2500_INO
#define SPORT_TELEMETRY
#endif
- #if defined FRSKY_CC2500_INO
+ #if defined FRSKYD_CC2500_INO
#define HUB_TELEMETRY
#endif
#endif
@@ -160,7 +160,7 @@ const PPM_Parameters PPM_prot[15]= {
// Dial Protocol Sub protocol RX_Num Power Auto Bind Option
/* 1 */ {MODE_FLYSKY, Flysky , 0 , P_HIGH , NO_AUTOBIND , 0 },
/* 2 */ {MODE_HUBSAN, 0 , 0 , P_HIGH , NO_AUTOBIND , 0 },
-/* 3 */ {MODE_FRSKY , 0 , 0 , P_HIGH , NO_AUTOBIND , 40 }, // D7 fine tuning
+/* 3 */ {MODE_FRSKYD, 0 , 0 , P_HIGH , NO_AUTOBIND , 40 }, // D7 fine tuning
/* 4 */ {MODE_HISKY , Hisky , 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