acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
SX126x.h (52597B)
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 72 // SX126X register map 73 #define RADIOLIB_SX126X_REG_HOPPING_ENABLE 0x0385 74 #define RADIOLIB_SX126X_REG_LR_FHSS_PACKET_LENGTH 0x0386 75 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_HOPPING_BLOCKS 0x0387 76 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_MSB(X) (0x0388 + (X)*6) 77 #define RADIOLIB_SX126X_REG_LR_FHSS_NUM_SYMBOLS_FREQX_LSB(X) (0x0389 + (X)*6) 78 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_0(X) (0x038A + (X)*6) 79 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_1(X) (0x038B + (X)*6) 80 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_2(X) (0x038C + (X)*6) 81 #define RADIOLIB_SX126X_REG_LR_FHSS_FREQX_3(X) (0x038D + (X)*6) 82 #define RADIOLIB_SX126X_REG_DIOX_OUT_ENABLE 0x0580 83 #define RADIOLIB_SX126X_REG_DIOX_IN_ENABLE 0x0583 84 #define RADIOLIB_SX126X_REG_DIOX_PULL_UP_CTRL 0x0584 85 #define RADIOLIB_SX126X_REG_DIOX_PULL_DOWN_CTRL 0x0585 86 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB 0x06B8 87 #define RADIOLIB_SX126X_REG_WHITENING_INITIAL_LSB 0x06B9 88 #define RADIOLIB_SX126X_REG_CRC_INITIAL_MSB 0x06BC 89 #define RADIOLIB_SX126X_REG_CRC_INITIAL_LSB 0x06BD 90 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE 91 #define RADIOLIB_SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF 92 #define RADIOLIB_SX126X_REG_SYNC_WORD_0 0x06C0 93 #define RADIOLIB_SX126X_REG_SYNC_WORD_1 0x06C1 94 #define RADIOLIB_SX126X_REG_SYNC_WORD_2 0x06C2 95 #define RADIOLIB_SX126X_REG_SYNC_WORD_3 0x06C3 96 #define RADIOLIB_SX126X_REG_SYNC_WORD_4 0x06C4 97 #define RADIOLIB_SX126X_REG_SYNC_WORD_5 0x06C5 98 #define RADIOLIB_SX126X_REG_SYNC_WORD_6 0x06C6 99 #define RADIOLIB_SX126X_REG_SYNC_WORD_7 0x06C7 100 #define RADIOLIB_SX126X_REG_NODE_ADDRESS 0x06CD 101 #define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE 102 #define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736 103 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740 104 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741 105 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_0 0x0819 106 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_1 0x081A 107 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_2 0x081B 108 #define RADIOLIB_SX126X_REG_RANDOM_NUMBER_3 0x081C 109 #define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC 110 #define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8 111 #define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7 112 #define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902 113 #define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911 114 #define RADIOLIB_SX126X_REG_XTB_TRIM 0x0912 115 #define RADIOLIB_SX126X_REG_DIO3_OUT_VOLTAGE_CTRL 0x0920 116 #define RADIOLIB_SX126X_REG_EVENT_MASK 0x0944 117 118 // undocumented registers 119 #define RADIOLIB_SX126X_REG_SENSITIVITY_CONFIG 0x0889 // SX1268 datasheet v1.1, section 15.1 120 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_0 0x029F // SX1268 datasheet v1.1, section 9.6 121 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_1 0x02A0 // SX1268 datasheet v1.1, section 9.6 122 #define RADIOLIB_SX126X_REG_RX_GAIN_RETENTION_2 0x02A1 // SX1268 datasheet v1.1, section 9.6 123 124 125 // SX126X SPI command variables 126 //RADIOLIB_SX126X_CMD_SET_SLEEP MSB LSB DESCRIPTION 127 #define RADIOLIB_SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default) 128 #define RADIOLIB_SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained 129 #define RADIOLIB_SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled 130 #define RADIOLIB_SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled 131 132 //RADIOLIB_SX126X_CMD_SET_STANDBY 133 #define RADIOLIB_SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator 134 #define RADIOLIB_SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator 135 136 //RADIOLIB_SX126X_CMD_SET_RX 137 #define RADIOLIB_SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode) 138 #define RADIOLIB_SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode) 139 140 //RADIOLIB_SX126X_CMD_SET_TX 141 #define RADIOLIB_SX126X_TX_TIMEOUT_NONE 0x000000 // 23 0 Tx timeout duration: no timeout (Tx single mode) 142 143 //RADIOLIB_SX126X_CMD_STOP_TIMER_ON_PREAMBLE 144 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default) 145 #define RADIOLIB_SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection 146 147 //RADIOLIB_SX126X_CMD_SET_REGULATOR_MODE 148 #define RADIOLIB_SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) 149 #define RADIOLIB_SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC 150 151 //RADIOLIB_SX126X_CMD_CALIBRATE 152 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled 153 #define RADIOLIB_SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled 154 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled 155 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled 156 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled 157 #define RADIOLIB_SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled 158 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled 159 #define RADIOLIB_SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled 160 #define RADIOLIB_SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled 161 #define RADIOLIB_SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled 162 #define RADIOLIB_SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled 163 #define RADIOLIB_SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled 164 #define RADIOLIB_SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled 165 #define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled 166 #define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks 167 168 //RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE 169 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B 170 #define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F 171 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75 172 #define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81 173 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1 174 #define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5 175 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7 176 #define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB 177 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1 178 #define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9 179 180 //RADIOLIB_SX126X_CMD_SET_PA_CONFIG 181 #define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07 182 #define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01 183 #define RADIOLIB_SX126X_PA_CONFIG_SX1262_8 0x00 184 185 //RADIOLIB_SX126X_CMD_SET_RX_TX_FALLBACK_MODE 186 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode 187 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator 188 #define RADIOLIB_SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default) 189 190 //RADIOLIB_SX126X_CMD_SET_DIO_IRQ_PARAMS 191 #define RADIOLIB_SX126X_IRQ_LR_FHSS_HOP 0b0100000000000000 // 14 14 PA ramped up during LR-FHSS hop 192 #define RADIOLIB_SX126X_IRQ_TIMEOUT 0b0000001000000000 // 9 9 Rx or Tx timeout 193 #define RADIOLIB_SX126X_IRQ_CAD_DETECTED 0b0000000100000000 // 8 8 channel activity detected 194 #define RADIOLIB_SX126X_IRQ_CAD_DONE 0b0000000010000000 // 7 7 channel activity detection finished 195 #define RADIOLIB_SX126X_IRQ_CRC_ERR 0b0000000001000000 // 6 6 wrong CRC received 196 #define RADIOLIB_SX126X_IRQ_HEADER_ERR 0b0000000000100000 // 5 5 LoRa header CRC error 197 #define RADIOLIB_SX126X_IRQ_HEADER_VALID 0b0000000000010000 // 4 4 valid LoRa header received 198 #define RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID 0b0000000000001000 // 3 3 valid sync word detected 199 #define RADIOLIB_SX126X_IRQ_RADIOLIB_PREAMBLE_DETECTED 0b0000000000000100 // 2 2 preamble detected 200 #define RADIOLIB_SX126X_IRQ_RX_DONE 0b0000000000000010 // 1 1 packet received 201 #define RADIOLIB_SX126X_IRQ_TX_DONE 0b0000000000000001 // 0 0 packet transmission completed 202 #define RADIOLIB_SX126X_IRQ_ALL 0b0100001111111111 // 14 0 all interrupts 203 #define RADIOLIB_SX126X_IRQ_NONE 0b0000000000000000 // 14 0 no interrupts 204 205 //RADIOLIB_SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 206 #define RADIOLIB_SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ 207 #define RADIOLIB_SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control 208 209 //RADIOLIB_SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 210 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V 211 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V 212 #define RADIOLIB_SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V 213 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V 214 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V 215 #define RADIOLIB_SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V 216 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V 217 #define RADIOLIB_SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V 218 219 //RADIOLIB_SX126X_CMD_SET_PACKET_TYPE 220 #define RADIOLIB_SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK 221 #define RADIOLIB_SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa 222 #define RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS 0x03 // 7 0 LR-FHSS 223 224 //RADIOLIB_SX126X_CMD_SET_TX_PARAMS 225 #define RADIOLIB_SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us 226 #define RADIOLIB_SX126X_PA_RAMP_20U 0x01 // 7 0 20 us 227 #define RADIOLIB_SX126X_PA_RAMP_40U 0x02 // 7 0 40 us 228 #define RADIOLIB_SX126X_PA_RAMP_80U 0x03 // 7 0 80 us 229 #define RADIOLIB_SX126X_PA_RAMP_200U 0x04 // 7 0 200 us 230 #define RADIOLIB_SX126X_PA_RAMP_800U 0x05 // 7 0 800 us 231 #define RADIOLIB_SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us 232 #define RADIOLIB_SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us 233 234 //RADIOLIB_SX126X_CMD_SET_MODULATION_PARAMS 235 #define RADIOLIB_SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none 236 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3 237 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5 238 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7 239 #define RADIOLIB_SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1 240 #define RADIOLIB_SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz 241 #define RADIOLIB_SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz 242 #define RADIOLIB_SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz 243 #define RADIOLIB_SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz 244 #define RADIOLIB_SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz 245 #define RADIOLIB_SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz 246 #define RADIOLIB_SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz 247 #define RADIOLIB_SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz 248 #define RADIOLIB_SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz 249 #define RADIOLIB_SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz 250 #define RADIOLIB_SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz 251 #define RADIOLIB_SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz 252 #define RADIOLIB_SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz 253 #define RADIOLIB_SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz 254 #define RADIOLIB_SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz 255 #define RADIOLIB_SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz 256 #define RADIOLIB_SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz 257 #define RADIOLIB_SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz 258 #define RADIOLIB_SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz 259 #define RADIOLIB_SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz 260 #define RADIOLIB_SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz 261 #define RADIOLIB_SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz 262 #define RADIOLIB_SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz 263 #define RADIOLIB_SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz 264 #define RADIOLIB_SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz 265 #define RADIOLIB_SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz 266 #define RADIOLIB_SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz 267 #define RADIOLIB_SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz 268 #define RADIOLIB_SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz 269 #define RADIOLIB_SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz 270 #define RADIOLIB_SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz 271 #define RADIOLIB_SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5 272 #define RADIOLIB_SX126X_LORA_CR_4_6 0x02 // 7 0 4/6 273 #define RADIOLIB_SX126X_LORA_CR_4_7 0x03 // 7 0 4/7 274 #define RADIOLIB_SX126X_LORA_CR_4_8 0x04 // 7 0 4/8 275 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled 276 #define RADIOLIB_SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled 277 278 //RADIOLIB_SX126X_CMD_SET_PACKET_PARAMS 279 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled 280 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits 281 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits 282 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits 283 #define RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits 284 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled 285 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only 286 #define RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast 287 #define RADIOLIB_SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides) 288 #define RADIOLIB_SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet) 289 #define RADIOLIB_SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled 290 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte 291 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte 292 #define RADIOLIB_SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted 293 #define RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted 294 #define RADIOLIB_SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled 295 #define RADIOLIB_SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled 296 #define RADIOLIB_SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit 297 #define RADIOLIB_SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit 298 #define RADIOLIB_SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled 299 #define RADIOLIB_SX126X_LORA_CRC_ON 0x01 // 7 0 enabled 300 #define RADIOLIB_SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard 301 #define RADIOLIB_SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted 302 303 //RADIOLIB_SX126X_CMD_SET_CAD_PARAMS 304 #define RADIOLIB_SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1 305 #define RADIOLIB_SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2 306 #define RADIOLIB_SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4 307 #define RADIOLIB_SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8 308 #define RADIOLIB_SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16 309 #define RADIOLIB_SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode 310 #define RADIOLIB_SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected 311 312 //RADIOLIB_SX126X_CMD_GET_STATUS 313 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC 314 #define RADIOLIB_SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC 315 #define RADIOLIB_SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS 316 #define RADIOLIB_SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX 317 #define RADIOLIB_SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX 318 #define RADIOLIB_SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved 319 #define RADIOLIB_SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out 320 #define RADIOLIB_SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command 321 #define RADIOLIB_SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute 322 #define RADIOLIB_SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done 323 #define RADIOLIB_SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed 324 325 //RADIOLIB_SX126X_CMD_GET_PACKET_STATUS 326 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error 327 #define RADIOLIB_SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error 328 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error 329 #define RADIOLIB_SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error 330 #define RADIOLIB_SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error 331 #define RADIOLIB_SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error 332 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received 333 #define RADIOLIB_SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent 334 335 //RADIOLIB_SX126X_CMD_GET_DEVICE_ERRORS 336 #define RADIOLIB_SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed 337 #define RADIOLIB_SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock 338 #define RADIOLIB_SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start 339 #define RADIOLIB_SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed 340 #define RADIOLIB_SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed 341 #define RADIOLIB_SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed 342 #define RADIOLIB_SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed 343 #define RADIOLIB_SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed 344 345 346 // SX126X SPI register variables 347 //RADIOLIB_SX126X_REG_HOPPING_ENABLE 348 #define RADIOLIB_SX126X_HOPPING_ENABLED 0b00000001 // 0 0 intra-packet hopping for LR-FHSS: enabled 349 #define RADIOLIB_SX126X_HOPPING_DISABLED 0b00000000 // 0 0 (disabled) 350 351 //RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB + LSB 352 #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. 353 #define RADIOLIB_SX126X_SYNC_WORD_PRIVATE 0x12 // actually 0x1424 You couldn't make this up if you tried. 354 355 356 /*! 357 \class SX126x 358 359 \brief Base class for %SX126x series. All derived classes for %SX126x (e.g. SX1262 or SX1268) inherit from this base class. 360 This class should not be instantiated directly from Arduino sketch, only from its derived classes. 361 */ 362 class SX126x: public PhysicalLayer { 363 public: 364 // introduce PhysicalLayer overloads 365 using PhysicalLayer::transmit; 366 using PhysicalLayer::receive; 367 using PhysicalLayer::startTransmit; 368 using PhysicalLayer::readData; 369 370 /*! 371 \brief Default constructor. 372 373 \param mod Instance of Module that will be used to communicate with the radio. 374 */ 375 SX126x(Module* mod); 376 377 Module* getMod(); 378 379 // basic methods 380 381 /*! 382 \brief Initialization method for LoRa modem. 383 384 \param cr LoRa coding rate denominator. Allowed values range from 5 to 8. 385 386 \param syncWord 1-byte LoRa sync word. 387 388 \param preambleLength LoRa preamble length in symbols. Allowed values range from 1 to 65535. 389 390 \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 391 392 \param useRegulatorLDO use the LDO instead of DC-DC converter (default false). This is necessary for some modules such as the LAMBDA from RF solutions. 393 394 \returns \ref status_codes 395 */ 396 int16_t begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); 397 398 /*! 399 \brief Initialization method for FSK modem. 400 401 \param br FSK bit rate in kbps. Allowed values range from 0.6 to 300.0 kbps. 402 403 \param freqDev Frequency deviation from carrier frequency in kHz. Allowed values range from 0.0 to 200.0 kHz. 404 405 \param rxBw Receiver bandwidth in kHz. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. 406 407 \param preambleLength FSK preamble length in bits. Allowed values range from 0 to 65535. 408 409 \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. 410 411 \param useRegulatorLDO use the LDO instead of DC-DC converter (default false). This is necessary for some modules such as the LAMBDA from RF solutions. 412 413 \returns \ref status_codes 414 */ 415 int16_t beginFSK(float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO = false); 416 417 /*! 418 \brief Reset method. Will reset the chip to the default state using RST pin. 419 420 \param verify Whether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly 421 by repeatedly issuing setStandby command. Enabled by default. 422 423 \returns \ref status_codes 424 */ 425 int16_t reset(bool verify = true); 426 427 /*! 428 \brief Blocking binary transmit method. 429 Overloads for string-based transmissions are implemented in PhysicalLayer. 430 431 \param data Binary data to be sent. 432 433 \param len Number of bytes to send. 434 435 \param addr Address to send the data to. Will only be added if address filtering was enabled. 436 437 \returns \ref status_codes 438 */ 439 int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; 440 441 /*! 442 \brief Blocking binary receive method. 443 Overloads for string-based transmissions are implemented in PhysicalLayer. 444 445 \param data Binary data to be sent. 446 447 \param len Number of bytes to send. 448 449 \returns \ref status_codes 450 */ 451 int16_t receive(uint8_t* data, size_t len) override; 452 453 /*! 454 \brief Starts direct mode transmission. 455 456 \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY. 457 458 \returns \ref status_codes 459 */ 460 int16_t transmitDirect(uint32_t frf = 0) override; 461 462 /*! 463 \brief Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as %SX126x series does not support direct mode reception. 464 Will always return RADIOLIB_ERR_UNKNOWN. 465 466 \returns \ref status_codes 467 */ 468 int16_t receiveDirect() override; 469 470 /*! 471 \brief Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. 472 473 \returns \ref status_codes 474 */ 475 int16_t scanChannel(); 476 477 /*! 478 \brief Sets the module to sleep mode. 479 480 \param retainConfig Set to true to retain configuration of the currently active modem ("warm start") or to false to discard current configuration ("cold start"). Defaults to true. 481 482 \returns \ref status_codes 483 */ 484 int16_t sleep(bool retainConfig = true); 485 486 /*! 487 \brief Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator). 488 489 \returns \ref status_codes 490 */ 491 int16_t standby() override; 492 493 /*! 494 \brief Sets the module to standby mode. 495 496 \param mode Oscillator to be used in standby mode. Can be set to RADIOLIB_SX126X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX126X_STANDBY_XOSC (32 MHz external crystal oscillator). 497 498 \returns \ref status_codes 499 */ 500 int16_t standby(uint8_t mode); 501 502 // interrupt methods 503 504 /*! 505 \brief Sets interrupt service routine to call when DIO1 activates. 506 507 \param func ISR to call. 508 */ 509 void setDio1Action(void (*func)(void)); 510 511 /*! 512 \brief Clears interrupt service routine to call when DIO1 activates. 513 */ 514 void clearDio1Action(); 515 516 /*! 517 \brief Interrupt-driven binary transmit method. 518 Overloads for string-based transmissions are implemented in PhysicalLayer. 519 520 \param data Binary data to be sent. 521 522 \param len Number of bytes to send. 523 524 \param addr Address to send the data to. Will only be added if address filtering was enabled. 525 526 \returns \ref status_codes 527 */ 528 int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; 529 530 /*! 531 \brief Interrupt-driven receive method. DIO1 will be activated when full packet is received. 532 533 \param timeout Raw timeout value, expressed as multiples of 15.625 us. Defaults to RADIOLIB_SX126X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to RADIOLIB_SX126X_RX_TIMEOUT_NONE for no timeout (Rx single mode). 534 If timeout other than infinite is set, signal will be generated on DIO1. 535 536 \returns \ref status_codes 537 */ 538 int16_t startReceive(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF); 539 540 /*! 541 \brief Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen. 542 Note that this function assumes the unit will take 500us + TCXO_delay to change state. See datasheet section 13.1.7, version 1.2. 543 544 \param rxPeriod The duration the receiver will be in Rx mode, in microseconds. 545 546 \param sleepPeriod The duration the receiver will not be in Rx mode, in microseconds. 547 548 \returns \ref status_codes 549 */ 550 int16_t startReceiveDutyCycle(uint32_t rxPeriod, uint32_t sleepPeriod); 551 552 /*! 553 \brief Calls \ref startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages. 554 555 \param senderPreambleLength Expected preamble length of the messages to receive. 556 If set to zero, the currently configured preamble length will be used. Defaults to zero. 557 558 \param minSymbols Parameters will be chosen to ensure that the unit will catch at least this many symbols of any preamble of the specified length. Defaults to 8. 559 According to Semtech, receiver requires 8 symbols to reliably latch a preamble. This makes this method redundant when transmitter preamble length is less than 17 (2*minSymbols + 1). 560 561 \returns \ref status_codes 562 */ 563 int16_t startReceiveDutyCycleAuto(uint16_t senderPreambleLength = 0, uint16_t minSymbols = 8); 564 565 /*! 566 \brief Reads the current IRQ status. 567 568 \returns IRQ status bits 569 */ 570 uint16_t getIrqStatus(); 571 572 /*! 573 \brief Reads data received after calling startReceive method. 574 575 \param data Pointer to array to save the received binary data. 576 577 \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically. 578 When more bytes than received are requested, only the number of bytes requested will be returned. 579 580 \returns \ref status_codes 581 */ 582 int16_t readData(uint8_t* data, size_t len) override; 583 584 /*! 585 \brief Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected, or upon timeout. 586 587 \returns \ref status_codes 588 */ 589 int16_t startChannelScan(); 590 591 /*! 592 \brief Read the channel scan result 593 594 \returns \ref status_codes 595 */ 596 int16_t getChannelScanResult(); 597 598 // configuration methods 599 600 /*! 601 \brief Sets LoRa bandwidth. Allowed values are 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125.0, 250.0 and 500.0 kHz. 602 603 \param bw LoRa bandwidth to be set in kHz. 604 605 \returns \ref status_codes 606 */ 607 int16_t setBandwidth(float bw); 608 609 /*! 610 \brief Sets LoRa spreading factor. Allowed values range from 5 to 12. 611 612 \param sf LoRa spreading factor to be set. 613 614 \returns \ref status_codes 615 */ 616 int16_t setSpreadingFactor(uint8_t sf); 617 618 /*! 619 \brief Sets LoRa coding rate denominator. Allowed values range from 5 to 8. 620 621 \param cr LoRa coding rate denominator to be set. 622 623 \returns \ref status_codes 624 */ 625 int16_t setCodingRate(uint8_t cr); 626 627 /*! 628 \brief Sets LoRa sync word. 629 630 \param syncWord LoRa sync word to be set. 631 632 \param controlBits Undocumented control bits, required for compatibility purposes. 633 634 \returns \ref status_codes 635 */ 636 int16_t setSyncWord(uint8_t syncWord, uint8_t controlBits = 0x44); 637 638 /*! 639 \brief Sets current protection limit. Can be set in 0.25 mA steps. 640 641 \param currentLimit current protection limit to be set in mA. 642 643 \returns \ref status_codes 644 */ 645 int16_t setCurrentLimit(float currentLimit); 646 647 /*! 648 \brief Reads current protection limit. 649 650 \returns Currently configured overcurrent protection limit in mA. 651 */ 652 float getCurrentLimit(); 653 654 /*! 655 \brief Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535. 656 657 \param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK). 658 659 \returns \ref status_codes 660 */ 661 int16_t setPreambleLength(uint16_t preambleLength); 662 663 /*! 664 \brief Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz. 665 666 \param freqDev FSK frequency deviation to be set in kHz. 667 668 \returns \ref status_codes 669 */ 670 int16_t setFrequencyDeviation(float freqDev) override; 671 672 /*! 673 \brief Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps. 674 675 \param br FSK bit rate to be set in kbps. 676 677 \returns \ref status_codes 678 */ 679 int16_t setBitRate(float br); 680 681 /*! 682 \brief Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. 683 684 \param FSK receiver bandwidth to be set in kHz. 685 686 \returns \ref status_codes 687 */ 688 int16_t setRxBandwidth(float rxBw); 689 690 /*! 691 \brief Sets time-bandwidth product of Gaussian filter applied for shaping. 692 Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5, RADIOLIB_SHAPING_0_7 or RADIOLIB_SHAPING_1_0. 693 Set to RADIOLIB_SHAPING_NONE to disable data shaping. 694 695 \param sh Time-bandwidth product of Gaussian filter to be set. 696 697 \returns \ref status_codes 698 */ 699 int16_t setDataShaping(uint8_t sh) override; 700 701 /*! 702 \brief Sets FSK sync word in the form of array of up to 8 bytes. 703 704 \param syncWord FSK sync word to be set. 705 706 \param len FSK sync word length in bytes. 707 708 \returns \ref status_codes 709 */ 710 int16_t setSyncWord(uint8_t* syncWord, uint8_t len); 711 712 /*! 713 \brief Sets FSK sync word in the form of array of up to 8 bytes. 714 715 \param syncWord FSK sync word to be set. 716 717 \param bitsLen FSK sync word length in bits. If length is not divisible by 8, least significant bits of syncWord will be ignored. 718 719 \returns \ref status_codes 720 */ 721 int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen); 722 723 /*! 724 \brief Sets node address. Calling this method will also enable address filtering for node address only. 725 726 \param nodeAddr Node address to be set. 727 728 \returns \ref status_codes 729 */ 730 int16_t setNodeAddress(uint8_t nodeAddr); 731 732 /*! 733 \brief Sets broadcast address. Calling this method will also enable address filtering for node and broadcast address. 734 735 \param broadAddr Node address to be set. 736 737 \returns \ref status_codes 738 */ 739 int16_t setBroadcastAddress(uint8_t broadAddr); 740 741 /*! 742 \brief Disables address filtering. Calling this method will also erase previously set addresses. 743 744 \returns \ref status_codes 745 */ 746 int16_t disableAddressFiltering(); 747 748 /*! 749 \brief Sets CRC configuration. 750 751 \param len CRC length in bytes, Allowed values are 1 or 2, set to 0 to disable CRC. 752 753 \param initial Initial CRC value. FSK only. Defaults to 0x1D0F (CCIT CRC). 754 755 \param polynomial Polynomial for CRC calculation. FSK only. Defaults to 0x1021 (CCIT CRC). 756 757 \param inverted Invert CRC bytes. FSK only. Defaults to true (CCIT CRC). 758 759 \returns \ref status_codes 760 */ 761 int16_t setCRC(uint8_t len, uint16_t initial = 0x1D0F, uint16_t polynomial = 0x1021, bool inverted = true); 762 763 /*! 764 \brief Sets FSK whitening parameters. 765 766 \param enabled True = Whitening enabled 767 768 \param initial Initial value used for the whitening LFSR in FSK mode. Defaults to 0x0100, use 0x01FF for SX127x compatibility. 769 770 \returns \ref status_codes 771 */ 772 int16_t setWhitening(bool enabled, uint16_t initial = 0x0100); 773 774 /*! 775 \brief Sets TCXO (Temperature Compensated Crystal Oscillator) configuration. 776 777 \param TCXO reference voltage in volts. Allowed values are 1.6, 1.7, 1.8, 2.2. 2.4, 2.7, 3.0 and 3.3 V. Set to 0 to disable TCXO. 778 NOTE: After setting this parameter to 0, the module will be reset (since there's no other way to disable TCXO). 779 780 \param TCXO timeout in us. Defaults to 5000 us. 781 782 \returns \ref status_codes 783 */ 784 int16_t setTCXO(float voltage, uint32_t delay = 5000); 785 786 /*! 787 \brief Set DIO2 to function as RF switch (default in Semtech example designs). 788 789 \returns \ref status_codes 790 */ 791 int16_t setDio2AsRfSwitch(bool enable = true); 792 793 /*! 794 \brief Gets effective data rate for the last transmitted packet. The value is calculated only for payload bytes. 795 796 \returns Effective data rate in bps. 797 */ 798 float getDataRate() const; 799 800 /*! 801 \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. 802 803 \returns RSSI of the last received packet in dBm. 804 */ 805 float getRSSI(); 806 807 /*! 808 \brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem. 809 810 \returns SNR of the last received packet in dB. 811 */ 812 float getSNR(); 813 814 /*! 815 \brief Query modem for the packet length of received payload. 816 817 \param update Update received packet length. Will return cached value when set to false. 818 819 \returns Length of last received packet in bytes. 820 */ 821 size_t getPacketLength(bool update = true) override; 822 823 /*! 824 \brief Set modem in fixed packet length mode. Available in FSK mode only. 825 826 \param len Packet length. 827 828 \returns \ref status_codes 829 */ 830 int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_SX126X_MAX_PACKET_LENGTH); 831 832 /*! 833 \brief Set modem in variable packet length mode. Available in FSK mode only. 834 835 \param len Maximum packet length. 836 837 \returns \ref status_codes 838 */ 839 int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_SX126X_MAX_PACKET_LENGTH); 840 841 /*! 842 \brief Get expected time-on-air for a given size of payload 843 844 \param len Payload length in bytes. 845 846 \returns Expected time-on-air in microseconds. 847 */ 848 uint32_t getTimeOnAir(size_t len); 849 850 /*! 851 \brief Get instantaneous RSSI value during recption of the packet. Should switch to FSK receive mode for LBT implementation. 852 853 \returns Instantaneous RSSI value in dBm, in steps of 0.5dBm 854 */ 855 float getRSSIInst(); 856 857 /*! 858 \brief Set implicit header mode for future reception/transmission. 859 860 \param len Payload length in bytes. 861 862 \returns \ref status_codes 863 */ 864 int16_t implicitHeader(size_t len); 865 866 /*! 867 \brief Set explicit header mode for future reception/transmission. 868 869 \returns \ref status_codes 870 */ 871 int16_t explicitHeader(); 872 873 /*! 874 \brief Set regulator mode to LDO. 875 876 \returns \ref status_codes 877 */ 878 int16_t setRegulatorLDO(); 879 880 /*! 881 \brief Set regulator mode to DC-DC. 882 883 \returns \ref status_codes 884 */ 885 int16_t setRegulatorDCDC(); 886 887 /*! 888 \brief Sets transmission encoding. Available in FSK mode only. Serves only as alias for PhysicalLayer compatibility. 889 890 \param encoding Encoding to be used. Set to 0 for NRZ, and 2 for whitening. 891 892 \returns \ref status_codes 893 */ 894 int16_t setEncoding(uint8_t encoding) override; 895 896 /*! 897 \brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state. 898 When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! 899 900 \param rxEn RX enable pin. 901 902 \param txEn TX enable pin. 903 */ 904 void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); 905 906 /*! 907 \brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to 908 the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX126x::autoLDRO() 909 910 \param enable Force LDRO to be always enabled (true) or disabled (false). 911 912 \returns \ref status_codes 913 */ 914 int16_t forceLDRO(bool enable); 915 916 /*! 917 \brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically 918 when symbol length exceeds 16 ms. 919 920 \returns \ref status_codes 921 */ 922 int16_t autoLDRO(); 923 924 /*! 925 \brief Get one truly random byte from RSSI noise. 926 927 \returns TRNG byte. 928 */ 929 uint8_t randomByte(); 930 931 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) 932 /*! 933 \brief Dummy method, to ensure PhysicalLayer compatibility. 934 935 \param func Ignored. 936 */ 937 void setDirectAction(void (*func)(void)); 938 939 /*! 940 \brief Dummy method, to ensure PhysicalLayer compatibility. 941 942 \param pin Ignored. 943 */ 944 void readBit(RADIOLIB_PIN_TYPE pin); 945 #endif 946 947 948 #if !defined(RADIOLIB_GODMODE) 949 protected: 950 #endif 951 // SX126x SPI command implementations 952 int16_t setTx(uint32_t timeout = 0); 953 int16_t setRx(uint32_t timeout); 954 int16_t setCad(); 955 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); 956 int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes); 957 int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes); 958 int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00); 959 int16_t readBuffer(uint8_t* data, uint8_t numBytes); 960 int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX126X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX126X_IRQ_NONE); 961 int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX126X_IRQ_ALL); 962 int16_t setRfFrequency(uint32_t frf); 963 int16_t calibrateImage(uint8_t* data); 964 uint8_t getPacketType(); 965 int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX126X_PA_RAMP_200U); 966 int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro); 967 int16_t setModulationParamsFSK(uint32_t br, uint8_t pulseShape, uint8_t rxBw, uint32_t freqDev); 968 int16_t setPacketParams(uint16_t preambleLength, uint8_t crcType, uint8_t payloadLength, uint8_t headerType, uint8_t invertIQ = RADIOLIB_SX126X_LORA_IQ_STANDARD); 969 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); 970 int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00); 971 int16_t setRegulatorMode(uint8_t mode); 972 uint8_t getStatus(); 973 uint32_t getPacketStatus(); 974 uint16_t getDeviceErrors(); 975 int16_t clearDeviceErrors(); 976 977 int16_t startReceiveCommon(uint32_t timeout = RADIOLIB_SX126X_RX_TIMEOUT_INF); 978 int16_t setFrequencyRaw(float freq); 979 int16_t setPacketMode(uint8_t mode, uint8_t len); 980 int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF); 981 982 // fixes to errata 983 int16_t fixSensitivity(); 984 int16_t fixPaClamping(); 985 int16_t fixImplicitTimeout(); 986 int16_t fixInvertedIQ(uint8_t iqConfig); 987 988 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) 989 protected: 990 #endif 991 Module* _mod; 992 993 // common low-level SPI interface 994 int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); 995 int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); 996 int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); 997 int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); 998 int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy, uint32_t timeout = 5000); 999 1000 #if !defined(RADIOLIB_GODMODE) 1001 protected: 1002 #endif 1003 1004 uint8_t _bw = 0, _sf = 0, _cr = 0, _ldro = 0, _crcType = 0, _headerType = 0; 1005 uint16_t _preambleLength = 0; 1006 float _bwKhz = 0; 1007 bool _ldroAuto = true; 1008 1009 uint32_t _br = 0, _freqDev = 0; 1010 uint8_t _rxBw = 0, _pulseShape = 0, _crcTypeFSK = 0, _syncWordLength = 0, _addrComp = 0, _whitening = 0, _packetType = 0; 1011 uint16_t _preambleLengthFSK = 0; 1012 float _rxBwKhz = 0; 1013 1014 float _dataRate = 0; 1015 1016 uint32_t _tcxoDelay = 0; 1017 1018 size_t _implicitLen = 0; 1019 1020 int16_t config(uint8_t modem); 1021 }; 1022 1023 #endif 1024 1025 #endif