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 !defined(RADIOLIB_EXCLUDE_SX126X)
7 
8 #include "../../Module.h"
9 
10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h"
11 
12 // SX126X physical layer properties
13 #define RADIOLIB_SX126X_FREQUENCY_STEP_SIZE 0.9536743164
14 #define RADIOLIB_SX126X_MAX_PACKET_LENGTH 255
15 #define RADIOLIB_SX126X_CRYSTAL_FREQ 32.0
16 #define RADIOLIB_SX126X_DIV_EXPONENT 25
17 
18 // SX126X SPI commands
19 // operational modes commands
20 #define RADIOLIB_SX126X_CMD_NOP 0x00
21 #define RADIOLIB_SX126X_CMD_SET_SLEEP 0x84
22 #define RADIOLIB_SX126X_CMD_SET_STANDBY 0x80
23 #define RADIOLIB_SX126X_CMD_SET_FS 0xC1
24 #define RADIOLIB_SX126X_CMD_SET_TX 0x83
25 #define RADIOLIB_SX126X_CMD_SET_RX 0x82
26 #define RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE 0x9F
27 #define RADIOLIB_SX126X_CMD_SET_RX_DUTY_CYCLE 0x94
28 #define RADIOLIB_SX126X_CMD_SET_CAD 0xC5
29 #define RADIOLIB_SX126X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1
30 #define RADIOLIB_SX126X_CMD_SET_TX_INFINITE_PREAMBLE 0xD2
31 #define RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE 0x96
32 #define RADIOLIB_SX126X_CMD_CALIBRATE 0x89
33 #define RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE 0x98
34 #define RADIOLIB_SX126X_CMD_SET_PA_CONFIG 0x95
35 #define RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE 0x93
36 
37 // register and buffer access commands
38 #define RADIOLIB_SX126X_CMD_WRITE_REGISTER 0x0D
39 #define RADIOLIB_SX126X_CMD_READ_REGISTER 0x1D
40 #define RADIOLIB_SX126X_CMD_WRITE_BUFFER 0x0E
41 #define RADIOLIB_SX126X_CMD_READ_BUFFER 0x1E
42 
43 // DIO and IRQ control
44 #define RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS 0x08
45 #define RADIOLIB_SX126X_CMD_GET_IRQ_STATUS 0x12
46 #define RADIOLIB_SX126X_CMD_CLEAR_IRQ_STATUS 0x02
47 #define RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D
48 #define RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 0x97
49 
50 // RF, modulation and packet commands
51 #define RADIOLIB_SX126X_CMD_SET_RF_FREQUENCY 0x86
52 #define RADIOLIB_SX126X_CMD_SET_PACKET_TYPE 0x8A
53 #define RADIOLIB_SX126X_CMD_GET_PACKET_TYPE 0x11
54 #define RADIOLIB_SX126X_CMD_SET_TX_PARAMS 0x8E
55 #define RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS 0x8B
56 #define RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS 0x8C
57 #define RADIOLIB_SX126X_CMD_SET_CAD_PARAMS 0x88
58 #define RADIOLIB_SX126X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F
59 #define RADIOLIB_SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0x0A
60 
61 // status commands
62 #define RADIOLIB_SX126X_CMD_GET_STATUS 0xC0
63 #define RADIOLIB_SX126X_CMD_GET_RSSI_INST 0x15
64 #define RADIOLIB_SX126X_CMD_GET_RX_BUFFER_STATUS 0x13
65 #define RADIOLIB_SX126X_CMD_GET_PACKET_STATUS 0x14
66 #define RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS 0x17
67 #define RADIOLIB_SX126X_CMD_CLEAR_DEVICE_ERRORS 0x07
68 #define RADIOLIB_SX126X_CMD_GET_STATS 0x10
69 #define RADIOLIB_SX126X_CMD_RESET_STATS 0x00
70 
71 #define RADIOLIB_SX126X_CMD_PRAM_UPDATE 0xD9
72 #define RADIOLIB_SX126X_CMD_SET_SCAN_PARAMS 0x9A
73 
74 // SX126X register map
75 #define RADIOLIB_SX126X_REG_VERSION_STRING 0x0320
76 #define RADIOLIB_SX126X_REG_HOPPING_ENABLE 0x0385
77 #define RADIOLIB_SX126X_REG_LR_FHSS_PACKET_LENGTH 0x0386
78 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387
79 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6)
80 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6)
81 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6)
82 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6)
83 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6)
84 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6)
85 #define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_RESULT 0x0401
86 #define RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE 0x0580
87 #define RADIOLIB_SX126X_REG_DIOX_IN_ENABLE 0x0583
88 #define RADIOLIB_SX126X_REG_DIOX_PULL_UP_CTRL 0x0584
89 #define RADIOLIB_SX126X_REG_DIOX_PULL_DOWN_CTRL 0x0585
90 #define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0 0x0587
91 #define RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE 0x0610
92 #define RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1 0x0680
93 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8
94 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9
95 #define RADIOLIB_SX126X_REG_RX_TX_PLD_LEN 0x06BB
96 #define RADIOLIB_SX126X_REG_CRC_INITIAL_MSB 0x06BC
97 #define RADIOLIB_SX126X_REG_CRC_INITIAL_LSB 0x06BD
98 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE
99 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF
100 #define RADIOLIB_SX126X_REG_SYNC_WORD_0 0x06C0
101 #define RADIOLIB_SX126X_REG_SYNC_WORD_1 0x06C1
102 #define RADIOLIB_SX126X_REG_SYNC_WORD_2 0x06C2
103 #define RADIOLIB_SX126X_REG_SYNC_WORD_3 0x06C3
104 #define RADIOLIB_SX126X_REG_SYNC_WORD_4 0x06C4
105 #define RADIOLIB_SX126X_REG_SYNC_WORD_5 0x06C5
106 #define RADIOLIB_SX126X_REG_SYNC_WORD_6 0x06C6
107 #define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7
108 #define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD
109 #define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE
110 #define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702
111 #define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704
112 #define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736
113 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740
114 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741
115 #define RADIOLIB_SX126X_REG_FREQ_ERROR 0x076B
116 #define RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS 0x07CD
117 #define RADIOLIB_SX126X_REG_RX_ADDR_PTR 0x0803
118 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_0 0x0819
119 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_1 0x081A
120 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_2 0x081B
121 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_3 0x081C
122 #define RADIOLIB_SX126X_REG_TX_MODULATION 0x0889
123 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_0 0x088B
124 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_1 0x088C
125 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_2 0x088D
126 #define RADIOLIB_SX126X_REG_RF_FREQUENCY_3 0x088E
127 #define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B
128 #define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC
129 #define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8
130 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3
131 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_P 0x08E4
132 #define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7
133 #define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902
134 #define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911
135 #define RADIOLIB_SX126X_REG_XTB_TRIM 0x0912
136 #define RADIOLIB_SX126X_REG_DIO3_OUT_VOLTAGE_CTRL 0x0920
137 #define RADIOLIB_SX126X_REG_EVENT_MASK 0x0944
138 #define RADIOLIB_SX126X_REG_PATCH_MEMORY_BASE 0x8000
139 
140 // undocumented registers
141 #define RADIOLIB_SX126X_REG_SENSITIVITY_CONFIG 0x0889 // SX1268 datasheet v1.1, section 15.1
142 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0 0x029F // SX1268 datasheet v1.1, section 9.6
143 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1 0x02A0 // SX1268 datasheet v1.1, section 9.6
144 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2 0x02A1 // SX1268 datasheet v1.1, section 9.6
145 
146 
147 // SX126X SPI command variables
148 //RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION
149 #define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default)
150 #define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained
151 #define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled
152 #define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled
153 
154 //RADIOLIB_SX126X_CMD_SET_STANDBY
155 #define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator
156 #define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator
157 
158 //RADIOLIB_SX126X_CMD_SET_RX
159 #define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode)
160 #define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode)
161 
162 //RADIOLIB_SX126X_CMD_SET_TX
163 #define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode)
164 
165 //RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE
166 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default)
167 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection
168 
169 //RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE
170 #define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default)
171 #define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC
172 
173 //RADIOLIB_SX126X_CMD_CALIBRATE
174 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled
175 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled
176 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled
177 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled
178 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled
179 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled
180 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled
181 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled
182 #define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled
183 #define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled
184 #define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled
185 #define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled
186 #define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled
187 #define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled
188 #define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks
189 
190 //RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE
191 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B
192 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F
193 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75
194 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81
195 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1
196 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5
197 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7
198 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB
199 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1
200 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9
201 
202 //RADIOLIB_SX126X_CMD_SET_PA_CONFIG
203 #define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07
204 #define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01
205 #define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00
206 
207 //RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE
208 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode
209 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator
210 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default)
211 
212 //RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS
213 #define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop
214 #define RADIOLIB_SX126X_IRQ_TIMEOUT 0b0000001000000000 // 9 9 Rx or Tx timeout
215 #define RADIOLIB_SX126X_IRQ_CAD_DETECTED 0b0000000100000000 // 8 8 channel activity detected
216 #define RADIOLIB_SX126X_IRQ_CAD_DONE 0b0000000010000000 // 7 7 channel activity detection finished
217 #define RADIOLIB_SX126X_IRQ_CRC_ERR 0b0000000001000000 // 6 6 wrong CRC received
218 #define RADIOLIB_SX126X_IRQ_HEADER_ERR 0b0000000000100000 // 5 5 LoRa header CRC error
219 #define RADIOLIB_SX126X_IRQ_HEADER_VALID 0b0000000000010000 // 4 4 valid LoRa header received
220 #define RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID 0b0000000000001000 // 3 3 valid sync word detected
221 #define RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected
222 #define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received
223 #define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed
224 #define RADIOLIB_SX126X_IRQ_RX_DEFAULT 0b0000001001100010 // 14 0 default for Rx (RX_DONE, TIMEOUT, CRC_ERR and HEADER_ERR)
225 #define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts
226 #define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts
227 
228 //RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL
229 #define RADIOLIB_SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ
230 #define RADIOLIB_SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control
231 
232 //RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL
233 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V
234 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V
235 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V
236 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V
237 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V
238 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V
239 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V
240 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V
241 
242 //RADIOLIB_SX126X_CMD_SET_PACKET_TYPE
243 #define RADIOLIB_SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK
244 #define RADIOLIB_SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa
245 #define RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS 0x03 // 7 0 LR-FHSS
246 
247 //RADIOLIB_SX126X_CMD_SET_TX_PARAMS
248 #define RADIOLIB_SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us
249 #define RADIOLIB_SX126X_PA_RAMP_20U 0x01 // 7 0 20 us
250 #define RADIOLIB_SX126X_PA_RAMP_40U 0x02 // 7 0 40 us
251 #define RADIOLIB_SX126X_PA_RAMP_80U 0x03 // 7 0 80 us
252 #define RADIOLIB_SX126X_PA_RAMP_200U 0x04 // 7 0 200 us
253 #define RADIOLIB_SX126X_PA_RAMP_800U 0x05 // 7 0 800 us
254 #define RADIOLIB_SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us
255 #define RADIOLIB_SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us
256 
257 //RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS
258 #define RADIOLIB_SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none
259 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3
260 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5
261 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7
262 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1
263 #define RADIOLIB_SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz
264 #define RADIOLIB_SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz
265 #define RADIOLIB_SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz
266 #define RADIOLIB_SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz
267 #define RADIOLIB_SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz
268 #define RADIOLIB_SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz
269 #define RADIOLIB_SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz
270 #define RADIOLIB_SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz
271 #define RADIOLIB_SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz
272 #define RADIOLIB_SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz
273 #define RADIOLIB_SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz
274 #define RADIOLIB_SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz
275 #define RADIOLIB_SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz
276 #define RADIOLIB_SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz
277 #define RADIOLIB_SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz
278 #define RADIOLIB_SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz
279 #define RADIOLIB_SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz
280 #define RADIOLIB_SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz
281 #define RADIOLIB_SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz
282 #define RADIOLIB_SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz
283 #define RADIOLIB_SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz
284 #define RADIOLIB_SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz
285 #define RADIOLIB_SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz
286 #define RADIOLIB_SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz
287 #define RADIOLIB_SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz
288 #define RADIOLIB_SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz
289 #define RADIOLIB_SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz
290 #define RADIOLIB_SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz
291 #define RADIOLIB_SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz
292 #define RADIOLIB_SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz
293 #define RADIOLIB_SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz
294 #define RADIOLIB_SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5
295 #define RADIOLIB_SX126X_LORA_CR_4_6 0x02 // 7 0 4/6
296 #define RADIOLIB_SX126X_LORA_CR_4_7 0x03 // 7 0 4/7
297 #define RADIOLIB_SX126X_LORA_CR_4_8 0x04 // 7 0 4/8
298 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled
299 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled
300 
301 //RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS
302 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled
303 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits
304 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits
305 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits
306 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits
307 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled
308 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only
309 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast
310 #define RADIOLIB_SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides)
311 #define RADIOLIB_SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet)
312 #define RADIOLIB_SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled
313 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte
314 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte
315 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted
316 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted
317 #define RADIOLIB_SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled
318 #define RADIOLIB_SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled
319 #define RADIOLIB_SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit
320 #define RADIOLIB_SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit
321 #define RADIOLIB_SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled
322 #define RADIOLIB_SX126X_LORA_CRC_ON 0x01 // 7 0 enabled
323 #define RADIOLIB_SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard
324 #define RADIOLIB_SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted
325 
326 //RADIOLIB_SX126X_CMD_SET_CAD_PARAMS
327 #define RADIOLIB_SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1
328 #define RADIOLIB_SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2
329 #define RADIOLIB_SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4
330 #define RADIOLIB_SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8
331 #define RADIOLIB_SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16
332 #define RADIOLIB_SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode
333 #define RADIOLIB_SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected
334 #define RADIOLIB_SX126X_CAD_PARAM_DEFAULT 0xFF // 7 0 used by the CAD methods to specify default parameter value
335 #define RADIOLIB_SX126X_CAD_PARAM_DET_MIN 10 // 7 0 default detMin CAD parameter
336 
337 //RADIOLIB_SX126X_CMD_GET_STATUS
338 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC
339 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC
340 #define RADIOLIB_SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS
341 #define RADIOLIB_SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX
342 #define RADIOLIB_SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX
343 #define RADIOLIB_SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved
344 #define RADIOLIB_SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out
345 #define RADIOLIB_SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command
346 #define RADIOLIB_SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute
347 #define RADIOLIB_SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done
348 #define RADIOLIB_SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed
349 
350 //RADIOLIB_SX126X_CMD_GET_PACKET_STATUS
351 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error
352 #define RADIOLIB_SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error
353 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error
354 #define RADIOLIB_SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error
355 #define RADIOLIB_SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error
356 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error
357 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received
358 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent
359 
360 //RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS
361 #define RADIOLIB_SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed
362 #define RADIOLIB_SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock
363 #define RADIOLIB_SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start
364 #define RADIOLIB_SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed
365 #define RADIOLIB_SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed
366 #define RADIOLIB_SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed
367 #define RADIOLIB_SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed
368 #define RADIOLIB_SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed
369 
370 
371 // SX126X SPI register variables
372 //RADIOLIB_SX126X_REG_HOPPING_ENABLE
373 #define RADIOLIB_SX126X_HOPPING_ENABLED 0b00000001 // 0 0 intra-packet hopping for LR-FHSS: enabled
374 #define RADIOLIB_SX126X_HOPPING_DISABLED 0b00000000 // 0 0 (disabled)
375 
376 //RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB + LSB
377 #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.
378 #define RADIOLIB_SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried.
379 
380 // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_1
381 #define RADIOLIB_SX126X_TX_BITBANG_1_DISABLED 0b00000000 // 6 4 Tx bitbang: disabled (default)
382 #define RADIOLIB_SX126X_TX_BITBANG_1_ENABLED 0b00010000 // 6 4 enabled
383 
384 // RADIOLIB_SX126X_REG_TX_BITBANG_ENABLE_0
385 #define RADIOLIB_SX126X_TX_BITBANG_0_DISABLED 0b00000000 // 3 0 Tx bitbang: disabled (default)
386 #define RADIOLIB_SX126X_TX_BITBANG_0_ENABLED 0b00001100 // 3 0 enabled
387 
388 // RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE
389 #define RADIOLIB_SX126X_DIO1_OUT_DISABLED 0b00000010 // 1 1 DIO1 output: disabled
390 #define RADIOLIB_SX126X_DIO1_OUT_ENABLED 0b00000000 // 1 1 enabled
391 #define RADIOLIB_SX126X_DIO2_OUT_DISABLED 0b00000100 // 2 2 DIO2 output: disabled
392 #define RADIOLIB_SX126X_DIO2_OUT_ENABLED 0b00000000 // 2 2 enabled
393 #define RADIOLIB_SX126X_DIO3_OUT_DISABLED 0b00001000 // 3 3 DIO3 output: disabled
394 #define RADIOLIB_SX126X_DIO3_OUT_ENABLED 0b00000000 // 3 3 enabled
395 
396 // RADIOLIB_SX126X_REG_DIOX_IN_ENABLE
397 #define RADIOLIB_SX126X_DIO1_IN_DISABLED 0b00000000 // 1 1 DIO1 input: disabled
398 #define RADIOLIB_SX126X_DIO1_IN_ENABLED 0b00000010 // 1 1 enabled
399 #define RADIOLIB_SX126X_DIO2_IN_DISABLED 0b00000000 // 2 2 DIO2 input: disabled
400 #define RADIOLIB_SX126X_DIO2_IN_ENABLED 0b00000100 // 2 2 enabled
401 #define RADIOLIB_SX126X_DIO3_IN_DISABLED 0b00000000 // 3 3 DIO3 input: disabled
402 #define RADIOLIB_SX126X_DIO3_IN_ENABLED 0b00001000 // 3 3 enabled
403 
404 // RADIOLIB_SX126X_REG_RX_GAIN
405 #define RADIOLIB_SX126X_RX_GAIN_BOOSTED 0x96 // 7 0 Rx gain: boosted
406 #define RADIOLIB_SX126X_RX_GAIN_POWER_SAVING 0x94 // 7 0 power saving
407 #define RADIOLIB_SX126X_RX_GAIN_SPECTRAL_SCAN 0xCB // 7 0 spectral scan
408 
409 // RADIOLIB_SX126X_REG_PATCH_UPDATE_ENABLE
410 #define RADIOLIB_SX126X_PATCH_UPDATE_DISABLED 0b00010000 // 4 4 patch update: disabled
411 #define RADIOLIB_SX126X_PATCH_UPDATE_ENABLED 0b00000000 // 4 4 enabled
412 
413 // RADIOLIB_SX126X_REG_SPECTRAL_SCAN_STATUS
414 #define RADIOLIB_SX126X_SPECTRAL_SCAN_NONE 0x00 // 7 0 spectral scan status: none
415 #define RADIOLIB_SX126X_SPECTRAL_SCAN_ONGOING 0x0F // 7 0 ongoing
416 #define RADIOLIB_SX126X_SPECTRAL_SCAN_ABORTED 0xF0 // 7 0 aborted
417 #define RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED 0xFF // 7 0 completed
418 
425 class SX126x: public PhysicalLayer {
426  public:
427  // introduce PhysicalLayer overloads
432 
438  SX126x(Module* mod);
439 
440  Module* getMod();
441 
442  // basic methods
443 
459  int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false);
460 
478  int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false);
479 
488  int16_t reset(bool verify = true);
489 
502  int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
503 
514  int16_t receive(uint8_t* data, size_t len) override;
515 
523  int16_t transmitDirect(uint32_t frf = 0) override;
524 
531  int16_t receiveDirect() override;
532 
544  int16_t scanChannel(uint8_t symbolNum = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin = RADIOLIB_SX126X_CAD_PARAM_DEFAULT);
545 
553  int16_t sleep(bool retainConfig = true);
554 
560  int16_t standby() override;
561 
569  int16_t standby(uint8_t mode);
570 
571  // interrupt methods
572 
578  void setDio1Action(void (*func)(void));
579 
583  void clearDio1Action();
584 
597  int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
598 
604  int16_t finishTransmit() override;
605 
618  int16_t startReceive(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
619 
634  int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
635 
651  int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
652 
658  uint16_t getIrqStatus();
659 
670  int16_t readData(uint8_t* data, size_t len) override;
671 
683  int16_t startChannelScan(uint8_t symbolNum = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin = RADIOLIB_SX126X_CAD_PARAM_DEFAULT);
684 
690  int16_t getChannelScanResult();
691 
692  // configuration methods
693 
701  int16_t setBandwidth(float bw);
702 
710  int16_t setSpreadingFactor(uint8_t sf);
711 
719  int16_t setCodingRate(uint8_t cr);
720 
730  int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44);
731 
739  int16_t setCurrentLimit(float currentLimit);
740 
746  float getCurrentLimit();
747 
755  int16_t setPreambleLength(uint16_t preambleLength);
756 
764  int16_t setFrequencyDeviation(float freqDev) override;
765 
773  int16_t setBitRate(float br);
774 
782  int16_t setRxBandwidth(float rxBw);
783 
793  int16_t setRxBoostedGainMode(bool rxbgm, bool persist = true);
794 
804  int16_t setDataShaping(uint8_t sh) override;
805 
815  int16_t setSyncWord(uint8_t* syncWord, uint8_t len);
816 
826  int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen);
827 
835  int16_t setNodeAddress(uint8_t nodeAddr);
836 
844  int16_t setBroadcastAddress(uint8_t broadAddr);
845 
851  int16_t disableAddressFiltering();
852 
866  int16_t setCRC(uint8_t len, uint16_t initial = 0x1D0F, uint16_t polynomial = 0x1021, bool inverted = true);
867 
877  int16_t setWhitening(bool enabled, uint16_t initial = 0x0100);
878 
889  int16_t setTCXO(float voltage, uint32_t delay = 5000);
890 
896  int16_t setDio2AsRfSwitch(bool enable = true);
897 
903  float getDataRate() const;
904 
910  float getRSSI();
911 
917  float getSNR();
918 
926  size_t getPacketLength(bool update = true) override;
927 
935  int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX126X_MAX_PACKET_LENGTH);
936 
944  int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX126X_MAX_PACKET_LENGTH);
945 
953  uint32_t getTimeOnAir(size_t len);
954 
960  float getRSSIInst();
961 
969  int16_t implicitHeader(size_t len);
970 
976  int16_t explicitHeader();
977 
983  int16_t setRegulatorLDO();
984 
990  int16_t setRegulatorDCDC();
991 
999  int16_t setEncoding(uint8_t encoding) override;
1000 
1002  void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
1003 
1005  void setRfSwitchTable(const RADIOLIB_PIN_TYPE (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]);
1006 
1015  int16_t forceLDRO(bool enable);
1016 
1023  int16_t autoLDRO();
1024 
1030  uint8_t randomByte();
1031 
1032  #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
1038  void setDirectAction(void (*func)(void));
1039 
1045  void readBit(RADIOLIB_PIN_TYPE pin);
1046  #endif
1047 
1048 
1049 #if !defined(RADIOLIB_GODMODE)
1050  protected:
1051 #endif
1052  // SX126x SPI command implementations
1053  int16_t setTx(uint32_t timeout = 0);
1054  int16_t setRx(uint32_t timeout);
1055  int16_t setCad(uint8_t symbolNum, uint8_t detPeak, uint8_t detMin);
1056  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);
1057  int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
1058  int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
1059  int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
1060  int16_t readBuffer(uint8_t* data, uint8_t numBytes);
1061  int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX126X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX126X_IRQ_NONE);
1062  virtual int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX126X_IRQ_ALL);
1063  int16_t setRfFrequency(uint32_t frf);
1064  int16_t calibrateImage(uint8_t* data);
1065  uint8_t getPacketType();
1066  int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX126X_PA_RAMP_200U);
1067  int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro);
1068  int16_t setModulationParamsFSK(uint32_t br, uint8_t pulseShape, uint8_t rxBw, uint32_t freqDev);
1069  int16_t setPacketParams(uint16_t preambleLength, uint8_t crcType, uint8_t payloadLength, uint8_t headerType, uint8_t invertIQ = RADIOLIB_SX126X_LORA_IQ_STANDARD);
1070  int16_t setPacketParamsFSK(uint16_t preambleLength, uint8_t crcType, uint8_t syncWordLength, uint8_t addrComp, uint8_t whitening, uint8_t packetType = RADIOLIB_SX126X_GFSK_PACKET_VARIABLE, uint8_t payloadLength = 0xFF, uint8_t preambleDetectorLength = RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16);
1071  int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);
1072  int16_t setRegulatorMode(uint8_t mode);
1073  uint8_t getStatus();
1074  uint32_t getPacketStatus();
1075  uint16_t getDeviceErrors();
1076  int16_t clearDeviceErrors();
1077 
1078  int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags = RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask = RADIOLIB_SX126X_IRQ_RX_DONE);
1079  int16_t setFrequencyRaw(float freq);
1080  int16_t setPacketMode(uint8_t mode, uint8_t len);
1081  int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
1082  int16_t directMode();
1083  int16_t packetMode();
1084 
1085  // fixes to errata
1086  int16_t fixSensitivity();
1087  int16_t fixPaClamping(bool enable = true);
1088  int16_t fixImplicitTimeout();
1089  int16_t fixInvertedIQ(uint8_t iqConfig);
1090 
1091 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
1092  protected:
1093 #endif
1094  Module* _mod;
1095 
1096  // common low-level SPI interface
1097  static int16_t SPIparseStatus(uint8_t in);
1098 
1099 #if !defined(RADIOLIB_GODMODE)
1100  protected:
1101 #endif
1102 
1103  uint8_t _bw = 0, _sf = 0, _cr = 0, _ldro = 0, _crcType = 0, _headerType = 0;
1104  uint16_t _preambleLength = 0;
1105  float _bwKhz = 0;
1106  bool _ldroAuto = true;
1107 
1108  uint32_t _br = 0, _freqDev = 0;
1109  uint8_t _rxBw = 0, _pulseShape = 0, _crcTypeFSK = 0, _syncWordLength = 0, _addrComp = 0, _whitening = 0, _packetType = 0;
1110  uint16_t _preambleLengthFSK = 0;
1111  float _rxBwKhz = 0;
1112 
1113  float _dataRate = 0;
1114 
1115  uint32_t _tcxoDelay = 0;
1116 
1117  size_t _implicitLen = 0;
1118  uint8_t _chipType = 0;
1119 
1120  // Allow subclasses to define different TX modes
1121  uint8_t _tx_mode = Module::MODE_TX;
1122 
1123  int16_t config(uint8_t modem);
1124  bool findChip(uint8_t type);
1125 };
1126 
1127 #endif
1128 
1129 #endif
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:16
static const size_t RFSWITCH_MAX_PINS
The maximum number of pins supported by the RF switch code.
Definition: Module.h:27
@ MODE_TX
Definition: Module.h:56
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14
int16_t transmit(__FlashStringHelper *fstr, uint8_t addr=0)
Arduino Flash String transmit method.
Definition: PhysicalLayer.cpp:12
int16_t readData(String &str, size_t len=0)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:141
int16_t startTransmit(String &str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:122
int16_t receive(String &str, size_t len=0)
Arduino String receive method.
Definition: PhysicalLayer.cpp:60
Base class for SX126x series. All derived classes for SX126x (e.g. SX1262 or SX1268) inherit from thi...
Definition: SX126x.h:425
int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength=0, uint16_t minSymbols=8, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE)
Calls startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages...
Definition: SX126x.cpp:575
void setDio1Action(void(*func)(void))
Sets interrupt service routine to call when DIO1 activates.
Definition: SX126x.cpp:458
float getRSSI()
Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
Definition: SX126x.cpp:1220
int16_t startChannelScan(uint8_t symbolNum=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin=RADIOLIB_SX126X_CAD_PARAM_DEFAULT)
Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is dete...
Definition: SX126x.cpp:683
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:995
int16_t setRegulatorLDO()
Set regulator mode to LDO.
Definition: SX126x.cpp:1308
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn)
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition: SX126x.cpp:1320
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:1316
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:91
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:730
int16_t startReceive(uint32_t timeout=RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE)
Interrupt-driven receive method. DIO1 will be activated when full packet is received.
Definition: SX126x.cpp:535
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition: SX126x.cpp:1304
int16_t forceLDRO(bool enable)
Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,...
Definition: SX126x.cpp:1328
int16_t setNodeAddress(uint8_t nodeAddr)
Sets node address. Calling this method will also enable address filtering for node address only.
Definition: SX126x.cpp:1075
int16_t setTCXO(float voltage, uint32_t delay=5000)
Sets TCXO (Temperature Compensated Crystal Oscillator) configuration.
Definition: SX126x.cpp:1380
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:895
int16_t setRegulatorDCDC()
Set regulator mode to DC-DC.
Definition: SX126x.cpp:1312
int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE)
Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen....
Definition: SX126x.cpp:548
int16_t setWhitening(bool enabled, uint16_t initial=0x0100)
Sets FSK whitening parameters.
Definition: SX126x.cpp:1179
void clearDio1Action()
Clears interrupt service routine to call when DIO1 activates.
Definition: SX126x.cpp:462
int16_t scanChannel(uint8_t symbolNum=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin=RADIOLIB_SX126X_CAD_PARAM_DEFAULT)
Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.
Definition: SX126x.cpp:416
int16_t standby() override
Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator)...
Definition: SX126x.cpp:446
int16_t setFrequencyDeviation(float freqDev) override
Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz.
Definition: SX126x.cpp:853
int16_t setBitRate(float br)
Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps.
Definition: SX126x.cpp:877
uint32_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition: SX126x.cpp:1258
uint8_t randomByte()
Get one truly random byte from RSSI noise.
Definition: SX126x.cpp:1349
int16_t receiveDirect() override
Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX126x series does...
Definition: SX126x.cpp:342
int16_t finishTransmit() override
Clean up after transmission is done.
Definition: SX126x.cpp:527
int16_t setCurrentLimit(float currentLimit)
Sets current protection limit. Can be set in 2.5 mA steps.
Definition: SX126x.cpp:818
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:958
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition: SX126x.cpp:326
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:1254
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:12
int16_t setCRC(uint8_t len, uint16_t initial=0x1D0F, uint16_t polynomial=0x1021, bool inverted=true)
Sets CRC configuration.
Definition: SX126x.cpp:1120
uint16_t getIrqStatus()
Reads the current IRQ status.
Definition: SX126x.cpp:1527
int16_t reset(bool verify=true)
Reset method. Will reset the chip to the default state using RST pin.
Definition: SX126x.cpp:185
int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits=0x44)
Sets LoRa sync word.
Definition: SX126x.cpp:807
float getCurrentLimit()
Reads current protection limit.
Definition: SX126x.cpp:831
SX126x(Module *mod)
Default constructor.
Definition: SX126x.cpp:4
int16_t setPreambleLength(uint16_t preambleLength)
Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535.
Definition: SX126x.cpp:840
int16_t transmit(__FlashStringHelper *fstr, uint8_t addr=0)
Arduino Flash String transmit method.
Definition: PhysicalLayer.cpp:12
int16_t autoLDRO()
Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,...
Definition: SX126x.cpp:1340
void setDirectAction(void(*func)(void))
Dummy method, to ensure PhysicalLayer compatibility.
Definition: SX126x.cpp:1371
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:1250
int16_t setBroadcastAddress(uint8_t broadAddr)
Sets broadcast address. Calling this method will also enable address filtering for node and broadcast...
Definition: SX126x.cpp:1092
int16_t getChannelScanResult()
Read the channel scan result.
Definition: SX126x.cpp:709
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition: SX126x.cpp:1243
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:1048
float getDataRate() const
Gets effective data rate for the last transmitted packet. The value is calculated only for payload by...
Definition: SX126x.cpp:1216
void setRfSwitchTable(const RADIOLIB_PIN_TYPE(&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:1324
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission.
Definition: SX126x.cpp:1300
float getRSSIInst()
Get instantaneous RSSI value during recption of the packet. Should switch to FSK receive mode for LBT...
Definition: SX126x.cpp:1293
float getSNR()
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
Definition: SX126x.cpp:1227
int16_t setDio2AsRfSwitch(bool enable=true)
Set DIO2 to function as RF switch (default in Semtech example designs).
Definition: SX126x.cpp:1428
int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Allowed values range from 5 to 12.
Definition: SX126x.cpp:781
int16_t readData(String &str, size_t len=0)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:141
int16_t startTransmit(String &str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:122
int16_t receive(String &str, size_t len=0)
Arduino String receive method.
Definition: PhysicalLayer.cpp:60
int16_t sleep(bool retainConfig=true)
Sets the module to sleep mode.
Definition: SX126x.cpp:430
int16_t disableAddressFiltering()
Disables address filtering. Calling this method will also erase previously set addresses.
Definition: SX126x.cpp:1109
int16_t setCodingRate(uint8_t cr)
Sets LoRa coding rate denominator. Allowed values range from 5 to 8.
Definition: SX126x.cpp:794
void readBit(RADIOLIB_PIN_TYPE pin)
Dummy method, to ensure PhysicalLayer compatibility.
Definition: SX126x.cpp:1375
Definition: Module.h:34