Skip to content

Commit ee08083

Browse files
author
Pascal Langer
committed
Update DSM_Rx_cyrf6936.ino
1 parent 4290c75 commit ee08083

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

Multiprotocol/DSM_Rx_cyrf6936.ino

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum {
3333
static void __attribute__((unused)) DSM_Rx_init()
3434
{
3535
DSM_cyrf_config();
36+
rx_disable_lna = IS_POWER_FLAG_on;
3637
if(IS_BIND_IN_PROGRESS)
3738
{
3839
//64 SDR Mode is configured so only the 8 first values are needed but need to write 16 values...
@@ -44,9 +45,10 @@ static void __attribute__((unused)) DSM_Rx_init()
4445
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x83); // Prepare to receive
4546
}
4647
else
48+
{
4749
DSM_cyrf_configdata();
48-
rx_disable_lna = IS_POWER_FLAG_on;
49-
CYRF_WriteRegister(CYRF_06_RX_CFG, rx_disable_lna ? 0x0A:0xCA); // AGC enabled/disabled, LNA enabled/disabled, Attenuator disabled, RX override enabled, Fast turn mode enabled, RX is 1MHz below TX
50+
CYRF_WriteRegister(CYRF_06_RX_CFG, rx_disable_lna ? 0x0A:0x4A); // AGC disabled, LNA disabled/enabled, Attenuator disabled, RX override enabled, Fast turn mode enabled, RX is 1MHz below TX
51+
}
5052
}
5153

5254
uint16_t convert_channel_DSM_nolimit(int32_t val)
@@ -67,11 +69,15 @@ static uint8_t __attribute__((unused)) DSM_Rx_check_packet()
6769
rx_status |= CYRF_ReadRegister(CYRF_07_RX_IRQ_STATUS);
6870
if((rx_status & 0x07) == 0x02)
6971
{ // data received with no errors
70-
if(CYRF_ReadRegister(CYRF_09_RX_COUNT)==16)
71-
{// 16 bytes
72+
len=CYRF_ReadRegister(CYRF_09_RX_COUNT);
73+
#ifdef DSM_DEBUG_RF
74+
debugln("l=%d",len);
75+
#endif
76+
if(len>=2 && len<=16)
77+
{
7278
// Read packet
7379
CYRF_WriteRegister(CYRF_07_RX_IRQ_STATUS, 0x80); // Need to set RXOW before data read
74-
CYRF_ReadDataPacketLen(packet, 16);
80+
CYRF_ReadDataPacketLen(packet, len);
7581

7682
// Check packet ID
7783
if ((DSM_rx_type&0x80) == 0)
@@ -93,9 +99,14 @@ static void __attribute__((unused)) DSM_Rx_build_telemetry_packet()
9399
if((DSM_rx_type&0xF0) == 0x00)
94100
nbr_bits=10; // Only DSM_22 is using a resolution of 1024
95101

102+
// Use packet length to calculate the number of channels
103+
len -= 2; // Remove header length
104+
len >>= 1; // Channels are on 2 bytes
105+
if(len==0) return; // No channels...
106+
96107
// Extract channels
97108
uint8_t idx;
98-
for (uint8_t i = 0; i < 7; i++)
109+
for (uint8_t i = 0; i < len; i++)
99110
{
100111
uint16_t value=(packet[i*2+2]<<8) | packet[i*2+3];
101112
if(value!=0xFFFF)
@@ -174,10 +185,10 @@ static void __attribute__((unused)) DSM_abort_channel_rx(uint8_t ch)
174185
{
175186
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
176187
CYRF_SetTxRxMode(IS_POWER_FLAG_on ? TXRX_OFF:RX_EN); // Force end state read
177-
if (rx_disable_lna != IS_POWER_FLAG_on)
188+
if (rx_disable_lna != IS_POWER_FLAG_on && IS_BIND_DONE)
178189
{
179190
rx_disable_lna = IS_POWER_FLAG_on;
180-
CYRF_WriteRegister(CYRF_06_RX_CFG, rx_disable_lna ? 0x0A:0xCA); // AGC enabled/disabled, LNA enabled/disabled, Attenuator disabled, RX override enabled, Fast turn mode enabled, RX is 1MHz below TX
191+
CYRF_WriteRegister(CYRF_06_RX_CFG, rx_disable_lna ? 0x0A:0x4A); // AGC disabled, LNA disabled/enabled, Attenuator disabled, RX override enabled, Fast turn mode enabled, RX is 1MHz below TX
181192
}
182193
if(ch&0x02) DSM_set_sop_data_crc(true ,DSM_rx_type&0x80); // Set sop data,crc seed and rf channel using CH1, DSM2/X
183194
if(ch&0x01) DSM_set_sop_data_crc(false,DSM_rx_type&0x80); // Set sop data,crc seed and rf channel using CH1, DSM2/X
@@ -215,7 +226,7 @@ uint16_t DSM_Rx_callback()
215226
for(uint8_t i=0;i<4;i++)
216227
{
217228
cyrfmfg_id[i]=packet_in[i]^0xFF;
218-
//eeprom_write_byte((EE_ADDR)temp++, cyrfmfg_id[i]);
229+
eeprom_write_byte((EE_ADDR)temp++, cyrfmfg_id[i]);
219230
debug(" %02X", cyrfmfg_id[i]);
220231
}
221232
// check num_ch
@@ -248,7 +259,7 @@ uint16_t DSM_Rx_callback()
248259
DSM_rx_type = 0xB2;
249260
break;
250261
}
251-
// eeprom_write_byte((EE_ADDR)temp, DSM_rx_type);
262+
eeprom_write_byte((EE_ADDR)temp, DSM_rx_type);
252263
debugln(", num_ch=%d, type=%02X",num_ch, DSM_rx_type);
253264
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
254265
CYRF_SetTxRxMode(TX_EN); // Force end state TX
@@ -456,7 +467,7 @@ uint16_t initDSM_Rx()
456467
cyrfmfg_id[i]=eeprom_read_byte((EE_ADDR)temp++);
457468
debug(" %02X", cyrfmfg_id[i]);
458469
}
459-
DSM_rx_type=0xB2; //eeprom_read_byte((EE_ADDR)temp);
470+
DSM_rx_type=eeprom_read_byte((EE_ADDR)temp);
460471
debugln(", type=%02X", DSM_rx_type);
461472
phase = DSM_RX_DATA_PREP;
462473
}

0 commit comments

Comments
 (0)