WFLY2: auto stop bind when the RX replies

This commit is contained in:
Pascal Langer 2020-12-15 23:58:56 +01:00
parent 667058269c
commit 6d38dd2d7a
3 changed files with 119 additions and 138 deletions

View File

@ -27,7 +27,7 @@ void A7105_WriteData(uint8_t len, uint8_t channel)
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
SPI_Write(packet[i]); SPI_Write(packet[i]);
A7105_CSN_on; A7105_CSN_on;
if(protocol!=PROTO_WFLY2 || phase==0) if(protocol!=PROTO_WFLY2)
{ {
if(!(protocol==PROTO_FLYSKY || protocol==PROTO_KYOSHO)) if(!(protocol==PROTO_FLYSKY || protocol==PROTO_KYOSHO))
{ {

View File

@ -19,7 +19,7 @@
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_REVISION 1 #define VERSION_REVISION 1
#define VERSION_PATCH_LEVEL 85 #define VERSION_PATCH_LEVEL 86
//****************** //******************
// Protocols // Protocols

View File

@ -20,18 +20,35 @@
//#define WFLY2_FORCE_ID //#define WFLY2_FORCE_ID
//WFLY2 constants & variables //WFLY2 constants & variables
#define WFLY2_BIND_COUNT 1000 #define WFLY2_BIND_COUNT 2777 // abort bind after 10sec
#define WFLY2_PACKET_SIZE 32 #define WFLY2_PACKET_SIZE 32
enum{ enum{
WFLY2_BIND,
WFLY2_DATA, WFLY2_DATA,
WFLY2_PLL_TX, WFLY2_PLL_TX,
WFLY2_RX, WFLY2_RX,
}; };
static void __attribute__((unused)) WFLY2_send_bind_packet() static void __attribute__((unused)) WFLY2_build_packet()
{ {
static uint16_t pseudo=0;
//End bind
if(IS_BIND_IN_PROGRESS && bind_counter)
{
bind_counter--;
if (bind_counter==0)
{
BIND_DONE;
A7105_WriteID(MProtocol_id);
rf_ch_num = 0;
}
}
memset(packet,0x00,WFLY2_PACKET_SIZE);
if(IS_BIND_IN_PROGRESS)
{
//Header //Header
packet[0] = 0x0F; // Bind packet packet[0] = 0x0F; // Bind packet
@ -39,39 +56,23 @@ static void __attribute__((unused)) WFLY2_send_bind_packet()
packet[1] = rx_tx_addr[3]; packet[1] = rx_tx_addr[3];
packet[2] = rx_tx_addr[2]; packet[2] = rx_tx_addr[2];
packet[3] = rx_tx_addr[1]; packet[3] = rx_tx_addr[1];
//packet[4] = 0x00; // Should be rx_tx_addr[0]&0x0F but bind is already using 0x00 so ....
//Unknown //Unknown
packet[4] = 0x00;
packet[5] = 0x01; packet[5] = 0x01;
//Freq //Freq
rf_ch_num = (hopping_frequency_no<<1)+0x08; rf_ch_num = (hopping_frequency_no<<1)+0x08;
packet[6] = rf_ch_num; packet[6] = rf_ch_num;
rf_ch_num = (rf_ch_num<<1)+0x10;
hopping_frequency_no++; hopping_frequency_no++;
if(hopping_frequency_no > 0x17) hopping_frequency_no=0x00; if(hopping_frequency_no > 0x17) hopping_frequency_no=0x00;
//Unknown //Unknown bytes 7..31
memset(&packet[7],0x00,25); }
else
//Debug {
#if 0
debug("ch=%02X P=",rf_ch_num);
for(uint8_t i=0; i<WFLY2_PACKET_SIZE; i++)
debug("%02X ", packet[i]);
debugln("");
#endif
//Send
A7105_WriteData(WFLY2_PACKET_SIZE, rf_ch_num);
}
static void __attribute__((unused)) WFLY2_build_packet()
{
static uint16_t pseudo=0;
//Header //Header
packet[0] = 0x00; // Normal packet //packet[0] = 0x00; // Normal packet
//Pseudo //Pseudo
uint16_t high_bit=(pseudo & 0x8000) ^ 0x8000; // toggle 0x8000 every other line uint16_t high_bit=(pseudo & 0x8000) ^ 0x8000; // toggle 0x8000 every other line
@ -83,17 +84,9 @@ static void __attribute__((unused)) WFLY2_build_packet()
//RF channel //RF channel
int8_t prev = rf_ch_num & 0x1F; int8_t prev = rf_ch_num & 0x1F;
rf_ch_num = (pseudo ^ (pseudo >> 7)) & 0x57; rf_ch_num = (pseudo ^ (pseudo >> 7));
if(rf_ch_num & 0x10) rf_ch_num = ((rf_ch_num>>1)&0x08) | (rf_ch_num & 0x47);
{ rf_ch_num = ((rf_ch_num>>2)&0x10) | (rf_ch_num & 0x1F);
rf_ch_num |= 0x08;
rf_ch_num &= 0x4F;
}
if(rf_ch_num & 0x40)
{
rf_ch_num |= 0x10;
rf_ch_num &= 0x1F;
}
rf_ch_num ^= rx_tx_addr[3] & 0x1F; rf_ch_num ^= rx_tx_addr[3] & 0x1F;
if(abs((int8_t)rf_ch_num-prev) <= 9) if(abs((int8_t)rf_ch_num-prev) <= 9)
{ {
@ -119,8 +112,8 @@ static void __attribute__((unused)) WFLY2_build_packet()
packet[7 + i*3] |= (temp>>4)&0xF0; // high byte packet[7 + i*3] |= (temp>>4)&0xF0; // high byte
} }
//Unknown //Unknown bytes 20..31
memset(&packet[20],0x00,12); }
//Debug //Debug
#if 0 #if 0
@ -135,7 +128,7 @@ static void __attribute__((unused)) WFLY2_build_packet()
static void __attribute__((unused)) WFLY2_Send_Telemetry() static void __attribute__((unused)) WFLY2_Send_Telemetry()
{ {
//Incoming packet values //Incoming packet values
v_lipo1=packet[3]<<1; // RX_batt*10 in V v_lipo1=packet[3]<<1; // RX_batt *10 in V
v_lipo2=packet[5]<<1; // Ext_batt*10 in V v_lipo2=packet[5]<<1; // Ext_batt*10 in V
RX_RSSI=(255-packet[7])>>1; // Looks to be the RX RSSI value direct from A7105 RX_RSSI=(255-packet[7])>>1; // Looks to be the RX RSSI value direct from A7105
@ -160,30 +153,13 @@ static void __attribute__((unused)) WFLY2_build_packet()
uint16_t ReadWFLY2() uint16_t ReadWFLY2()
{ {
uint16_t start; uint16_t start;
#ifdef WFLY2_HUB_TELEMETRY
uint8_t status; uint8_t status;
#endif
#ifndef FORCE_WFLY2_TUNING #ifndef FORCE_WFLY2_TUNING
A7105_AdjustLOBaseFreq(1); A7105_AdjustLOBaseFreq(1);
#endif #endif
switch(phase) switch(phase)
{ {
case WFLY2_BIND:
bind_counter--;
if (bind_counter)
{
WFLY2_send_bind_packet();
return WFLY2_PACKET_PERIOD;
}
else
{
BIND_DONE;
A7105_WriteID(MProtocol_id);
rf_ch_num = 0;
phase++; // WFLY2_DATA
}
case WFLY2_DATA: case WFLY2_DATA:
#ifdef MULTI_SYNC #ifdef MULTI_SYNC
telemetry_set_input_sync(WFLY2_PACKET_PERIOD); telemetry_set_input_sync(WFLY2_PACKET_PERIOD);
@ -211,16 +187,13 @@ uint16_t ReadWFLY2()
return WFLY2_BUFFER_TIME; return WFLY2_BUFFER_TIME;
case WFLY2_PLL_TX: case WFLY2_PLL_TX:
#ifdef WFLY2_HUB_TELEMETRY
//Check RX status //Check RX status
status=A7105_ReadReg(A7105_00_MODE); status=A7105_ReadReg(A7105_00_MODE);
//debugln("S:%02X", status); //debugln("S:%02X", status);
#endif
//PLL //PLL
A7105_Strobe(A7105_PLL); A7105_Strobe(A7105_PLL);
#ifdef WFLY2_HUB_TELEMETRY
//Read incoming packet even if bad/not present to not change too much the TX timing, might want to reorg the code... //Read incoming packet even if bad/not present to not change too much the TX timing, might want to reorg the code...
A7105_ReadData(WFLY2_PACKET_SIZE); A7105_ReadData(WFLY2_PACKET_SIZE);
@ -234,11 +207,24 @@ uint16_t ReadWFLY2()
debug(" %02X", packet[i]); debug(" %02X", packet[i]);
debugln(""); debugln("");
#endif #endif
//Packet match the ID ?
if(IS_BIND_IN_PROGRESS)
{
if(packet[0]==0x0F && packet[1]==rx_tx_addr[3] && packet[2]==rx_tx_addr[2] && packet[3]==rx_tx_addr[1] && packet[4]==0x00)
{
bind_counter=1; // End bind
debugln("Bind done");
//packet[5..7] contains the RXID
}
}
#ifdef WFLY2_HUB_TELEMETRY
else
if(packet[0]==0 && packet[1]==rx_tx_addr[3] && packet[2]==(rx_tx_addr[2] & 0x03)) if(packet[0]==0 && packet[1]==rx_tx_addr[3] && packet[2]==(rx_tx_addr[2] & 0x03))
{//Packet match the ID
WFLY2_Send_Telemetry(); // Packet looks good do send telem to the radio WFLY2_Send_Telemetry(); // Packet looks good do send telem to the radio
} }
#endif #endif
}
//Change RF channel //Change RF channel
A7105_WriteReg(A7105_0F_PLL_I, (rf_ch_num<<1)+0x10); A7105_WriteReg(A7105_0F_PLL_I, (rf_ch_num<<1)+0x10);
@ -280,20 +266,15 @@ uint16_t initWFLY2()
MProtocol_id |= 0x50000000; // As recommended on the A7105 datasheet MProtocol_id |= 0x50000000; // As recommended on the A7105 datasheet
set_rx_tx_addr(MProtocol_id); // Update the ID set_rx_tx_addr(MProtocol_id); // Update the ID
if(IS_BIND_IN_PROGRESS)
A7105_WriteID(0x50FFFFFE); // Bind ID
else
A7105_WriteID(MProtocol_id);
hopping_frequency_no=0; hopping_frequency_no=0;
rf_ch_num = 0; rf_ch_num = 0;
if(IS_BIND_IN_PROGRESS)
{
bind_counter = WFLY2_BIND_COUNT; bind_counter = WFLY2_BIND_COUNT;
A7105_WriteID(0x50FFFFFE); // Bind ID
phase = WFLY2_BIND;
}
else
{
A7105_WriteID(MProtocol_id);
phase = WFLY2_DATA; phase = WFLY2_DATA;
}
#ifdef WFLY2_HUB_TELEMETRY #ifdef WFLY2_HUB_TELEMETRY
packet_count = 0; packet_count = 0;
telemetry_lost = 1; telemetry_lost = 1;