RadioLib
Universal wireless communication library for Arduino
SX126x.h
1 #if !defined(_RADIOLIB_SX126X_H)
2 #define _RADIOLIB_SX126X_H
3 
4 #include "../../TypeDef.h"
5 
6 #if !RADIOLIB_EXCLUDE_SX126X
7 
8 #include "../../Module.h"
9 
10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h"
11 #include "../../utils/FEC.h"
12 #include "../../utils/CRC.h"
13 
14 // SX126X physical layer properties
15 #define RADIOLIB_SX126X_FREQUENCY_STEP_SIZE 0.9536743164
16 #define RADIOLIB_SX126X_MAX_PACKET_LENGTH 255
17 #define RADIOLIB_SX126X_CRYSTAL_FREQ 32.0
18 #define RADIOLIB_SX126X_DIV_EXPONENT 25
19 
20 // SX126X SPI commands
21 // operational modes commands
22 #define RADIOLIB_SX126X_CMD_NOP 0x00
23 #define RADIOLIB_SX126X_CMD_SET_SLEEP 0x84
24 #define RADIOLIB_SX126X_CMD_SET_STANDBY 0x80
25 #define RADIOLIB_SX126X_CMD_SET_FS 0xC1
26 #define RADIOLIB_SX126X_CMD_SET_TX 0x83
27 #define RADIOLIB_SX126X_CMD_SET_RX 0x82
28 #define RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE 0x9F
29 #define RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE 0x94
30 #define RADIOLIB_SX126X_CMD_SET_CAD 0xC5
31 #define RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1
32 #define RADIOLIB_SX126X_CMD_SET_TX_INFINITE_PREAMBLE 0xD2
33 #define RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE 0x96
34 #define RADIOLIB_SX126X_CMD_CALIBRATE 0x89
35 #define RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE 0x98
36 #define RADIOLIB_SX126X_CMD_SET_PA_CONFIG 0x95
37 #define RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE 0x93
38 
39 // register and buffer access commands
40 #define RADIOLIB_SX126X_CMD_WRITE_REGISTER 0x0D
41 #define RADIOLIB_SX126X_CMD_READ_REGISTER 0x1D
42 #define RADIOLIB_SX126X_CMD_WRITE_BUFFER 0x0E
43 #define RADIOLIB_SX126X_CMD_READ_BUFFER 0x1E
44 
45 // DIO and IRQ control
46 #define RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS 0x08
47 #define RADIOLIB_SX126X_CMD_GET_IRQ_STATUS 0x12
48 #define RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS 0x02
49 #define RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D
50 #define RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 0x97
51 
52 // RF, modulation and packet commands
53 #define RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY 0x86
54 #define RADIOLIB_SX126X_CMD_SET_PACKET_TYPE 0x8A
55 #define RADIOLIB_SX126X_CMD_GET_PACKET_TYPE 0x11
56 #define RADIOLIB_SX126X_CMD_SET_TX_PARAMS 0x8E
57 #define RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS 0x8B
58 #define RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS 0x8C
59 #define RADIOLIB_SX126X_CMD_SET_CAD_PARAMS 0x88
60 #define RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F
61 #define RADIOLIB_SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0xA0
62 
63 // status commands
64 #define RADIOLIB_SX126X_CMD_GET_STATUS 0xC0
65 #define RADIOLIB_SX126X_CMD_GET_RSSI_INST 0x15
66 #define RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS 0x13
67 #define RADIOLIB_SX126X_CMD_GET_PACKET_STATUS 0x14
68 #define RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS 0x17
69 #define RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS 0x07
70 #define RADIOLIB_SX126X_CMD_GET_STATS 0x10
71 #define RADIOLIB_SX126X_CMD_RESET_STATS 0x00
72 
73 #define RADIOLIB_SX126X_CMD_PRAM_UPDATE 0xD9
74 #define RADIOLIB_SX126X_CMD_SET_LBT_SCAN_PARAMS 0x9A
75 #define RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS 0x9B
76 
77 // SX126X register map
78 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0 0x029F // SX1268 datasheet v1.1, section 9.6
79 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1 0x02A0 // SX1268 datasheet v1.1, section 9.6
80 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2 0x02A1 // SX1268 datasheet v1.1, section 9.6
81 #define RADIOLIB_SX126X_REG_VERSION_STRING 0x0320
82 #define RADIOLIB_SX126X_REG_HOPPING_ENABLE 0x0385
83 #define RADIOLIB_SX126X_REG_LR_FHSS_PACKET_LENGTH 0x0386
84 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387
85 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6)
86 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6)
87 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6)
88 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6)
89 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6)
90 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6)
91 #define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT 0x0401
92 #define RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE 0x0580
93 #define RADIOLIB_SX126X_REG_DIOX_DRIVE_STRENGTH 0x0582
94 #define RADIOLIB_SX126X_REG_DIOX_IN_ENABLE 0x0583
95 #define RADIOLIB_SX126X_REG_DIOX_PULL_UP_CTRL 0x0584
96 #define RADIOLIB_SX126X_REG_DIOX_PULL_DOWN_CTRL 0x0585
97 #define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 0x0587
98 #define RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE 0x0610
99 #define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 0x0680
100 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8
101 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9
102 #define RADIOLIB_SX126X_REG_RX_TX_PLD_LEN 0x06BB
103 #define RADIOLIB_SX126X_REG_CRC_INITIAL_MSB 0x06BC
104 #define RADIOLIB_SX126X_REG_CRC_INITIAL_LSB 0x06BD
105 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE
106 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF
107 #define RADIOLIB_SX126X_REG_SYNC_WORD_0 0x06C0
108 #define RADIOLIB_SX126X_REG_SYNC_WORD_1 0x06C1
109 #define RADIOLIB_SX126X_REG_SYNC_WORD_2 0x06C2
110 #define RADIOLIB_SX126X_REG_SYNC_WORD_3 0x06C3
111 #define RADIOLIB_SX126X_REG_SYNC_WORD_4 0x06C4
112 #define RADIOLIB_SX126X_REG_SYNC_WORD_5 0x06C5
113 #define RADIOLIB_SX126X_REG_SYNC_WORD_6 0x06C6
114 #define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7
115 #define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD
116 #define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE
117 #define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702
118 #define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704
119 #define RADIOLIB_SX126X_REG_LORA_SYNC_TIMEOUT 0x0706
120 #define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736
121 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740
122 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741
123 #define RADIOLIB_SX126X_REG_FREQ_ERROR 0x076B
124 #define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS 0x07CD
125 #define RADIOLIB_SX126X_REG_RX_ADDR_PTR 0x0803
126 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_0 0x0819
127 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_1 0x081A
128 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_2 0x081B
129 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_3 0x081C
130 #define RADIOLIB_SX126X_REG_SENSITIVITY_CONFIG 0x0889 // SX1268 datasheet v1.1, section 15.1
131 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_0 0x088B
132 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_1 0x088C
133 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_2 0x088D
134 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_3 0x088E
135 #define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B
136 #define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC
137 #define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8
138 #define RADIOLIB_SX126X_REG_ANA_LNA 0x08E2
139 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3
140 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_P 0x08E4
141 #define RADIOLIB_SX126X_REG_ANA_MIXER 0x08E5
142 #define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7
143 #define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902
144 #define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911
145 #define RADIOLIB_SX126X_REG_XTB_TRIM 0x0912
146 #define RADIOLIB_SX126X_REG_DIO3_OUT_VOLTAGE_CTRL 0x0920
147 #define RADIOLIB_SX126X_REG_EVENT_MASK 0x0944
148 #define RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE 0x8000
149 
150 // SX126X SPI command variables
151 //RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION
152 #define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default)
153 #define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained
154 #define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled
155 #define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled
156 
157 //RADIOLIB_SX126X_CMD_SET_STANDBY
158 #define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator
159 #define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator
160 
161 //RADIOLIB_SX126X_CMD_SET_RX
162 #define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode)
163 #define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode)
164 
165 //RADIOLIB_SX126X_CMD_SET_TX
166 #define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode)
167 
168 //RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE
169 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default)
170 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection
171 
172 //RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE
173 #define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default)
174 #define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC
175 
176 //RADIOLIB_SX126X_CMD_CALIBRATE
177 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled
178 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled
179 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled
180 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled
181 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled
182 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled
183 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled
184 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled
185 #define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled
186 #define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled
187 #define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled
188 #define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled
189 #define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled
190 #define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled
191 #define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks
192 
193 //RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE
194 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B
195 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F
196 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75
197 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81
198 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1
199 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5
200 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7
201 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB
202 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1
203 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9
204 #define RADIOLIB_SX126X_CAL_IMG_FREQ_TRIG_MHZ (20.0)
205 
206 //RADIOLIB_SX126X_CMD_SET_PA_CONFIG
207 #define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07
208 #define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01
209 #define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00
210 
211 //RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE
212 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode
213 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator
214 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default)
215 
216 //RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS
217 #define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop
218 #define RADIOLIB_SX126X_IRQ_TIMEOUT 0b0000001000000000 // 9 9 Rx or Tx timeout
219 #define RADIOLIB_SX126X_IRQ_CAD_DETECTED 0b0000000100000000 // 8 8 channel activity detected
220 #define RADIOLIB_SX126X_IRQ_CAD_DONE 0b0000000010000000 // 7 7 channel activity detection finished
221 #define RADIOLIB_SX126X_IRQ_CRC_ERR 0b0000000001000000 // 6 6 wrong CRC received
222 #define RADIOLIB_SX126X_IRQ_HEADER_ERR 0b0000000000100000 // 5 5 LoRa header CRC error
223 #define RADIOLIB_SX126X_IRQ_HEADER_VALID 0b0000000000010000 // 4 4 valid LoRa header received
224 #define RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID 0b0000000000001000 // 3 3 valid sync word detected
225 #define RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected
226 #define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received
227 #define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed
228 #define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts
229 #define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts
230 
231 //RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL
232 #define RADIOLIB_SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ
233 #define RADIOLIB_SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control
234 
235 //RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL
236 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V
237 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V
238 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V
239 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V
240 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V
241 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V
242 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V
243 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V
244 
245 //RADIOLIB_SX126X_CMD_SET_PACKET_TYPE
246 #define RADIOLIB_SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK
247 #define RADIOLIB_SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa
248 #define RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS 0x03 // 7 0 LR-FHSS
249 
250 //RADIOLIB_SX126X_CMD_SET_TX_PARAMS
251 #define RADIOLIB_SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us
252 #define RADIOLIB_SX126X_PA_RAMP_20U 0x01 // 7 0 20 us
253 #define RADIOLIB_SX126X_PA_RAMP_40U 0x02 // 7 0 40 us
254 #define RADIOLIB_SX126X_PA_RAMP_80U 0x03 // 7 0 80 us
255 #define RADIOLIB_SX126X_PA_RAMP_200U 0x04 // 7 0 200 us
256 #define RADIOLIB_SX126X_PA_RAMP_800U 0x05 // 7 0 800 us
257 #define RADIOLIB_SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us
258 #define RADIOLIB_SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us
259 
260 //RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS
261 #define RADIOLIB_SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none
262 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3
263 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5
264 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7
265 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1
266 #define RADIOLIB_SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz
267 #define RADIOLIB_SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz
268 #define RADIOLIB_SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz
269 #define RADIOLIB_SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz
270 #define RADIOLIB_SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz
271 #define RADIOLIB_SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz
272 #define RADIOLIB_SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz
273 #define RADIOLIB_SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz
274 #define RADIOLIB_SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz
275 #define RADIOLIB_SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz
276 #define RADIOLIB_SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz
277 #define RADIOLIB_SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz
278 #define RADIOLIB_SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz
279 #define RADIOLIB_SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz
280 #define RADIOLIB_SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz
281 #define RADIOLIB_SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz
282 #define RADIOLIB_SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz
283 #define RADIOLIB_SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz
284 #define RADIOLIB_SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz
285 #define RADIOLIB_SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz
286 #define RADIOLIB_SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz
287 #define RADIOLIB_SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz
288 #define RADIOLIB_SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz
289 #define RADIOLIB_SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz
290 #define RADIOLIB_SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz
291 #define RADIOLIB_SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz
292 #define RADIOLIB_SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz
293 #define RADIOLIB_SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz
294 #define RADIOLIB_SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz
295 #define RADIOLIB_SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz
296 #define RADIOLIB_SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz
297 #define RADIOLIB_SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5
298 #define RADIOLIB_SX126X_LORA_CR_4_6 0x02 // 7 0 4/6
299 #define RADIOLIB_SX126X_LORA_CR_4_7 0x03 // 7 0 4/7
300 #define RADIOLIB_SX126X_LORA_CR_4_8 0x04 // 7 0 4/8
301 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled
302 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled
303 
304 //RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS
305 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled
306 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits
307 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits
308 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits
309 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits
310 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled
311 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only
312 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast
313 #define RADIOLIB_SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides)
314 #define RADIOLIB_SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet)
315 #define RADIOLIB_SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled
316 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte
317 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte
318 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted
319 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted
320 #define RADIOLIB_SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled
321 #define RADIOLIB_SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled
322 #define RADIOLIB_SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit
323 #define RADIOLIB_SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit
324 #define RADIOLIB_SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled
325 #define RADIOLIB_SX126X_LORA_CRC_ON 0x01 // 7 0 enabled
326 #define RADIOLIB_SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard
327 #define RADIOLIB_SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted
328 
329 //RADIOLIB_SX126X_CMD_SET_CAD_PARAMS
330 #define RADIOLIB_SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1
331 #define RADIOLIB_SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2
332 #define RADIOLIB_SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4
333 #define RADIOLIB_SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8
334 #define RADIOLIB_SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16
335 #define RADIOLIB_SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode
336 #define RADIOLIB_SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected
337 #define RADIOLIB_SX126X_CAD_PARAM_DEFAULT 0xFF // 7 0 used by the CAD methods to specify default parameter value
338 #define RADIOLIB_SX126X_CAD_PARAM_DET_MIN 10 // 7 0 default detMin CAD parameter
339 
340 //RADIOLIB_SX126X_CMD_GET_STATUS
341 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC
342 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC
343 #define RADIOLIB_SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS
344 #define RADIOLIB_SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX
345 #define RADIOLIB_SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX
346 #define RADIOLIB_SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved
347 #define RADIOLIB_SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out
348 #define RADIOLIB_SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command
349 #define RADIOLIB_SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute
350 #define RADIOLIB_SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done
351 #define RADIOLIB_SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed
352 
353 //RADIOLIB_SX126X_CMD_GET_PACKET_STATUS
354 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error
355 #define RADIOLIB_SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error
356 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error
357 #define RADIOLIB_SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error
358 #define RADIOLIB_SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error
359 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error
360 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received
361 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent
362 
363 //RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS
364 #define RADIOLIB_SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed
365 #define RADIOLIB_SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock
366 #define RADIOLIB_SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start
367 #define RADIOLIB_SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed
368 #define RADIOLIB_SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed
369 #define RADIOLIB_SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed
370 #define RADIOLIB_SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed
371 #define RADIOLIB_SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed
372 
373 //RADIOLIB_SX126X_CMD_SET_LBT_SCAN_PARAMS + RADIOLIB_SX126X_CMD_SET_SPECTR_SCAN_PARAMS
374 #define RADIOLIB_SX126X_SCAN_INTERVAL_7_68_US 10 // 7 0 RSSI reading interval: 7.68 us
375 #define RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US 11 // 7 0 8.20 us
376 #define RADIOLIB_SX126X_SCAN_INTERVAL_8_68_US 12 // 7 0 8.68 us
377 
378 // SX126X SPI register variables
379 //RADIOLIB_SX126X_REG_HOPPING_ENABLE
380 #define RADIOLIB_SX126X_HOPPING_ENABLED 0b00000001 // 0 0 intra-packet hopping for LR-FHSS: enabled
381 #define RADIOLIB_SX126X_HOPPING_DISABLED 0b00000000 // 0 0 (disabled)
382 
383 //RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB + LSB
384 #define RADIOLIB_SX126X_SYNC_WORD_PUBLIC 0x34 // actually 0x3444 NOTE: The low nibbles in each byte (0x_4_4) are masked out since apparently, they're reserved.
385 #define RADIOLIB_SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried.
386 
387 // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1
388 #define RADIOLIB_SX126X_TX_BITBANG_1_DISABLED 0b00000000 // 6 4 Tx bitbang: disabled (default)
389 #define RADIOLIB_SX126X_TX_BITBANG_1_ENABLED 0b00010000 // 6 4 enabled
390 
391 // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0
392 #define RADIOLIB_SX126X_TX_BITBANG_0_DISABLED 0b00000000 // 3 0 Tx bitbang: disabled (default)
393 #define RADIOLIB_SX126X_TX_BITBANG_0_ENABLED 0b00001100 // 3 0 enabled
394 
395 // RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE
396 #define RADIOLIB_SX126X_DIO1_OUT_DISABLED 0b00000010 // 1 1 DIO1 output: disabled
397 #define RADIOLIB_SX126X_DIO1_OUT_ENABLED 0b00000000 // 1 1 enabled
398 #define RADIOLIB_SX126X_DIO2_OUT_DISABLED 0b00000100 // 2 2 DIO2 output: disabled
399 #define RADIOLIB_SX126X_DIO2_OUT_ENABLED 0b00000000 // 2 2 enabled
400 #define RADIOLIB_SX126X_DIO3_OUT_DISABLED 0b00001000 // 3 3 DIO3 output: disabled
401 #define RADIOLIB_SX126X_DIO3_OUT_ENABLED 0b00000000 // 3 3 enabled
402 
403 // RADIOLIB_SX126X_REG_DIOX_IN_ENABLE
404 #define RADIOLIB_SX126X_DIO1_IN_DISABLED 0b00000000 // 1 1 DIO1 input: disabled
405 #define RADIOLIB_SX126X_DIO1_IN_ENABLED 0b00000010 // 1 1 enabled
406 #define RADIOLIB_SX126X_DIO2_IN_DISABLED 0b00000000 // 2 2 DIO2 input: disabled
407 #define RADIOLIB_SX126X_DIO2_IN_ENABLED 0b00000100 // 2 2 enabled
408 #define RADIOLIB_SX126X_DIO3_IN_DISABLED 0b00000000 // 3 3 DIO3 input: disabled
409 #define RADIOLIB_SX126X_DIO3_IN_ENABLED 0b00001000 // 3 3 enabled
410 
411 // RADIOLIB_SX126X_REG_RX_GAIN
412 #define RADIOLIB_SX126X_RX_GAIN_BOOSTED 0x96 // 7 0 Rx gain: boosted
413 #define RADIOLIB_SX126X_RX_GAIN_POWER_SAVING 0x94 // 7 0 power saving
414 #define RADIOLIB_SX126X_RX_GAIN_SPECTRAL_SCAN 0xCB // 7 0 spectral scan
415 
416 // RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE
417 #define RADIOLIB_SX126X_PATCH_UPDATE_DISABLED 0b00000000 // 4 4 patch update: disabled
418 #define RADIOLIB_SX126X_PATCH_UPDATE_ENABLED 0b00010000 // 4 4 enabled
419 
420 // RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS
421 #define RADIOLIB_SX126X_SPECTRAL_SCAN_NONE 0x00 // 7 0 spectral scan status: none
422 #define RADIOLIB_SX126X_SPECTRAL_SCAN_ONGOING 0x0F // 7 0 ongoing
423 #define RADIOLIB_SX126X_SPECTRAL_SCAN_ABORTED 0xF0 // 7 0 aborted
424 #define RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED 0xFF // 7 0 completed
425 
426 // RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW
427 #define RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2) // 7 0 default RSSI average window
428 
429 // RADIOLIB_SX126X_REG_ANA_LNA
430 #define RADIOLIB_SX126X_LNA_RNG_DISABLED 0b00000001 // 0 0 random number: disabled
431 #define RADIOLIB_SX126X_LNA_RNG_ENABLED 0b00000000 // 0 0 enabled
432 
433 // RADIOLIB_SX126X_REG_ANA_MIXER
434 #define RADIOLIB_SX126X_MIXER_RNG_DISABLED 0b00000001 // 7 7 random number: disabled
435 #define RADIOLIB_SX126X_MIXER_RNG_ENABLED 0b00000000 // 7 7 enabled
436 
437 // size of the spectral scan result
438 #define RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE (33)
439 
440 // LR-FHSS configuration
441 #define RADIOLIB_SX126X_LR_FHSS_CR_5_6 (0x00UL << 0) // 7 0 LR FHSS coding rate: 5/6
442 #define RADIOLIB_SX126X_LR_FHSS_CR_2_3 (0x01UL << 0) // 7 0 2/3
443 #define RADIOLIB_SX126X_LR_FHSS_CR_1_2 (0x02UL << 0) // 7 0 1/2
444 #define RADIOLIB_SX126X_LR_FHSS_CR_1_3 (0x03UL << 0) // 7 0 1/3
445 #define RADIOLIB_SX126X_LR_FHSS_MOD_TYPE_GMSK (0x00UL << 0) // 7 0 LR FHSS modulation: GMSK
446 #define RADIOLIB_SX126X_LR_FHSS_GRID_STEP_FCC (0x00UL << 0) // 7 0 LR FHSS step size: 25.390625 kHz (FCC)
447 #define RADIOLIB_SX126X_LR_FHSS_GRID_STEP_NON_FCC (0x01UL << 0) // 7 0 3.90625 kHz (non-FCC)
448 #define RADIOLIB_SX126X_LR_FHSS_HOPPING_DISABLED (0x00UL << 0) // 7 0 LR FHSS hopping: disabled
449 #define RADIOLIB_SX126X_LR_FHSS_HOPPING_ENABLED (0x01UL << 0) // 7 0 enabled
450 #define RADIOLIB_SX126X_LR_FHSS_BW_39_06 (0x00UL << 0) // 7 0 LR FHSS bandwidth: 39.06 kHz
451 #define RADIOLIB_SX126X_LR_FHSS_BW_85_94 (0x01UL << 0) // 7 0 85.94 kHz
452 #define RADIOLIB_SX126X_LR_FHSS_BW_136_72 (0x02UL << 0) // 7 0 136.72 kHz
453 #define RADIOLIB_SX126X_LR_FHSS_BW_183_59 (0x03UL << 0) // 7 0 183.59 kHz
454 #define RADIOLIB_SX126X_LR_FHSS_BW_335_94 (0x04UL << 0) // 7 0 335.94 kHz
455 #define RADIOLIB_SX126X_LR_FHSS_BW_386_72 (0x05UL << 0) // 7 0 386.72 kHz
456 #define RADIOLIB_SX126X_LR_FHSS_BW_722_66 (0x06UL << 0) // 7 0 722.66 kHz
457 #define RADIOLIB_SX126X_LR_FHSS_BW_773_44 (0x07UL << 0) // 7 0 773.44 kHz
458 #define RADIOLIB_SX126X_LR_FHSS_BW_1523_4 (0x08UL << 0) // 7 0 1523.4 kHz
459 #define RADIOLIB_SX126X_LR_FHSS_BW_1574_2 (0x09UL << 0) // 7 0 1574.2 kHz
460 
461 // LR-FHSS packet lengths
462 #define RADIOLIB_SX126X_LR_FHSS_MAX_ENC_SIZE (608)
463 #define RADIOLIB_SX126X_LR_FHSS_HEADER_BITS (114)
464 #define RADIOLIB_SX126X_LR_FHSS_HDR_BYTES (10)
465 #define RADIOLIB_SX126X_LR_FHSS_SYNC_WORD_BYTES (4)
466 #define RADIOLIB_SX126X_LR_FHSS_FRAG_BITS (48)
467 #define RADIOLIB_SX126X_LR_FHSS_BLOCK_PREAMBLE_BITS (2)
468 #define RADIOLIB_SX126X_LR_FHSS_BLOCK_BITS (RADIOLIB_SX126X_LR_FHSS_FRAG_BITS + RADIOLIB_SX126X_LR_FHSS_BLOCK_PREAMBLE_BITS)
469 
475 class SX126x: public PhysicalLayer {
476  public:
477  // introduce PhysicalLayer overloads
482 
487  explicit SX126x(Module* mod);
488 
492  bool XTAL;
493 
498 
499  // basic methods
500 
510  int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false);
511 
523  int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false);
524 
534  int16_t beginLRFHSS(uint8_t bw, uint8_t cr, bool narrowGrid, float tcxoVoltage, bool useRegulatorLDO = false);
535 
544  int16_t setLrFhssConfig(uint8_t bw, uint8_t cr, uint8_t hdrCount = 3, uint16_t hopSeqId = 0x100);
545 
552  int16_t reset(bool verify = true);
553 
562  int16_t transmit(const uint8_t* data, size_t len, uint8_t addr = 0) override;
563 
571  int16_t receive(uint8_t* data, size_t len) override;
572 
578  int16_t transmitDirect(uint32_t frf = 0) override;
579 
585  int16_t receiveDirect() override;
586 
592  int16_t scanChannel() override;
593 
599  int16_t scanChannel(const ChannelScanConfig_t &config) override;
600 
606  int16_t sleep() override;
607 
614  int16_t sleep(bool retainConfig);
615 
620  int16_t standby() override;
621 
629  int16_t standby(uint8_t mode, bool wakeup = true);
630 
631  // interrupt methods
632 
637  void setDio1Action(void (*func)(void));
638 
642  void clearDio1Action();
643 
648  void setPacketReceivedAction(void (*func)(void)) override;
649 
653  void clearPacketReceivedAction() override;
654 
659  void setPacketSentAction(void (*func)(void)) override;
660 
664  void clearPacketSentAction() override;
665 
670  void setChannelScanAction(void (*func)(void)) override;
671 
675  void clearChannelScanAction() override;
676 
685  int16_t startTransmit(const uint8_t* data, size_t len, uint8_t addr = 0) override;
686 
691  int16_t finishTransmit() override;
692 
699  int16_t startReceive() override;
700 
716  int16_t startReceive(uint32_t timeout, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK, size_t len = 0);
717 
730  int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK);
731 
746  int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK);
747 
756  int16_t readData(uint8_t* data, size_t len) override;
757 
763  int16_t startChannelScan() override;
764 
771  int16_t startChannelScan(const ChannelScanConfig_t &config) override;
772 
777  int16_t getChannelScanResult() override;
778 
779  // configuration methods
780 
786  int16_t setBandwidth(float bw);
787 
793  int16_t setSpreadingFactor(uint8_t sf);
794 
800  int16_t setCodingRate(uint8_t cr);
801 
808  int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44);
809 
815  int16_t setCurrentLimit(float currentLimit);
816 
821  float getCurrentLimit();
822 
828  int16_t setPreambleLength(size_t preambleLength) override;
829 
835  int16_t setFrequencyDeviation(float freqDev) override;
836 
842  int16_t setBitRate(float br) override;
843 
849  int16_t setDataRate(DataRate_t dr) override;
850 
856  int16_t checkDataRate(DataRate_t dr) override;
857 
864  int16_t setRxBandwidth(float rxBw);
865 
874  int16_t setRxBoostedGainMode(bool rxbgm, bool persist = true);
875 
883  int16_t setDataShaping(uint8_t sh) override;
884 
892  int16_t setSyncWord(uint8_t* syncWord, size_t len) override;
893 
901  int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen);
902 
908  int16_t setNodeAddress(uint8_t addr);
909 
916  int16_t setBroadcastAddress(uint8_t broadAddr);
917 
922  int16_t disableAddressFiltering();
923 
932  int16_t setCRC(uint8_t len, uint16_t initial = 0x1D0F, uint16_t polynomial = 0x1021, bool inverted = true);
933 
941  int16_t setWhitening(bool enabled, uint16_t initial = 0x01FF);
942 
952  int16_t setTCXO(float voltage, uint32_t delay = 5000);
953 
958  int16_t setDio2AsRfSwitch(bool enable = true);
959 
964  float getDataRate() const;
965 
971  float getRSSI() override;
972 
978  float getRSSI(bool packet);
979 
984  float getSNR() override;
985 
993  float getFrequencyError();
994 
1000  size_t getPacketLength(bool update = true) override;
1001 
1008  size_t getPacketLength(bool update, uint8_t* offset);
1009 
1015  int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX126X_MAX_PACKET_LENGTH);
1016 
1022  int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX126X_MAX_PACKET_LENGTH);
1023 
1029  RadioLibTime_t getTimeOnAir(size_t len) override;
1030 
1036  RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override;
1037 
1042  uint32_t getIrqFlags() override;
1043 
1049  int16_t setIrqFlags(uint32_t irq) override;
1050 
1056  int16_t clearIrqFlags(uint32_t irq) override;
1057 
1063  int16_t implicitHeader(size_t len);
1064 
1069  int16_t explicitHeader();
1070 
1075  int16_t setRegulatorLDO();
1076 
1081  int16_t setRegulatorDCDC();
1082 
1088  int16_t setEncoding(uint8_t encoding) override;
1089 
1091  void setRfSwitchPins(uint32_t rxEn, uint32_t txEn);
1092 
1094  void setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]);
1095 
1104  int16_t forceLDRO(bool enable);
1105 
1112  int16_t autoLDRO();
1113 
1118  uint8_t randomByte() override;
1119 
1125  int16_t invertIQ(bool enable) override;
1126 
1132  int16_t getModem(ModemType_t* modem) override;
1133 
1134  #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
1139  void setDirectAction(void (*func)(void)) override;
1140 
1145  void readBit(uint32_t pin) override;
1146  #endif
1147 
1157  int16_t uploadPatch(const uint32_t* patch, size_t len, bool nonvolatile = true);
1158 
1166  int16_t spectralScanStart(uint16_t numSamples, uint8_t window = RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval = RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US);
1167 
1171  void spectralScanAbort();
1172 
1177  int16_t spectralScanGetStatus();
1178 
1184  int16_t spectralScanGetResult(uint16_t* results);
1185 
1197  int16_t setPaConfig(uint8_t paDutyCycle, uint8_t deviceSel, uint8_t hpMax = RADIOLIB_SX126X_PA_CONFIG_HP_MAX, uint8_t paLut = RADIOLIB_SX126X_PA_CONFIG_PA_LUT);
1198 
1206  int16_t calibrateImage(float freq);
1207 
1215  int16_t calibrateImageRejection(float freqMin, float freqMax);
1216 
1221  int16_t setPaRampTime(uint8_t rampTime);
1222 
1223 #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
1224  protected:
1225 #endif
1226  Module* getMod() override;
1227 
1228  // SX126x SPI command implementations
1229  int16_t setFs();
1230  int16_t setTx(uint32_t timeout = 0);
1231  int16_t setRx(uint32_t timeout);
1232  int16_t setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin, uint8_t exitMode, RadioLibTime_t timeout);
1233  int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
1234  int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
1235  int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
1236  int16_t readBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
1237  int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX126X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX126X_IRQ_NONE);
1238  virtual int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX126X_IRQ_ALL);
1239  int16_t setRfFrequency(uint32_t frf);
1240  int16_t calibrateImage(uint8_t* data);
1241  uint8_t getPacketType();
1242  int16_t setTxParams(uint8_t power, uint8_t rampTime);
1243  int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro);
1244  int16_t setModulationParamsFSK(uint32_t br, uint8_t sh, uint8_t rxBw, uint32_t freqDev);
1245  int16_t setPacketParams(uint16_t preambleLen, uint8_t crcType, uint8_t payloadLen, uint8_t hdrType, uint8_t invertIQ);
1246  int16_t setPacketParamsFSK(uint16_t preambleLen, uint8_t preambleDetectorLen, uint8_t crcType, uint8_t syncWordLen, uint8_t addrCmp, uint8_t whiten, uint8_t packType = RADIOLIB_SX126X_GFSK_PACKET_VARIABLE, uint8_t payloadLen = 0xFF);
1247  int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);
1248  int16_t setRegulatorMode(uint8_t mode);
1249  uint8_t getStatus();
1250  uint32_t getPacketStatus();
1251  uint16_t getDeviceErrors();
1252  int16_t clearDeviceErrors();
1253 
1254 #if !RADIOLIB_GODMODE
1255  protected:
1256 #endif
1257  const char* chipType = NULL;
1258  uint8_t bandwidth = 0;
1259  float freqMHz = 0;
1260 
1261  // Allow subclasses to define different TX modes
1262  uint8_t txMode = Module::MODE_TX;
1263 
1264  int16_t setFrequencyRaw(float freq);
1265  int16_t fixPaClamping(bool enable = true);
1266 
1267  // common low-level SPI interface
1268  static int16_t SPIparseStatus(uint8_t in);
1269 
1270 #if !RADIOLIB_GODMODE
1271  private:
1272 #endif
1273  Module* mod;
1274 
1275  uint8_t spreadingFactor = 0, codingRate = 0, ldrOptimize = 0, crcTypeLoRa = 0, headerType = 0;
1276  uint16_t preambleLengthLoRa = 0;
1277  float bandwidthKhz = 0;
1278  bool ldroAuto = true;
1279 
1280  uint32_t bitRate = 0, frequencyDev = 0;
1281  uint8_t preambleDetLength = 0, rxBandwidth = 0, pulseShape = 0, crcTypeFSK = 0, syncWordLength = 0, addrComp = 0, whitening = 0, packetType = 0;
1282  uint16_t preambleLengthFSK = 0;
1283  float rxBandwidthKhz = 0;
1284  uint8_t nodeAddr = 0;
1285 
1286  float dataRateMeasured = 0;
1287 
1288  uint32_t tcxoDelay = 0;
1289  uint8_t pwr = 0;
1290 
1291  size_t implicitLen = 0;
1292  uint8_t invertIQEnabled = RADIOLIB_SX126X_LORA_IQ_STANDARD;
1293 
1294  // LR-FHSS stuff - there's a lot of it because all the encoding happens in software
1295  uint8_t lrFhssCr = RADIOLIB_SX126X_LR_FHSS_CR_2_3;
1296  uint8_t lrFhssBw = RADIOLIB_SX126X_LR_FHSS_BW_722_66;
1297  uint8_t lrFhssHdrCount = 3;
1298  uint8_t lrFhssSyncWord[RADIOLIB_SX126X_LR_FHSS_SYNC_WORD_BYTES] = { 0x12, 0xAD, 0x10, 0x1B };
1299  bool lrFhssGridNonFcc = false;
1300  uint16_t lrFhssNgrid = 0;
1301  uint16_t lrFhssLfsrState = 0;
1302  uint16_t lrFhssPoly = 0;
1303  uint16_t lrFhssSeed = 0;
1304  uint16_t lrFhssHopSeqId = 0;
1305  size_t lrFhssFrameBitsRem = 0;
1306  size_t lrFhssFrameHopsRem = 0;
1307  size_t lrFhssHopNum = 0;
1308 
1309  int16_t modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem);
1310  int16_t config(uint8_t modem);
1311  bool findChip(const char* verStr);
1312  int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, RadioLibIrqFlags_t irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK);
1313  int16_t setPacketMode(uint8_t mode, uint8_t len);
1314  int16_t setHeaderType(uint8_t hdrType, size_t len = 0xFF);
1315  int16_t directMode();
1316  int16_t packetMode();
1317 
1318  // fixes to errata
1319  int16_t fixSensitivity();
1320  int16_t fixImplicitTimeout();
1321  int16_t fixInvertedIQ(uint8_t iqConfig);
1322 
1323  // LR-FHSS utilities
1324  int16_t buildLRFHSSPacket(const uint8_t* in, size_t in_len, uint8_t* out, size_t* out_len, size_t* out_bits, size_t* out_hops);
1325  int16_t resetLRFHSS();
1326  uint16_t stepLRFHSS();
1327  int16_t setLRFHSSHop(uint8_t index);
1328 
1329  void regdump();
1330  void effectEvalPre(uint8_t* buff, uint32_t start);
1331  void effectEvalPost(uint8_t* buff, uint32_t start);
1332  void effectEval();
1333 };
1334 
1335 #endif
1336 
1337 #endif
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:73
static const size_t RFSWITCH_MAX_PINS
The maximum number of pins supported by the RF switch code. Note: It is not recommended to use this c...
Definition: Module.h:82
@ MODE_TX
Transmission mode.
Definition: Module.h:119
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:151
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:206
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition: PhysicalLayer.cpp:53
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:148
virtual int16_t receive(uint8_t *data, size_t len)
Binary receive method. Must be implemented in module class.
Definition: PhysicalLayer.cpp:111
Base class for SX126x series. All derived classes for SX126x (e.g. SX1262 or SX1268) inherit from thi...
Definition: SX126x.h:475
int16_t startChannelScan() override
Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is dete...
Definition: SX126x.cpp:794
float getFrequencyError()
Gets frequency error of the latest received packet. WARNING: This functionality is based on SX128x im...
Definition: SX126x.cpp:1425
void setRfSwitchPins(uint32_t rxEn, uint32_t txEn)
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition: SX126x.cpp:1598
void setDio1Action(void(*func)(void))
Sets interrupt service routine to call when DIO1 activates.
Definition: SX126x.cpp:479
int16_t setPaConfig(uint8_t paDutyCycle, uint8_t deviceSel, uint8_t hpMax=RADIOLIB_SX126X_PA_CONFIG_HP_MAX, uint8_t paLut=RADIOLIB_SX126X_PA_CONFIG_PA_LUT)
Set the PA configuration. Allows user to optimize PA for a specific output power and matching network...
Definition: SX126x.cpp:1910
RadioLibTime_t getTimeOnAir(size_t len) override
Get expected time-on-air for a given size of payload.
Definition: SX126x.cpp:1486
uint8_t randomByte() override
Get one truly random byte from RSSI noise.
Definition: SX126x.cpp:1627
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override
Calculate the timeout value for this specific module / series (in number of symbols or units of time)
Definition: SX126x.cpp:1557
int16_t setDataShaping(uint8_t sh) override
Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPI...
Definition: SX126x.cpp:1156
int16_t setRegulatorLDO()
Set regulator mode to LDO.
Definition: SX126x.cpp:1586
int16_t invertIQ(bool enable) override
Enable/disable inversion of the I and Q signals.
Definition: SX126x.cpp:1656
int16_t uploadPatch(const uint32_t *patch, size_t len, bool nonvolatile=true)
Upload binary patch into the SX126x device RAM. Patch is needed to e.g., enable spectral scan and mus...
Definition: SX126x.cpp:1699
int16_t setEncoding(uint8_t encoding) override
Sets transmission encoding. Available in FSK mode only. Serves only as alias for PhysicalLayer compat...
Definition: SX126x.cpp:1594
void setRfSwitchTable(const uint32_t(&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[])
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition: SX126x.cpp:1602
int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO=false)
Initialization method for FSK modem.
Definition: SX126x.cpp:68
int16_t setBandwidth(float bw)
Sets LoRa bandwidth. Allowed values are 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125....
Definition: SX126x.cpp:854
int16_t calibrateImage(float freq)
Perform image rejection calibration for the specified frequency. Will try to use Semtech-defined pres...
Definition: SX126x.cpp:1957
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:206
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition: SX126x.cpp:1582
void clearChannelScanAction() override
Clears interrupt service routine to call when a channel scan is finished.
Definition: SX126x.cpp:507
int16_t forceLDRO(bool enable)
Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,...
Definition: SX126x.cpp:1606
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition: PhysicalLayer.cpp:53
void setDirectAction(void(*func)(void)) override
Set interrupt service routine function to call when data bit is received in direct mode.
Definition: SX126x.cpp:1690
int16_t setIrqFlags(uint32_t irq) override
Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).
Definition: SX126x.cpp:1570
int16_t spectralScanGetStatus()
Read the status of spectral scan.
Definition: SX126x.cpp:1766
void clearPacketReceivedAction() override
Clears interrupt service routine to call when a packet is received.
Definition: SX126x.cpp:491
int16_t setTCXO(float voltage, uint32_t delay=5000)
Sets TCXO (Temperature Compensated Crystal Oscillator) configuration.
Definition: SX126x.cpp:1786
float getSNR() override
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
Definition: SX126x.cpp:1409
int16_t setRxBandwidth(float rxBw)
Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19....
Definition: SX126x.cpp:1077
int16_t setRegulatorDCDC()
Set regulator mode to DC-DC.
Definition: SX126x.cpp:1590
int16_t startReceive() override
Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalL...
Definition: SX126x.cpp:639
void clearDio1Action()
Clears interrupt service routine to call when DIO1 activates.
Definition: SX126x.cpp:483
int16_t checkDataRate(DataRate_t dr) override
Check the data rate can be configured by this module.
Definition: SX126x.cpp:1056
void setPacketReceivedAction(void(*func)(void)) override
Sets interrupt service routine to call when a packet is received.
Definition: SX126x.cpp:487
float getRSSI() override
Gets recorded signal strength indicator. Overload with packet mode enabled for PhysicalLayer compatib...
Definition: SX126x.cpp:1391
int16_t standby() override
Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator)...
Definition: SX126x.cpp:462
int16_t setFrequencyDeviation(float freqDev) override
Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz.
Definition: SX126x.cpp:982
void spectralScanAbort()
Abort an ongoing spectral scan.
Definition: SX126x.cpp:1762
int16_t getModem(ModemType_t *modem) override
Get modem currently in use by the radio.
Definition: SX126x.cpp:1670
int16_t sleep() override
Sets the module to sleep mode. To wake the device up, call standby(). Overload with warm start enable...
Definition: SX126x.cpp:442
int16_t receiveDirect() override
Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX126x series does...
Definition: SX126x.cpp:339
int16_t spectralScanStart(uint16_t numSamples, uint8_t window=RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval=RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US)
Start spectral scan. Requires binary path to be uploaded.
Definition: SX126x.cpp:1746
int16_t finishTransmit() override
Clean up after transmission is done.
Definition: SX126x.cpp:624
int16_t setCurrentLimit(float currentLimit)
Sets current protection limit. Can be set in 2.5 mA steps.
Definition: SX126x.cpp:942
int16_t setRxBoostedGainMode(bool rxbgm, bool persist=true)
Enables or disables Rx Boosted Gain mode as described in SX126x datasheet section 9....
Definition: SX126x.cpp:1140
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition: SX126x.cpp:323
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:148
int16_t variablePacketLengthMode(uint8_t maxLen=RADIOLIB_SX126X_MAX_PACKET_LENGTH)
Set modem in variable packet length mode. Available in FSK mode only.
Definition: SX126x.cpp:1482
int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO=false)
Initialization method for LoRa modem.
Definition: SX126x.cpp:22
int16_t setCRC(uint8_t len, uint16_t initial=0x1D0F, uint16_t polynomial=0x1021, bool inverted=true)
Sets CRC configuration.
Definition: SX126x.cpp:1291
int16_t reset(bool verify=true)
Reset method. Will reset the chip to the default state using RST pin.
Definition: SX126x.cpp:163
int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits=0x44)
Sets LoRa sync word.
Definition: SX126x.cpp:931
int16_t setLrFhssConfig(uint8_t bw, uint8_t cr, uint8_t hdrCount=3, uint16_t hopSeqId=0x100)
Sets LR-FHSS configuration.
Definition: SX126x.cpp:150
int16_t calibrateImageRejection(float freqMin, float freqMax)
Perform image rejection calibration for the specified frequency band. WARNING: Use at your own risk!...
Definition: SX126x.cpp:1994
float getCurrentLimit()
Reads current protection limit.
Definition: SX126x.cpp:955
SX126x(Module *mod)
Default constructor.
Definition: SX126x.cpp:6
int16_t clearIrqFlags(uint32_t irq) override
Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).
Definition: SX126x.cpp:1574
uint32_t getIrqFlags() override
Read currently active IRQ flags.
Definition: SX126x.cpp:1564
virtual int16_t receive(uint8_t *data, size_t len)
Binary receive method. Must be implemented in module class.
Definition: PhysicalLayer.cpp:111
int16_t autoLDRO()
Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,...
Definition: SX126x.cpp:1618
int16_t fixedPacketLengthMode(uint8_t len=RADIOLIB_SX126X_MAX_PACKET_LENGTH)
Set modem in fixed packet length mode. Available in FSK mode only.
Definition: SX126x.cpp:1478
int16_t setBroadcastAddress(uint8_t broadAddr)
Sets broadcast address. Calling this method will also enable address filtering for node and broadcast...
Definition: SX126x.cpp:1263
int16_t setBitRate(float br) override
Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps.
Definition: SX126x.cpp:1006
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition: SX126x.cpp:1458
int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen)
Sets FSK sync word in the form of array of up to 8 bytes.
Definition: SX126x.cpp:1226
void setPacketSentAction(void(*func)(void)) override
Sets interrupt service routine to call when a packet is sent.
Definition: SX126x.cpp:495
void readBit(uint32_t pin) override
Function to read and process data bit in direct reception mode.
Definition: SX126x.cpp:1694
int16_t scanChannel() override
Performs scan for LoRa transmission in the current channel. Detects both preamble and payload....
Definition: SX126x.cpp:413
float getDataRate() const
Gets effective data rate for the last transmitted packet. The value is calculated only for payload by...
Definition: SX126x.cpp:1387
int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength=0, uint16_t minSymbols=8, RadioLibIrqFlags_t irqFlags=RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask=RADIOLIB_IRQ_RX_DEFAULT_MASK)
Calls startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages...
Definition: SX126x.cpp:684
int16_t setPreambleLength(size_t preambleLength) override
Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535.
Definition: SX126x.cpp:964
int16_t setPaRampTime(uint8_t rampTime)
Set PA ramp-up time. Set to 200us by default.
Definition: SX126x.cpp:2002
bool XTAL
Whether the module has an XTAL (true) or TCXO (false). Defaults to false.
Definition: SX126x.h:492
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission.
Definition: SX126x.cpp:1578
int16_t setNodeAddress(uint8_t addr)
Sets node address. Calling this method will also enable address filtering for node address only.
Definition: SX126x.cpp:1245
int16_t setDio2AsRfSwitch(bool enable=true)
Set DIO2 to function as RF switch (default in Semtech example designs).
Definition: SX126x.cpp:1839
int16_t spectralScanGetResult(uint16_t *results)
Read the result of spectral scan.
Definition: SX126x.cpp:1774
int16_t setWhitening(bool enabled, uint16_t initial=0x01FF)
Sets FSK whitening parameters.
Definition: SX126x.cpp:1350
int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Allowed values range from 5 to 12.
Definition: SX126x.cpp:905
bool standbyXOSC
Whether to use XOSC (true) or RC (false) oscillator in standby mode. Defaults to false.
Definition: SX126x.h:497
void setChannelScanAction(void(*func)(void)) override
Sets interrupt service routine to call when a channel scan is finished.
Definition: SX126x.cpp:503
int16_t setDataRate(DataRate_t dr) override
Set data.
Definition: SX126x.cpp:1027
void clearPacketSentAction() override
Clears interrupt service routine to call when a packet is sent.
Definition: SX126x.cpp:499
int16_t beginLRFHSS(uint8_t bw, uint8_t cr, bool narrowGrid, float tcxoVoltage, bool useRegulatorLDO=false)
Initialization method for LR-FHSS modem. This modem only supports transmission!
Definition: SX126x.cpp:122
int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, RadioLibIrqFlags_t irqFlags=RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask=RADIOLIB_IRQ_RX_DEFAULT_MASK)
Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen....
Definition: SX126x.cpp:657
int16_t disableAddressFiltering()
Disables address filtering. Calling this method will also erase previously set addresses.
Definition: SX126x.cpp:1280
int16_t setCodingRate(uint8_t cr)
Sets LoRa coding rate denominator. Allowed values range from 5 to 8.
Definition: SX126x.cpp:918
int16_t getChannelScanResult() override
Read the channel scan result.
Definition: SX126x.cpp:835
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition: TypeDef.h:642
uint32_t RadioLibIrqFlags_t
Type used for radio-agnostic IRQ flags. IRQ to enable corresponds to the bit index (RadioLibIrq_t)....
Definition: TypeDef.h:648
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition: Module.h:89
Common channel scan configuration structure.
Definition: PhysicalLayer.h:125
Common data rate structure.
Definition: PhysicalLayer.h:74