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_FREQ_ERROR 0x076B
191#define RH_SX126x_REG_LR_HEADER_CRC 0x076B
192#define RH_SX126x_REG_LR_HEADER_CRC_POS ( 4U )
193#define RH_SX126x_REG_LR_HEADER_CRC_MASK ( 0x01UL << SX126X_REG_LR_HEADER_CRC_POS )
195#define RH_SX126x_REG_SPECTRAL_SCAN_STATUS 0x07CD
198#define RH_SX126x_REG_RX_ADDRESS_POINTER 0x0803
201#define RH_SX126x_REG_RNGBASEADDRESS 0x0819
204#define RH_SX126x_REG_TX_MODULATION 0x0889
206#define RH_SX126x_REG_RF_FREQUENCY_0 0x088B
207#define RH_SX126x_REG_RF_FREQUENCY_1 0x088C
208#define RH_SX126x_REG_RF_FREQUENCY_2 0x088D
209#define RH_SX126x_REG_RF_FREQUENCY_3 0x088E
211#define RH_SX126x_REG_RSSI_AVG_WINDOW 0x089B
216#define RH_SX126x_REG_RXGAIN 0x08AC
219#define RH_SX126x_REG_TX_CLAMP_CFG 0x08D8
220#define RH_SX126x_REG_TX_CLAMP_CFG_POS ( 1U )
221#define RH_SX126x_REG_TX_CLAMP_CFG_MASK ( 0x0FUL << SX126X_REG_TX_CLAMP_CFG_POS )
224#define RH_SX126x_REG_ANA_LNA 0x08E2
226#define RH_SX126x_REG_LNA_CAP_TUNE_N 0x08E3
227#define RH_SX126x_REG_LNA_CAP_TUNE_P 0x08E4
230#define RH_SX126x_REG_ANA_MIXER 0x08E5
233#define RH_SX126x_REG_OCP 0x08E7
236#define RH_SX126x_REG_RTC_CTRL 0x0902
239#define RH_SX126x_REG_XTATRIM 0x0911
243#define RH_SX126x_REG_DIO3_OUTPUT_VOLTAGE 0x0920
246#define RH_SX126x_REG_EVT_CLR 0x0944
247#define RH_SX126x_REG_EVT_CLR_TIMEOUT_POS ( 1U )
248#define RH_SX126x_REG_EVT_CLR_TIMEOUT_MASK ( 0x01UL << SX126X_REG_EVT_CLR_TIMEOUT_POS )
250#define RH_SX126x_REG_PATCH_MEMORY_BASE 0x8000
254#define RH_SX126x_SLEEP_START_COLD 0b00000000
255#define RH_SX126x_SLEEP_START_WARM 0b00000100
256#define RH_SX126x_SLEEP_RTC_OFF 0b00000000
257#define RH_SX126x_SLEEP_RTC_ON 0b00000001
260#define RH_SX126x_STANDBY_RC 0x00
261#define RH_SX126x_STANDBY_XOSC 0x01
264#define RH_SX126x_RX_TIMEOUT_NONE 0x000000
265#define RH_SX126x_RX_TIMEOUT_INF 0xFFFFFF
268#define RH_SX126x_TX_TIMEOUT_NONE 0x000000
271#define RH_SX126x_STOP_ON_PREAMBLE_OFF 0x00
272#define RH_SX126x_STOP_ON_PREAMBLE_ON 0x01
275#define RH_SX126x_REGULATOR_LDO 0x00
276#define RH_SX126x_REGULATOR_DC_DC 0x01
279#define RH_SX126x_CALIBRATE_IMAGE_OFF 0b00000000
280#define RH_SX126x_CALIBRATE_IMAGE_ON 0b01000000
281#define RH_SX126x_CALIBRATE_ADC_BULK_P_OFF 0b00000000
282#define RH_SX126x_CALIBRATE_ADC_BULK_P_ON 0b00100000
283#define RH_SX126x_CALIBRATE_ADC_BULK_N_OFF 0b00000000
284#define RH_SX126x_CALIBRATE_ADC_BULK_N_ON 0b00010000
285#define RH_SX126x_CALIBRATE_ADC_PULSE_OFF 0b00000000
286#define RH_SX126x_CALIBRATE_ADC_PULSE_ON 0b00001000
287#define RH_SX126x_CALIBRATE_PLL_OFF 0b00000000
288#define RH_SX126x_CALIBRATE_PLL_ON 0b00000100
289#define RH_SX126x_CALIBRATE_RC13M_OFF 0b00000000
290#define RH_SX126x_CALIBRATE_RC13M_ON 0b00000010
291#define RH_SX126x_CALIBRATE_RC64K_OFF 0b00000000
292#define RH_SX126x_CALIBRATE_RC64K_ON 0b00000001
293#define RH_SX126x_CALIBRATE_ALL 0b01111111
296#define RH_SX126x_CAL_IMG_430_MHZ_1 0x6B
297#define RH_SX126x_CAL_IMG_430_MHZ_2 0x6F
298#define RH_SX126x_CAL_IMG_470_MHZ_1 0x75
299#define RH_SX126x_CAL_IMG_470_MHZ_2 0x81
300#define RH_SX126x_CAL_IMG_779_MHZ_1 0xC1
301#define RH_SX126x_CAL_IMG_779_MHZ_2 0xC5
302#define RH_SX126x_CAL_IMG_863_MHZ_1 0xD7
303#define RH_SX126x_CAL_IMG_863_MHZ_2 0xDB
304#define RH_SX126x_CAL_IMG_902_MHZ_1 0xE1
305#define RH_SX126x_CAL_IMG_902_MHZ_2 0xE9
308#define RH_SX126x_PA_CONFIG_HP_MAX 0x07
310#define RH_SX126x_PA_CONFIG_DEVICE_SEL_SX1261 0x01
311#define RH_SX126x_PA_CONFIG_DEVICE_SEL_SX1262 0x00
313#define RH_SX126x_PA_CONFIG_PA_LUT 0x01
314#define RH_SX126x_PA_CONFIG_SX1262_8 0x00
317#define RH_SX126x_RX_TX_FALLBACK_MODE_FS 0x40
318#define RH_SX126x_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30
319#define RH_SX126x_RX_TX_FALLBACK_MODE_STDBY_RC 0x20
322#define RH_SX126x_IRQ_LR_FHSS_HOP 0b0100000000000000
323#define RH_SX126x_IRQ_TIMEOUT 0b0000001000000000
324#define RH_SX126x_IRQ_CAD_DETECTED 0b0000000100000000
325#define RH_SX126x_IRQ_CAD_DONE 0b0000000010000000
326#define RH_SX126x_IRQ_CRC_ERR 0b0000000001000000
327#define RH_SX126x_IRQ_HEADER_ERR 0b0000000000100000
328#define RH_SX126x_IRQ_HEADER_VALID 0b0000000000010000
329#define RH_SX126x_IRQ_SYNC_WORD_VALID 0b0000000000001000
330#define RH_SX126x_IRQ_PREAMBLE_DETECTED 0b0000000000000100
331#define RH_SX126x_IRQ_RX_DONE 0b0000000000000010
332#define RH_SX126x_IRQ_TX_DONE 0b0000000000000001
333#define RH_SX126x_IRQ_RX_DEFAULT 0b0000001001100010
334#define RH_SX126x_IRQ_ALL 0b0100001111111111
335#define RH_SX126x_IRQ_NONE 0b0000000000000000
338#define RH_SX126x_DIO2_AS_IRQ 0x00
339#define RH_SX126x_DIO2_AS_RF_SWITCH 0x01
342#define RH_SX126x_DIO3_OUTPUT_1_6 0x00
343#define RH_SX126x_DIO3_OUTPUT_1_7 0x01
344#define RH_SX126x_DIO3_OUTPUT_1_8 0x02
345#define RH_SX126x_DIO3_OUTPUT_2_2 0x03
346#define RH_SX126x_DIO3_OUTPUT_2_4 0x04
347#define RH_SX126x_DIO3_OUTPUT_2_7 0x05
348#define RH_SX126x_DIO3_OUTPUT_3_0 0x06
349#define RH_SX126x_DIO3_OUTPUT_3_3 0x07
352#define RH_SX126x_PACKET_TYPE_GFSK 0x00
353#define RH_SX126x_PACKET_TYPE_LORA 0x01
354#define RH_SX126x_PACKET_TYPE_LR_FHSS 0x03
357#define RH_SX126x_PA_RAMP_10U 0x00
358#define RH_SX126x_PA_RAMP_20U 0x01
359#define RH_SX126x_PA_RAMP_40U 0x02
360#define RH_SX126x_PA_RAMP_80U 0x03
361#define RH_SX126x_PA_RAMP_200U 0x04
362#define RH_SX126x_PA_RAMP_800U 0x05
363#define RH_SX126x_PA_RAMP_1700U 0x06
364#define RH_SX126x_PA_RAMP_3400U 0x07
368#define RH_SX126x_GFSK_RX_BW_4_8 0x1F
369#define RH_SX126x_GFSK_RX_BW_5_8 0x17
370#define RH_SX126x_GFSK_RX_BW_7_3 0x0F
371#define RH_SX126x_GFSK_RX_BW_9_7 0x1E
372#define RH_SX126x_GFSK_RX_BW_11_7 0x16
373#define RH_SX126x_GFSK_RX_BW_14_6 0x0E
374#define RH_SX126x_GFSK_RX_BW_19_5 0x1D
375#define RH_SX126x_GFSK_RX_BW_23_4 0x15
376#define RH_SX126x_GFSK_RX_BW_29_3 0x0D
377#define RH_SX126x_GFSK_RX_BW_39_0 0x1C
378#define RH_SX126x_GFSK_RX_BW_46_9 0x14
379#define RH_SX126x_GFSK_RX_BW_58_6 0x0C
380#define RH_SX126x_GFSK_RX_BW_78_2 0x1B
381#define RH_SX126x_GFSK_RX_BW_93_8 0x13
382#define RH_SX126x_GFSK_RX_BW_117_3 0x0B
383#define RH_SX126x_GFSK_RX_BW_156_2 0x1A
384#define RH_SX126x_GFSK_RX_BW_187_2 0x12
385#define RH_SX126x_GFSK_RX_BW_234_3 0x0A
386#define RH_SX126x_GFSK_RX_BW_312_0 0x19
387#define RH_SX126x_GFSK_RX_BW_373_6 0x11
388#define RH_SX126x_GFSK_RX_BW_467_0 0x09
390#define RH_SX126x_LORA_BW_7_8 0x00
391#define RH_SX126x_LORA_BW_10_4 0x08
392#define RH_SX126x_LORA_BW_15_6 0x01
393#define RH_SX126x_LORA_BW_20_8 0x09
394#define RH_SX126x_LORA_BW_31_25 0x02
395#define RH_SX126x_LORA_BW_41_7 0x0A
396#define RH_SX126x_LORA_BW_62_5 0x03
397#define RH_SX126x_LORA_BW_125_0 0x04
398#define RH_SX126x_LORA_BW_250_0 0x05
399#define RH_SX126x_LORA_BW_500_0 0x06
401#define RH_SX126x_LORA_CR_4_5 0x01
402#define RH_SX126x_LORA_CR_4_6 0x02
403#define RH_SX126x_LORA_CR_4_7 0x03
404#define RH_SX126x_LORA_CR_4_8 0x04
406#define RH_SX126x_LORA_SF_32 5
407#define RH_SX126x_LORA_SF_64 6
408#define RH_SX126x_LORA_SF_128 7
409#define RH_SX126x_LORA_SF_256 8
410#define RH_SX126x_LORA_SF_512 9
411#define RH_SX126x_LORA_SF_1024 10
412#define RH_SX126x_LORA_SF_2048 11
413#define RH_SX126x_LORA_SF_4096 12
415#define RH_SX126x_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00
416#define RH_SX126x_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01
419#define RH_SX126x_GFSK_PREAMBLE_DETECT_OFF 0x00
420#define RH_SX126x_GFSK_PREAMBLE_DETECT_8 0x04
421#define RH_SX126x_GFSK_PREAMBLE_DETECT_16 0x05
422#define RH_SX126x_GFSK_PREAMBLE_DETECT_24 0x06
423#define RH_SX126x_GFSK_PREAMBLE_DETECT_32 0x07
424#define RH_SX126x_GFSK_ADDRESS_FILT_OFF 0x00
425#define RH_SX126x_GFSK_ADDRESS_FILT_NODE 0x01
426#define RH_SX126x_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02
427#define RH_SX126x_GFSK_PACKET_FIXED 0x00
428#define RH_SX126x_GFSK_PACKET_VARIABLE 0x01
429#define RH_SX126x_GFSK_CRC_OFF 0x01
430#define RH_SX126x_GFSK_CRC_1_BYTE 0x00
431#define RH_SX126x_GFSK_CRC_2_BYTE 0x02
432#define RH_SX126x_GFSK_CRC_1_BYTE_INV 0x04
433#define RH_SX126x_GFSK_CRC_2_BYTE_INV 0x06
434#define RH_SX126x_GFSK_WHITENING_OFF 0x00
435#define RH_SX126x_GFSK_WHITENING_ON 0x01
436#define RH_SX126x_LORA_PACKET_VARIABLE 0x00
437#define RH_SX126x_LORA_PACKET_FIXED 0x01
438#define RH_SX126x_LORA_HEADER_EXPLICIT 0x00
439#define RH_SX126x_LORA_HEADER_IMPLICIT 0x01
440#define RH_SX126x_LORA_CRC_OFF 0x00
441#define RH_SX126x_LORA_CRC_ON 0x01
442#define RH_SX126x_LORA_IQ_STANDARD 0x00
443#define RH_SX126x_LORA_IQ_INVERTED 0x01
446#define RH_SX126x_CAD_ON_1_SYMB 0x00
447#define RH_SX126x_CAD_ON_2_SYMB 0x01
448#define RH_SX126x_CAD_ON_4_SYMB 0x02
449#define RH_SX126x_CAD_ON_8_SYMB 0x03
450#define RH_SX126x_CAD_ON_16_SYMB 0x04
451#define RH_SX126x_CAD_GOTO_STDBY 0x00
452#define RH_SX126x_CAD_GOTO_RX 0x01
453#define RH_SX126x_CAD_PARAM_DEFAULT 0xFF
454#define RH_SX126x_CAD_PARAM_DET_MIN 10
457#define RH_SX126x_STATUS_MODE_STDBY_RC 0b00100000
458#define RH_SX126x_STATUS_MODE_STDBY_XOSC 0b00110000
459#define RH_SX126x_STATUS_MODE_FS 0b01000000
460#define RH_SX126x_STATUS_MODE_RX 0b01010000
461#define RH_SX126x_STATUS_MODE_TX 0b01100000
462#define RH_SX126x_STATUS_DATA_AVAILABLE 0b00000100
463#define RH_SX126x_STATUS_CMD_TIMEOUT 0b00000110
464#define RH_SX126x_STATUS_CMD_INVALID 0b00001000
465#define RH_SX126x_STATUS_CMD_FAILED 0b00001010
466#define RH_SX126x_STATUS_TX_DONE 0b00001100
467#define RH_SX126x_STATUS_SPI_FAILED 0b11111111
470#define RH_SX126x_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000
471#define RH_SX126x_GFSK_RX_STATUS_SYNC_ERR 0b01000000
472#define RH_SX126x_GFSK_RX_STATUS_ADRS_ERR 0b00100000
473#define RH_SX126x_GFSK_RX_STATUS_CRC_ERR 0b00010000
474#define RH_SX126x_GFSK_RX_STATUS_LENGTH_ERR 0b00001000
475#define RH_SX126x_GFSK_RX_STATUS_ABORT_ERR 0b00000100
476#define RH_SX126x_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010
477#define RH_SX126x_GFSK_RX_STATUS_PACKET_SENT 0b00000001
480#define RH_SX126x_PA_RAMP_ERR 0b100000000
481#define RH_SX126x_PLL_LOCK_ERR 0b001000000
482#define RH_SX126x_XOSC_START_ERR 0b000100000
483#define RH_SX126x_IMG_CALIB_ERR 0b000010000
484#define RH_SX126x_ADC_CALIB_ERR 0b000001000
485#define RH_SX126x_PLL_CALIB_ERR 0b000000100
486#define RH_SX126x_RC13M_CALIB_ERR 0b000000010
487#define RH_SX126x_RC64K_CALIB_ERR 0b000000001
490#define RH_SX126x_SCAN_INTERVAL_7_68_US 10
491#define RH_SX126x_SCAN_INTERVAL_8_20_US 11
492#define RH_SX126x_SCAN_INTERVAL_8_68_US 12
496#define RH_SX126x_HOPPING_ENABLED 0b00000001
497#define RH_SX126x_HOPPING_DISABLED 0b00000000
500#define RH_SX126x_SYNC_WORD_PUBLIC 0x34
501#define RH_SX126x_SYNC_WORD_PRIVATE 0x12
504#define RH_SX126x_TX_BITBANG_1_DISABLED 0b00000000
505#define RH_SX126x_TX_BITBANG_1_ENABLED 0b00010000
508#define RH_SX126x_TX_BITBANG_0_DISABLED 0b00000000
509#define RH_SX126x_TX_BITBANG_0_ENABLED 0b00001100
512#define RH_SX126x_DIO1_OUT_DISABLED 0b00000010
513#define RH_SX126x_DIO1_OUT_ENABLED 0b00000000
514#define RH_SX126x_DIO2_OUT_DISABLED 0b00000100
515#define RH_SX126x_DIO2_OUT_ENABLED 0b00000000
516#define RH_SX126x_DIO3_OUT_DISABLED 0b00001000
517#define RH_SX126x_DIO3_OUT_ENABLED 0b00000000
520#define RH_SX126x_DIO1_IN_DISABLED 0b00000000
521#define RH_SX126x_DIO1_IN_ENABLED 0b00000010
522#define RH_SX126x_DIO2_IN_DISABLED 0b00000000
523#define RH_SX126x_DIO2_IN_ENABLED 0b00000100
524#define RH_SX126x_DIO3_IN_DISABLED 0b00000000
525#define RH_SX126x_DIO3_IN_ENABLED 0b00001000
528#define RH_SX126x_RX_GAIN_BOOSTED 0x96
529#define RH_SX126x_RX_GAIN_POWER_SAVING 0x94
530#define RH_SX126x_RX_GAIN_SPECTRAL_SCAN 0xCB
533#define RH_SX126x_PATCH_UPDATE_DISABLED 0b00000000
534#define RH_SX126x_PATCH_UPDATE_ENABLED 0b00010000
537#define RH_SX126x_SPECTRAL_SCAN_NONE 0x00
538#define RH_SX126x_SPECTRAL_SCAN_ONGOING 0x0F
539#define RH_SX126x_SPECTRAL_SCAN_ABORTED 0xF0
540#define RH_SX126x_SPECTRAL_SCAN_COMPLETED 0xFF
543#define RH_SX126x_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2)
546#define RH_SX126x_LNA_RNG_DISABLED 0b00000001
547#define RH_SX126x_LNA_RNG_ENABLED 0b00000000
550#define RH_SX126x_MIXER_RNG_DISABLED 0b00000001
551#define RH_SX126x_MIXER_RNG_ENABLED 0b00000000
554#define RH_SX126x_SPECTRAL_SCAN_RES_SIZE (33)
819 RadioPinConfigMode_EOT = 0,
820 RadioPinConfigMode_IDLE,
821 RadioPinConfigMode_RX,
822 RadioPinConfigMode_TX_LOW_POWER,
823 RadioPinConfigMode_TX_HIGH_POWER,
827 #define RH_SX126x_MAX_RADIO_PIN_CONFIG_MODES (RadioPinConfigMode_TX_HIGH_POWER + 1)
830 #define RH_SX126x_MAX_RADIO_CONTROL_PINS (3)
838 bool pinState[RH_SX126x_MAX_RADIO_CONTROL_PINS];
846 uint8_t pinNumber[RH_SX126x_MAX_RADIO_CONTROL_PINS];
878 RH_SX126x(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, uint8_t busyPin = RH_INVALID_PIN, uint8_t resetPin = RH_INVALID_PIN,
926 virtual bool recv(uint8_t* buf, uint8_t* len);
938 virtual bool send(
const uint8_t* data, uint8_t len);
991 virtual bool sleep();
1052 bool sendCommand(uint8_t command, uint8_t data[], uint8_t len);
1061 bool getCommand(uint8_t command, uint8_t data[], uint8_t len);
1064 bool readRegisters(uint16_t address, uint8_t data[], uint8_t len);
1070 bool writeRegisters(uint16_t address, uint8_t data[], uint8_t len);
1076 bool writeBuffer(uint8_t offset,
const uint8_t data[], uint8_t len);
1079 bool writeBuffer(uint8_t offset,
const char* text);
1082 bool readBuffer(uint8_t offset, uint8_t data[], uint8_t len);
1085 bool setPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut);
1088 bool setTxParams(uint8_t power, uint8_t rampTime);
1102 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);
1127 bool setTCXO(
float voltage, uint32_t delay);
1130 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);
1146 bool setTx(uint32_t timeout);
1152 bool setRx(uint32_t timeout);
1162 bool setDioIrqParams(uint16_t irqmask, uint16_t dio1mask, uint16_t dio2mask, uint16_t dio3mask);
1220 static RH_SX126x* _deviceForInterrupt[];
1223 uint8_t _interruptPin;
1227 uint8_t _myInterruptIndex;
1230 volatile uint8_t _bufLen;
1233 uint8_t _buf[RH_SX126x_MAX_PAYLOAD_LEN];
1236 volatile bool _rxBufValid;
1248 uint16_t _preambleLength = 8;
1251 bool _invertIQ =
false;
1258 bool _lorabw500 =
false;
1261 RadioPinConfig* _radioPinConfig =
nullptr;
1273 float _bandwidth = 0.0;
1279 volatile uint16_t _lastirq;
1282 volatile bool _iflag =
false;
1285 uint16_t _irqMask = RH_SX126x_IRQ_CAD_DETECTED
1286 | RH_SX126x_IRQ_CAD_DONE
1287 | RH_SX126x_IRQ_CRC_ERR
1288 | RH_SX126x_IRQ_HEADER_ERR
1289 | RH_SX126x_IRQ_RX_DONE
1290 | RH_SX126x_IRQ_TX_DONE;
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:758
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:1051
int lastSNR()
Definition RH_SX126x.cpp:534
bool printRegisters(uint16_t address, uint8_t count)
Definition RH_SX126x.cpp:844
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:917
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:1105
void clearIflag()
Reset the interrupt flag. For debugging.
Definition RH_SX126x.h:1026
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:1030
virtual uint8_t maxMessageLength()
Definition RH_SX126x.cpp:400
void setModeTx()
Definition RH_SX126x.cpp:464
RadioPinConfigMode
Definition RH_SX126x.h:818
virtual bool recv(uint8_t *buf, uint8_t *len)
Definition RH_SX126x.cpp:331
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:713
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:735
virtual bool send(const uint8_t *data, uint8_t len)
Definition RH_SX126x.cpp:352
uint8_t readRegister(uint16_t address)
Read and return a single register byte from the radio.
Definition RH_SX126x.cpp:652
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:1140
void setInvertIQ(bool invertIQ)
Definition RH_SX126x.cpp:1190
virtual bool modeWillChange(RHMode)
Definition RH_SX126x.h:1198
bool setRegulatorMode(uint8_t mode)
Definition RH_SX126x.cpp:1156
bool getIflag()
Return true if an interrupt has occurred since the last clearIflag(). For debugging.
Definition RH_SX126x.h:1023
bool setLoRaSyncWord(uint16_t sync)
Set the 16 bit LoRa sync word.
Definition RH_SX126x.cpp:985
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:875
void setModeRx()
Definition RH_SX126x.cpp:453
bool setPacketParametersLoRa(uint8_t payload_length)
Set the necessary radio packet parameters for a forthcoming transmission of payload_length bytes.
Definition RH_SX126x.cpp:1036
bool setCad()
Starts the radio in Clear Air Detect (CAD) mode. CAUTION: NOT YET WORKING, always retuns false.
Definition RH_SX126x.cpp:1120
virtual bool sleep()
Definition RH_SX126x.cpp:442
bool setFrequency(float centre, bool calibrate=true)
Definition RH_SX126x.cpp:405
bool clearDeviceErrors()
Clear the radio error byte.
Definition RH_SX126x.cpp:859
virtual bool waitUntilNotBusy()
Definition RH_SX126x.cpp:544
virtual bool isChannelActive()
Definition RH_SX126x.cpp:518
bool setPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut)
Set the radio Power Amplifier configuration.
Definition RH_SX126x.cpp:729
void clearLastIrq()
REsets the last interrupt mask. For debugging.
Definition RH_SX126x.h:1029
ModemConfigChoice
Definition RH_SX126x.h:804
@ LoRa_Bw31_25Cr48Sf512
Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range.
Definition RH_SX126x.h:807
@ LoRa_Bw500Cr45Sf128
Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range.
Definition RH_SX126x.h:806
@ LoRa_Bw125Cr48Sf4096
Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, low data rate, CRC on. Slow+long range.
Definition RH_SX126x.h:808
@ LoRa_Bw125Cr45Sf128
Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range.
Definition RH_SX126x.h:805
@ LoRa_Bw125Cr45Sf2048
Bw = 125 kHz, Cr = 4/5, Sf = 2048chips/symbol, CRC on. Slow+long range.
Definition RH_SX126x.h:809
void setModeIdle()
Definition RH_SX126x.cpp:432
virtual bool available()
Definition RH_SX126x.cpp:309
bool readRegisters(uint16_t address, uint8_t data[], uint8_t len)
Read multiple registers from the radio.
Definition RH_SX126x.cpp:635
void handleInterrupt()
Definition RH_SX126x.cpp:200
bool setModemRegisters(const ModemConfig *config)
Definition RH_SX126x.cpp:476
uint16_t getIrqStatus()
Return the radio IRQ state.
Definition RH_SX126x.cpp:1176
bool setDIO3AsTcxoCtrl(uint8_t voltage, uint32_t delay)
Definition RH_SX126x.cpp:996
PacketType
Packet types the modem can be configured for.
Definition RH_SX126x.h:762
@ PacketTypeLoRa
Use LoRA packets.
Definition RH_SX126x.h:763
@ PacketTypeGFSK
Use GFSK packets.
Definition RH_SX126x.h:764
virtual bool setRadioPinsForMode(RadioPinConfigMode mode)
Definition RH_SX126x.cpp:1207
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:1064
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:1057
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:693
bool setOCPConfiguration(uint8_t setting)
Set the radio power amplifier over-current protection.
Definition RH_SX126x.cpp:991
bool setTx(uint32_t timeout)
Definition RH_SX126x.cpp:1071
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:1161
virtual bool setupInterruptHandler()
Do whatever is necesary to establish the interrupt handler. Subclasses may have different needs.
Definition RH_SX126x.cpp:141
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:577
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:621
uint8_t getPacketType()
return the current packet type
Definition RH_SX126x.cpp:1183
uint16_t lastIrq()
Return the last interrupt mask, for debugging.
Definition RH_SX126x.h:1020
bool clearIrqStatus(uint16_t mask)
Clear the radio IRQ state.
Definition RH_SX126x.cpp:1170
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:870
void enableRawMode(bool enable)
Tells the driver to enable RAW mode, which prevents the transmissions of the 4 byte address header.
Definition RH_SX126x.cpp:135
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:1195
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:1242
void validateRxBuf()
Examine the revceive buffer to determine whether the message is for this node.
Definition RH_SX126x.cpp:291
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:968
void setPreambleLength(uint16_t bytes)
Definition RH_SX126x.cpp:513
bool setTCXO(float voltage, uint32_t delay)
Set the voltage to use for the TCXO oven.
Definition RH_SX126x.cpp:1005
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:659
bool setTxContinuous()
Definition RH_SX126x.cpp:1099
void enableCrcErrorIrq(bool enable)
Enable or disable the ability to detect CRC errors.
Definition RH_SX126x.cpp:126
bool writeRegister(uint16_t address, uint8_t data)
Write a single byte to the given register.
Definition RH_SX126x.cpp:686
bool calibrate(uint8_t calib_param)
Cause the radio to calibrate all its sections at the currently selected frequency.
Definition RH_SX126x.cpp:974
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:979
bool setDIO2AsRfSwitchCtrl(bool value)
Definition RH_SX126x.cpp:865
virtual bool setTxPower(int8_t power)
Definition RH_SX126x.cpp:741
uint8_t getStatus()
Read and return the radio status byte.
Definition RH_SX126x.cpp:564
float getFrequencyError()
Returns the frequency error from the last received packet.
Definition RH_SX126x.cpp:1258
void clearRxBuf()
Clear our local receive buffer.
Definition RH_SX126x.cpp:322
bool setModemConfig(ModemConfigChoice index)
Definition RH_SX126x.cpp:502
Defines register values for a set of modem configuration registers.
Definition RH_SX126x.h:775
uint8_t p4
Value for setModulationParameters parameter 4.
Definition RH_SX126x.h:780
uint8_t p8
Value for setModulationParameters parameter 8.
Definition RH_SX126x.h:784
uint8_t p5
Value for setModulationParameters parameter 5.
Definition RH_SX126x.h:781
uint8_t p7
Value for setModulationParameters parameter 7.
Definition RH_SX126x.h:783
uint8_t p1
Value for setModulationParameters parameter 1.
Definition RH_SX126x.h:777
uint8_t p2
Value for setModulationParameters parameter 2.
Definition RH_SX126x.h:778
uint8_t p3
Value for setModulationParameters parameter 3.
Definition RH_SX126x.h:779
uint8_t p6
Value for setModulationParameters parameter 6.
Definition RH_SX126x.h:782
Definition RH_SX126x.h:834
Definition RH_SX126x.h:844