17#include <RHSPIDriver.h>
21#define RH_SX126x_NUM_INTERRUPTS 3
24#define RH_SX126x_FIFO_SIZE 255
28#define RH_SX126x_MAX_PAYLOAD_LEN RH_SX126x_FIFO_SIZE
32#define RH_SX126x_HEADER_LEN 4
37#ifndef RH_SX126x_MAX_MESSAGE_LEN
38 #define RH_SX126x_MAX_MESSAGE_LEN (RH_SX126x_MAX_PAYLOAD_LEN - RH_SX126x_HEADER_LEN)
42#define RH_SX126x_XTAL_FREQ 32000000.0
45#define RH_SX126x_FSTEP (RH_SX126x_XTAL_FREQ / 33554432)
48#define RH_SX126x_CMD_NOP 0x00
49#define RH_SX126x_CMD_SET_SLEEP 0x84
50#define RH_SX126x_CMD_SET_STANDBY 0x80
51#define RH_SX126x_CMD_SET_FS 0xC1
52#define RH_SX126x_CMD_SET_TX 0x83
53#define RH_SX126x_CMD_SET_RX 0x82
54#define RH_SX126x_CMD_SET_STOP_TIMER_ON_PREAMBLE 0x9F
55#define RH_SX126x_CMD_SET_RX_DUTY_CYCLE 0x94
56#define RH_SX126x_CMD_SET_CAD 0xC5
57#define RH_SX126x_CMD_SET_TX_CONTINUOUS_WAVE 0xD1
58#define RH_SX126x_CMD_SET_TX_INFINITE_PREAMBLE 0xD2
59#define RH_SX126x_CMD_SET_REGULATOR_MODE 0x96
60#define RH_SX126x_CMD_CALIBRATE 0x89
61#define RH_SX126x_CMD_CALIBRATE_IMAGE 0x98
62#define RH_SX126x_CMD_SET_PA_CFG 0x95
63#define RH_SX126x_CMD_SET_RX_TX_FALLBACK_MODE 0x93
66#define RH_SX126x_CMD_WRITE_REGISTER 0x0D
67#define RH_SX126x_CMD_READ_REGISTER 0x1D
68#define RH_SX126x_CMD_WRITE_BUFFER 0x0E
69#define RH_SX126x_CMD_READ_BUFFER 0x1E
72#define RH_SX126x_CMD_SET_DIO_IRQ_PARAMS 0x08
73#define RH_SX126x_CMD_GET_IRQ_STATUS 0x12
74#define RH_SX126x_CMD_CLR_IRQ_STATUS 0x02
75#define RH_SX126x_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D
76#define RH_SX126x_CMD_SET_DIO3_AS_TCXO_CTRL 0x97
79#define RH_SX126x_CMD_SET_RF_FREQUENCY 0x86
80#define RH_SX126x_CMD_SET_PKT_TYPE 0x8A
81#define RH_SX126x_CMD_GET_PKT_TYPE 0x11
82#define RH_SX126x_CMD_SET_TX_PARAMS 0x8E
83#define RH_SX126x_CMD_SET_MODULATION_PARAMS 0x8B
84#define RH_SX126x_CMD_SET_PKT_PARAMS 0x8C
85#define RH_SX126x_CMD_SET_CAD_PARAMS 0x88
86#define RH_SX126x_CMD_SET_BUFFER_BASE_ADDRESS 0x8F
87#define RH_SX126x_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0xA0
90#define RH_SX126x_CMD_GET_STATUS 0xC0
91#define RH_SX126x_CMD_GET_RX_BUFFER_STATUS 0x13
92#define RH_SX126x_CMD_GET_PKT_STATUS 0x14
93#define RH_SX126x_CMD_GET_RSSI_INST 0x15
94#define RH_SX126x_CMD_GET_STATS 0x10
95#define RH_SX126x_CMD_RESET_STATS 0x00
98#define RH_SX126x_CMD_GET_DEVICE_ERRORS 0x17
99#define RH_SX126x_CMD_CLR_DEVICE_ERRORS 0x07
104#define RH_SX126x_REG_RETENTION_LIST_BASE_ADDRESS 0x029F
106#define RH_SX126x_REG_VERSION_STRING 0x0320
107#define RH_SX126x_REG_HOPPING_ENABLE 0x0385
108#define RH_SX126x_REG_LR_FHSS_PACKET_LENGTH 0x0386
109#define RH_SX126x_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387
110#define RH_SX126x_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6)
111#define RH_SX126x_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6)
112#define RH_SX126x_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6)
113#define RH_SX126x_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6)
114#define RH_SX126x_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6)
115#define RH_SX126x_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6)
116#define RH_SX126x_REG_SPECTRAL_SCAN_RESULT 0x0401
119#define RH_SX126x_REG_OUT_DIS_REG 0x0580
120#define RH_SX126x_REG_OUT_DIS_REG_DIO3_POS ( 3U )
121#define RH_SX126x_REG_OUT_DIS_REG_DIO3_MASK ( 0x01UL << SX126X_REG_OUT_DIS_REG_DIO3_POS )
123#define RH_SX126x_REG_DIOX_DRIVE_STRENGTH 0x0582
126#define RH_SX126x_REG_IN_EN_REG 0x0583
127#define RH_SX126x_REG_IN_EN_REG_DIO3_POS ( 3U )
128#define RH_SX126x_REG_IN_EN_REG_DIO3_MASK ( 0x01UL << SX126X_REG_IN_EN_REG_DIO3_POS )
130#define RH_SX126x_REG_DIOX_PULLUP 0x0584
131#define RH_SX126x_REG_DIOX_PULLDOWN 0x0585
134#define RH_SX126x_REG_BITBANG_B_REG 0x0587
135#define RH_SX126x_REG_BITBANG_B_REG_ENABLE_POS ( 0U )
136#define RH_SX126x_REG_BITBANG_B_REG_ENABLE_MASK ( 0x0FUL << SX126X_REG_BITBANG_B_REG_ENABLE_POS )
137#define RH_SX126x_REG_BITBANG_B_REG_ENABLE_VAL ( 0x0CUL << SX126X_REG_BITBANG_B_REG_ENABLE_POS )
139#define RH_SX126x_REG_PATCH_UPDATE_ENABLE 0x0610
142#define RH_SX126x_REG_BITBANG_A_REG 0x0680
143#define RH_SX126x_REG_BITBANG_A_REG_ENABLE_POS ( 4U )
144#define RH_SX126x_REG_BITBANG_A_REG_ENABLE_MASK ( 0x07UL << SX126X_REG_BITBANG_A_REG_ENABLE_POS )
145#define RH_SX126x_REG_BITBANG_A_REG_ENABLE_VAL ( 0x01UL << SX126X_REG_BITBANG_A_REG_ENABLE_POS )
148#define RH_SX126x_REG_WHITSEEDBASEADDRESS 0x06B8
151#define RH_SX126x_REG_RXTX_PAYLOAD_LEN 0x06BB
154#define RH_SX126x_REG_CRCSEEDBASEADDRESS 0x06BC
157#define RH_SX126x_REG_CRCPOLYBASEADDRESS 0x06BE
160#define RH_SX126x_REG_SYNCWORDBASEADDRESS 0x06C0
164#define RH_SX126x_REG_GFSK_NODE_ADDRESS 0x06CD
168#define RH_SX126x_REG_GFSK_BROADCAST_ADDRESS 0x06CE
170#define RH_SX126x_REG_PAYLOAD_LENGTH 0x0702
171#define RH_SX126x_REG_PACKET_PARAMS 0x0704
174#define RH_SX126x_REG_LR_SYNCH_TIMEOUT 0x0706
177#define RH_SX126x_REG_IQ_POLARITY 0x0736
182#define RH_SX126x_REG_LR_SYNCWORD 0x0740
185#define RH_SX126x_REG_LR_HEADER_CR 0x0749
186#define RH_SX126x_REG_LR_HEADER_CR_POS ( 4U )
187#define RH_SX126x_REG_LR_HEADER_CR_MASK ( 0x07UL << SX126X_REG_LR_HEADER_CR_POS )
190#define RH_SX126x_REG_LR_HEADER_CRC 0x076B
191#define RH_SX126x_REG_LR_HEADER_CRC_POS ( 4U )
192#define RH_SX126x_REG_LR_HEADER_CRC_MASK ( 0x01UL << SX126X_REG_LR_HEADER_CRC_POS )
194#define RH_SX126x_REG_SPECTRAL_SCAN_STATUS 0x07CD
197#define RH_SX126x_REG_RX_ADDRESS_POINTER 0x0803
200#define RH_SX126x_REG_RNGBASEADDRESS 0x0819
203#define RH_SX126x_REG_TX_MODULATION 0x0889
205#define RH_SX126x_REG_RF_FREQUENCY_0 0x088B
206#define RH_SX126x_REG_RF_FREQUENCY_1 0x088C
207#define RH_SX126x_REG_RF_FREQUENCY_2 0x088D
208#define RH_SX126x_REG_RF_FREQUENCY_3 0x088E
210#define RH_SX126x_REG_RSSI_AVG_WINDOW 0x089B
215#define RH_SX126x_REG_RXGAIN 0x08AC
218#define RH_SX126x_REG_TX_CLAMP_CFG 0x08D8
219#define RH_SX126x_REG_TX_CLAMP_CFG_POS ( 1U )
220#define RH_SX126x_REG_TX_CLAMP_CFG_MASK ( 0x0FUL << SX126X_REG_TX_CLAMP_CFG_POS )
223#define RH_SX126x_REG_ANA_LNA 0x08E2
225#define RH_SX126x_REG_LNA_CAP_TUNE_N 0x08E3
226#define RH_SX126x_REG_LNA_CAP_TUNE_P 0x08E4
229#define RH_SX126x_REG_ANA_MIXER 0x08E5
232#define RH_SX126x_REG_OCP 0x08E7
235#define RH_SX126x_REG_RTC_CTRL 0x0902
238#define RH_SX126x_REG_XTATRIM 0x0911
242#define RH_SX126x_REG_DIO3_OUTPUT_VOLTAGE 0x0920
245#define RH_SX126x_REG_EVT_CLR 0x0944
246#define RH_SX126x_REG_EVT_CLR_TIMEOUT_POS ( 1U )
247#define RH_SX126x_REG_EVT_CLR_TIMEOUT_MASK ( 0x01UL << SX126X_REG_EVT_CLR_TIMEOUT_POS )
249#define RH_SX126x_REG_PATCH_MEMORY_BASE 0x8000
253#define RH_SX126x_SLEEP_START_COLD 0b00000000
254#define RH_SX126x_SLEEP_START_WARM 0b00000100
255#define RH_SX126x_SLEEP_RTC_OFF 0b00000000
256#define RH_SX126x_SLEEP_RTC_ON 0b00000001
259#define RH_SX126x_STANDBY_RC 0x00
260#define RH_SX126x_STANDBY_XOSC 0x01
263#define RH_SX126x_RX_TIMEOUT_NONE 0x000000
264#define RH_SX126x_RX_TIMEOUT_INF 0xFFFFFF
267#define RH_SX126x_TX_TIMEOUT_NONE 0x000000
270#define RH_SX126x_STOP_ON_PREAMBLE_OFF 0x00
271#define RH_SX126x_STOP_ON_PREAMBLE_ON 0x01
274#define RH_SX126x_REGULATOR_LDO 0x00
275#define RH_SX126x_REGULATOR_DC_DC 0x01
278#define RH_SX126x_CALIBRATE_IMAGE_OFF 0b00000000
279#define RH_SX126x_CALIBRATE_IMAGE_ON 0b01000000
280#define RH_SX126x_CALIBRATE_ADC_BULK_P_OFF 0b00000000
281#define RH_SX126x_CALIBRATE_ADC_BULK_P_ON 0b00100000
282#define RH_SX126x_CALIBRATE_ADC_BULK_N_OFF 0b00000000
283#define RH_SX126x_CALIBRATE_ADC_BULK_N_ON 0b00010000
284#define RH_SX126x_CALIBRATE_ADC_PULSE_OFF 0b00000000
285#define RH_SX126x_CALIBRATE_ADC_PULSE_ON 0b00001000
286#define RH_SX126x_CALIBRATE_PLL_OFF 0b00000000
287#define RH_SX126x_CALIBRATE_PLL_ON 0b00000100
288#define RH_SX126x_CALIBRATE_RC13M_OFF 0b00000000
289#define RH_SX126x_CALIBRATE_RC13M_ON 0b00000010
290#define RH_SX126x_CALIBRATE_RC64K_OFF 0b00000000
291#define RH_SX126x_CALIBRATE_RC64K_ON 0b00000001
292#define RH_SX126x_CALIBRATE_ALL 0b01111111
295#define RH_SX126x_CAL_IMG_430_MHZ_1 0x6B
296#define RH_SX126x_CAL_IMG_430_MHZ_2 0x6F
297#define RH_SX126x_CAL_IMG_470_MHZ_1 0x75
298#define RH_SX126x_CAL_IMG_470_MHZ_2 0x81
299#define RH_SX126x_CAL_IMG_779_MHZ_1 0xC1
300#define RH_SX126x_CAL_IMG_779_MHZ_2 0xC5
301#define RH_SX126x_CAL_IMG_863_MHZ_1 0xD7
302#define RH_SX126x_CAL_IMG_863_MHZ_2 0xDB
303#define RH_SX126x_CAL_IMG_902_MHZ_1 0xE1
304#define RH_SX126x_CAL_IMG_902_MHZ_2 0xE9
307#define RH_SX126x_PA_CONFIG_HP_MAX 0x07
309#define RH_SX126x_PA_CONFIG_DEVICE_SEL_SX1261 0x01
310#define RH_SX126x_PA_CONFIG_DEVICE_SEL_SX1262 0x00
312#define RH_SX126x_PA_CONFIG_PA_LUT 0x01
313#define RH_SX126x_PA_CONFIG_SX1262_8 0x00
316#define RH_SX126x_RX_TX_FALLBACK_MODE_FS 0x40
317#define RH_SX126x_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30
318#define RH_SX126x_RX_TX_FALLBACK_MODE_STDBY_RC 0x20
321#define RH_SX126x_IRQ_LR_FHSS_HOP 0b0100000000000000
322#define RH_SX126x_IRQ_TIMEOUT 0b0000001000000000
323#define RH_SX126x_IRQ_CAD_DETECTED 0b0000000100000000
324#define RH_SX126x_IRQ_CAD_DONE 0b0000000010000000
325#define RH_SX126x_IRQ_CRC_ERR 0b0000000001000000
326#define RH_SX126x_IRQ_HEADER_ERR 0b0000000000100000
327#define RH_SX126x_IRQ_HEADER_VALID 0b0000000000010000
328#define RH_SX126x_IRQ_SYNC_WORD_VALID 0b0000000000001000
329#define RH_SX126x_IRQ_PREAMBLE_DETECTED 0b0000000000000100
330#define RH_SX126x_IRQ_RX_DONE 0b0000000000000010
331#define RH_SX126x_IRQ_TX_DONE 0b0000000000000001
332#define RH_SX126x_IRQ_RX_DEFAULT 0b0000001001100010
333#define RH_SX126x_IRQ_ALL 0b0100001111111111
334#define RH_SX126x_IRQ_NONE 0b0000000000000000
337#define RH_SX126x_DIO2_AS_IRQ 0x00
338#define RH_SX126x_DIO2_AS_RF_SWITCH 0x01
341#define RH_SX126x_DIO3_OUTPUT_1_6 0x00
342#define RH_SX126x_DIO3_OUTPUT_1_7 0x01
343#define RH_SX126x_DIO3_OUTPUT_1_8 0x02
344#define RH_SX126x_DIO3_OUTPUT_2_2 0x03
345#define RH_SX126x_DIO3_OUTPUT_2_4 0x04
346#define RH_SX126x_DIO3_OUTPUT_2_7 0x05
347#define RH_SX126x_DIO3_OUTPUT_3_0 0x06
348#define RH_SX126x_DIO3_OUTPUT_3_3 0x07
351#define RH_SX126x_PACKET_TYPE_GFSK 0x00
352#define RH_SX126x_PACKET_TYPE_LORA 0x01
353#define RH_SX126x_PACKET_TYPE_LR_FHSS 0x03
356#define RH_SX126x_PA_RAMP_10U 0x00
357#define RH_SX126x_PA_RAMP_20U 0x01
358#define RH_SX126x_PA_RAMP_40U 0x02
359#define RH_SX126x_PA_RAMP_80U 0x03
360#define RH_SX126x_PA_RAMP_200U 0x04
361#define RH_SX126x_PA_RAMP_800U 0x05
362#define RH_SX126x_PA_RAMP_1700U 0x06
363#define RH_SX126x_PA_RAMP_3400U 0x07
367#define RH_SX126x_GFSK_RX_BW_4_8 0x1F
368#define RH_SX126x_GFSK_RX_BW_5_8 0x17
369#define RH_SX126x_GFSK_RX_BW_7_3 0x0F
370#define RH_SX126x_GFSK_RX_BW_9_7 0x1E
371#define RH_SX126x_GFSK_RX_BW_11_7 0x16
372#define RH_SX126x_GFSK_RX_BW_14_6 0x0E
373#define RH_SX126x_GFSK_RX_BW_19_5 0x1D
374#define RH_SX126x_GFSK_RX_BW_23_4 0x15
375#define RH_SX126x_GFSK_RX_BW_29_3 0x0D
376#define RH_SX126x_GFSK_RX_BW_39_0 0x1C
377#define RH_SX126x_GFSK_RX_BW_46_9 0x14
378#define RH_SX126x_GFSK_RX_BW_58_6 0x0C
379#define RH_SX126x_GFSK_RX_BW_78_2 0x1B
380#define RH_SX126x_GFSK_RX_BW_93_8 0x13
381#define RH_SX126x_GFSK_RX_BW_117_3 0x0B
382#define RH_SX126x_GFSK_RX_BW_156_2 0x1A
383#define RH_SX126x_GFSK_RX_BW_187_2 0x12
384#define RH_SX126x_GFSK_RX_BW_234_3 0x0A
385#define RH_SX126x_GFSK_RX_BW_312_0 0x19
386#define RH_SX126x_GFSK_RX_BW_373_6 0x11
387#define RH_SX126x_GFSK_RX_BW_467_0 0x09
389#define RH_SX126x_LORA_BW_7_8 0x00
390#define RH_SX126x_LORA_BW_10_4 0x08
391#define RH_SX126x_LORA_BW_15_6 0x01
392#define RH_SX126x_LORA_BW_20_8 0x09
393#define RH_SX126x_LORA_BW_31_25 0x02
394#define RH_SX126x_LORA_BW_41_7 0x0A
395#define RH_SX126x_LORA_BW_62_5 0x03
396#define RH_SX126x_LORA_BW_125_0 0x04
397#define RH_SX126x_LORA_BW_250_0 0x05
398#define RH_SX126x_LORA_BW_500_0 0x06
400#define RH_SX126x_LORA_CR_4_5 0x01
401#define RH_SX126x_LORA_CR_4_6 0x02
402#define RH_SX126x_LORA_CR_4_7 0x03
403#define RH_SX126x_LORA_CR_4_8 0x04
405#define RH_SX126x_LORA_SF_32 5
406#define RH_SX126x_LORA_SF_64 6
407#define RH_SX126x_LORA_SF_128 7
408#define RH_SX126x_LORA_SF_256 8
409#define RH_SX126x_LORA_SF_512 9
410#define RH_SX126x_LORA_SF_1024 10
411#define RH_SX126x_LORA_SF_2048 11
412#define RH_SX126x_LORA_SF_4096 12
414#define RH_SX126x_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00
415#define RH_SX126x_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01
418#define RH_SX126x_GFSK_PREAMBLE_DETECT_OFF 0x00
419#define RH_SX126x_GFSK_PREAMBLE_DETECT_8 0x04
420#define RH_SX126x_GFSK_PREAMBLE_DETECT_16 0x05
421#define RH_SX126x_GFSK_PREAMBLE_DETECT_24 0x06
422#define RH_SX126x_GFSK_PREAMBLE_DETECT_32 0x07
423#define RH_SX126x_GFSK_ADDRESS_FILT_OFF 0x00
424#define RH_SX126x_GFSK_ADDRESS_FILT_NODE 0x01
425#define RH_SX126x_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02
426#define RH_SX126x_GFSK_PACKET_FIXED 0x00
427#define RH_SX126x_GFSK_PACKET_VARIABLE 0x01
428#define RH_SX126x_GFSK_CRC_OFF 0x01
429#define RH_SX126x_GFSK_CRC_1_BYTE 0x00
430#define RH_SX126x_GFSK_CRC_2_BYTE 0x02
431#define RH_SX126x_GFSK_CRC_1_BYTE_INV 0x04
432#define RH_SX126x_GFSK_CRC_2_BYTE_INV 0x06
433#define RH_SX126x_GFSK_WHITENING_OFF 0x00
434#define RH_SX126x_GFSK_WHITENING_ON 0x01
435#define RH_SX126x_LORA_PACKET_VARIABLE 0x00
436#define RH_SX126x_LORA_PACKET_FIXED 0x01
437#define RH_SX126x_LORA_HEADER_EXPLICIT 0x00
438#define RH_SX126x_LORA_HEADER_IMPLICIT 0x01
439#define RH_SX126x_LORA_CRC_OFF 0x00
440#define RH_SX126x_LORA_CRC_ON 0x01
441#define RH_SX126x_LORA_IQ_STANDARD 0x00
442#define RH_SX126x_LORA_IQ_INVERTED 0x01
445#define RH_SX126x_CAD_ON_1_SYMB 0x00
446#define RH_SX126x_CAD_ON_2_SYMB 0x01
447#define RH_SX126x_CAD_ON_4_SYMB 0x02
448#define RH_SX126x_CAD_ON_8_SYMB 0x03
449#define RH_SX126x_CAD_ON_16_SYMB 0x04
450#define RH_SX126x_CAD_GOTO_STDBY 0x00
451#define RH_SX126x_CAD_GOTO_RX 0x01
452#define RH_SX126x_CAD_PARAM_DEFAULT 0xFF
453#define RH_SX126x_CAD_PARAM_DET_MIN 10
456#define RH_SX126x_STATUS_MODE_STDBY_RC 0b00100000
457#define RH_SX126x_STATUS_MODE_STDBY_XOSC 0b00110000
458#define RH_SX126x_STATUS_MODE_FS 0b01000000
459#define RH_SX126x_STATUS_MODE_RX 0b01010000
460#define RH_SX126x_STATUS_MODE_TX 0b01100000
461#define RH_SX126x_STATUS_DATA_AVAILABLE 0b00000100
462#define RH_SX126x_STATUS_CMD_TIMEOUT 0b00000110
463#define RH_SX126x_STATUS_CMD_INVALID 0b00001000
464#define RH_SX126x_STATUS_CMD_FAILED 0b00001010
465#define RH_SX126x_STATUS_TX_DONE 0b00001100
466#define RH_SX126x_STATUS_SPI_FAILED 0b11111111
469#define RH_SX126x_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000
470#define RH_SX126x_GFSK_RX_STATUS_SYNC_ERR 0b01000000
471#define RH_SX126x_GFSK_RX_STATUS_ADRS_ERR 0b00100000
472#define RH_SX126x_GFSK_RX_STATUS_CRC_ERR 0b00010000
473#define RH_SX126x_GFSK_RX_STATUS_LENGTH_ERR 0b00001000
474#define RH_SX126x_GFSK_RX_STATUS_ABORT_ERR 0b00000100
475#define RH_SX126x_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010
476#define RH_SX126x_GFSK_RX_STATUS_PACKET_SENT 0b00000001
479#define RH_SX126x_PA_RAMP_ERR 0b100000000
480#define RH_SX126x_PLL_LOCK_ERR 0b001000000
481#define RH_SX126x_XOSC_START_ERR 0b000100000
482#define RH_SX126x_IMG_CALIB_ERR 0b000010000
483#define RH_SX126x_ADC_CALIB_ERR 0b000001000
484#define RH_SX126x_PLL_CALIB_ERR 0b000000100
485#define RH_SX126x_RC13M_CALIB_ERR 0b000000010
486#define RH_SX126x_RC64K_CALIB_ERR 0b000000001
489#define RH_SX126x_SCAN_INTERVAL_7_68_US 10
490#define RH_SX126x_SCAN_INTERVAL_8_20_US 11
491#define RH_SX126x_SCAN_INTERVAL_8_68_US 12
495#define RH_SX126x_HOPPING_ENABLED 0b00000001
496#define RH_SX126x_HOPPING_DISABLED 0b00000000
499#define RH_SX126x_SYNC_WORD_PUBLIC 0x34
500#define RH_SX126x_SYNC_WORD_PRIVATE 0x12
503#define RH_SX126x_TX_BITBANG_1_DISABLED 0b00000000
504#define RH_SX126x_TX_BITBANG_1_ENABLED 0b00010000
507#define RH_SX126x_TX_BITBANG_0_DISABLED 0b00000000
508#define RH_SX126x_TX_BITBANG_0_ENABLED 0b00001100
511#define RH_SX126x_DIO1_OUT_DISABLED 0b00000010
512#define RH_SX126x_DIO1_OUT_ENABLED 0b00000000
513#define RH_SX126x_DIO2_OUT_DISABLED 0b00000100
514#define RH_SX126x_DIO2_OUT_ENABLED 0b00000000
515#define RH_SX126x_DIO3_OUT_DISABLED 0b00001000
516#define RH_SX126x_DIO3_OUT_ENABLED 0b00000000
519#define RH_SX126x_DIO1_IN_DISABLED 0b00000000
520#define RH_SX126x_DIO1_IN_ENABLED 0b00000010
521#define RH_SX126x_DIO2_IN_DISABLED 0b00000000
522#define RH_SX126x_DIO2_IN_ENABLED 0b00000100
523#define RH_SX126x_DIO3_IN_DISABLED 0b00000000
524#define RH_SX126x_DIO3_IN_ENABLED 0b00001000
527#define RH_SX126x_RX_GAIN_BOOSTED 0x96
528#define RH_SX126x_RX_GAIN_POWER_SAVING 0x94
529#define RH_SX126x_RX_GAIN_SPECTRAL_SCAN 0xCB
532#define RH_SX126x_PATCH_UPDATE_DISABLED 0b00000000
533#define RH_SX126x_PATCH_UPDATE_ENABLED 0b00010000
536#define RH_SX126x_SPECTRAL_SCAN_NONE 0x00
537#define RH_SX126x_SPECTRAL_SCAN_ONGOING 0x0F
538#define RH_SX126x_SPECTRAL_SCAN_ABORTED 0xF0
539#define RH_SX126x_SPECTRAL_SCAN_COMPLETED 0xFF
542#define RH_SX126x_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2)
545#define RH_SX126x_LNA_RNG_DISABLED 0b00000001
546#define RH_SX126x_LNA_RNG_ENABLED 0b00000000
549#define RH_SX126x_MIXER_RNG_DISABLED 0b00000001
550#define RH_SX126x_MIXER_RNG_ENABLED 0b00000000
553#define RH_SX126x_SPECTRAL_SCAN_RES_SIZE (33)
818 RadioPinConfigMode_EOT = 0,
819 RadioPinConfigMode_IDLE,
820 RadioPinConfigMode_RX,
821 RadioPinConfigMode_TX_LOW_POWER,
822 RadioPinConfigMode_TX_HIGH_POWER,
826 #define RH_SX126x_MAX_RADIO_PIN_CONFIG_MODES (RadioPinConfigMode_TX_HIGH_POWER + 1)
829 #define RH_SX126x_MAX_RADIO_CONTROL_PINS (3)
837 bool pinState[RH_SX126x_MAX_RADIO_CONTROL_PINS];
845 uint8_t pinNumber[RH_SX126x_MAX_RADIO_CONTROL_PINS];
877 RH_SX126x(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, uint8_t busyPin = RH_INVALID_PIN, uint8_t resetPin = RH_INVALID_PIN,
925 virtual bool recv(uint8_t* buf, uint8_t* len);
937 virtual bool send(
const uint8_t* data, uint8_t len);
990 virtual bool sleep();
1030 bool sendCommand(uint8_t command, uint8_t data[], uint8_t len);
1039 bool getCommand(uint8_t command, uint8_t data[], uint8_t len);
1042 bool readRegisters(uint16_t address, uint8_t data[], uint8_t len);
1048 bool writeRegisters(uint16_t address, uint8_t data[], uint8_t len);
1054 bool writeBuffer(uint8_t offset,
const uint8_t data[], uint8_t len);
1057 bool writeBuffer(uint8_t offset,
const char* text);
1060 bool readBuffer(uint8_t offset, uint8_t data[], uint8_t len);
1063 bool setPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut);
1066 bool setTxParams(uint8_t power, uint8_t rampTime);
1080 bool setModulationParameters(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4, uint8_t p5, uint8_t p6, uint8_t p7, uint8_t p8);
1105 bool setTCXO(
float voltage, uint32_t delay);
1108 bool setPacketParams(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4, uint8_t p5, uint8_t p6, uint8_t p7, uint8_t p8, uint8_t p9);
1124 bool setTx(uint32_t timeout);
1130 bool setRx(uint32_t timeout);
1140 bool setDioIrqParams(uint16_t irqmask, uint16_t dio1mask, uint16_t dio2mask, uint16_t dio3mask);
1198 static RH_SX126x* _deviceForInterrupt[];
1201 uint8_t _interruptPin;
1205 uint8_t _myInterruptIndex;
1208 volatile uint8_t _bufLen;
1211 uint8_t _buf[RH_SX126x_MAX_PAYLOAD_LEN];
1214 volatile bool _rxBufValid;
1226 uint16_t _preambleLength = 8;
1229 bool _invertIQ =
false;
1236 bool _lorabw500 =
false;
1239 RadioPinConfig* _radioPinConfig =
nullptr;
RHMode
Defines different operating modes for the transport hardware.
Definition: RHGenericDriver.h:49
virtual RHMode mode()
Definition: RHGenericDriver.cpp:165
Base class for SPI interfaces.
Definition: RHGenericSPI.h:31
Base class for RadioHead drivers that use the SPI bus to communicate with its transport hardware.
Definition: RHSPIDriver.h:39
Driver to send and receive unaddressed, unreliable datagrams via a Semtech SX126X family LoRa capable...
Definition: RH_SX126x.h:757
bool setBufferBaseAddress(uint8_t txbase, uint8_t rxbase)
Low level function to set the address wherge the next radBuffer or writeBuffer will occur.
Definition: RH_SX126x.cpp:993
int lastSNR()
Definition: RH_SX126x.cpp:510
bool printRegisters(uint16_t address, uint8_t count)
Definition: RH_SX126x.cpp:820
bool setModulationParametersLoRa(uint8_t sf, float bw, uint8_t cr, bool ldro)
Set the low-level registers for the desired LoRA modulation scheme.
Definition: RH_SX126x.cpp:859
bool setRx(uint32_t timeout)
Set the radio to receive mode. Automatically configures the radio control pins to the configuration R...
Definition: RH_SX126x.cpp:1047
bool setPacketParams(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4, uint8_t p5, uint8_t p6, uint8_t p7, uint8_t p8, uint8_t p9)
Low level function to set the radio packet confiuration.
Definition: RH_SX126x.cpp:972
virtual uint8_t maxMessageLength()
Definition: RH_SX126x.cpp:376
void setModeTx()
Definition: RH_SX126x.cpp:440
RadioPinConfigMode
Definition: RH_SX126x.h:817
virtual bool recv(uint8_t *buf, uint8_t *len)
Definition: RH_SX126x.cpp:319
bool readBuffer(uint8_t offset, uint8_t data[], uint8_t len)
Read multibyte data from the radio IO buffer at the current buffer address.
Definition: RH_SX126x.cpp:689
bool setTxParams(uint8_t power, uint8_t rampTime)
Set the radio power output. CAUTION: for internal use only. Users should use setTxPower()
Definition: RH_SX126x.cpp:711
virtual bool send(const uint8_t *data, uint8_t len)
Definition: RH_SX126x.cpp:337
uint8_t readRegister(uint16_t address)
Read and return a single register byte from the radio.
Definition: RH_SX126x.cpp:628
bool setRxBoostMode(bool boost, bool retain)
Sets whether radios receiver gain boost should be enabled instead of the default power saving mode.
Definition: RH_SX126x.cpp:1082
void setInvertIQ(bool invertIQ)
Definition: RH_SX126x.cpp:1132
virtual bool modeWillChange(RHMode)
Definition: RH_SX126x.h:1176
bool setRegulatorMode(uint8_t mode)
Definition: RH_SX126x.cpp:1098
bool setLoRaSyncWord(uint16_t sync)
Set the 16 bit LoRa sync word.
Definition: RH_SX126x.cpp:927
bool setModulationParameters(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4, uint8_t p5, uint8_t p6, uint8_t p7, uint8_t p8)
Set the low-level registers for any desired modulation scheme.
Definition: RH_SX126x.cpp:851
void setModeRx()
Definition: RH_SX126x.cpp:429
bool setPacketParametersLoRa(uint8_t payload_length)
Set the necessary radio packet parameters for a forthcoming transmission of payload_length bytes.
Definition: RH_SX126x.cpp:978
bool setCad()
Starts the radio in Clear Air Detect (CAD) mode. CAUTION: NOT YET WORKING, always retuns false.
Definition: RH_SX126x.cpp:1062
virtual bool sleep()
Definition: RH_SX126x.cpp:418
bool setFrequency(float centre, bool calibrate=true)
Definition: RH_SX126x.cpp:381
bool clearDeviceErrors()
Clear the radio error byte.
Definition: RH_SX126x.cpp:835
virtual bool waitUntilNotBusy()
Definition: RH_SX126x.cpp:520
virtual bool isChannelActive()
Definition: RH_SX126x.cpp:494
bool setPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut)
Set the radio Power Amplifier configuration.
Definition: RH_SX126x.cpp:705
ModemConfigChoice
Definition: RH_SX126x.h:803
@ LoRa_Bw31_25Cr48Sf512
Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range.
Definition: RH_SX126x.h:806
@ LoRa_Bw500Cr45Sf128
Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range.
Definition: RH_SX126x.h:805
@ LoRa_Bw125Cr48Sf4096
Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, low data rate, CRC on. Slow+long range.
Definition: RH_SX126x.h:807
@ LoRa_Bw125Cr45Sf128
Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range.
Definition: RH_SX126x.h:804
@ LoRa_Bw125Cr45Sf2048
Bw = 125 kHz, Cr = 4/5, Sf = 2048chips/symbol, CRC on. Slow+long range.
Definition: RH_SX126x.h:808
void setModeIdle()
Definition: RH_SX126x.cpp:408
virtual bool available()
Definition: RH_SX126x.cpp:297
bool readRegisters(uint16_t address, uint8_t data[], uint8_t len)
Read multiple registers from the radio.
Definition: RH_SX126x.cpp:611
void handleInterrupt()
Definition: RH_SX126x.cpp:193
bool setModemRegisters(const ModemConfig *config)
Definition: RH_SX126x.cpp:452
uint16_t getIrqStatus()
Return the radio IRQ state.
Definition: RH_SX126x.cpp:1118
bool setDIO3AsTcxoCtrl(uint8_t voltage, uint32_t delay)
Definition: RH_SX126x.cpp:938
PacketType
Packet types the modem can be configured for.
Definition: RH_SX126x.h:761
@ PacketTypeLoRa
Use LoRA packets.
Definition: RH_SX126x.h:762
@ PacketTypeGFSK
Use GFSK packets.
Definition: RH_SX126x.h:763
virtual bool setRadioPinsForMode(RadioPinConfigMode mode)
Definition: RH_SX126x.cpp:1149
bool setStandby(uint8_t config)
Set the radio to sleep mode. Automatically configures the radio control pins to the configuration Rad...
Definition: RH_SX126x.cpp:1006
bool setSleep(uint8_t config)
Set the radio to sleep mode. Automatically configures the radio control pins to the configuration Rad...
Definition: RH_SX126x.cpp:999
bool writeBuffer(uint8_t offset, const uint8_t data[], uint8_t len)
Write multibyte data to the radio IO buffer at the current buffer address.
Definition: RH_SX126x.cpp:669
bool setOCPConfiguration(uint8_t setting)
Set the radio power amplifier over-current protection.
Definition: RH_SX126x.cpp:933
bool setTx(uint32_t timeout)
Definition: RH_SX126x.cpp:1013
bool setDioIrqParams(uint16_t irqmask, uint16_t dio1mask, uint16_t dio2mask, uint16_t dio3mask)
Configures the conditions under which the radio will enable an interrupt, and for which DIO pins.
Definition: RH_SX126x.cpp:1103
virtual bool setupInterruptHandler()
Do whatever is necesary to establish the interrupt handler. Subclasses may have different needs.
Definition: RH_SX126x.cpp:134
bool sendCommand(uint8_t command, uint8_t data[], uint8_t len)
Send a command with multi-byte data to the radio.
Definition: RH_SX126x.cpp:553
bool getCommand(uint8_t command, uint8_t data[], uint8_t len)
Send a command to the radio and get a multi-byte respose.
Definition: RH_SX126x.cpp:597
uint8_t getPacketType()
return the current packet type
Definition: RH_SX126x.cpp:1125
bool clearIrqStatus(uint16_t mask)
Clear the radio IRQ state.
Definition: RH_SX126x.cpp:1112
bool setRxFallbackMode(uint8_t mode)
Sets the mode that the radio will change to after a transmit or receive is complete.
Definition: RH_SX126x.cpp:846
bool fixPAClamping(bool enable)
Per SX1262_datasheet.pdf Rev 1.2 section 15.2, this fixes an error in the radio Power Amplifier clamp...
Definition: RH_SX126x.cpp:1137
virtual bool init()
Definition: RH_SX126x.cpp:58
virtual RadioPinConfigEntry * findRadioPinConfigEntry(RadioPinConfigMode mode)
Find the pin configuration entry for a desired radio mode.
Definition: RH_SX126x.cpp:1184
void validateRxBuf()
Examine the revceive buffer to determine whether the message is for this node.
Definition: RH_SX126x.cpp:279
bool setModulationParametersGFSK(uint32_t br, uint8_t sh, uint8_t rxBw, uint32_t freqDev)
Set the low-level registers for the desired GFSK modulation scheme.
Definition: RH_SX126x.cpp:910
RH_SX126x(uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, uint8_t busyPin=RH_INVALID_PIN, uint8_t resetPin=RH_INVALID_PIN, RHGenericSPI &spi=hardware_spi, RadioPinConfig *radioPinConfig=nullptr)
Definition: RH_SX126x.cpp:42
void setPreambleLength(uint16_t bytes)
Definition: RH_SX126x.cpp:489
bool setTCXO(float voltage, uint32_t delay)
Set the voltage to use for the TCXO oven.
Definition: RH_SX126x.cpp:947
bool writeRegisters(uint16_t address, uint8_t data[], uint8_t len)
Write multibyte data to the given register and sunbsequent registers.
Definition: RH_SX126x.cpp:635
bool setTxContinuous()
Definition: RH_SX126x.cpp:1041
bool writeRegister(uint16_t address, uint8_t data)
Write a single byte to the given register.
Definition: RH_SX126x.cpp:662
bool calibrate(uint8_t calib_param)
Cause the radio to calibrate all its sections at the currently selected frequency.
Definition: RH_SX126x.cpp:916
bool calibrateImage(uint8_t f1, uint8_t f2)
Allows the user to calibrate the image rejection of the device for the device operating frequency ban...
Definition: RH_SX126x.cpp:921
bool setDIO2AsRfSwitchCtrl(bool value)
Definition: RH_SX126x.cpp:841
virtual bool setTxPower(int8_t power)
Definition: RH_SX126x.cpp:717
uint8_t getStatus()
Read and return the radio status byte.
Definition: RH_SX126x.cpp:540
void clearRxBuf()
Clear our local receive buffer.
Definition: RH_SX126x.cpp:310
bool setModemConfig(ModemConfigChoice index)
Definition: RH_SX126x.cpp:478
Defines register values for a set of modem configuration registers.
Definition: RH_SX126x.h:774
uint8_t p4
Value for setModulationParameters parameter 4.
Definition: RH_SX126x.h:779
uint8_t p8
Value for setModulationParameters parameter 8.
Definition: RH_SX126x.h:783
uint8_t p5
Value for setModulationParameters parameter 5.
Definition: RH_SX126x.h:780
uint8_t p7
Value for setModulationParameters parameter 7.
Definition: RH_SX126x.h:782
uint8_t p1
Value for setModulationParameters parameter 1.
Definition: RH_SX126x.h:776
uint8_t p2
Value for setModulationParameters parameter 2.
Definition: RH_SX126x.h:777
uint8_t p3
Value for setModulationParameters parameter 3.
Definition: RH_SX126x.h:778
uint8_t p6
Value for setModulationParameters parameter 6.
Definition: RH_SX126x.h:781
Definition: RH_SX126x.h:833
Definition: RH_SX126x.h:843