@@ -18,14 +18,10 @@ static uint32_t beginTX;
1818static uint32_t endTX;
1919#endif
2020
21- // RxTimeout is expressed in periods of the 32.768kHz RTC
22- #define RX_TIMEOUT_PERIOD_BASE_NANOS 1000000000 / 32768 // TODO check for LR1121
23-
2421LR1121Driver::LR1121Driver (): SX12xxDriverCommon()
2522{
2623 useFSK = false ;
2724 instance = this ;
28- timeout = 0xFFFFFF ;
2925 lastSuccessfulPacketRadio = SX12XX_Radio_1;
3026 fallBackMode = LR1121_MODE_FS;
3127 useFEC = false ;
@@ -131,12 +127,12 @@ transitioning from FS mode and the other from Standby mode. This causes the tx d
131127void LR1121Driver::startCWTest (uint32_t freq, SX12XX_Radio_Number_t radioNumber)
132128{
133129 // Set a basic Config that can be used for both 2.4G and SubGHz bands.
134- Config (LR11XX_RADIO_LORA_BW_62, LR11XX_RADIO_LORA_SF6, LR11XX_RADIO_LORA_CR_4_8, freq, 12 , false , 8 , 0 , false , 0 , 0 , radioNumber);
130+ Config (LR11XX_RADIO_LORA_BW_62, LR11XX_RADIO_LORA_SF6, LR11XX_RADIO_LORA_CR_4_8, freq, 12 , false , 8 , false , 0 , 0 , radioNumber);
135131 hal.WriteCommand (LR11XX_RADIO_SET_TX_CW_OC, radioNumber);
136132}
137133
138134void LR1121Driver::Config (uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
139- uint8_t PreambleLength, bool InvertIQ, uint8_t _PayloadLength, uint32_t rxtimeout,
135+ uint8_t PreambleLength, bool InvertIQ, uint8_t _PayloadLength,
140136 bool setFSKModulation, uint8_t fskSyncWord1, uint8_t fskSyncWord2,
141137 SX12XX_Radio_Number_t radioNumber)
142138{
@@ -158,8 +154,6 @@ void LR1121Driver::Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
158154 inverted = LR11XX_RADIO_LORA_IQ_STANDARD;
159155 }
160156
161- SetRxTimeoutUs (rxtimeout);
162-
163157 SetMode (LR1121_MODE_STDBY_RC, radioNumber);
164158
165159 useFSK = setFSKModulation;
@@ -201,7 +195,7 @@ void LR1121Driver::Config(uint8_t bw, uint8_t sf, uint8_t cr, uint32_t regfreq,
201195 SetPacketParamsLoRa (PreambleLength, packetLengthType, PayloadLength, inverted, radioNumber);
202196 }
203197
204- SetFrequencyHz (regfreq, radioNumber);
198+ SetFrequencyReg (regfreq, radioNumber, false );
205199
206200 ClearIrqStatus (radioNumber);
207201
@@ -282,15 +276,6 @@ void LR1121Driver::SetDioAsRfSwitch()
282276 hal.WriteCommand (LR11XX_SYSTEM_SET_DIO_AS_RF_SWITCH_OC, switchbuf, sizeof (switchbuf), SX12XX_Radio_All);
283277}
284278
285- void LR1121Driver::SetRxTimeoutUs (uint32_t interval)
286- {
287- timeout = 0xFFFFFF ; // no timeout, continuous mode
288- if (interval)
289- {
290- timeout = interval * 1000 / RX_TIMEOUT_PERIOD_BASE_NANOS;
291- }
292- }
293-
294279void LR1121Driver::CorrectRegisterForSF6 (uint8_t sf, SX12XX_Radio_Number_t radioNumber)
295280{
296281 // 8.3.1 SetModulationParams
@@ -431,10 +416,9 @@ void ICACHE_RAM_ATTR LR1121Driver::SetPaConfig(bool isSubGHz, SX12XX_Radio_Numbe
431416 hal.WriteCommand (LR11XX_RADIO_SET_PA_CFG_OC, Pabuf, sizeof (Pabuf), radioNumber);
432417}
433418
434- void LR1121Driver::SetMode (lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber, uint32_t incomingTimeout )
419+ void LR1121Driver::SetMode (lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Number_t radioNumber)
435420{
436421 WORD_ALIGNED_ATTR uint8_t buf[5 ] = {0 };
437- uint32_t tempTimeout;
438422
439423 switch (OPmode)
440424 {
@@ -460,20 +444,6 @@ void LR1121Driver::SetMode(lr11xx_RadioOperatingModes_t OPmode, SX12XX_Radio_Num
460444 hal.WriteCommand (LR11XX_SYSTEM_SET_FS_OC, radioNumber);
461445 break ;
462446
463- case LR1121_MODE_RX:
464- // 7.2.2 SetRx
465- tempTimeout = incomingTimeout ? (incomingTimeout * 1000 / RX_TIMEOUT_PERIOD_BASE_NANOS) : timeout;
466-
467- // incomingTimeout is below the minimum period so lets set it to 1.
468- if (incomingTimeout && !tempTimeout)
469- tempTimeout = 1 ;
470-
471- buf[0 ] = tempTimeout >> 16 ;
472- buf[1 ] = tempTimeout >> 8 ;
473- buf[2 ] = tempTimeout & 0xFF ;
474- hal.WriteCommand (LR11XX_RADIO_SET_RX_OC, buf, 3 , radioNumber);
475- break ;
476-
477447 case LR1121_MODE_RX_CONT:
478448 // 7.2.2 SetRx
479449 buf[0 ] = 0xFF ;
@@ -529,24 +499,31 @@ void LR1121Driver::SetPacketParamsLoRa(uint8_t PreambleLength, lr11xx_RadioLoRaP
529499 hal.WriteCommand (LR11XX_RADIO_SET_PKT_PARAM_OC, buf, sizeof (buf), radioNumber);
530500}
531501
532- void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyHz (uint32_t freq, SX12XX_Radio_Number_t radioNumber)
502+ void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyReg (uint32_t freq, SX12XX_Radio_Number_t radioNumber, bool doRx, uint32_t rxTime )
533503{
534- // 7.2.1 SetRfFrequency
535- uint8_t buf[4 ];
536- buf[0 ] = freq >> 24 ;
537- buf[1 ] = freq >> 16 ;
538- buf[2 ] = freq >> 8 ;
539- buf[3 ] = freq & 0xFF ;
540- hal.WriteCommand (LR11XX_RADIO_SET_RF_FREQUENCY_OC, buf, sizeof (buf), radioNumber);
504+ uint8_t buf[7 ] = {
505+ (uint8_t )(freq >> 24 ),
506+ (uint8_t )(freq >> 16 ),
507+ (uint8_t )(freq >> 8 ),
508+ (uint8_t )(freq),
509+ 0xFF ,
510+ 0xFF ,
511+ 0xFF ,
512+ };
513+ if (doRx)
514+ {
515+ // SetRfFrequency_SetRX
516+ hal.WriteCommand (LR11XX_RADIO_SET_FREQ_SET_RX, buf, sizeof (buf), radioNumber);
517+ }
518+ else
519+ {
520+ // 7.2.1 SetRfFrequency
521+ hal.WriteCommand (LR11XX_RADIO_SET_RF_FREQUENCY_OC, buf, 4 , radioNumber);
522+ }
541523
542524 currFreq = freq;
543525}
544526
545- void ICACHE_RAM_ATTR LR1121Driver::SetFrequencyReg (uint32_t freq, SX12XX_Radio_Number_t radioNumber)
546- {
547- SetFrequencyHz (freq, radioNumber);
548- }
549-
550527// 4.1.1 SetDioIrqParams
551528void LR1121Driver::SetDioIrqParams ()
552529{
@@ -720,9 +697,9 @@ bool ICACHE_RAM_ATTR LR1121Driver::RXnbISR(SX12XX_Radio_Number_t radioNumber)
720697 return true ;
721698}
722699
723- void ICACHE_RAM_ATTR LR1121Driver::RXnb (lr11xx_RadioOperatingModes_t rxMode, uint32_t incomingTimeout )
700+ void ICACHE_RAM_ATTR LR1121Driver::RXnb ()
724701{
725- SetMode (rxMode , SX12XX_Radio_All, incomingTimeout );
702+ SetMode (LR1121_MODE_RX_CONT , SX12XX_Radio_All);
726703}
727704
728705bool ICACHE_RAM_ATTR LR1121Driver::GetFrequencyErrorbool (SX12XX_Radio_Number_t radioNumber)
0 commit comments