1#if !defined(_RADIOLIB_SX128X_H)
2#define _RADIOLIB_SX128X_H
4#include "../../TypeDef.h"
6#if !RADIOLIB_EXCLUDE_SX128X
8#include "../../Module.h"
10#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
13#define RADIOLIB_SX128X_FREQUENCY_STEP_SIZE 198.3642578
14#define RADIOLIB_SX128X_MAX_PACKET_LENGTH 255
15#define RADIOLIB_SX128X_CRYSTAL_FREQ 52.0f
16#define RADIOLIB_SX128X_DIV_EXPONENT 18
17#define RADIOLIB_SX128X_POUT_MIN -18
18#define RADIOLIB_SX128X_POUT_MAX 13
21#define RADIOLIB_SX128X_CMD_NOP 0x00
22#define RADIOLIB_SX128X_CMD_GET_STATUS 0xC0
23#define RADIOLIB_SX128X_CMD_WRITE_REGISTER 0x18
24#define RADIOLIB_SX128X_CMD_READ_REGISTER 0x19
25#define RADIOLIB_SX128X_CMD_WRITE_BUFFER 0x1A
26#define RADIOLIB_SX128X_CMD_READ_BUFFER 0x1B
27#define RADIOLIB_SX128X_CMD_SAVE_CONTEXT 0xD5
28#define RADIOLIB_SX128X_CMD_SET_SLEEP 0x84
29#define RADIOLIB_SX128X_CMD_SET_STANDBY 0x80
30#define RADIOLIB_SX128X_CMD_SET_FS 0xC1
31#define RADIOLIB_SX128X_CMD_SET_TX 0x83
32#define RADIOLIB_SX128X_CMD_SET_RX 0x82
33#define RADIOLIB_SX128X_CMD_SET_RX_DUTY_CYCLE 0x94
34#define RADIOLIB_SX128X_CMD_SET_CAD 0xC5
35#define RADIOLIB_SX128X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1
36#define RADIOLIB_SX128X_CMD_SET_TX_CONTINUOUS_PREAMBLE 0xD2
37#define RADIOLIB_SX128X_CMD_SET_PACKET_TYPE 0x8A
38#define RADIOLIB_SX128X_CMD_GET_PACKET_TYPE 0x03
39#define RADIOLIB_SX128X_CMD_SET_RF_FREQUENCY 0x86
40#define RADIOLIB_SX128X_CMD_SET_TX_PARAMS 0x8E
41#define RADIOLIB_SX128X_CMD_SET_CAD_PARAMS 0x88
42#define RADIOLIB_SX128X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F
43#define RADIOLIB_SX128X_CMD_SET_MODULATION_PARAMS 0x8B
44#define RADIOLIB_SX128X_CMD_SET_PACKET_PARAMS 0x8C
45#define RADIOLIB_SX128X_CMD_GET_RX_BUFFER_STATUS 0x17
46#define RADIOLIB_SX128X_CMD_GET_PACKET_STATUS 0x1D
47#define RADIOLIB_SX128X_CMD_GET_RSSI_INST 0x1F
48#define RADIOLIB_SX128X_CMD_SET_DIO_IRQ_PARAMS 0x8D
49#define RADIOLIB_SX128X_CMD_GET_IRQ_STATUS 0x15
50#define RADIOLIB_SX128X_CMD_CLEAR_IRQ_STATUS 0x97
51#define RADIOLIB_SX128X_CMD_SET_REGULATOR_MODE 0x96
52#define RADIOLIB_SX128X_CMD_SET_SAVE_CONTEXT 0xD5
53#define RADIOLIB_SX128X_CMD_SET_AUTO_TX 0x98
54#define RADIOLIB_SX128X_CMD_SET_AUTO_FS 0x9E
55#define RADIOLIB_SX128X_CMD_SET_PERF_COUNTER_MODE 0x9C
56#define RADIOLIB_SX128X_CMD_SET_LONG_PREAMBLE 0x9B
57#define RADIOLIB_SX128X_CMD_SET_UART_SPEED 0x9D
58#define RADIOLIB_SX128X_CMD_SET_RANGING_ROLE 0xA3
59#define RADIOLIB_SX128X_CMD_SET_ADVANCED_RANGING 0x9A
62#define RADIOLIB_SX128X_REG_VERSION_STRING 0x01F0
63#define RADIOLIB_SX128X_REG_GAIN_MODE 0x0891
64#define RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2 0x0895
65#define RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING 0x089E
66#define RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1 0x089F
67#define RADIOLIB_SX128X_REG_SYNCH_PEAK_ATTENUATION 0x08C2
68#define RADIOLIB_SX128X_REG_LORA_FIXED_PAYLOAD_LENGTH 0x0901
69#define RADIOLIB_SX128X_REG_LORA_HEADER_MODE 0x0903
70#define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_3 0x0912
71#define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_2 0x0913
72#define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_1 0x0914
73#define RADIOLIB_SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_0 0x0915
74#define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3 0x0916
75#define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_2 0x0917
76#define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_1 0x0918
77#define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_0 0x0919
78#define RADIOLIB_SX128X_REG_RANGING_FILTER_WINDOW_SIZE 0x091E
79#define RADIOLIB_SX128X_REG_RANGING_FILTER_RESET 0x0923
80#define RADIOLIB_SX128X_REG_RANGING_TYPE 0x0924
81#define RADIOLIB_SX128X_REG_LORA_SF_CONFIG 0x0925
82#define RADIOLIB_SX128X_REG_RANGING_ADDRESS_SWITCH 0x0927
83#define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_BYTE_2 0x092B
84#define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_MSB 0x092C
85#define RADIOLIB_SX128X_REG_RANGING_CALIBRATION_LSB 0x092D
86#define RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH 0x0931
87#define RADIOLIB_SX128X_REG_FREQ_ERROR_CORRECTION 0x093C
88#define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_MSB 0x0944
89#define RADIOLIB_SX128X_REG_LORA_SYNC_WORD_LSB 0x0945
90#define RADIOLIB_SX128X_REG_LORA_RX_CODING_RATE 0x0950
91#define RADIOLIB_SX128X_REG_RANGING_FILTER_RSSI_OFFSET 0x0953
92#define RADIOLIB_SX128X_REG_FEI_MSB 0x0954
93#define RADIOLIB_SX128X_REG_FEI_MID 0x0955
94#define RADIOLIB_SX128X_REG_FEI_LSB 0x0956
95#define RADIOLIB_SX128X_REG_RANGING_ADDRESS_MSB 0x095F
96#define RADIOLIB_SX128X_REG_RANGING_ADDRESS_LSB 0x0960
97#define RADIOLIB_SX128X_REG_RANGING_RESULT_MSB 0x0961
98#define RADIOLIB_SX128X_REG_RANGING_RESULT_MID 0x0962
99#define RADIOLIB_SX128X_REG_RANGING_RESULT_LSB 0x0963
100#define RADIOLIB_SX128X_REG_RANGING_RSSI 0x0964
101#define RADIOLIB_SX128X_REG_RANGING_LORA_CLOCK_ENABLE 0x097F
102#define RADIOLIB_SX128X_REG_PACKET_PREAMBLE_SETTINGS 0x09C1
103#define RADIOLIB_SX128X_REG_WHITENING_INITIAL_VALUE 0x09C5
104#define RADIOLIB_SX128X_REG_CRC_POLYNOMIAL_MSB 0x09C6
105#define RADIOLIB_SX128X_REG_CRC_POLYNOMIAL_LSB 0x09C7
106#define RADIOLIB_SX128X_REG_CRC_INITIAL_MSB 0x09C8
107#define RADIOLIB_SX128X_REG_CRC_INITIAL_LSB 0x09C9
108#define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_MSB 0x09C7
109#define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_MID (RADIOLIB_SX128X_REG_CRC_INITIAL_MSB)
110#define RADIOLIB_SX128X_REG_BLE_CRC_INITIAL_LSB (RADIOLIB_SX128X_REG_CRC_INITIAL_LSB)
111#define RADIOLIB_SX128X_REG_SYNCH_ADDRESS_CONTROL 0x09CD
112#define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_4 0x09CE
113#define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_3 0x09CF
114#define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_2 0x09D0
115#define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_1 0x09D1
116#define RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_0 0x09D2
117#define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_4 0x09D3
118#define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_3 0x09D4
119#define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_2 0x09D5
120#define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_1 0x09D6
121#define RADIOLIB_SX128X_REG_SYNC_WORD_2_BYTE_0 0x09D7
122#define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_4 0x09D8
123#define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_3 0x09D9
124#define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_2 0x09DA
125#define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_1 0x09DB
126#define RADIOLIB_SX128X_REG_SYNC_WORD_3_BYTE_0 0x09DC
127#define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_3 (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_3)
128#define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_2 (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_2)
129#define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_1 (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_1)
130#define RADIOLIB_SX128X_REG_ACCESS_ADDRESS_BYTE_0 (RADIOLIB_SX128X_REG_SYNC_WORD_1_BYTE_0)
134#define RADIOLIB_SX128X_STATUS_MODE_STDBY_RC 0b01000000
135#define RADIOLIB_SX128X_STATUS_MODE_STDBY_XOSC 0b01100000
136#define RADIOLIB_SX128X_STATUS_MODE_FS 0b10000000
137#define RADIOLIB_SX128X_STATUS_MODE_RX 0b10100000
138#define RADIOLIB_SX128X_STATUS_MODE_TX 0b11000000
139#define RADIOLIB_SX128X_STATUS_CMD_PROCESSED 0b00000100
140#define RADIOLIB_SX128X_STATUS_DATA_AVAILABLE 0b00001000
141#define RADIOLIB_SX128X_STATUS_CMD_TIMEOUT 0b00001100
142#define RADIOLIB_SX128X_STATUS_CMD_ERROR 0b00010000
143#define RADIOLIB_SX128X_STATUS_CMD_FAILED 0b00010100
144#define RADIOLIB_SX128X_STATUS_TX_DONE 0b00011000
145#define RADIOLIB_SX128X_STATUS_BUSY 0b00000001
146#define RADIOLIB_SX128X_STATUS_SPI_FAILED 0b11111111
149#define RADIOLIB_SX128X_SLEEP_DATA_BUFFER_FLUSH 0b00000000
150#define RADIOLIB_SX128X_SLEEP_DATA_BUFFER_RETAIN 0b00000010
151#define RADIOLIB_SX128X_SLEEP_DATA_RAM_FLUSH 0b00000000
152#define RADIOLIB_SX128X_SLEEP_DATA_RAM_RETAIN 0b00000001
155#define RADIOLIB_SX128X_STANDBY_RC 0x00
156#define RADIOLIB_SX128X_STANDBY_XOSC 0x01
159#define RADIOLIB_SX128X_PERIOD_BASE_15_625_US 0x00
160#define RADIOLIB_SX128X_PERIOD_BASE_62_5_US 0x01
161#define RADIOLIB_SX128X_PERIOD_BASE_1_MS 0x02
162#define RADIOLIB_SX128X_PERIOD_BASE_4_MS 0x03
165#define RADIOLIB_SX128X_TX_TIMEOUT_NONE 0x0000
168#define RADIOLIB_SX128X_RX_TIMEOUT_NONE 0x0000
169#define RADIOLIB_SX128X_RX_TIMEOUT_INF 0xFFFF
172#define RADIOLIB_SX128X_PACKET_TYPE_GFSK 0x00
173#define RADIOLIB_SX128X_PACKET_TYPE_LORA 0x01
174#define RADIOLIB_SX128X_PACKET_TYPE_RANGING 0x02
175#define RADIOLIB_SX128X_PACKET_TYPE_FLRC 0x03
176#define RADIOLIB_SX128X_PACKET_TYPE_BLE 0x04
179#define RADIOLIB_SX128X_PA_RAMP_02_US 0x00
180#define RADIOLIB_SX128X_PA_RAMP_04_US 0x20
181#define RADIOLIB_SX128X_PA_RAMP_06_US 0x40
182#define RADIOLIB_SX128X_PA_RAMP_08_US 0x60
183#define RADIOLIB_SX128X_PA_RAMP_10_US 0x80
184#define RADIOLIB_SX128X_PA_RAMP_12_US 0xA0
185#define RADIOLIB_SX128X_PA_RAMP_16_US 0xC0
186#define RADIOLIB_SX128X_PA_RAMP_20_US 0xE0
189#define RADIOLIB_SX128X_CAD_ON_1_SYMB 0x00
190#define RADIOLIB_SX128X_CAD_ON_2_SYMB 0x20
191#define RADIOLIB_SX128X_CAD_ON_4_SYMB 0x40
192#define RADIOLIB_SX128X_CAD_ON_8_SYMB 0x60
193#define RADIOLIB_SX128X_CAD_ON_16_SYMB 0x80
194#define RADIOLIB_SX128X_CAD_PARAM_DEFAULT RADIOLIB_SX128X_CAD_ON_8_SYMB
197#define RADIOLIB_SX128X_BLE_GFSK_BR_2_000_BW_2_4 0x04
198#define RADIOLIB_SX128X_BLE_GFSK_BR_1_600_BW_2_4 0x28
199#define RADIOLIB_SX128X_BLE_GFSK_BR_1_000_BW_2_4 0x4C
200#define RADIOLIB_SX128X_BLE_GFSK_BR_1_000_BW_1_2 0x45
201#define RADIOLIB_SX128X_BLE_GFSK_BR_0_800_BW_2_4 0x70
202#define RADIOLIB_SX128X_BLE_GFSK_BR_0_800_BW_1_2 0x69
203#define RADIOLIB_SX128X_BLE_GFSK_BR_0_500_BW_1_2 0x8D
204#define RADIOLIB_SX128X_BLE_GFSK_BR_0_500_BW_0_6 0x86
205#define RADIOLIB_SX128X_BLE_GFSK_BR_0_400_BW_1_2 0xB1
206#define RADIOLIB_SX128X_BLE_GFSK_BR_0_400_BW_0_6 0xAA
207#define RADIOLIB_SX128X_BLE_GFSK_BR_0_250_BW_0_6 0xCE
208#define RADIOLIB_SX128X_BLE_GFSK_BR_0_250_BW_0_3 0xC7
209#define RADIOLIB_SX128X_BLE_GFSK_BR_0_125_BW_0_3 0xEF
210#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_35 0x00
211#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_50 0x01
212#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_0_75 0x02
213#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_00 0x03
214#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_25 0x04
215#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_50 0x05
216#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_1_75 0x06
217#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_00 0x07
218#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_25 0x08
219#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_50 0x09
220#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_2_75 0x0A
221#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_00 0x0B
222#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_25 0x0C
223#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_50 0x0D
224#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_3_75 0x0E
225#define RADIOLIB_SX128X_BLE_GFSK_MOD_IND_4_00 0x0F
226#define RADIOLIB_SX128X_BLE_GFSK_BT_OFF 0x00
227#define RADIOLIB_SX128X_BLE_GFSK_BT_1_0 0x10
228#define RADIOLIB_SX128X_BLE_GFSK_BT_0_5 0x20
229#define RADIOLIB_SX128X_FLRC_BR_1_300_BW_1_2 0x45
230#define RADIOLIB_SX128X_FLRC_BR_1_000_BW_1_2 0x69
231#define RADIOLIB_SX128X_FLRC_BR_0_650_BW_0_6 0x86
232#define RADIOLIB_SX128X_FLRC_BR_0_520_BW_0_6 0xAA
233#define RADIOLIB_SX128X_FLRC_BR_0_325_BW_0_3 0xC7
234#define RADIOLIB_SX128X_FLRC_BR_0_260_BW_0_3 0xEB
235#define RADIOLIB_SX128X_FLRC_CR_1_2 0x00
236#define RADIOLIB_SX128X_FLRC_CR_3_4 0x02
237#define RADIOLIB_SX128X_FLRC_CR_1_0 0x04
238#define RADIOLIB_SX128X_FLRC_BT_OFF 0x00
239#define RADIOLIB_SX128X_FLRC_BT_1_0 0x10
240#define RADIOLIB_SX128X_FLRC_BT_0_5 0x20
241#define RADIOLIB_SX128X_LORA_SF_5 0x50
242#define RADIOLIB_SX128X_LORA_SF_6 0x60
243#define RADIOLIB_SX128X_LORA_SF_7 0x70
244#define RADIOLIB_SX128X_LORA_SF_8 0x80
245#define RADIOLIB_SX128X_LORA_SF_9 0x90
246#define RADIOLIB_SX128X_LORA_SF_10 0xA0
247#define RADIOLIB_SX128X_LORA_SF_11 0xB0
248#define RADIOLIB_SX128X_LORA_SF_12 0xC0
249#define RADIOLIB_SX128X_LORA_BW_1625_00 0x0A
250#define RADIOLIB_SX128X_LORA_BW_812_50 0x18
251#define RADIOLIB_SX128X_LORA_BW_406_25 0x26
252#define RADIOLIB_SX128X_LORA_BW_203_125 0x34
253#define RADIOLIB_SX128X_LORA_CR_4_5 0x01
254#define RADIOLIB_SX128X_LORA_CR_4_6 0x02
255#define RADIOLIB_SX128X_LORA_CR_4_7 0x03
256#define RADIOLIB_SX128X_LORA_CR_4_8 0x04
257#define RADIOLIB_SX128X_LORA_CR_4_5_LI 0x05
258#define RADIOLIB_SX128X_LORA_CR_4_6_LI 0x06
259#define RADIOLIB_SX128X_LORA_CR_4_8_LI 0x07
262#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_OFF 0x00
263#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1 0x10
264#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_2 0x20
265#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_2 0x30
266#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_3 0x40
267#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_3 0x50
268#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_2_3 0x60
269#define RADIOLIB_SX128X_GFSK_FLRC_SYNC_WORD_1_2_3 0x70
270#define RADIOLIB_SX128X_GFSK_FLRC_PACKET_FIXED 0x00
271#define RADIOLIB_SX128X_GFSK_FLRC_PACKET_VARIABLE 0x20
272#define RADIOLIB_SX128X_GFSK_FLRC_CRC_OFF 0x00
273#define RADIOLIB_SX128X_GFSK_FLRC_CRC_1_BYTE 0x10
274#define RADIOLIB_SX128X_GFSK_FLRC_CRC_2_BYTE 0x20
275#define RADIOLIB_SX128X_GFSK_FLRC_CRC_3_BYTE 0x30
276#define RADIOLIB_SX128X_GFSK_BLE_WHITENING_ON 0x00
277#define RADIOLIB_SX128X_GFSK_BLE_WHITENING_OFF 0x08
278#define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_31 0x00
279#define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_37 0x20
280#define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_TEST 0x40
281#define RADIOLIB_SX128X_BLE_PAYLOAD_LENGTH_MAX_255 0x80
282#define RADIOLIB_SX128X_BLE_CRC_OFF 0x00
283#define RADIOLIB_SX128X_BLE_CRC_3_BYTE 0x10
284#define RADIOLIB_SX128X_BLE_PRBS_9 0x00
285#define RADIOLIB_SX128X_BLE_EYELONG 0x04
286#define RADIOLIB_SX128X_BLE_EYESHORT 0x08
287#define RADIOLIB_SX128X_BLE_PRBS_15 0x0C
288#define RADIOLIB_SX128X_BLE_ALL_1 0x10
289#define RADIOLIB_SX128X_BLE_ALL_0 0x14
290#define RADIOLIB_SX128X_BLE_EYELONG_INV 0x18
291#define RADIOLIB_SX128X_BLE_EYESHORT_INV 0x1C
292#define RADIOLIB_SX128X_FLRC_SYNC_WORD_OFF 0x00
293#define RADIOLIB_SX128X_FLRC_SYNC_WORD_ON 0x04
294#define RADIOLIB_SX128X_LORA_HEADER_EXPLICIT 0x00
295#define RADIOLIB_SX128X_LORA_HEADER_IMPLICIT 0x80
296#define RADIOLIB_SX128X_LORA_CRC_OFF 0x00
297#define RADIOLIB_SX128X_LORA_CRC_ON 0x20
298#define RADIOLIB_SX128X_LORA_IQ_STANDARD 0x40
299#define RADIOLIB_SX128X_LORA_IQ_INVERTED 0x00
302#define RADIOLIB_SX128X_PACKET_STATUS_SYNC_ERROR 0b01000000
303#define RADIOLIB_SX128X_PACKET_STATUS_LENGTH_ERROR 0b00100000
304#define RADIOLIB_SX128X_PACKET_STATUS_CRC_ERROR 0b00010000
305#define RADIOLIB_SX128X_PACKET_STATUS_ABORT_ERROR 0b00001000
306#define RADIOLIB_SX128X_PACKET_STATUS_HEADER_RECEIVED 0b00000100
307#define RADIOLIB_SX128X_PACKET_STATUS_PACKET_RECEIVED 0b00000010
308#define RADIOLIB_SX128X_PACKET_STATUS_PACKET_CTRL_BUSY 0b00000001
309#define RADIOLIB_SX128X_PACKET_STATUS_RX_PID 0b11000000
310#define RADIOLIB_SX128X_PACKET_STATUS_NO_ACK 0b00100000
311#define RADIOLIB_SX128X_PACKET_STATUS_RX_PID_ERROR 0b00010000
312#define RADIOLIB_SX128X_PACKET_STATUS_PACKET_SENT 0b00000001
313#define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_ERROR 0b00000000
314#define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_1 0b00000001
315#define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_2 0b00000010
316#define RADIOLIB_SX128X_PACKET_STATUS_SYNC_DET_3 0b00000100
319#define RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED 0x8000
320#define RADIOLIB_SX128X_IRQ_ADVANCED_RANGING_DONE 0x8000
321#define RADIOLIB_SX128X_IRQ_RX_TX_TIMEOUT 0x4000
322#define RADIOLIB_SX128X_IRQ_CAD_DETECTED 0x2000
323#define RADIOLIB_SX128X_IRQ_CAD_DONE 0x1000
324#define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_REQ_VALID 0x0800
325#define RADIOLIB_SX128X_IRQ_RANGING_MASTER_TIMEOUT 0x0400
326#define RADIOLIB_SX128X_IRQ_RANGING_MASTER_RES_VALID 0x0200
327#define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_REQ_DISCARD 0x0100
328#define RADIOLIB_SX128X_IRQ_RANGING_SLAVE_RESP_DONE 0x0080
329#define RADIOLIB_SX128X_IRQ_CRC_ERROR 0x0040
330#define RADIOLIB_SX128X_IRQ_HEADER_ERROR 0x0020
331#define RADIOLIB_SX128X_IRQ_HEADER_VALID 0x0010
332#define RADIOLIB_SX128X_IRQ_SYNC_WORD_ERROR 0x0008
333#define RADIOLIB_SX128X_IRQ_SYNC_WORD_VALID 0x0004
334#define RADIOLIB_SX128X_IRQ_RX_DONE 0x0002
335#define RADIOLIB_SX128X_IRQ_TX_DONE 0x0001
336#define RADIOLIB_SX128X_IRQ_NONE 0x0000
337#define RADIOLIB_SX128X_IRQ_ALL 0xFFFF
340#define RADIOLIB_SX128X_REGULATOR_LDO 0x00
341#define RADIOLIB_SX128X_REGULATOR_DC_DC 0x01
344#define RADIOLIB_SX128X_RANGING_ROLE_MASTER 0x01
345#define RADIOLIB_SX128X_RANGING_ROLE_SLAVE 0x00
348#define RADIOLIB_SX128X_SYNC_WORD_PRIVATE 0x12
414 int16_t
reset(
bool verify =
true);
424 int16_t
transmit(
const uint8_t* data,
size_t len, uint8_t addr = 0)
override;
469 int16_t
sleep()
override;
477 int16_t
sleep(
bool retainConfig);
492 int16_t
standby(uint8_t mode)
override;
501 int16_t
standby(uint8_t mode,
bool wakeup);
538 int16_t
readData(uint8_t* data,
size_t len)
override;
618 int16_t
setCodingRate(uint8_t cr,
bool longInterleaving =
false)
override;
635 int16_t
setModem(ModemType_t modem)
override;
642 int16_t
getModem(ModemType_t* modem)
override;
645 int16_t
getMode(RadioModeType_t* mode)
override;
694 int16_t
setSyncWord(uint8_t* sync,
size_t len)
override;
702 int16_t
setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44);
711 int16_t
setCRC(uint8_t len, uint32_t initial = 0x1D0F, uint16_t polynomial = 0x1021);
872 int16_t
invertIQ(
bool enable)
override;
881 int16_t
writeTxBuffer(
const uint8_t* data,
size_t len)
override;
886 #if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
897 void readBit(uint32_t pin)
override;
900#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
903 const char* chipType = NULL;
905 Module* getMod()
override;
906 int16_t modSetup(uint8_t modem);
909 uint32_t bandwidthHz = 0;
910 uint8_t bandwidth = 0, spreadingFactor = 0, codingRateLoRa = 0;
911 uint8_t preambleLengthLoRa = 0, headerType = 0, payloadLen = 0, crcLoRa = 0;
915 int16_t writeRegister(uint16_t addr,
const uint8_t* data, uint8_t numBytes);
916 int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
917 int16_t writeBuffer(
const uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
918 int16_t readBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
919 int16_t setTx(uint16_t periodBaseCount = RADIOLIB_SX128X_TX_TIMEOUT_NONE, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_4_MS);
920 int16_t setRx(uint16_t periodBaseCount, uint8_t periodBase = RADIOLIB_SX128X_PERIOD_BASE_4_MS);
921 int16_t setCad(uint8_t symbolNum);
922 uint8_t getPacketType();
923 int16_t setRfFrequency(uint32_t frf);
924 int16_t setTxParams(uint8_t pwr, uint8_t rampTime = RADIOLIB_SX128X_PA_RAMP_10_US);
925 int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);
926 int16_t setModulationParams(uint8_t modParam1, uint8_t modParam2, uint8_t modParam3);
927 int16_t setPacketParamsGFSK(uint8_t preambleLen, uint8_t syncLen, uint8_t syncMatch, uint8_t crcLen, uint8_t whiten, uint8_t hdrType, uint8_t payLen = 0xFF);
928 int16_t setPacketParamsBLE(uint8_t connState, uint8_t crcLen, uint8_t bleTest, uint8_t whiten);
929 int16_t setPacketParamsLoRa(uint8_t preambleLen, uint8_t hdrType, uint8_t payLen, uint8_t crc, uint8_t invIQ = RADIOLIB_SX128X_LORA_IQ_STANDARD);
930 int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX128X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX128X_IRQ_NONE);
931 int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX128X_IRQ_ALL);
932 int16_t setRangingRole(uint8_t role);
933 int16_t setPacketType(uint8_t type);
936 int16_t config(uint8_t modem);
944 static int16_t SPIparseStatus(uint8_t in);
948 uint32_t rxTimeout = 0;
949 bool standbyXOSC =
false;
952 uint8_t invertIQEnabled = RADIOLIB_SX128X_LORA_IQ_STANDARD;
955 float modIndexReal = 0;
956 uint32_t frequencyDev = 0;
957 uint32_t bitRateBps = 0;
958 uint8_t bitRate = 0, modIndex = 0, shaping = 0;
959 uint8_t preambleLengthGFSK = 0, syncWordLen = 0, syncWordMatch = 0, crcGFSK = 0, whitening = 0;
960 uint8_t packetType = RADIOLIB_SX128X_GFSK_FLRC_PACKET_VARIABLE;
963 uint8_t codingRateFLRC = 0;
966 uint8_t connectionState = 0, crcBLE = 0, bleTestPayload = 0;
968 bool findChip(
const char* verStr);
969 int16_t setPacketMode(uint8_t mode, uint8_t len);
970 int16_t setHeaderType(uint8_t hdrType,
size_t len = 0xFF);
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition Module.h:74
static const size_t RFSWITCH_MAX_PINS
The maximum number of pins supported by the RF switch code. Note: It is not recommended to use this c...
Definition Module.h:83
virtual int16_t startReceive()
Sets module to received mode using its default configuration.
Definition PhysicalLayer.cpp:131
virtual int16_t readData(uint8_t *data, size_t len)
Reads data that was received after calling startReceive method.
Definition PhysicalLayer.cpp:235
int16_t transmit(const char *str, uint8_t addr=0)
C-string transmit method.
Definition PhysicalLayer.cpp:53
int16_t startTransmit(const char *str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition PhysicalLayer.cpp:157
virtual int16_t receive(uint8_t *data, size_t len, RadioLibTime_t timeout=0)
Binary receive method. Must be implemented in module class.
Definition PhysicalLayer.cpp:111
PhysicalLayer()
Default constructor.
Definition PhysicalLayer.cpp:5
int16_t begin(const ConfigLoRa_t &config)
Initialization method for LoRa modem.
Definition SX128x.cpp:25
void setDio1Action(void(*func)(void))
Sets interrupt service routine to call when DIO1 activates.
Definition SX128x.cpp:415
RadioLibTime_t calculateRxTimeout(RadioLibTime_t timeoutUs) override
Calculate the timeout value for this specific module / series (in number of symbols or units of time)...
Definition SX128x.cpp:1355
int16_t setFrequency(uint32_t freq) override
Sets carrier frequency. Allowed values are in range from 2400 to 2500 MHz.
Definition SX128x.cpp:549
int16_t beginBLE(const ConfigBLE_t &config)
Initialization method for BLE modem.
Definition SX128x.cpp:111
int16_t setFrequencyDeviation(uint32_t freqDev) override
Sets FSK frequency deviation. Allowed values range from 0 to 3200 kHz.
Definition SX128x.cpp:895
int16_t checkDataRate(DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE) override
Check the data rate can be configured by this module.
Definition SX128x.cpp:796
int16_t setOutputPower(int8_t power) override
Sets output power. Allowed values are in range from -18 to 13 dBm. When using an external PA,...
Definition SX128x.cpp:676
int16_t setModem(ModemType_t modem) override
Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default p...
Definition SX128x.cpp:686
void setDirectAction(void(*func)(void)) override
Dummy method, to ensure PhysicalLayer compatibility.
Definition SX128x.cpp:1562
float getRSSI() override
Gets RSSI (Received Signal Strength Indicator) of the last received packet.
Definition SX128x.cpp:1156
int16_t reset(bool verify=true)
Reset method. Will reset the chip to the default state using RST pin.
Definition SX128x.cpp:187
int16_t standby() override
Sets the module to standby mode (overload for PhysicalLayer compatibility). Uses 13 MHz RC oscillator...
Definition SX128x.cpp:393
int32_t getFrequencyError()
Gets frequency error of the latest received packet.
Definition SX128x.cpp:1211
int16_t scanChannel() override
Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.
Definition SX128x.cpp:341
int16_t fixedPacketLengthMode(uint8_t len=RADIOLIB_SX128X_MAX_PACKET_LENGTH)
Set modem in fixed packet length mode. Available in GFSK and FLRC modes only.
Definition SX128x.cpp:1277
int16_t setGainControl(uint8_t gain=0)
Enables or disables receiver manual gain control.
Definition SX128x.cpp:1120
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition SX128x.cpp:1243
int16_t transmit(const uint8_t *data, size_t len, uint8_t addr=0) override
Blocking binary transmit method. Overloads for string-based transmissions are implemented in Physical...
Definition SX128x.cpp:222
int16_t invertIQ(bool enable) override
Enable/disable inversion of the I and Q signals.
Definition SX128x.cpp:1397
RadioLibTime_t calculateTimeOnAir(ModemType_t modem, DataRate_t dr, PacketConfig_t pc, size_t len) override
Calculate the expected time-on-air for a given modem, data rate, packet configuration and payload siz...
Definition SX128x.cpp:1285
int16_t receive(uint8_t *data, size_t len, RadioLibTime_t timeout=0) override
Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalL...
Definition SX128x.cpp:264
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition SX128x.cpp:318
void setRfSwitchPins(uint32_t rxEn, uint32_t txEn)
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition SX128x.cpp:1374
int16_t variablePacketLengthMode(uint8_t maxLen=RADIOLIB_SX128X_MAX_PACKET_LENGTH)
Set modem in variable packet length mode. Available in GFSK and FLRC modes only.
Definition SX128x.cpp:1281
int16_t finishReceive() override
Clean up after reception is done.
Definition SX128x.cpp:466
int16_t stageMode(RadioModeType_t mode, RadioModeConfig_t *cfg) override
Stage mode of the radio to be launched later using launchMode.
Definition SX128x.cpp:1411
int16_t setIrqFlags(uint32_t irq) override
Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).
Definition SX128x.cpp:479
int16_t setSpreadingFactor(uint8_t sf) override
Sets LoRa spreading factor. Allowed values range from 5 to 12.
Definition SX128x.cpp:592
int16_t setPreambleLength(size_t len, size_t detLen=0xFFFFFFFF) override
Sets preamble length for currently active modem. Allowed values range from 1 to 65535.
Definition SX128x.cpp:745
int16_t setHighSensitivityMode(bool enable)
Enables or disables receiver high sensitivity mode.
Definition SX128x.cpp:1103
int16_t setSyncWord(uint8_t *sync, size_t len) override
Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem,...
Definition SX128x.cpp:955
int16_t setBandwidth(uint32_t bw) override
Sets LoRa bandwidth. Allowed values are 203125, 406250, 812500 and 1625000 Hz.
Definition SX128x.cpp:557
int16_t startReceive() override
Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalL...
Definition SX128x.cpp:423
int16_t setEncoding(uint8_t encoding) override
Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility.
Definition SX128x.cpp:1370
int16_t setWhitening(bool enabled)
Sets whitening parameters, not available for LoRa or FLRC modem.
Definition SX128x.cpp:1072
uint8_t randomByte() override
Dummy random method, to ensure PhysicalLayer compatibility.
Definition SX128x.cpp:1391
int16_t setAccessAddress(uint32_t addr)
Sets BLE access address.
Definition SX128x.cpp:1092
int16_t getLoRaRxHeaderInfo(uint8_t *cr, bool *hasCRC)
Get LoRa header information from last received packet. Only valid in explicit header mode.
Definition SX128x.cpp:1263
int16_t startChannelScan() override
Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is dete...
Definition SX128x.cpp:487
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition SX128x.cpp:1366
int16_t readData(uint8_t *data, size_t len) override
Reads data received after calling startReceive method. When the packet length is not known in advance...
Definition SX128x.cpp:427
int16_t setStandbyXOSC(bool enable)
Set standby mode to be used. XOSC standby uses more power, but allows faster switching between Rx and...
Definition SX128x.cpp:1382
int16_t setDataShaping(uint8_t sh) override
Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPI...
Definition SX128x.cpp:925
SX128x(Module *mod)
Default constructor.
Definition SX128x.cpp:6
uint32_t getIrqFlags() override
Read currently active IRQ flags.
Definition SX128x.cpp:475
int16_t setCRC(uint8_t len, uint32_t initial=0x1D0F, uint16_t polynomial=0x1021)
Sets CRC configuration.
Definition SX128x.cpp:1008
int16_t getMode(RadioModeType_t *mode) override
Read the operating mode the radio is in, as the chip reports it. Unlike PhysicalLayer::stagedMode,...
Definition SX128x.cpp:716
int16_t setCodingRate(uint8_t cr, bool longInterleaving=false) override
Sets LoRa coding rate denominator. Allowed values range from 4 to 8. Note that a value of 4 means no ...
Definition SX128x.cpp:635
int16_t writeTxBuffer(const uint8_t *data, size_t len) override
Write a payload into the transmit buffer without staging or starting a transmission....
Definition SX128x.cpp:1511
int16_t sleep() override
Sets the module to sleep mode. To wake the device up, call standby(). Overload for PhysicalLayer comp...
Definition SX128x.cpp:371
int16_t beginFLRC(const ConfigFLRC_t &config)
Initialization method for FLRC modem.
Definition SX128x.cpp:144
void clearDio1Action()
Clears interrupt service routine to call when DIO1 activates.
Definition SX128x.cpp:419
int16_t getChannelScanResult() override
Read the channel scan result.
Definition SX128x.cpp:528
int16_t clearTxBuffer() override
Discard a payload previously written by writeTxBuffer. On radios whose transmit buffer is simply over...
Definition SX128x.cpp:1528
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission.
Definition SX128x.cpp:1362
int16_t launchMode() override
Launch previously staged mode.
Definition SX128x.cpp:1533
void setRfSwitchTable(const uint32_t(&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[])
Some modules contain external RF switch controlled by pins. This function gives RadioLib control over...
Definition SX128x.cpp:1378
int16_t getModem(ModemType_t *modem) override
Get modem currently in use by the radio.
Definition SX128x.cpp:701
float getSNR() override
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging mode...
Definition SX128x.cpp:1191
uint16_t getIrqStatus()
Reads the current IRQ status.
Definition SX128x.cpp:1721
RadioLibTime_t getTimeOnAir(size_t len) override
Get expected time-on-air for a given size of payload.
Definition SX128x.cpp:1307
int16_t beginGFSK(const ConfigFSK_t &config)
Initialization method for GFSK modem.
Definition SX128x.cpp:64
void readBit(uint32_t pin) override
Dummy method, to ensure PhysicalLayer compatibility.
Definition SX128x.cpp:1568
int16_t setBitRate(uint32_t br) override
Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for ...
Definition SX128x.cpp:822
int16_t clearIrqFlags(uint32_t irq) override
Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).
Definition SX128x.cpp:483
int16_t receiveDirect() override
Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does...
Definition SX128x.cpp:333
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:783
Definition PhysicalLayer.h:375
Definition PhysicalLayer.h:360
Definition PhysicalLayer.h:310
Definition PhysicalLayer.h:292
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition Module.h:90
Common channel scan configuration structure.
Definition PhysicalLayer.h:168
Common data rate structure.
Definition PhysicalLayer.h:74
Common packet configuration structure.
Definition PhysicalLayer.h:119
Definition PhysicalLayer.h:214