Skip to content

Commit

Permalink
CYRF6936: Findbestchannels flag addition
Browse files Browse the repository at this point in the history
  • Loading branch information
pascallanger committed Mar 25, 2024
1 parent 9e9c395 commit 5acc3a8
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 13 deletions.
9 changes: 7 additions & 2 deletions Multiprotocol/CYRF6936_SPI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void CYRF_WriteDataPacket(const uint8_t dpbuffer[])
}
*/
//NOTE: This routine will reset the CRC Seed
void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uint8_t min, uint8_t max)
void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uint8_t min, uint8_t max, uint8_t forced)
{
#define NUM_FREQ 80
#define FREQ_OFFSET 4
Expand All @@ -269,7 +269,12 @@ void CYRF_FindBestChannels(uint8_t *channels, uint8_t len, uint8_t minspace, uin
delayMilliseconds(1);
for(i = 0; i < NUM_FREQ; i++)
{
CYRF_ConfigRFChannel(protocol==PROTO_LOSI?i|1:i);
if(((i&1) && forced == FIND_CHANNEL_EVEN) || (!(i&1) && forced == FIND_CHANNEL_ODD))
{
rssi[i] = 0xFF;
continue;
}
CYRF_ConfigRFChannel(i); //protocol==PROTO_LOSI?i|1:i);
delayMicroseconds(270); //slow channel require 270usec for synthesizer to settle
if( !(CYRF_ReadRegister(CYRF_05_RX_CTRL) & 0x80)) {
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x80); //Prepare to receive
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/DSM_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ void DSM_init()
else if(sub_protocol != DSMR)
{
uint8_t tmpch[10];
CYRF_FindBestChannels(tmpch, 10, 5, 3, 75);
CYRF_FindBestChannels(tmpch, 10, 5, 3, 75, FIND_CHANNEL_ANY);
//
uint8_t idx = random(0xfefefefe) % 10;
hopping_frequency[0] = tmpch[idx];
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/Devo_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ static void __attribute__((unused)) DEVO_cyrf_init()

static void __attribute__((unused)) DEVO_set_radio_channels()
{
CYRF_FindBestChannels(hopping_frequency, 3, 4, 4, 80);
CYRF_FindBestChannels(hopping_frequency, 3, 4, 4, 80, FIND_CHANNEL_ANY);
hopping_frequency[3] = hopping_frequency[0];
hopping_frequency[4] = hopping_frequency[1];
}
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/J6Pro_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void __attribute__((unused)) j6pro_set_radio_channels()
{
//FIXME: Query free channels
//lowest channel is 0x08, upper channel is 0x4d?
CYRF_FindBestChannels(hopping_frequency, 3, 5, 8, 77);
CYRF_FindBestChannels(hopping_frequency, 3, 5, 8, 77, FIND_CHANNEL_ANY);
hopping_frequency[3] = hopping_frequency[0];
}

Expand Down
6 changes: 4 additions & 2 deletions Multiprotocol/Kyosho3_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "iface_cyrf6936.h"

#define KYOSHO3_FORCE_ID
//#define KYOSHO3_FORCE_ID
//#define KYOSHO3_DEBUG

#define KYOSHO3_BIND_PACKET_SIZE 4
Expand Down Expand Up @@ -102,7 +102,8 @@ void KYOSHO3_init()
CYRF_WritePreamble(0x333304);

//Find a free even channel
CYRF_FindBestChannels(hopping_frequency,1,1,0x04,0x50);
CYRF_FindBestChannels(hopping_frequency,1,1,0x04,0x50, FIND_CHANNEL_EVEN);
hopping_frequency[0] = 0x04;

#ifdef KYOSHO3_FORCE_ID // data taken from TX dump
rx_tx_addr[1]=0x01;
Expand All @@ -114,6 +115,7 @@ void KYOSHO3_init()
debugln("ID: %02X %02X %02X",rx_tx_addr[1],rx_tx_addr[2],rx_tx_addr[3]);
debugln("RF CH: %02X",hopping_frequency[0]);
#endif

CYRF_ConfigRFChannel(hopping_frequency[0]);

bind_counter=1000;
Expand Down
3 changes: 1 addition & 2 deletions Multiprotocol/Losi_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ void LOSI_init()
{
LOSI_cyrf_init();

CYRF_FindBestChannels(hopping_frequency, 1, 0, 0x07, 0x4F); // 0x07 and 0x4F are unknown limits, this routine resets the CRC Seed to 0
hopping_frequency[0] |= 1; // Only odd channels are used, integrated in CYRF code...
CYRF_FindBestChannels(hopping_frequency, 1, 0, 0x07, 0x4F, FIND_CHANNEL_ODD); // 0x07 and 0x4F are unknown limits, this routine resets the CRC Seed to 0

crc8 = 0;
crc8 = (uint16_t)LOSI_check(((rx_tx_addr[2]&0x0F) << 8) + rx_tx_addr[3]) >> 12;
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/Multiprotocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define VERSION_MAJOR 1
#define VERSION_MINOR 3
#define VERSION_REVISION 4
#define VERSION_PATCH_LEVEL 4
#define VERSION_PATCH_LEVEL 5

#define MODE_SERIAL 0

Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/TRAXXAS_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ void TRAXXAS_init()
//Read CYRF ID
CYRF_GetMfgData(cyrfmfg_id);
//cyrfmfg_id[0]+=RX_num; // Not needed since the TX and RX have to match
CYRF_FindBestChannels(hopping_frequency,1,1,0x02,0x21);
CYRF_FindBestChannels(hopping_frequency,1,1,0x02,0x21, FIND_CHANNEL_ANY);
#ifdef TRAXXAS_FORCE_ID // data taken from TX dump
cyrfmfg_id[0]=0x65; // CYRF MFG ID
cyrfmfg_id[1]=0xE2;
Expand Down
2 changes: 1 addition & 1 deletion Multiprotocol/WK2x01_cyrf6936.ino
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ void WK_init()
CYRF_SetTxRxMode(TX_EN);

hopping_frequency_no=0;
CYRF_FindBestChannels(hopping_frequency, 3, 4, 4, 80);
CYRF_FindBestChannels(hopping_frequency, 3, 4, 4, 80, FIND_CHANNEL_ANY);
CYRF_ConfigRFChannel(hopping_frequency[0]);

packet_count = 0;
Expand Down
6 changes: 5 additions & 1 deletion Multiprotocol/iface_cyrf6936.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ enum CYRF_PWR {
CYRF_PWR_DEFAULT,
};


enum FIND_CHANNEL {
FIND_CHANNEL_ANY = 0,
FIND_CHANNEL_EVEN = 1,
FIND_CHANNEL_ODD = 2,
};

/* SPI CYRF6936 */
/*
Expand Down

0 comments on commit 5acc3a8

Please sign in to comment.