22#include " common.h"
33#include " logging.h"
44#include " LBT.h"
5+ #include " config.h"
56
67LQCALC<100 > LBTSuccessCalc;
78static uint32_t rxStartTime;
@@ -10,14 +11,38 @@ static uint32_t rxStartTime;
1011 #define LBT_RSSI_THRESHOLD_OFFSET_DB 0
1112#endif
1213
13- bool LBTEnabled = false ;
14+ static bool LBTEnabled = false ;
1415static uint32_t validRSSIdelayUs = 0 ;
1516
16- static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs (
17- SX1280_RadioLoRaSpreadingFactors_t SF,
18- uint8_t radio_type
19- )
17+ void EnableLBT ()
2018{
19+ #if defined(Regulatory_Domain_EU_CE_2400)
20+ LBTEnabled = config.GetPower () > PWR_10mW;
21+ #if defined(RADIO_LR1121)
22+ LBTEnabled = LBTEnabled && (ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_LORA_2G4 || ExpressLRS_currAirRate_Modparams->radio_type == RADIO_TYPE_LR1121_GFSK_2G4);
23+ #endif
24+ #endif
25+ }
26+
27+ static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs (uint8_t SF, uint8_t radio_type)
28+ {
29+ #if defined(RADIO_LR1121)
30+ if (radio_type == RADIO_TYPE_LR1121_LORA_2G4)
31+ {
32+ switch ((lr11xx_radio_lora_sf_t )SF)
33+ {
34+ case LR11XX_RADIO_LORA_SF5: return 100 ;
35+ case LR11XX_RADIO_LORA_SF6: return 141 ;
36+ case LR11XX_RADIO_LORA_SF7: return 218 ;
37+ case LR11XX_RADIO_LORA_SF8: return 218 ;
38+ default : return 218 ;
39+ }
40+ }
41+ if (radio_type == RADIO_TYPE_LR1121_GFSK_2G4)
42+ {
43+ return 60 + 20 ; // switching time (60us) + 20us settling time (seems fine when testing)
44+ }
45+ #elif defined(RADIO_SX128X)
2146 // The necessary wait time from RX start to valid instant RSSI reading
2247 // changes with the spreading factor setting.
2348 // The worst case necessary wait time is TX->RX switch time + Lora symbol time
@@ -37,24 +62,22 @@ static uint32_t ICACHE_RAM_ATTR SpreadingFactorToRSSIvalidDelayUs(
3762
3863 if (radio_type == RADIO_TYPE_SX128x_LORA)
3964 {
40- switch (SF)
41- {
42- case SX1280_LORA_SF5: return 100 ;
43- case SX1280_LORA_SF6: return 141 ;
44- case SX1280_LORA_SF7: return 218 ;
45- case SX1280_LORA_SF8: return 480 ;
46- default : return 480 ;
47- }
65+ switch ((SX1280_RadioLoRaSpreadingFactors_t) SF)
66+ {
67+ case SX1280_LORA_SF5: return 100 ;
68+ case SX1280_LORA_SF6: return 141 ;
69+ case SX1280_LORA_SF7: return 218 ;
70+ case SX1280_LORA_SF8: return 480 ;
71+ default : return 480 ;
72+ }
4873 }
49- else if (radio_type == RADIO_TYPE_SX128x_FLRC)
74+ if (radio_type == RADIO_TYPE_SX128x_FLRC)
5075 {
5176 return 60 + 20 ; // switching time (60us) + 20us settling time (seems fine when testing)
5277 }
53- else
54- {
55- ERRLN (" LBT not support on this radio type" );
56- return 0 ;
57- }
78+ #endif
79+ ERRLN (" LBT not support on this radio type" );
80+ return 0 ;
5881}
5982
6083static int8_t ICACHE_RAM_ATTR PowerEnumToLBTLimit (PowerLevels_e txPower, uint8_t radio_type)
@@ -65,8 +88,8 @@ static int8_t ICACHE_RAM_ATTR PowerEnumToLBTLimit(PowerLevels_e txPower, uint8_t
6588 // different RF frontends.
6689 // TODO: Maybe individual adjustment offset for differences in
6790 // rssi reading between bandwidth setting is also necessary when other BW than 0.8MHz are used.
68-
69- if (radio_type == RADIO_TYPE_SX128x_LORA )
91+ # if defined(RADIO_LR1121)
92+ if (radio_type == RADIO_TYPE_LR1121_LORA_2G4 )
7093 {
7194 switch (txPower)
7295 {
@@ -78,7 +101,7 @@ static int8_t ICACHE_RAM_ATTR PowerEnumToLBTLimit(PowerLevels_e txPower, uint8_t
78101 default : return -71 + LBT_RSSI_THRESHOLD_OFFSET_DB;
79102 }
80103 }
81- else if (radio_type == RADIO_TYPE_SX128x_FLRC )
104+ if (radio_type == RADIO_TYPE_LR1121_GFSK_2G4 )
82105 {
83106 switch (txPower)
84107 {
@@ -90,11 +113,34 @@ static int8_t ICACHE_RAM_ATTR PowerEnumToLBTLimit(PowerLevels_e txPower, uint8_t
90113 default : return -73 + LBT_RSSI_THRESHOLD_OFFSET_DB;
91114 }
92115 }
93- else
116+ #elif defined(RADIO_SX128X)
117+ if (radio_type == RADIO_TYPE_SX128x_LORA)
94118 {
95- ERRLN (" LBT not support on this radio type" );
96- return 0 ;
119+ switch (txPower)
120+ {
121+ case PWR_10mW: return -61 + LBT_RSSI_THRESHOLD_OFFSET_DB;
122+ case PWR_25mW: return -65 + LBT_RSSI_THRESHOLD_OFFSET_DB;
123+ case PWR_50mW: return -68 + LBT_RSSI_THRESHOLD_OFFSET_DB;
124+ case PWR_100mW: return -71 + LBT_RSSI_THRESHOLD_OFFSET_DB;
125+ // Values above 100mW are not relevant, default to 100mW threshold
126+ default : return -71 + LBT_RSSI_THRESHOLD_OFFSET_DB;
127+ }
97128 }
129+ if (radio_type == RADIO_TYPE_SX128x_FLRC)
130+ {
131+ switch (txPower)
132+ {
133+ case PWR_10mW: return -63 + LBT_RSSI_THRESHOLD_OFFSET_DB;
134+ case PWR_25mW: return -67 + LBT_RSSI_THRESHOLD_OFFSET_DB;
135+ case PWR_50mW: return -70 + LBT_RSSI_THRESHOLD_OFFSET_DB;
136+ case PWR_100mW: return -73 + LBT_RSSI_THRESHOLD_OFFSET_DB;
137+ // Values above 100mW are not relevant, default to 100mW threshold
138+ default : return -73 + LBT_RSSI_THRESHOLD_OFFSET_DB;
139+ }
140+ }
141+ ERRLN (" LBT not support on this radio type" );
142+ #endif
143+ return 0 ;
98144}
99145
100146void ICACHE_RAM_ATTR SetClearChannelAssessmentTime (void )
@@ -103,10 +149,16 @@ void ICACHE_RAM_ATTR SetClearChannelAssessmentTime(void)
103149 return ;
104150
105151 rxStartTime = micros ();
106- validRSSIdelayUs = SpreadingFactorToRSSIvalidDelayUs ((SX1280_RadioLoRaSpreadingFactors_t) ExpressLRS_currAirRate_Modparams->sf , ExpressLRS_currAirRate_Modparams->radio_type );
152+ validRSSIdelayUs = SpreadingFactorToRSSIvalidDelayUs (ExpressLRS_currAirRate_Modparams->sf , ExpressLRS_currAirRate_Modparams->radio_type );
107153
108154#if defined(TARGET_TX)
109- Radio.RXnb (SX1280_MODE_RX, validRSSIdelayUs);
155+ #if defined(RADIO_LR1121)
156+ Radio.RXnb (LR1121_MODE_RX, validRSSIdelayUs);
157+ #elif defined(RADIO_SX128X)
158+ Radio.RXnb (SX1280_MODE_RX, validRSSIdelayUs);
159+ #else
160+ #error No continuous receive mode defined for this radio type
161+ #endif
110162#endif
111163}
112164
0 commit comments