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 |
RF69.h (57343B)
1 #if !defined(_RADIOLIB_RF69_H) 2 #define _RADIOLIB_RF69_H 3 4 #include "../../TypeDef.h" 5 6 #if !defined(RADIOLIB_EXCLUDE_RF69) 7 8 #include "../../Module.h" 9 10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h" 11 12 // RF69 physical layer properties 13 #define RADIOLIB_RF69_FREQUENCY_STEP_SIZE 61.03515625 14 #define RADIOLIB_RF69_MAX_PACKET_LENGTH 64 15 #define RADIOLIB_RF69_CRYSTAL_FREQ 32.0 16 #define RADIOLIB_RF69_DIV_EXPONENT 19 17 18 // RF69 register map 19 #define RADIOLIB_RF69_REG_FIFO 0x00 20 #define RADIOLIB_RF69_REG_OP_MODE 0x01 21 #define RADIOLIB_RF69_REG_DATA_MODUL 0x02 22 #define RADIOLIB_RF69_REG_BITRATE_MSB 0x03 23 #define RADIOLIB_RF69_REG_BITRATE_LSB 0x04 24 #define RADIOLIB_RF69_REG_FDEV_MSB 0x05 25 #define RADIOLIB_RF69_REG_FDEV_LSB 0x06 26 #define RADIOLIB_RF69_REG_FRF_MSB 0x07 27 #define RADIOLIB_RF69_REG_FRF_MID 0x08 28 #define RADIOLIB_RF69_REG_FRF_LSB 0x09 29 #define RADIOLIB_RF69_REG_OSC_1 0x0A 30 #define RADIOLIB_RF69_REG_AFC_CTRL 0x0B 31 #define RADIOLIB_RF69_REG_LISTEN_1 0x0D 32 #define RADIOLIB_RF69_REG_LISTEN_2 0x0E 33 #define RADIOLIB_RF69_REG_LISTEN_3 0x0F 34 #define RADIOLIB_RF69_REG_VERSION 0x10 35 #define RADIOLIB_RF69_REG_PA_LEVEL 0x11 36 #define RADIOLIB_RF69_REG_PA_RAMP 0x12 37 #define RADIOLIB_RF69_REG_OCP 0x13 38 #define RADIOLIB_RF69_REG_LNA 0x18 39 #define RADIOLIB_RF69_REG_RX_BW 0x19 40 #define RADIOLIB_RF69_REG_AFC_BW 0x1A 41 #define RADIOLIB_RF69_REG_OOK_PEAK 0x1B 42 #define RADIOLIB_RF69_REG_OOK_AVG 0x1C 43 #define RADIOLIB_RF69_REG_OOK_FIX 0x1D 44 #define RADIOLIB_RF69_REG_AFC_FEI 0x1E 45 #define RADIOLIB_RF69_REG_AFC_MSB 0x1F 46 #define RADIOLIB_RF69_REG_AFC_LSB 0x20 47 #define RADIOLIB_RF69_REG_FEI_MSB 0x21 48 #define RADIOLIB_RF69_REG_FEI_LSB 0x22 49 #define RADIOLIB_RF69_REG_RSSI_CONFIG 0x23 50 #define RADIOLIB_RF69_REG_RSSI_VALUE 0x24 51 #define RADIOLIB_RF69_REG_DIO_MAPPING_1 0x25 52 #define RADIOLIB_RF69_REG_DIO_MAPPING_2 0x26 53 #define RADIOLIB_RF69_REG_IRQ_FLAGS_1 0x27 54 #define RADIOLIB_RF69_REG_IRQ_FLAGS_2 0x28 55 #define RADIOLIB_RF69_REG_RSSI_THRESH 0x29 56 #define RADIOLIB_RF69_REG_RX_TIMEOUT_1 0x2A 57 #define RADIOLIB_RF69_REG_RX_TIMEOUT_2 0x2B 58 #define RADIOLIB_RF69_REG_PREAMBLE_MSB 0x2C 59 #define RADIOLIB_RF69_REG_PREAMBLE_LSB 0x2D 60 #define RADIOLIB_RF69_REG_SYNC_CONFIG 0x2E 61 #define RADIOLIB_RF69_REG_SYNC_VALUE_1 0x2F 62 #define RADIOLIB_RF69_REG_SYNC_VALUE_2 0x30 63 #define RADIOLIB_RF69_REG_SYNC_VALUE_3 0x31 64 #define RADIOLIB_RF69_REG_SYNC_VALUE_4 0x32 65 #define RADIOLIB_RF69_REG_SYNC_VALUE_5 0x33 66 #define RADIOLIB_RF69_REG_SYNC_VALUE_6 0x34 67 #define RADIOLIB_RF69_REG_SYNC_VALUE_7 0x35 68 #define RADIOLIB_RF69_REG_SYNC_VALUE_8 0x36 69 #define RADIOLIB_RF69_REG_PACKET_CONFIG_1 0x37 70 #define RADIOLIB_RF69_REG_PAYLOAD_LENGTH 0x38 71 #define RADIOLIB_RF69_REG_NODE_ADRS 0x39 72 #define RADIOLIB_RF69_REG_BROADCAST_ADRS 0x3A 73 #define RADIOLIB_RF69_REG_AUTO_MODES 0x3B 74 #define RADIOLIB_RF69_REG_FIFO_THRESH 0x3C 75 #define RADIOLIB_RF69_REG_PACKET_CONFIG_2 0x3D 76 #define RADIOLIB_RF69_REG_AES_KEY_1 0x3E 77 #define RADIOLIB_RF69_REG_AES_KEY_2 0x3F 78 #define RADIOLIB_RF69_REG_AES_KEY_3 0x40 79 #define RADIOLIB_RF69_REG_AES_KEY_4 0x41 80 #define RADIOLIB_RF69_REG_AES_KEY_5 0x42 81 #define RADIOLIB_RF69_REG_AES_KEY_6 0x43 82 #define RADIOLIB_RF69_REG_AES_KEY_7 0x44 83 #define RADIOLIB_RF69_REG_AES_KEY_8 0x45 84 #define RADIOLIB_RF69_REG_AES_KEY_9 0x46 85 #define RADIOLIB_RF69_REG_AES_KEY_10 0x47 86 #define RADIOLIB_RF69_REG_AES_KEY_11 0x48 87 #define RADIOLIB_RF69_REG_AES_KEY_12 0x49 88 #define RADIOLIB_RF69_REG_AES_KEY_13 0x4A 89 #define RADIOLIB_RF69_REG_AES_KEY_14 0x4B 90 #define RADIOLIB_RF69_REG_AES_KEY_15 0x4C 91 #define RADIOLIB_RF69_REG_AES_KEY_16 0x4D 92 #define RADIOLIB_RF69_REG_TEMP_1 0x4E 93 #define RADIOLIB_RF69_REG_TEMP_2 0x4F 94 #define RADIOLIB_RF69_REG_TEST_LNA 0x58 95 #define RADIOLIB_RF69_REG_TEST_PA1 0x5A 96 #define RADIOLIB_RF69_REG_TEST_PA2 0x5C 97 #define RADIOLIB_RF69_REG_TEST_DAGC 0x6F 98 99 // RF69 modem settings 100 // RF69_REG_OP_MODE MSB LSB DESCRIPTION 101 #define RADIOLIB_RF69_SEQUENCER_OFF 0b00000000 // 7 7 disable automatic sequencer 102 #define RADIOLIB_RF69_SEQUENCER_ON 0b10000000 // 7 7 enable automatic sequencer 103 #define RADIOLIB_RF69_LISTEN_OFF 0b00000000 // 6 6 disable Listen mode 104 #define RADIOLIB_RF69_LISTEN_ON 0b01000000 // 6 6 enable Listen mode 105 #define RADIOLIB_RF69_LISTEN_ABORT 0b00100000 // 5 5 abort Listen mode (has to be set together with RF69_LISTEN_OFF) 106 #define RADIOLIB_RF69_SLEEP 0b00000000 // 4 2 sleep 107 #define RADIOLIB_RF69_STANDBY 0b00000100 // 4 2 standby 108 #define RADIOLIB_RF69_FS 0b00001000 // 4 2 frequency synthesis 109 #define RADIOLIB_RF69_TX 0b00001100 // 4 2 transmit 110 #define RADIOLIB_RF69_RX 0b00010000 // 4 2 receive 111 112 // RF69_REG_DATA_MODUL 113 #define RADIOLIB_RF69_PACKET_MODE 0b00000000 // 6 5 packet mode (default) 114 #define RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC 0b01000000 // 6 5 continuous mode with bit synchronizer 115 #define RADIOLIB_RF69_CONTINUOUS_MODE 0b01100000 // 6 5 continuous mode without bit synchronizer 116 #define RADIOLIB_RF69_FSK 0b00000000 // 4 3 modulation: FSK (default) 117 #define RADIOLIB_RF69_OOK 0b00001000 // 4 3 OOK 118 #define RADIOLIB_RF69_NO_SHAPING 0b00000000 // 1 0 modulation shaping: no shaping (default) 119 #define RADIOLIB_RF69_FSK_GAUSSIAN_1_0 0b00000001 // 1 0 FSK modulation Gaussian filter, BT = 1.0 120 #define RADIOLIB_RF69_FSK_GAUSSIAN_0_5 0b00000010 // 1 0 FSK modulation Gaussian filter, BT = 0.5 121 #define RADIOLIB_RF69_FSK_GAUSSIAN_0_3 0b00000011 // 1 0 FSK modulation Gaussian filter, BT = 0.3 122 #define RADIOLIB_RF69_OOK_FILTER_BR 0b00000001 // 1 0 OOK modulation filter, f_cutoff = BR 123 #define RADIOLIB_RF69_OOK_FILTER_2BR 0b00000010 // 1 0 OOK modulation filter, f_cutoff = 2*BR 124 125 // RF69_REG_BITRATE_MSB + REG_BITRATE_LSB 126 #define RADIOLIB_RF69_BITRATE_MSB 0x1A // 7 0 bit rate setting: rate = F(XOSC) / BITRATE 127 #define RADIOLIB_RF69_BITRATE_LSB 0x0B // 7 0 default value: 4.8 kbps 0x40 // 7 0 128 129 // RF69_REG_FDEV_MSB + REG_FDEV_LSB 130 #define RADIOLIB_RF69_FDEV_MSB 0x00 // 5 0 frequency deviation: f_dev = f_step * FDEV 131 #define RADIOLIB_RF69_FDEV_LSB 0x52 // 7 0 default value: 5 kHz 132 133 // RF69_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB 134 #define RADIOLIB_RF69_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19 135 #define RADIOLIB_RF69_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz 136 #define RADIOLIB_RF69_FRF_LSB 0x00 // 7 0 default value: 915 MHz 137 138 // RF69_REG_OSC_1 139 #define RADIOLIB_RF69_RC_CAL_START 0b10000000 // 7 7 force RC oscillator calibration 140 #define RADIOLIB_RF69_RC_CAL_RUNNING 0b00000000 // 6 6 RC oscillator calibration is still running 141 #define RADIOLIB_RF69_RC_CAL_DONE 0b00000000 // 5 5 RC oscillator calibration has finished 142 143 // RF69_REG_AFC_CTRL 144 #define RADIOLIB_RF69_AFC_LOW_BETA_OFF 0b00000000 // 5 5 standard AFC routine 145 #define RADIOLIB_RF69_AFC_LOW_BETA_ON 0b00100000 // 5 5 improved AFC routine for signals with modulation index less than 2 146 147 // RF69_REG_LISTEN_1 148 #define RADIOLIB_RF69_LISTEN_RES_IDLE_64_US 0b01000000 // 7 6 resolution of Listen mode idle time: 64 us 149 #define RADIOLIB_RF69_LISTEN_RES_IDLE_4_1_MS 0b10000000 // 7 6 4.1 ms (default) 150 #define RADIOLIB_RF69_LISTEN_RES_IDLE_262_MS 0b11000000 // 7 6 262 ms 151 #define RADIOLIB_RF69_LISTEN_RES_RX_64_US 0b00010000 // 5 4 resolution of Listen mode rx time: 64 us (default) 152 #define RADIOLIB_RF69_LISTEN_RES_RX_4_1_MS 0b00100000 // 5 4 4.1 ms 153 #define RADIOLIB_RF69_LISTEN_RES_RX_262_MS 0b00110000 // 5 4 262 ms 154 #define RADIOLIB_RF69_LISTEN_ACCEPT_ABOVE_RSSI_THRESH 0b00000000 // 3 3 packet acceptance criteria: RSSI above threshold 155 #define RADIOLIB_RF69_LISTEN_ACCEPT_MATCH_SYNC_ADDRESS 0b00001000 // 3 3 RSSI above threshold AND sync address matched 156 #define RADIOLIB_RF69_LISTEN_END_KEEP_RX 0b00000000 // 2 1 action after packet acceptance: stay in Rx mode 157 #define RADIOLIB_RF69_LISTEN_END_KEEP_RX_TIMEOUT 0b00000010 // 2 1 stay in Rx mode until timeout (default) 158 #define RADIOLIB_RF69_LISTEN_END_KEEP_RX_TIMEOUT_RESUME 0b00000100 // 2 1 stay in Rx mode until timeout, Listen mode will resume 159 160 // RF69_REG_LISTEN_2 161 #define RADIOLIB_RF69_LISTEN_COEF_IDLE 0xF5 // 7 0 duration of idle phase in Listen mode 162 163 // RF69_REG_LISTEN_3 164 #define RADIOLIB_RF69_LISTEN_COEF_RX 0x20 // 7 0 duration of Rx phase in Listen mode 165 166 // RF69_REG_VERSION 167 #define RADIOLIB_RF69_CHIP_VERSION 0x24 // 7 0 168 169 // RF69_REG_PA_LEVEL 170 #define RADIOLIB_RF69_PA0_OFF 0b00000000 // 7 7 PA0 disabled 171 #define RADIOLIB_RF69_PA0_ON 0b10000000 // 7 7 PA0 enabled (default) 172 #define RADIOLIB_RF69_PA1_OFF 0b00000000 // 6 6 PA1 disabled (default) 173 #define RADIOLIB_RF69_PA1_ON 0b01000000 // 6 6 PA1 enabled 174 #define RADIOLIB_RF69_PA2_OFF 0b00000000 // 5 5 PA2 disabled (default) 175 #define RADIOLIB_RF69_PA2_ON 0b00100000 // 5 5 PA2 enabled 176 #define RADIOLIB_RF69_OUTPUT_POWER 0b00011111 // 4 0 output power: P_out = -18 + OUTPUT_POWER 177 178 // RF69_REG_PA_RAMP 179 #define RADIOLIB_RF69_PA_RAMP_3_4_MS 0b00000000 // 3 0 PA ramp rise/fall time: 3.4 ms 180 #define RADIOLIB_RF69_PA_RAMP_2_MS 0b00000001 // 3 0 2 ms 181 #define RADIOLIB_RF69_PA_RAMP_1_MS 0b00000010 // 3 0 1 ms 182 #define RADIOLIB_RF69_PA_RAMP_500_US 0b00000011 // 3 0 500 us 183 #define RADIOLIB_RF69_PA_RAMP_250_US 0b00000100 // 3 0 250 us 184 #define RADIOLIB_RF69_PA_RAMP_125_US 0b00000101 // 3 0 125 us 185 #define RADIOLIB_RF69_PA_RAMP_100_US 0b00000110 // 3 0 100 us 186 #define RADIOLIB_RF69_PA_RAMP_62_US 0b00000111 // 3 0 62 us 187 #define RADIOLIB_RF69_PA_RAMP_50_US 0b00001000 // 3 0 50 us 188 #define RADIOLIB_RF69_PA_RAMP_40_US 0b00001001 // 3 0 40 us (default) 189 #define RADIOLIB_RF69_PA_RAMP_31_US 0b00001010 // 3 0 31 us 190 #define RADIOLIB_RF69_PA_RAMP_25_US 0b00001011 // 3 0 25 us 191 #define RADIOLIB_RF69_PA_RAMP_20_US 0b00001100 // 3 0 20 us 192 #define RADIOLIB_RF69_PA_RAMP_15_US 0b00001101 // 3 0 15 us 193 #define RADIOLIB_RF69_PA_RAMP_12_US 0b00001110 // 3 0 12 us 194 #define RADIOLIB_RF69_PA_RAMP_10_US 0b00001111 // 3 0 10 us 195 196 // RF69_REG_OCP 197 #define RADIOLIB_RF69_OCP_OFF 0b00000000 // 4 4 PA overload current protection disabled 198 #define RADIOLIB_RF69_OCP_ON 0b00010000 // 4 4 PA overload current protection enabled 199 #define RADIOLIB_RF69_OCP_TRIM 0b00001010 // 3 0 OCP current: I_max(OCP_TRIM = 0b1010) = 95 mA 200 201 // RF69_REG_LNA 202 #define RADIOLIB_RF69_LNA_Z_IN_50_OHM 0b00000000 // 7 7 LNA input impedance: 50 ohm 203 #define RADIOLIB_RF69_LNA_Z_IN_200_OHM 0b10000000 // 7 7 200 ohm 204 #define RADIOLIB_RF69_LNA_CURRENT_GAIN 0b00001000 // 5 3 manually set LNA current gain 205 #define RADIOLIB_RF69_LNA_GAIN_AUTO 0b00000000 // 2 0 LNA gain setting: set automatically by AGC 206 #define RADIOLIB_RF69_LNA_GAIN_MAX 0b00000001 // 2 0 max gain 207 #define RADIOLIB_RF69_LNA_GAIN_MAX_6_DB 0b00000010 // 2 0 max gain - 6 dB 208 #define RADIOLIB_RF69_LNA_GAIN_MAX_12_DB 0b00000011 // 2 0 max gain - 12 dB 209 #define RADIOLIB_RF69_LNA_GAIN_MAX_24_DB 0b00000100 // 2 0 max gain - 24 dB 210 #define RADIOLIB_RF69_LNA_GAIN_MAX_36_DB 0b00000101 // 2 0 max gain - 36 dB 211 #define RADIOLIB_RF69_LNA_GAIN_MAX_48_DB 0b00000110 // 2 0 max gain - 48 dB 212 213 // RF69_REG_RX_BW 214 #define RADIOLIB_RF69_DCC_FREQ 0b01000000 // 7 5 DC offset canceller cutoff frequency (4% Rx BW by default) 215 #define RADIOLIB_RF69_RX_BW_MANT_16 0b00000000 // 4 3 Channel filter bandwidth FSK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 2)) 216 #define RADIOLIB_RF69_RX_BW_MANT_20 0b00001000 // 4 3 OOK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 3)) 217 #define RADIOLIB_RF69_RX_BW_MANT_24 0b00010000 // 4 3 218 #define RADIOLIB_RF69_RX_BW_EXP 0b00000101 // 2 0 default RxBwExp value = 5 219 220 // RF69_REG_AFC_BW 221 #define RADIOLIB_RF69_DCC_FREQ_AFC 0b10000000 // 7 5 default DccFreq parameter for AFC 222 #define RADIOLIB_RF69_DCC_RX_BW_MANT_AFC 0b00001000 // 4 3 default RxBwMant parameter for AFC 223 #define RADIOLIB_RF69_DCC_RX_BW_EXP_AFC 0b00000011 // 2 0 default RxBwExp parameter for AFC 224 225 // RF69_REG_OOK_PEAK 226 #define RADIOLIB_RF69_OOK_THRESH_FIXED 0b00000000 // 7 6 OOK threshold type: fixed 227 #define RADIOLIB_RF69_OOK_THRESH_PEAK 0b01000000 // 7 6 peak (default) 228 #define RADIOLIB_RF69_OOK_THRESH_AVERAGE 0b10000000 // 7 6 average 229 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_0_5_DB 0b00000000 // 5 3 OOK demodulator step size: 0.5 dB (default) 230 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_1_0_DB 0b00001000 // 5 3 1.0 dB 231 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_1_5_DB 0b00010000 // 5 3 1.5 dB 232 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_2_0_DB 0b00011000 // 5 3 2.0 dB 233 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_3_0_DB 0b00100000 // 5 3 3.0 dB 234 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_4_0_DB 0b00101000 // 5 3 4.0 dB 235 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_5_0_DB 0b00110000 // 5 3 5.0 dB 236 #define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_6_0_DB 0b00111000 // 5 3 6.0 dB 237 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_1_CHIP 0b00000000 // 2 0 OOK demodulator step period: once per chip (default) 238 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_2_CHIP 0b00000001 // 2 0 once every 2 chips 239 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_4_CHIP 0b00000010 // 2 0 once every 4 chips 240 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_8_CHIP 0b00000011 // 2 0 once every 8 chips 241 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_2_1_CHIP 0b00000100 // 2 0 2 times per chip 242 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_4_1_CHIP 0b00000101 // 2 0 4 times per chip 243 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_8_1_CHIP 0b00000110 // 2 0 8 times per chip 244 #define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_16_1_CHIP 0b00000111 // 2 0 16 times per chip 245 246 // RF69_REG_OOK_AVG 247 #define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_32_PI 0b00000000 // 7 6 OOK average filter coefficient: chip rate / 32*pi 248 #define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_8_PI 0b01000000 // 7 6 chip rate / 8*pi 249 #define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_4_PI 0b10000000 // 7 6 chip rate / 4*pi (default) 250 #define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_2_PI 0b11000000 // 7 6 chip rate / 2*pi 251 252 // RF69_REG_OOK_FIX 253 #define RADIOLIB_RF69_OOK_FIXED_THRESH 0b00000110 // 7 0 default OOK fixed threshold (6 dB) 254 255 // RF69_REG_AFC_FEI 256 #define RADIOLIB_RF69_FEI_RUNNING 0b00000000 // 6 6 FEI status: on-going 257 #define RADIOLIB_RF69_FEI_DONE 0b01000000 // 6 6 done 258 #define RADIOLIB_RF69_FEI_START 0b00100000 // 5 5 force new FEI measurement 259 #define RADIOLIB_RF69_AFC_RUNNING 0b00000000 // 4 4 AFC status: on-going 260 #define RADIOLIB_RF69_AFC_DONE 0b00010000 // 4 4 done 261 #define RADIOLIB_RF69_AFC_AUTOCLEAR_OFF 0b00000000 // 3 3 AFC register autoclear disabled 262 #define RADIOLIB_RF69_AFC_AUTOCLEAR_ON 0b00001000 // 3 3 AFC register autoclear enabled 263 #define RADIOLIB_RF69_AFC_AUTO_OFF 0b00000000 // 2 2 perform AFC only manually 264 #define RADIOLIB_RF69_AFC_AUTO_ON 0b00000100 // 2 2 perform AFC each time Rx mode is started 265 #define RADIOLIB_RF69_AFC_CLEAR 0b00000010 // 1 1 clear AFC register 266 #define RADIOLIB_RF69_AFC_START 0b00000001 // 0 0 start AFC 267 268 // RF69_REG_RSSI_CONFIG 269 #define RADIOLIB_RF69_RSSI_RUNNING 0b00000000 // 1 1 RSSI status: on-going 270 #define RADIOLIB_RF69_RSSI_DONE 0b00000010 // 1 1 done 271 #define RADIOLIB_RF69_RSSI_START 0b00000001 // 0 0 start RSSI measurement 272 273 // RF69_REG_DIO_MAPPING_1 274 #define RADIOLIB_RF69_DIO0_CONT_MODE_READY 0b11000000 // 7 6 275 #define RADIOLIB_RF69_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6 276 #define RADIOLIB_RF69_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6 277 #define RADIOLIB_RF69_DIO0_CONT_TIMEOUT 0b01000000 // 7 6 278 #define RADIOLIB_RF69_DIO0_CONT_RSSI 0b10000000 // 7 6 279 #define RADIOLIB_RF69_DIO0_CONT_TX_READY 0b01000000 // 7 6 280 #define RADIOLIB_RF69_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6 281 #define RADIOLIB_RF69_DIO0_PACK_CRC_OK 0b00000000 // 7 6 282 #define RADIOLIB_RF69_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6 283 #define RADIOLIB_RF69_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6 284 #define RADIOLIB_RF69_DIO0_PACK_RSSI 0b11000000 // 7 6 285 #define RADIOLIB_RF69_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6 286 #define RADIOLIB_RF69_DIO0_PACK_TX_READY 0b01000000 // 7 6 287 #define RADIOLIB_RF69_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4 288 #define RADIOLIB_RF69_DIO1_CONT_DCLK 0b00000000 // 5 4 289 #define RADIOLIB_RF69_DIO1_CONT_RX_READY 0b00010000 // 5 4 290 #define RADIOLIB_RF69_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4 291 #define RADIOLIB_RF69_DIO1_CONT_TX_READY 0b00010000 // 5 4 292 #define RADIOLIB_RF69_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4 293 #define RADIOLIB_RF69_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4 294 #define RADIOLIB_RF69_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4 295 #define RADIOLIB_RF69_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4 296 #define RADIOLIB_RF69_DIO1_PACK_TIMEOUT 0b00110000 // 5 4 297 #define RADIOLIB_RF69_DIO2_CONT_DATA 0b00000000 // 3 2 298 #define RADIOLIB_RF69_DIO2_PACK_FIFO_NOT_EMPTY 0b00000000 // 3 2 299 #define RADIOLIB_RF69_DIO2_PACK_AUTO_MODE 0b00001100 // 3 2 300 #define RADIOLIB_RF69_DIO2_PACK_DATA 0b00000100 // 3 2 301 #define RADIOLIB_RF69_DIO3_CONT_AUTO_MODE 0b00000010 // 0 1 302 #define RADIOLIB_RF69_DIO3_CONT_RSSI 0b00000000 // 0 1 303 #define RADIOLIB_RF69_DIO3_CONT_RX_READY 0b00000001 // 0 1 304 #define RADIOLIB_RF69_DIO3_CONT_TIMEOUT 0b00000011 // 0 1 305 #define RADIOLIB_RF69_DIO3_CONT_TX_READY 0b00000001 // 0 1 306 #define RADIOLIB_RF69_DIO3_PACK_FIFO_FULL 0b00000000 // 0 1 307 #define RADIOLIB_RF69_DIO3_PACK_PLL_LOCK 0b00000011 // 0 1 308 #define RADIOLIB_RF69_DIO3_PACK_RSSI 0b00000001 // 0 1 309 #define RADIOLIB_RF69_DIO3_PACK_SYNC_ADDRESSS 0b00000010 // 0 1 310 #define RADIOLIB_RF69_DIO3_PACK_TX_READY 0b00000001 // 0 1 311 312 // RF69_REG_DIO_MAPPING_2 313 #define RADIOLIB_RF69_DIO4_CONT_PLL_LOCK 0b11000000 // 7 6 314 #define RADIOLIB_RF69_DIO4_CONT_TIMEOUT 0b00000000 // 7 6 315 #define RADIOLIB_RF69_DIO4_CONT_RX_READY 0b01000000 // 7 6 316 #define RADIOLIB_RF69_DIO4_CONT_SYNC_ADDRESS 0b10000000 // 7 6 317 #define RADIOLIB_RF69_DIO4_CONT_TX_READY 0b01000000 // 7 6 318 #define RADIOLIB_RF69_DIO4_PACK_PLL_LOCK 0b11000000 // 7 6 319 #define RADIOLIB_RF69_DIO4_PACK_TIMEOUT 0b00000000 // 7 6 320 #define RADIOLIB_RF69_DIO4_PACK_RSSI 0b01000000 // 7 6 321 #define RADIOLIB_RF69_DIO4_PACK_RX_READY 0b10000000 // 7 6 322 #define RADIOLIB_RF69_DIO4_PACK_MODE_READY 0b00000000 // 7 6 323 #define RADIOLIB_RF69_DIO4_PACK_TX_READY 0b01000000 // 7 6 324 #define RADIOLIB_RF69_DIO5_CONT_MODE_READY 0b00110000 // 5 4 325 #define RADIOLIB_RF69_DIO5_CONT_CLK_OUT 0b00000000 // 5 4 326 #define RADIOLIB_RF69_DIO5_CONT_RSSI 0b00010000 // 5 4 327 #define RADIOLIB_RF69_DIO5_PACK_MODE_READY 0b00110000 // 5 4 328 #define RADIOLIB_RF69_DIO5_PACK_CLK_OUT 0b00000000 // 5 4 329 #define RADIOLIB_RF69_DIO5_PACK_DATA 0b00010000 // 5 4 330 #define RADIOLIB_RF69_CLK_OUT_FXOSC 0b00000000 // 2 0 ClkOut frequency: F(XOSC) 331 #define RADIOLIB_RF69_CLK_OUT_FXOSC_2 0b00000001 // 2 0 F(XOSC) / 2 332 #define RADIOLIB_RF69_CLK_OUT_FXOSC_4 0b00000010 // 2 0 F(XOSC) / 4 333 #define RADIOLIB_RF69_CLK_OUT_FXOSC_8 0b00000011 // 2 0 F(XOSC) / 8 334 #define RADIOLIB_RF69_CLK_OUT_FXOSC_16 0b00000100 // 2 0 F(XOSC) / 16 335 #define RADIOLIB_RF69_CLK_OUT_FXOSC_32 0b00000101 // 2 0 F(XOSC) / 31 336 #define RADIOLIB_RF69_CLK_OUT_RC 0b00000110 // 2 0 RC 337 #define RADIOLIB_RF69_CLK_OUT_OFF 0b00000111 // 2 0 disabled (default) 338 339 // RF69_REG_IRQ_FLAGS_1 340 #define RADIOLIB_RF69_IRQ_MODE_READY 0b10000000 // 7 7 requested mode was set 341 #define RADIOLIB_RF69_IRQ_RX_READY 0b01000000 // 6 6 Rx mode ready 342 #define RADIOLIB_RF69_IRQ_TX_READY 0b00100000 // 5 5 Tx mode ready 343 #define RADIOLIB_RF69_IRQ_PLL_LOCK 0b00010000 // 4 4 PLL is locked 344 #define RADIOLIB_RF69_IRQ_RSSI 0b00001000 // 3 3 RSSI value exceeded RssiThreshold 345 #define RADIOLIB_RF69_IRQ_TIMEOUT 0b00000100 // 2 2 timeout occurred 346 #define RADIOLIB_RF69_IRQ_AUTO_MODE 0b00000010 // 1 1 entered intermediate mode 347 #define RADIOLIB_RF69_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address detected 348 349 // RF69_REG_IRQ_FLAGS_2 350 #define RADIOLIB_RF69_IRQ_FIFO_FULL 0b10000000 // 7 7 FIFO is full 351 #define RADIOLIB_RF69_IRQ_FIFO_NOT_EMPTY 0b01000000 // 6 6 FIFO contains at least 1 byte 352 #define RADIOLIB_RF69_IRQ_FIFO_LEVEL 0b00100000 // 5 5 FIFO contains more than FifoThreshold bytes 353 #define RADIOLIB_RF69_IRQ_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred 354 #define RADIOLIB_RF69_IRQ_PACKET_SENT 0b00001000 // 3 3 packet was sent 355 #define RADIOLIB_RF69_IRQ_PAYLOAD_READY 0b00000100 // 2 2 last payload byte received and CRC check passed 356 #define RADIOLIB_RF69_IRQ_CRC_OK 0b00000010 // 1 1 CRC check passed 357 358 // RF69_REG_RSSI_THRESH 359 #define RADIOLIB_RF69_RSSI_THRESHOLD 0xE4 // 7 0 RSSI threshold level (2 dB by default) 360 361 // RF69_REG_RX_TIMEOUT_1 362 #define RADIOLIB_RF69_TIMEOUT_RX_START_OFF 0x00 // 7 0 RSSI interrupt timeout disabled (default) 363 #define RADIOLIB_RF69_TIMEOUT_RX_START 0xFF // 7 0 timeout will occur if RSSI interrupt is not received 364 365 // RF69_REG_RX_TIMEOUT_2 366 #define RADIOLIB_RF69_TIMEOUT_RSSI_THRESH_OFF 0x00 // 7 0 PayloadReady interrupt timeout disabled (default) 367 #define RADIOLIB_RF69_TIMEOUT_RSSI_THRESH 0xFF // 7 0 timeout will occur if PayloadReady interrupt is not received 368 369 // RF69_REG_PREAMBLE_MSB + REG_PREAMBLE_MSB 370 #define RADIOLIB_RF69_PREAMBLE_MSB 0x00 // 7 0 2-byte preamble size value 371 #define RADIOLIB_RF69_PREAMBLE_LSB 0x03 // 7 0 372 373 // RF69_REG_SYNC_CONFIG 374 #define RADIOLIB_RF69_SYNC_OFF 0b00000000 // 7 7 sync word detection off 375 #define RADIOLIB_RF69_SYNC_ON 0b10000000 // 7 7 sync word detection on (default) 376 #define RADIOLIB_RF69_FIFO_FILL_CONDITION_SYNC 0b00000000 // 6 6 FIFO fill condition: on SyncAddress interrupt (default) 377 #define RADIOLIB_RF69_FIFO_FILL_CONDITION 0b01000000 // 6 6 as long as the bit is set 378 #define RADIOLIB_RF69_SYNC_SIZE 0b00001000 // 5 3 size of sync word: SyncSize + 1 bytes 379 #define RADIOLIB_RF69_SYNC_TOL 0b00000000 // 2 0 number of tolerated errors in sync word 380 381 // RF69_REG_SYNC_VALUE_1 - SYNC_VALUE_8 382 #define RADIOLIB_RF69_SYNC_BYTE_1 0x01 // 7 0 sync word: 1st byte (MSB) 383 #define RADIOLIB_RF69_SYNC_BYTE_2 0x01 // 7 0 2nd byte 384 #define RADIOLIB_RF69_SYNC_BYTE_3 0x01 // 7 0 3rd byte 385 #define RADIOLIB_RF69_SYNC_BYTE_4 0x01 // 7 0 4th byte 386 #define RADIOLIB_RF69_SYNC_BYTE_5 0x01 // 7 0 5th byte 387 #define RADIOLIB_RF69_SYNC_BYTE_6 0x01 // 7 0 6th byte 388 #define RADIOLIB_RF69_SYNC_BYTE_7 0x01 // 7 0 7th byte 389 #define RADIOLIB_RF69_SYNC_BYTE_8 0x01 // 7 0 8th byte (LSB) 390 391 // RF69_REG_PACKET_CONFIG_1 392 #define RADIOLIB_RF69_PACKET_FORMAT_FIXED 0b00000000 // 7 7 fixed packet length (default) 393 #define RADIOLIB_RF69_PACKET_FORMAT_VARIABLE 0b10000000 // 7 7 variable packet length 394 #define RADIOLIB_RF69_DC_FREE_NONE 0b00000000 // 6 5 DC-free encoding: none (default) 395 #define RADIOLIB_RF69_DC_FREE_MANCHESTER 0b00100000 // 6 5 Manchester 396 #define RADIOLIB_RF69_DC_FREE_WHITENING 0b01000000 // 6 5 Whitening 397 #define RADIOLIB_RF69_CRC_OFF 0b00000000 // 4 4 CRC disabled 398 #define RADIOLIB_RF69_CRC_ON 0b00010000 // 4 4 CRC enabled (default) 399 #define RADIOLIB_RF69_CRC_AUTOCLEAR_ON 0b00000000 // 3 3 discard packet when CRC check fails (default) 400 #define RADIOLIB_RF69_CRC_AUTOCLEAR_OFF 0b00001000 // 3 3 keep packet when CRC check fails 401 #define RADIOLIB_RF69_ADDRESS_FILTERING_OFF 0b00000000 // 2 1 address filtering: none (default) 402 #define RADIOLIB_RF69_ADDRESS_FILTERING_NODE 0b00000010 // 2 1 node 403 #define RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST 0b00000100 // 2 1 node or broadcast 404 405 // RF69_REG_PAYLOAD_LENGTH 406 #define RADIOLIB_RF69_PAYLOAD_LENGTH 0xFF // 7 0 payload length 407 408 // RF69_REG_AUTO_MODES 409 #define RADIOLIB_RF69_ENTER_COND_NONE 0b00000000 // 7 5 condition for entering intermediate mode: none, AutoModes disabled (default) 410 #define RADIOLIB_RF69_ENTER_COND_FIFO_NOT_EMPTY 0b00100000 // 7 5 FifoNotEmpty rising edge 411 #define RADIOLIB_RF69_ENTER_COND_FIFO_LEVEL 0b01000000 // 7 5 FifoLevel rising edge 412 #define RADIOLIB_RF69_ENTER_COND_CRC_OK 0b01100000 // 7 5 CrcOk rising edge 413 #define RADIOLIB_RF69_ENTER_COND_PAYLOAD_READY 0b10000000 // 7 5 PayloadReady rising edge 414 #define RADIOLIB_RF69_ENTER_COND_SYNC_ADDRESS 0b10100000 // 7 5 SyncAddress rising edge 415 #define RADIOLIB_RF69_ENTER_COND_PACKET_SENT 0b11000000 // 7 5 PacketSent rising edge 416 #define RADIOLIB_RF69_ENTER_COND_FIFO_EMPTY 0b11100000 // 7 5 FifoNotEmpty falling edge 417 #define RADIOLIB_RF69_EXIT_COND_NONE 0b00000000 // 4 2 condition for exiting intermediate mode: none, AutoModes disabled (default) 418 #define RADIOLIB_RF69_EXIT_COND_FIFO_EMPTY 0b00100000 // 4 2 FifoNotEmpty falling edge 419 #define RADIOLIB_RF69_EXIT_COND_FIFO_LEVEL 0b01000000 // 4 2 FifoLevel rising edge 420 #define RADIOLIB_RF69_EXIT_COND_CRC_OK 0b01100000 // 4 2 CrcOk rising edge 421 #define RADIOLIB_RF69_EXIT_COND_PAYLOAD_READY 0b10000000 // 4 2 PayloadReady rising edge 422 #define RADIOLIB_RF69_EXIT_COND_SYNC_ADDRESS 0b10100000 // 4 2 SyncAddress rising edge 423 #define RADIOLIB_RF69_EXIT_COND_PACKET_SENT 0b11000000 // 4 2 PacketSent rising edge 424 #define RADIOLIB_RF69_EXIT_COND_TIMEOUT 0b11100000 // 4 2 timeout rising edge 425 #define RADIOLIB_RF69_INTER_MODE_SLEEP 0b00000000 // 1 0 intermediate mode: sleep (default) 426 #define RADIOLIB_RF69_INTER_MODE_STANDBY 0b00000001 // 1 0 standby 427 #define RADIOLIB_RF69_INTER_MODE_RX 0b00000010 // 1 0 Rx 428 #define RADIOLIB_RF69_INTER_MODE_TX 0b00000011 // 1 0 Tx 429 430 // RF69_REG_FIFO_THRESH 431 #define RADIOLIB_RF69_TX_START_CONDITION_FIFO_LEVEL 0b00000000 // 7 7 packet transmission start condition: FifoLevel 432 #define RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY 0b10000000 // 7 7 FifoNotEmpty (default) 433 #define RADIOLIB_RF69_FIFO_THRESH 0x1F // 6 0 default threshold to trigger FifoLevel interrupt 434 435 // RF69_REG_PACKET_CONFIG_2 436 #define RADIOLIB_RF69_INTER_PACKET_RX_DELAY 0b00000000 // 7 4 delay between FIFO empty and start of new RSSI phase 437 #define RADIOLIB_RF69_RESTART_RX 0b00000100 // 2 2 force receiver into wait mode 438 #define RADIOLIB_RF69_AUTO_RX_RESTART_OFF 0b00000000 // 1 1 auto Rx restart disabled 439 #define RADIOLIB_RF69_AUTO_RX_RESTART_ON 0b00000010 // 1 1 auto Rx restart enabled (default) 440 #define RADIOLIB_RF69_AES_OFF 0b00000000 // 0 0 AES encryption disabled (default) 441 #define RADIOLIB_RF69_AES_ON 0b00000001 // 0 0 AES encryption enabled, payload size limited to 66 bytes 442 443 // RF69_REG_TEST_LNA 444 #define RADIOLIB_RF69_TEST_LNA_BOOST_NORMAL 0x1B // 7 0 445 #define RADIOLIB_RF69_TEST_LNA_BOOST_HIGH 0x2D // 7 0 446 447 // RF69_REG_TEMP_1 448 #define RADIOLIB_RF69_TEMP_MEAS_START 0b00001000 // 3 3 trigger temperature measurement 449 #define RADIOLIB_RF69_TEMP_MEAS_RUNNING 0b00000100 // 2 2 temperature measurement status: on-going 450 #define RADIOLIB_RF69_TEMP_MEAS_DONE 0b00000000 // 2 2 done 451 452 // RF69_REG_TEST_DAGC 453 #define RADIOLIB_RF69_CONTINUOUS_DAGC_NORMAL 0x00 // 7 0 fading margin improvement: normal mode 454 #define RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_ON 0x20 // 7 0 improved mode for AfcLowBetaOn 455 #define RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_OFF 0x30 // 7 0 improved mode for AfcLowBetaOff (default) 456 457 // RF69_REG_TEST_PA1 458 #define RADIOLIB_RF69_PA1_NORMAL 0x55 // 7 0 PA_BOOST: none 459 #define RADIOLIB_RF69_PA1_20_DBM 0x5D // 7 0 +20 dBm 460 461 // RF69_REG_TEST_PA2 462 #define RADIOLIB_RF69_PA2_NORMAL 0x70 // 7 0 PA_BOOST: none 463 #define RADIOLIB_RF69_PA2_20_DBM 0x7C // 7 0 +20 dBm 464 465 /*! 466 \class RF69 467 468 \brief Control class for %RF69 module. Also serves as base class for SX1231. 469 */ 470 class RF69: public PhysicalLayer { 471 public: 472 // introduce PhysicalLayer overloads 473 using PhysicalLayer::transmit; 474 using PhysicalLayer::receive; 475 using PhysicalLayer::startTransmit; 476 using PhysicalLayer::readData; 477 478 /*! 479 \brief Default constructor. 480 481 \param mod Instance of Module that will be used to communicate with the radio. 482 */ 483 RF69(Module* module); 484 485 Module* getMod(); 486 487 // basic methods 488 489 /*! 490 \brief Initialization method. 491 492 \param freq Carrier frequency in MHz. Defaults to 434.0 MHz. 493 494 \param br Bit rate to be used in kbps. Defaults to 4.8 kbps. 495 496 \param freqDev Frequency deviation from carrier frequency in kHz Defaults to 5.0 kHz. 497 498 \param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz. 499 500 \param power Output power in dBm. Defaults to 10 dBm. 501 502 \param preambleLen Preamble Length in bits. Defaults to 16 bits. 503 504 \returns \ref status_codes 505 */ 506 int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16); 507 508 /*! 509 \brief Reset method. Will reset the chip to the default state using RST pin. 510 */ 511 void reset(); 512 513 /*! 514 \brief Blocking binary transmit method. 515 Overloads for string-based transmissions are implemented in PhysicalLayer. 516 517 \param data Binary data to be sent. 518 519 \param len Number of bytes to send. 520 521 \param addr Address to send the data to. Will only be added if address filtering was enabled. 522 523 \returns \ref status_codes 524 */ 525 int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override; 526 527 /*! 528 \brief Blocking binary receive method. 529 Overloads for string-based transmissions are implemented in PhysicalLayer. 530 531 \param data Binary data to be sent. 532 533 \param len Number of bytes to send. 534 535 \returns \ref status_codes 536 */ 537 int16_t receive(uint8_t* data, size_t len) override; 538 539 /*! 540 \brief Sets the module to sleep mode. 541 542 \returns \ref status_codes 543 */ 544 int16_t sleep(); 545 546 /*! 547 \brief Sets the module to standby mode. 548 549 \returns \ref status_codes 550 */ 551 int16_t standby() override; 552 553 /*! 554 \brief Starts direct mode transmission. 555 556 \param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY. 557 558 \returns \ref status_codes 559 */ 560 int16_t transmitDirect(uint32_t frf = 0) override; 561 562 /*! 563 \brief Starts direct mode reception. 564 565 \returns \ref status_codes 566 */ 567 int16_t receiveDirect() override; 568 569 /*! 570 \brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions. 571 */ 572 int16_t packetMode(); 573 574 // hardware AES support 575 576 /*! 577 \brief Sets AES key. 578 579 \param Key to be used for AES encryption. Must be exactly 16 bytes long. 580 */ 581 void setAESKey(uint8_t* key); 582 583 /*! 584 \brief Enables AES encryption. 585 586 \returns \ref status_codes 587 */ 588 int16_t enableAES(); 589 590 /*! 591 \brief Disables AES encryption. 592 593 \returns \ref status_codes 594 */ 595 int16_t disableAES(); 596 597 // interrupt methods 598 599 /*! 600 \brief Sets interrupt service routine to call when DIO0 activates. 601 602 \param func ISR to call. 603 */ 604 void setDio0Action(void (*func)(void)); 605 606 /*! 607 \brief Clears interrupt service routine to call when DIO0 activates. 608 */ 609 void clearDio0Action(); 610 611 /*! 612 \brief Sets interrupt service routine to call when DIO1 activates. 613 614 \param func ISR to call. 615 */ 616 void setDio1Action(void (*func)(void)); 617 618 /*! 619 \brief Clears interrupt service routine to call when DIO1 activates. 620 */ 621 void clearDio1Action(); 622 623 /*! 624 \brief Set interrupt service routine function to call when FIFO is empty. 625 626 \param func Pointer to interrupt service routine. 627 */ 628 void setFifoEmptyAction(void (*func)(void)); 629 630 /*! 631 \brief Clears interrupt service routine to call when FIFO is empty. 632 */ 633 void clearFifoEmptyAction(); 634 635 /*! 636 \brief Set interrupt service routine function to call when FIFO is full. 637 638 \param func Pointer to interrupt service routine. 639 */ 640 void setFifoFullAction(void (*func)(void)); 641 642 /*! 643 \brief Clears interrupt service routine to call when FIFO is full. 644 */ 645 void clearFifoFullAction(); 646 647 /*! 648 \brief Set interrupt service routine function to call when FIFO is empty. 649 650 \param data Pointer to the transmission buffer. 651 652 \param totalLen Total number of bytes to transmit. 653 654 \param remLen Pointer to a counter holding the number of bytes that have been transmitted so far. 655 656 \returns True when a complete packet is sent, false if more data is needed. 657 */ 658 bool fifoAdd(uint8_t* data, int totalLen, volatile int* remLen); 659 660 /*! 661 \brief Set interrupt service routine function to call when FIFO is sufficently full to read. 662 663 \param data Pointer to a buffer that stores the receive data. 664 665 \param totalLen Total number of bytes to receive. 666 667 \param rcvLen Pointer to a counter holding the number of bytes that have been received so far. 668 669 \returns True when a complete packet is received, false if more data is needed. 670 */ 671 bool fifoGet(volatile uint8_t* data, int totalLen, volatile int* rcvLen); 672 673 /*! 674 \brief Interrupt-driven binary transmit method. 675 Overloads for string-based transmissions are implemented in PhysicalLayer. 676 677 \param data Binary data to be sent. 678 679 \param len Number of bytes to send. 680 681 \param addr Address to send the data to. Will only be added if address filtering was enabled. 682 683 \returns \ref status_codes 684 */ 685 int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; 686 687 /*! 688 \brief Interrupt-driven receive method. GDO0 will be activated when full packet is received. 689 690 \returns \ref status_codes 691 */ 692 int16_t startReceive(); 693 694 /*! 695 \brief Reads data received after calling startReceive method. 696 697 \param data Pointer to array to save the received binary data. 698 699 \param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically. 700 When more bytes than received are requested, only the number of bytes requested will be returned. 701 702 \returns \ref status_codes 703 */ 704 int16_t readData(uint8_t* data, size_t len) override; 705 706 // configuration methods 707 708 /*! 709 \brief Sets carrier frequency. Allowed values are in bands 290.0 to 340.0 MHz, 431.0 to 510.0 MHz and 862.0 to 1020.0 MHz. 710 711 \param freq Carrier frequency to be set in MHz. 712 713 \returns \ref status_codes 714 */ 715 int16_t setFrequency(float freq); 716 717 /*! 718 \brief Sets bit rate. Allowed values range from 1.2 to 300.0 kbps. 719 720 \param br Bit rate to be set in kbps. 721 722 \returns \ref status_codes 723 */ 724 int16_t setBitRate(float br); 725 726 /*! 727 \brief Sets receiver bandwidth. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25.0, 31.3, 41.7, 50.0, 62.5, 83.3, 100.0, 125.0, 166.7, 200.0, 250.0, 333.3, 400.0 and 500.0 kHz. 728 729 \param rxBw Receiver bandwidth to be set in kHz. 730 731 \returns \ref status_codes 732 */ 733 int16_t setRxBandwidth(float rxBw); 734 735 /*! 736 \brief Sets frequency deviation. 737 738 \param freqDev Frequency deviation to be set in kHz. 739 740 \returns \ref status_codes 741 */ 742 int16_t setFrequencyDeviation(float freqDev) override; 743 744 /*! 745 \brief Sets output power. Allowed values range from -18 to 13 dBm for low power modules (RF69C/CW) or -2 to 20 dBm (RF69H/HC/HCW). 746 747 \param power Output power to be set in dBm. 748 749 \param highPower Set to true when using modules high power port (RF69H/HC/HCW). Defaults to false (models without high power port - RF69C/CW). 750 751 \returns \ref status_codes 752 */ 753 int16_t setOutputPower(int8_t power, bool highPower = false); 754 755 /*! 756 \brief Sets sync word. Up to 8 bytes can be set as sync word. 757 758 \param syncWord Pointer to the array of sync word bytes. 759 760 \param len Sync word length in bytes. 761 762 \param maxErrBits Maximum allowed number of bit errors in received sync word. Defaults to 0. 763 */ 764 int16_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0); 765 766 /*! 767 \brief Sets preamble length. 768 769 \param preambleLen Preamble length to be set (in bits), allowed values: 16, 24, 32, 48, 64, 96, 128 and 192. 770 771 \returns \ref status_codes 772 */ 773 int16_t setPreambleLength(uint8_t preambleLen); 774 775 /*! 776 \brief Sets node address. Calling this method will also enable address filtering for node address only. 777 778 \param nodeAddr Node address to be set. 779 780 \returns \ref status_codes 781 */ 782 int16_t setNodeAddress(uint8_t nodeAddr); 783 784 /*! 785 \brief Sets broadcast address. Calling this method will also enable address filtering for node and broadcast address. 786 787 \param broadAddr Node address to be set. 788 789 \returns \ref status_codes 790 */ 791 int16_t setBroadcastAddress(uint8_t broadAddr); 792 793 /*! 794 \brief Disables address filtering. Calling this method will also erase previously set addresses. 795 796 \returns \ref status_codes 797 */ 798 int16_t disableAddressFiltering(); 799 800 // measurement methods 801 802 /*! 803 \brief Sets ambient temperature. Required to correct values from on-board temperature sensor. 804 805 \param tempAmbient Ambient temperature in degrees Celsius. 806 */ 807 void setAmbientTemperature(int16_t tempAmbient); 808 809 /*! 810 \brief Measures temperature. 811 812 \returns Measured temperature in degrees Celsius. 813 */ 814 int16_t getTemperature(); 815 816 /*! 817 \brief Query modem for the packet length of received payload. 818 819 \param update Update received packet length. Will return cached value when set to false. 820 821 \returns Length of last received packet in bytes. 822 */ 823 size_t getPacketLength(bool update = true) override; 824 825 /*! 826 \brief Enables/disables OOK modulation instead of FSK. 827 Note: This function calls setRxBandwidth again, since register values differ based on OOK mode being enabled/disabled 828 829 \param enableOOK Enable (true) or disable (false) OOK. 830 831 \returns \ref status_codes 832 */ 833 int16_t setOOK(bool enableOOK); 834 835 /*! 836 \brief Selects the type of threshold in the OOK data slicer 837 838 \param type Threshold type: RADIOLIB_RF69_OOK_THRESH_PEAK(default), RADIOLIB_RF69_OOK_THRESH_FIXED or RADIOLIB_RF69_OOK_THRESH_AVERAGE 839 840 \returns \ref status_codes 841 */ 842 int16_t setOokThresholdType(uint8_t type); 843 844 /*! 845 \brief Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used. 846 847 \param value Fixed threshold value (in dB) in the OOK demodulator. Used when OokThresType = RADIOLIB_RF69_OOK_THRESH_FIXED. 848 849 \returns \ref status_codes 850 */ 851 int16_t setOokFixedThreshold(uint8_t value); 852 853 /*! 854 \brief Period of decrement of the RSSI threshold in the OOK demodulator. 855 856 \param value Use defines RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_X_X_CHIP 857 858 \returns \ref status_codes 859 */ 860 int16_t setOokPeakThresholdDecrement(uint8_t value); 861 862 /*! 863 \brief Set modem in fixed packet length mode. 864 865 \param len Packet length. 866 867 \returns \ref status_codes 868 */ 869 int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_RF69_MAX_PACKET_LENGTH); 870 871 /*! 872 \brief Set modem in variable packet length mode. 873 874 \param len Maximum packet length. 875 876 \returns \ref status_codes 877 */ 878 int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_RF69_MAX_PACKET_LENGTH); 879 880 /*! 881 \brief Enable sync word filtering and generation. 882 883 \param numBits Sync word length in bits. 884 885 \returns \ref status_codes 886 */ 887 int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0); 888 889 /*! 890 \brief Disable preamble and sync word filtering and generation. 891 892 \returns \ref status_codes 893 */ 894 int16_t disableSyncWordFiltering(); 895 896 /*! 897 \brief Enable Bit synchronization in continuous mode. 898 899 \returns \ref status_codes 900 */ 901 int16_t enableContinuousModeBitSync(); 902 903 /*! 904 \brief Disable Bit synchronization in continuous mode. 905 906 \returns \ref status_codes 907 */ 908 int16_t disableContinuousModeBitSync(); 909 910 /*! 911 \brief Enable CRC filtering and generation. 912 913 \param crcOn Set or unset CRC filtering. 914 915 \returns \ref status_codes 916 */ 917 int16_t setCrcFiltering(bool crcOn = true); 918 919 /*! 920 \brief Set modem in "sniff" mode: no packet filtering (e.g., no preamble, sync word, address, CRC). 921 922 \param promiscuous Set or unset promiscuous mode. 923 924 \returns \ref status_codes 925 */ 926 int16_t setPromiscuousMode(bool promiscuous = true); 927 928 /*! 929 \brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. 930 Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. 931 932 \param sh Gaussian shaping bandwidth-time product that will be used for data shaping 933 934 \returns \ref status_codes 935 */ 936 int16_t setDataShaping(uint8_t sh) override; 937 938 /*! 939 \brief Sets transmission encoding. 940 Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. 941 942 \param encoding Encoding to be used. 943 944 \returns \ref status_codes 945 */ 946 int16_t setEncoding(uint8_t encoding) override; 947 948 /*! 949 \brief Enable/disable LNA Boost mode (disabled by default). 950 951 \param value True to enable, false to disable. 952 953 \returns \ref status_codes 954 */ 955 int16_t setLnaTestBoost(bool value); 956 957 /*! 958 \brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. 959 960 \returns Last packet RSSI in dBm. 961 */ 962 float getRSSI(); 963 964 /*! 965 \brief Sets the RSSI value above which the RSSI interrupt is signaled 966 967 \param dbm A dBm value between -127.5 and 0 inclusive 968 969 \returns \ref status_codes 970 */ 971 int16_t setRSSIThreshold(float dbm); 972 973 /*! 974 \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. 975 When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch! 976 977 \param rxEn RX enable pin. 978 979 \param txEn TX enable pin. 980 */ 981 void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn); 982 983 /*! 984 \brief Get one truly random byte from RSSI noise. 985 986 \returns TRNG byte. 987 */ 988 uint8_t randomByte(); 989 990 /*! 991 \brief Read version SPI register. Should return RF69_CHIP_VERSION (0x24) if SX127x is connected and working. 992 993 \returns Version register contents or \ref status_codes 994 */ 995 int16_t getChipVersion(); 996 997 #if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE) 998 /*! 999 \brief Set interrupt service routine function to call when data bit is receveid in direct mode. 1000 1001 \param func Pointer to interrupt service routine. 1002 */ 1003 void setDirectAction(void (*func)(void)); 1004 1005 /*! 1006 \brief Function to read and process data bit in direct reception mode. 1007 1008 \param pin Pin on which to read. 1009 */ 1010 void readBit(RADIOLIB_PIN_TYPE pin); 1011 #endif 1012 1013 /*! 1014 \brief Configure DIO pin mapping to get a given signal on a DIO pin (if available). 1015 1016 \param pin Pin number onto which a signal is to be placed. 1017 1018 \param value The value that indicates which function to place on that pin. See chip datasheet for details. 1019 1020 \returns \ref status_codes 1021 */ 1022 int16_t setDIOMapping(RADIOLIB_PIN_TYPE pin, uint8_t value); 1023 1024 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL) 1025 protected: 1026 #endif 1027 Module* _mod; 1028 1029 #if !defined(RADIOLIB_GODMODE) 1030 protected: 1031 #endif 1032 1033 float _freq = 0; 1034 float _br = 0; 1035 float _rxBw = 0; 1036 bool _ook = false; 1037 int16_t _tempOffset = 0; 1038 int8_t _power = 0; 1039 1040 size_t _packetLength = 0; 1041 bool _packetLengthQueried = false; 1042 uint8_t _packetLengthConfig = RADIOLIB_RF69_PACKET_FORMAT_VARIABLE; 1043 1044 bool _promiscuous = false; 1045 1046 uint8_t _syncWordLength = 2; 1047 1048 bool _bitSync = true; 1049 1050 int16_t config(); 1051 int16_t directMode(); 1052 int16_t setPacketMode(uint8_t mode, uint8_t len); 1053 1054 #if !defined(RADIOLIB_GODMODE) 1055 private: 1056 #endif 1057 int16_t setMode(uint8_t mode); 1058 void clearIRQFlags(); 1059 void clearFIFO(size_t count); 1060 }; 1061 1062 #endif 1063 1064 #endif