Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SX1280Lib by
sx1280.h
00001 /* 00002 ______ _ 00003 / _____) _ | | 00004 ( (____ _____ ____ _| |_ _____ ____| |__ 00005 \____ \| ___ | (_ _) ___ |/ ___) _ \ 00006 _____) ) ____| | | || |_| ____( (___| | | | 00007 (______/|_____)_|_|_| \__)_____)\____)_| |_| 00008 (C)2016 Semtech 00009 00010 Description: Driver for SX1280 devices 00011 00012 License: Revised BSD License, see LICENSE.TXT file include in the project 00013 00014 Maintainer: Miguel Luis, Gregory Cristian and Matthieu Verdy 00015 */ 00016 #ifndef __SX1280_H__ 00017 #define __SX1280_H__ 00018 00019 #include "radio.h" 00020 00021 /*! 00022 * \brief Enables/disables driver debug features 00023 */ 00024 #define SX1280_DEBUG 0 00025 00026 /*! 00027 * \brief Hardware IO IRQ callback function definition 00028 */ 00029 class SX1280; 00030 typedef void ( SX1280::*DioIrqHandler )( void ); 00031 00032 /*! 00033 * \brief IRQ triggers callback function definition 00034 */ 00035 class SX1280Hal; 00036 typedef void ( SX1280Hal::*Trigger )( void ); 00037 00038 /*! 00039 * \brief Provides the frequency of the chip running on the radio and the frequency step 00040 * 00041 * \remark These defines are used for computing the frequency divider to set the RF frequency 00042 */ 00043 #define XTAL_FREQ 52000000 00044 #define FREQ_STEP ( ( double )( XTAL_FREQ / pow( 2.0, 18.0 ) ) ) 00045 00046 /*! 00047 * \brief Compensation delay for SetAutoTx method in microseconds 00048 */ 00049 #define AUTO_TX_OFFSET 33 00050 00051 /*! 00052 * \brief The address of the register holding the first byte defining the CRC seed 00053 * 00054 * \remark Only used for packet types GFSK and Flrc 00055 */ 00056 #define REG_LR_CRCSEEDBASEADDR 0x09C8 00057 00058 /*! 00059 * \brief The address of the register holding the first byte defining the CRC polynomial 00060 * 00061 * \remark Only used for packet types GFSK and Flrc 00062 */ 00063 #define REG_LR_CRCPOLYBASEADDR 0x09C6 00064 00065 /*! 00066 * \brief The address of the register holding the first byte defining the whitening seed 00067 * 00068 * \remark Only used for packet types GFSK, FLRC and BLE 00069 */ 00070 #define REG_LR_WHITSEEDBASEADDR 0x09C5 00071 00072 /*! 00073 * \brief The address of the register holding the ranging id check length 00074 * 00075 * \remark Only used for packet type Ranging 00076 */ 00077 #define REG_LR_RANGINGIDCHECKLENGTH 0x0931 00078 00079 /*! 00080 * \brief The address of the register holding the device ranging id 00081 * 00082 * \remark Only used for packet type Ranging 00083 */ 00084 #define REG_LR_DEVICERANGINGADDR 0x0916 00085 00086 /*! 00087 * \brief The address of the register holding the device ranging id 00088 * 00089 * \remark Only used for packet type Ranging 00090 */ 00091 #define REG_LR_REQUESTRANGINGADDR 0x0912 00092 00093 /*! 00094 * \brief The address of the register holding ranging results configuration 00095 * and the corresponding mask 00096 * 00097 * \remark Only used for packet type Ranging 00098 */ 00099 #define REG_LR_RANGINGRESULTCONFIG 0x0924 00100 #define MASK_RANGINGMUXSEL 0xCF 00101 00102 /*! 00103 * \brief The address of the register holding the first byte of ranging results 00104 * Only used for packet type Ranging 00105 */ 00106 #define REG_LR_RANGINGRESULTBASEADDR 0x0961 00107 00108 /*! 00109 * \brief The address of the register allowing to read ranging results 00110 * 00111 * \remark Only used for packet type Ranging 00112 */ 00113 #define REG_LR_RANGINGRESULTSFREEZE 0x097F 00114 00115 /*! 00116 * \brief The address of the register holding the first byte of ranging calibration 00117 * 00118 * \remark Only used for packet type Ranging 00119 */ 00120 #define REG_LR_RANGINGRERXTXDELAYCAL 0x092C 00121 00122 /*! 00123 *\brief The address of the register holding the ranging filter window size 00124 * 00125 * \remark Only used for packet type Ranging 00126 */ 00127 #define REG_LR_RANGINGFILTERWINDOWSIZE 0x091E 00128 00129 /*! 00130 *\brief The address of the register to reset for clearing ranging filter 00131 * 00132 * \remark Only used for packet type Ranging 00133 */ 00134 #define REG_LR_RANGINGRESULTCLEARREG 0x0923 00135 00136 /*! 00137 * \brief The default number of samples considered in built-in ranging filter 00138 */ 00139 #define DEFAULT_RANGING_FILTER_SIZE 127 00140 00141 /*! 00142 * \brief The address of the register holding LORA packet parameters 00143 */ 00144 #define REG_LR_PACKETPARAMS 0x903 00145 00146 /*! 00147 * \brief The address of the register holding payload length 00148 * 00149 * \remark Do NOT try to read it directly. Use GetRxBuffer( ) instead. 00150 */ 00151 #define REG_LR_PAYLOADLENGTH 0x901 00152 00153 /*! 00154 * \brief The addresses of the registers holding SyncWords values 00155 * 00156 * \remark The addresses depends on the Packet Type in use, and not all 00157 * SyncWords are available for every Packet Type 00158 */ 00159 #define REG_LR_SYNCWORDBASEADDRESS1 0x09CE 00160 #define REG_LR_SYNCWORDBASEADDRESS2 0x09D3 00161 #define REG_LR_SYNCWORDBASEADDRESS3 0x09D8 00162 00163 /*! 00164 * \brief The MSB address and mask used to read the estimated frequency 00165 * error 00166 */ 00167 #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MSB 0x0954 00168 #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MASK 0x0FFFFF 00169 00170 /*! 00171 * \brief Defines how many bit errors are tolerated in sync word detection 00172 */ 00173 #define REG_LR_SYNCWORDTOLERANCE 0x09CD 00174 00175 /*! 00176 * \brief Represents the states of the radio 00177 */ 00178 typedef enum 00179 { 00180 RF_IDLE = 0x00, //!< The radio is idle 00181 RF_RX_RUNNING, //!< The radio is in reception state 00182 RF_TX_RUNNING, //!< The radio is in transmission state 00183 RF_CAD, //!< The radio is doing channel activity detection 00184 }RadioStates_t; 00185 00186 /*! 00187 * \brief Represents the operating mode the radio is actually running 00188 */ 00189 typedef enum 00190 { 00191 MODE_SLEEP = 0x00, //! The radio is in sleep mode 00192 MODE_CALIBRATION, //! The radio is in calibration mode 00193 MODE_STDBY_RC, //! The radio is in standby mode with RC oscillator 00194 MODE_STDBY_XOSC, //! The radio is in standby mode with XOSC oscillator 00195 MODE_FS, //! The radio is in frequency synthesis mode 00196 MODE_RX, //! The radio is in receive mode 00197 MODE_TX, //! The radio is in transmit mode 00198 MODE_CAD //! The radio is in channel activity detection mode 00199 }RadioOperatingModes_t; 00200 00201 /*! 00202 * \brief Declares the oscillator in use while in standby mode 00203 * 00204 * Using the STDBY_RC standby mode allow to reduce the energy consumption 00205 * STDBY_XOSC should be used for time critical applications 00206 */ 00207 typedef enum 00208 { 00209 STDBY_RC = 0x00, 00210 STDBY_XOSC = 0x01, 00211 }RadioStandbyModes_t; 00212 00213 /*! 00214 * \brief Declares the power regulation used to power the device 00215 * 00216 * This command allows the user to specify if DC-DC or LDO is used for power regulation. 00217 * Using only LDO implies that the Rx or Tx current is doubled 00218 */ 00219 typedef enum 00220 { 00221 USE_LDO = 0x00, //! Use LDO (default value) 00222 USE_DCDC = 0x01, //! Use DCDC 00223 }RadioRegulatorModes_t; 00224 00225 /*! 00226 * \brief Represents the possible packet type (i.e. modem) used 00227 */ 00228 typedef enum 00229 { 00230 PACKET_TYPE_GFSK = 0x00, 00231 PACKET_TYPE_LORA, 00232 PACKET_TYPE_RANGING, 00233 PACKET_TYPE_FLRC, 00234 PACKET_TYPE_BLE, 00235 PACKET_TYPE_NONE = 0x0F, 00236 }RadioPacketTypes_t; 00237 00238 /*! 00239 * \brief Represents the ramping time for power amplifier 00240 */ 00241 typedef enum 00242 { 00243 RADIO_RAMP_02_US = 0x00, 00244 RADIO_RAMP_04_US = 0x20, 00245 RADIO_RAMP_06_US = 0x40, 00246 RADIO_RAMP_08_US = 0x60, 00247 RADIO_RAMP_10_US = 0x80, 00248 RADIO_RAMP_12_US = 0xA0, 00249 RADIO_RAMP_16_US = 0xC0, 00250 RADIO_RAMP_20_US = 0xE0, 00251 }RadioRampTimes_t; 00252 00253 /*! 00254 * \brief Represents the number of symbols to be used for channel activity detection operation 00255 */ 00256 typedef enum 00257 { 00258 LORA_CAD_01_SYMBOL = 0x00, 00259 LORA_CAD_02_SYMBOL = 0x20, 00260 LORA_CAD_04_SYMBOL = 0x40, 00261 LORA_CAD_08_SYMBOL = 0x60, 00262 LORA_CAD_16_SYMBOL = 0x80, 00263 }RadioLoRaCadSymbols_t; 00264 00265 /*! 00266 * \brief Represents the possible combinations of bitrate and bandwidth for 00267 * GFSK and BLE packet types 00268 * 00269 * The bitrate is expressed in Mb/s and the bandwidth in MHz 00270 */ 00271 typedef enum 00272 { 00273 GFSK_BLE_BR_2_000_BW_2_4 = 0x04, 00274 GFSK_BLE_BR_1_600_BW_2_4 = 0x28, 00275 GFSK_BLE_BR_1_000_BW_2_4 = 0x4C, 00276 GFSK_BLE_BR_1_000_BW_1_2 = 0x45, 00277 GFSK_BLE_BR_0_800_BW_2_4 = 0x70, 00278 GFSK_BLE_BR_0_800_BW_1_2 = 0x69, 00279 GFSK_BLE_BR_0_500_BW_1_2 = 0x8D, 00280 GFSK_BLE_BR_0_500_BW_0_6 = 0x86, 00281 GFSK_BLE_BR_0_400_BW_1_2 = 0xB1, 00282 GFSK_BLE_BR_0_400_BW_0_6 = 0xAA, 00283 GFSK_BLE_BR_0_250_BW_0_6 = 0xCE, 00284 GFSK_BLE_BR_0_250_BW_0_3 = 0xC7, 00285 GFSK_BLE_BR_0_125_BW_0_3 = 0xEF, 00286 }RadioGfskBleBitrates_t; 00287 00288 /*! 00289 * \brief Represents the modulation index used in GFSK and BLE packet 00290 * types 00291 */ 00292 typedef enum 00293 { 00294 GFSK_BLE_MOD_IND_0_35 = 0, 00295 GFSK_BLE_MOD_IND_0_50 = 1, 00296 GFSK_BLE_MOD_IND_0_75 = 2, 00297 GFSK_BLE_MOD_IND_1_00 = 3, 00298 GFSK_BLE_MOD_IND_1_25 = 4, 00299 GFSK_BLE_MOD_IND_1_50 = 5, 00300 GFSK_BLE_MOD_IND_1_75 = 6, 00301 GFSK_BLE_MOD_IND_2_00 = 7, 00302 GFSK_BLE_MOD_IND_2_25 = 8, 00303 GFSK_BLE_MOD_IND_2_50 = 9, 00304 GFSK_BLE_MOD_IND_2_75 = 10, 00305 GFSK_BLE_MOD_IND_3_00 = 11, 00306 GFSK_BLE_MOD_IND_3_25 = 12, 00307 GFSK_BLE_MOD_IND_3_50 = 13, 00308 GFSK_BLE_MOD_IND_3_75 = 14, 00309 GFSK_BLE_MOD_IND_4_00 = 15, 00310 }RadioGfskBleModIndexes_t; 00311 00312 /*! 00313 * \brief Represents the possible combination of bitrate and bandwidth for FLRC 00314 * packet type 00315 * 00316 * The bitrate is in Mb/s and the bitrate in MHz 00317 */ 00318 typedef enum 00319 { 00320 FLRC_BR_1_300_BW_1_2 = 0x45, 00321 FLRC_BR_1_040_BW_1_2 = 0x69, 00322 FLRC_BR_0_650_BW_0_6 = 0x86, 00323 FLRC_BR_0_520_BW_0_6 = 0xAA, 00324 FLRC_BR_0_325_BW_0_3 = 0xC7, 00325 FLRC_BR_0_260_BW_0_3 = 0xEB, 00326 }RadioFlrcBitrates_t; 00327 00328 /*! 00329 * \brief Represents the possible values for coding rate parameter in FLRC 00330 * packet type 00331 */ 00332 typedef enum 00333 { 00334 FLRC_CR_1_2 = 0x00, 00335 FLRC_CR_3_4 = 0x02, 00336 FLRC_CR_1_0 = 0x04, 00337 }RadioFlrcCodingRates_t; 00338 00339 /*! 00340 * \brief Represents the modulation shaping parameter for GFSK, FLRC and BLE 00341 * packet types 00342 */ 00343 typedef enum 00344 { 00345 RADIO_MOD_SHAPING_BT_OFF = 0x00, //! No filtering 00346 RADIO_MOD_SHAPING_BT_1_0 = 0x10, 00347 RADIO_MOD_SHAPING_BT_0_5 = 0x20, 00348 }RadioModShapings_t; 00349 00350 /*! 00351 * \brief Represents the possible spreading factor values in LORA packet types 00352 */ 00353 typedef enum 00354 { 00355 LORA_SF5 = 0x50, 00356 LORA_SF6 = 0x60, 00357 LORA_SF7 = 0x70, 00358 LORA_SF8 = 0x80, 00359 LORA_SF9 = 0x90, 00360 LORA_SF10 = 0xA0, 00361 LORA_SF11 = 0xB0, 00362 LORA_SF12 = 0xC0, 00363 }RadioLoRaSpreadingFactors_t; 00364 00365 /*! 00366 * \brief Represents the bandwidth values for LORA packet type 00367 */ 00368 typedef enum 00369 { 00370 LORA_BW_0200 = 0x34, 00371 LORA_BW_0400 = 0x26, 00372 LORA_BW_0800 = 0x18, 00373 LORA_BW_1600 = 0x0A, 00374 }RadioLoRaBandwidths_t; 00375 00376 /*! 00377 * \brief Represents the coding rate values for LORA packet type 00378 */ 00379 typedef enum 00380 { 00381 LORA_CR_4_5 = 0x01, 00382 LORA_CR_4_6 = 0x02, 00383 LORA_CR_4_7 = 0x03, 00384 LORA_CR_4_8 = 0x04, 00385 LORA_CR_LI_4_5 = 0x05, 00386 LORA_CR_LI_4_6 = 0x06, 00387 LORA_CR_LI_4_7 = 0x07, 00388 }RadioLoRaCodingRates_t; 00389 00390 /*! 00391 * \brief Represents the preamble length values for GFSK and FLRC packet 00392 * types 00393 */ 00394 typedef enum 00395 { 00396 PREAMBLE_LENGTH_04_BITS = 0x00, //!< Preamble length: 04 bits 00397 PREAMBLE_LENGTH_08_BITS = 0x10, //!< Preamble length: 08 bits 00398 PREAMBLE_LENGTH_12_BITS = 0x20, //!< Preamble length: 12 bits 00399 PREAMBLE_LENGTH_16_BITS = 0x30, //!< Preamble length: 16 bits 00400 PREAMBLE_LENGTH_20_BITS = 0x40, //!< Preamble length: 20 bits 00401 PREAMBLE_LENGTH_24_BITS = 0x50, //!< Preamble length: 24 bits 00402 PREAMBLE_LENGTH_28_BITS = 0x60, //!< Preamble length: 28 bits 00403 PREAMBLE_LENGTH_32_BITS = 0x70, //!< Preamble length: 32 bits 00404 }RadioPreambleLengths_t; 00405 00406 /*! 00407 * \brief Represents the SyncWord length for FLRC packet type 00408 */ 00409 typedef enum 00410 { 00411 FLRC_NO_SYNCWORD = 0x00, 00412 FLRC_SYNCWORD_LENGTH_4_BYTE = 0x04, 00413 }RadioFlrcSyncWordLengths_t; 00414 00415 /*! 00416 * \brief The length of sync words for GFSK packet type 00417 */ 00418 typedef enum 00419 { 00420 GFSK_SYNCWORD_LENGTH_1_BYTE = 0x00, //!< Sync word length: 1 byte 00421 GFSK_SYNCWORD_LENGTH_2_BYTE = 0x02, //!< Sync word length: 2 bytes 00422 GFSK_SYNCWORD_LENGTH_3_BYTE = 0x04, //!< Sync word length: 3 bytes 00423 GFSK_SYNCWORD_LENGTH_4_BYTE = 0x06, //!< Sync word length: 4 bytes 00424 GFSK_SYNCWORD_LENGTH_5_BYTE = 0x08, //!< Sync word length: 5 bytes 00425 }RadioSyncWordLengths_t; 00426 00427 /*! 00428 * \brief Represents the possible combinations of SyncWord correlators 00429 * activated for GFSK and FLRC packet types 00430 */ 00431 typedef enum 00432 { 00433 RADIO_RX_MATCH_SYNCWORD_OFF = 0x00, //!< No correlator turned on, i.e. do not search for SyncWord 00434 RADIO_RX_MATCH_SYNCWORD_1 = 0x10, 00435 RADIO_RX_MATCH_SYNCWORD_2 = 0x20, 00436 RADIO_RX_MATCH_SYNCWORD_1_2 = 0x30, 00437 RADIO_RX_MATCH_SYNCWORD_3 = 0x40, 00438 RADIO_RX_MATCH_SYNCWORD_1_3 = 0x50, 00439 RADIO_RX_MATCH_SYNCWORD_2_3 = 0x60, 00440 RADIO_RX_MATCH_SYNCWORD_1_2_3 = 0x70, 00441 }RadioSyncWordRxMatchs_t; 00442 00443 /*! 00444 * \brief Radio packet length mode for GFSK and FLRC packet types 00445 */ 00446 typedef enum 00447 { 00448 RADIO_PACKET_FIXED_LENGTH = 0x00, //!< The packet is known on both sides, no header included in the packet 00449 RADIO_PACKET_VARIABLE_LENGTH = 0x20, //!< The packet is on variable size, header included 00450 }RadioPacketLengthModes_t; 00451 00452 /*! 00453 * \brief Represents the CRC length for GFSK and FLRC packet types 00454 * 00455 * \warning Not all configurations are available for both GFSK and FLRC 00456 * packet type. Refer to the datasheet for possible configuration. 00457 */ 00458 typedef enum 00459 { 00460 RADIO_CRC_OFF = 0x00, //!< No CRC in use 00461 RADIO_CRC_1_BYTES = 0x10, 00462 RADIO_CRC_2_BYTES = 0x20, 00463 RADIO_CRC_3_BYTES = 0x30, 00464 }RadioCrcTypes_t; 00465 00466 /*! 00467 * \brief Radio whitening mode activated or deactivated for GFSK, FLRC and 00468 * BLE packet types 00469 */ 00470 typedef enum 00471 { 00472 RADIO_WHITENING_ON = 0x00, 00473 RADIO_WHITENING_OFF = 0x08, 00474 }RadioWhiteningModes_t; 00475 00476 /*! 00477 * \brief Holds the packet length mode of a LORA packet type 00478 */ 00479 typedef enum 00480 { 00481 LORA_PACKET_VARIABLE_LENGTH = 0x00, //!< The packet is on variable size, header included 00482 LORA_PACKET_FIXED_LENGTH = 0x80, //!< The packet is known on both sides, no header included in the packet 00483 LORA_PACKET_EXPLICIT = LORA_PACKET_VARIABLE_LENGTH, 00484 LORA_PACKET_IMPLICIT = LORA_PACKET_FIXED_LENGTH, 00485 }RadioLoRaPacketLengthsModes_t; 00486 00487 /*! 00488 * \brief Represents the CRC mode for LORA packet type 00489 */ 00490 typedef enum 00491 { 00492 LORA_CRC_ON = 0x20, //!< CRC activated 00493 LORA_CRC_OFF = 0x00, //!< CRC not used 00494 }RadioLoRaCrcModes_t; 00495 00496 /*! 00497 * \brief Represents the IQ mode for LORA packet type 00498 */ 00499 typedef enum 00500 { 00501 LORA_IQ_NORMAL = 0x40, 00502 LORA_IQ_INVERTED = 0x00, 00503 }RadioLoRaIQModes_t; 00504 00505 /*! 00506 * \brief Represents the length of the ID to check in ranging operation 00507 */ 00508 typedef enum 00509 { 00510 RANGING_IDCHECK_LENGTH_08_BITS = 0x00, 00511 RANGING_IDCHECK_LENGTH_16_BITS, 00512 RANGING_IDCHECK_LENGTH_24_BITS, 00513 RANGING_IDCHECK_LENGTH_32_BITS, 00514 }RadioRangingIdCheckLengths_t; 00515 00516 /*! 00517 * \brief Represents the result type to be used in ranging operation 00518 */ 00519 typedef enum 00520 { 00521 RANGING_RESULT_RAW = 0x00, 00522 RANGING_RESULT_AVERAGED = 0x01, 00523 RANGING_RESULT_DEBIASED = 0x02, 00524 RANGING_RESULT_FILTERED = 0x03, 00525 }RadioRangingResultTypes_t; 00526 00527 /*! 00528 * \brief Represents the connection state for BLE packet type 00529 */ 00530 typedef enum 00531 { 00532 BLE_MASTER_SLAVE = 0x00, 00533 BLE_ADVERTISER = 0x20, 00534 BLE_TX_TEST_MODE = 0x40, 00535 BLE_RX_TEST_MODE = 0x60, 00536 BLE_RXTX_TEST_MODE = 0x80, 00537 }RadioBleConnectionStates_t; 00538 00539 /*! 00540 * \brief Represents the CRC field length for BLE packet type 00541 */ 00542 typedef enum 00543 { 00544 BLE_CRC_OFF = 0x00, 00545 BLE_CRC_3B = 0x10, 00546 }RadioBleCrcFields_t; 00547 00548 /*! 00549 * \brief Represents the specific packets to use in BLE packet type 00550 */ 00551 typedef enum 00552 { 00553 BLE_PRBS_9 = 0x00, //!< Pseudo Random Binary Sequence based on 9th degree polynomial 00554 BLE_PRBS_15 = 0x0C, //!< Pseudo Random Binary Sequence based on 15th degree polynomial 00555 BLE_EYELONG_1_0 = 0x04, //!< Repeated '11110000' sequence 00556 BLE_EYELONG_0_1 = 0x18, //!< Repeated '00001111' sequence 00557 BLE_EYESHORT_1_0 = 0x08, //!< Repeated '10101010' sequence 00558 BLE_EYESHORT_0_1 = 0x1C, //!< Repeated '01010101' sequence 00559 BLE_ALL_1 = 0x10, //!< Repeated '11111111' sequence 00560 BLE_ALL_0 = 0x14, //!< Repeated '00000000' sequence 00561 }RadioBlePacketTypes_t; 00562 00563 /*! 00564 * \brief Represents the interruption masks available for the radio 00565 * 00566 * \remark Note that not all these interruptions are available for all packet types 00567 */ 00568 typedef enum 00569 { 00570 IRQ_RADIO_NONE = 0x0000, 00571 IRQ_TX_DONE = 0x0001, 00572 IRQ_RX_DONE = 0x0002, 00573 IRQ_SYNCWORD_VALID = 0x0004, 00574 IRQ_SYNCWORD_ERROR = 0x0008, 00575 IRQ_HEADER_VALID = 0x0010, 00576 IRQ_HEADER_ERROR = 0x0020, 00577 IRQ_CRC_ERROR = 0x0040, 00578 IRQ_RANGING_SLAVE_RESPONSE_DONE = 0x0080, 00579 IRQ_RANGING_SLAVE_REQUEST_DISCARDED = 0x0100, 00580 IRQ_RANGING_MASTER_RESULT_VALID = 0x0200, 00581 IRQ_RANGING_MASTER_RESULT_TIMEOUT = 0x0400, 00582 IRQ_RANGING_SLAVE_REQUEST_VALID = 0x0800, 00583 IRQ_CAD_DONE = 0x1000, 00584 IRQ_CAD_ACTIVITY_DETECTED = 0x2000, 00585 IRQ_RX_TX_TIMEOUT = 0x4000, 00586 IRQ_PREAMBLE_DETECTED = 0x8000, 00587 IRQ_RADIO_ALL = 0xFFFF, 00588 }RadioIrqMasks_t; 00589 00590 /*! 00591 * \brief Represents the digital input/output of the radio 00592 */ 00593 typedef enum 00594 { 00595 RADIO_DIO1 = 0x02, 00596 RADIO_DIO2 = 0x04, 00597 RADIO_DIO3 = 0x08, 00598 }RadioDios_t; 00599 00600 /*! 00601 * \brief Represents the tick size available for Rx/Tx timeout operations 00602 */ 00603 typedef enum 00604 { 00605 RADIO_TICK_SIZE_0015_US = 0x00, 00606 RADIO_TICK_SIZE_0062_US = 0x01, 00607 RADIO_TICK_SIZE_1000_US = 0x02, 00608 RADIO_TICK_SIZE_4000_US = 0x03, 00609 }RadioTickSizes_t; 00610 00611 /*! 00612 * \brief Represents the role of the radio during ranging operations 00613 */ 00614 typedef enum 00615 { 00616 RADIO_RANGING_ROLE_SLAVE = 0x00, 00617 RADIO_RANGING_ROLE_MASTER = 0x01, 00618 }RadioRangingRoles_t; 00619 00620 /*! 00621 * \brief Represents all possible opcode understood by the radio 00622 */ 00623 typedef enum RadioCommands_u 00624 { 00625 RADIO_GET_STATUS = 0xC0, 00626 RADIO_WRITE_REGISTER = 0x18, 00627 RADIO_READ_REGISTER = 0x19, 00628 RADIO_WRITE_BUFFER = 0x1A, 00629 RADIO_READ_BUFFER = 0x1B, 00630 RADIO_SET_SLEEP = 0x84, 00631 RADIO_SET_STANDBY = 0x80, 00632 RADIO_SET_FS = 0xC1, 00633 RADIO_SET_TX = 0x83, 00634 RADIO_SET_RX = 0x82, 00635 RADIO_SET_RXDUTYCYCLE = 0x94, 00636 RADIO_SET_CAD = 0xC5, 00637 RADIO_SET_TXCONTINUOUSWAVE = 0xD1, 00638 RADIO_SET_TXCONTINUOUSPREAMBLE = 0xD2, 00639 RADIO_SET_PACKETTYPE = 0x8A, 00640 RADIO_GET_PACKETTYPE = 0x03, 00641 RADIO_SET_RFFREQUENCY = 0x86, 00642 RADIO_SET_TXPARAMS = 0x8E, 00643 RADIO_SET_CADPARAMS = 0x88, 00644 RADIO_SET_BUFFERBASEADDRESS = 0x8F, 00645 RADIO_SET_MODULATIONPARAMS = 0x8B, 00646 RADIO_SET_PACKETPARAMS = 0x8C, 00647 RADIO_GET_RXBUFFERSTATUS = 0x17, 00648 RADIO_GET_PACKETSTATUS = 0x1D, 00649 RADIO_GET_RSSIINST = 0x1F, 00650 RADIO_SET_DIOIRQPARAMS = 0x8D, 00651 RADIO_GET_IRQSTATUS = 0x15, 00652 RADIO_CLR_IRQSTATUS = 0x97, 00653 RADIO_CALIBRATE = 0x89, 00654 RADIO_SET_REGULATORMODE = 0x96, 00655 RADIO_SET_SAVECONTEXT = 0xD5, 00656 RADIO_SET_AUTOTX = 0x98, 00657 RADIO_SET_AUTORX = 0x9E, 00658 RADIO_SET_LONGPREAMBLE = 0x9B, 00659 RADIO_SET_UARTSPEED = 0x9D, 00660 RADIO_SET_RANGING_ROLE = 0xA3, 00661 }RadioCommands_t; 00662 00663 /*! 00664 * \brief Represents an amount of time measurable by the radio clock 00665 * 00666 * @code 00667 * Time = Step * NbSteps 00668 * Example: 00669 * Step = RADIO_TICK_SIZE_4000_US( 4 ms ) 00670 * NbSteps = 1000 00671 * Time = 4e-3 * 1000 = 4 seconds 00672 * @endcode 00673 */ 00674 typedef struct TickTime_s 00675 { 00676 RadioTickSizes_t Step; //!< The step of ticktime 00677 /*! 00678 * \brief The number of steps for ticktime 00679 * Special values are: 00680 * - 0x0000 for single mode 00681 * - 0xFFFF for continuous mode 00682 */ 00683 uint16_t NbSteps; 00684 }TickTime_t; 00685 00686 /*! 00687 * \brief RX_TX_CONTINUOUS and RX_TX_SINGLE are two particular values for TickTime. 00688 * The former keep the radio in Rx or Tx mode, even after successfull reception 00689 * or transmission. It should never generate Timeout interrupt. 00690 * The later let the radio enought time to make one reception or transmission. 00691 * No Timeout interrupt is generated, and the radio fall in StandBy mode after 00692 * reception or transmission. 00693 */ 00694 #define RX_TX_CONTINUOUS ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0xFFFF } 00695 #define RX_TX_SINGLE ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0 } 00696 00697 /*! 00698 * \brief The type describing the modulation parameters for every packet types 00699 */ 00700 typedef struct 00701 { 00702 RadioPacketTypes_t PacketType; //!< Packet to which the modulation parameters are referring to. 00703 struct 00704 { 00705 /*! 00706 * \brief Holds the GFSK modulation parameters 00707 * 00708 * In GFSK modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 00709 */ 00710 struct 00711 { 00712 RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations 00713 RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations 00714 RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations 00715 }Gfsk; 00716 /*! 00717 * \brief Holds the LORA modulation parameters 00718 * 00719 * LORA modulation is defined by Spreading Factor (SF), Bandwidth and Coding Rate 00720 */ 00721 struct 00722 { 00723 RadioLoRaSpreadingFactors_t SpreadingFactor; //!< Spreading Factor for the LORA modulation 00724 RadioLoRaBandwidths_t Bandwidth; //!< Bandwidth for the LORA modulation 00725 RadioLoRaCodingRates_t CodingRate; //!< Coding rate for the LORA modulation 00726 }LoRa; 00727 /*! 00728 * \brief Holds the FLRC modulation parameters 00729 * 00730 * In FLRC modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 00731 */ 00732 struct 00733 { 00734 RadioFlrcBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for FLRC modulation 00735 RadioFlrcCodingRates_t CodingRate; //!< The coding rate for FLRC modulation 00736 RadioModShapings_t ModulationShaping; //!< The modulation shaping for FLRC modulation 00737 }Flrc; 00738 /*! 00739 * \brief Holds the BLE modulation parameters 00740 * 00741 * In BLE modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 00742 */ 00743 struct 00744 { 00745 RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations 00746 RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations 00747 RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations 00748 }Ble; 00749 }Params; //!< Holds the modulation parameters structure 00750 }ModulationParams_t; 00751 00752 /*! 00753 * \brief The type describing the packet parameters for every packet types 00754 */ 00755 typedef struct 00756 { 00757 RadioPacketTypes_t PacketType; //!< Packet to which the packet parameters are referring to. 00758 struct 00759 { 00760 /*! 00761 * \brief Holds the GFSK packet parameters 00762 */ 00763 struct 00764 { 00765 RadioPreambleLengths_t PreambleLength; //!< The preamble length for GFSK packet type 00766 RadioSyncWordLengths_t SyncWordLength; //!< The synchronization word length for GFSK packet type 00767 RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word 00768 RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the GFSK packet. If the header is implicit, it will not be transmitted 00769 uint8_t PayloadLength; //!< Size of the payload in the GFSK packet 00770 RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the GFSK packet 00771 RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable 00772 }Gfsk; 00773 /*! 00774 * \brief Holds the LORA packet parameters 00775 */ 00776 struct 00777 { 00778 uint8_t PreambleLength; //!< The preamble length is the number of LORA symbols in the preamble. To set it, use the following formula @code Number of symbols = PreambleLength[3:0] * ( 2^PreambleLength[7:4] ) @endcode 00779 RadioLoRaPacketLengthsModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the LORA packet. If the header is implicit, it will not be transmitted 00780 uint8_t PayloadLength; //!< Size of the payload in the LORA packet 00781 RadioLoRaCrcModes_t CrcMode; //!< Size of CRC block in LORA packet 00782 RadioLoRaIQModes_t InvertIQ; //!< Allows to swap IQ for LORA packet 00783 }LoRa; 00784 /*! 00785 * \brief Holds the FLRC packet parameters 00786 */ 00787 struct 00788 { 00789 RadioPreambleLengths_t PreambleLength; //!< The preamble length for FLRC packet type 00790 RadioFlrcSyncWordLengths_t SyncWordLength; //!< The synchronization word length for FLRC packet type 00791 RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word 00792 RadioPacketLengthModes_t HeaderType; //!< If the header is explicit, it will be transmitted in the FLRC packet. If the header is implicit, it will not be transmitted. 00793 uint8_t PayloadLength; //!< Size of the payload in the FLRC packet 00794 RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the FLRC packet 00795 RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable 00796 }Flrc; 00797 /*! 00798 * \brief Holds the BLE packet parameters 00799 */ 00800 struct 00801 { 00802 RadioBleConnectionStates_t ConnectionState; //!< The BLE state 00803 RadioBleCrcFields_t CrcField; //!< Size of the CRC block in the BLE packet 00804 RadioBlePacketTypes_t BlePacketType; //!< Special BLE packet types 00805 RadioWhiteningModes_t Whitening; //!< Usage of whitening on PDU and CRC blocks of BLE packet 00806 }Ble; 00807 }Params; //!< Holds the packet parameters structure 00808 }PacketParams_t; 00809 00810 /*! 00811 * \brief Represents the packet status for every packet type 00812 */ 00813 typedef struct 00814 { 00815 RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to. 00816 union 00817 { 00818 struct 00819 { 00820 int8_t RssiSync; //!< The RSSI measured on last packet 00821 struct 00822 { 00823 bool SyncError :1; //!< SyncWord error on last packet 00824 bool LengthError :1; //!< Length error on last packet 00825 bool CrcError :1; //!< CRC error on last packet 00826 bool AbortError :1; //!< Abort error on last packet 00827 bool HeaderReceived :1; //!< Header received on last packet 00828 bool PacketReceived :1; //!< Packet received 00829 bool PacketControlerBusy :1; //!< Packet controller busy 00830 }ErrorStatus; //!< The error status Byte 00831 struct 00832 { 00833 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 00834 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 00835 }TxRxStatus; //!< The Tx/Rx status Byte 00836 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 00837 }Gfsk; 00838 struct 00839 { 00840 int8_t RssiPkt; //!< The RSSI of the last packet 00841 int8_t SnrPkt; //!< The SNR of the last packet 00842 struct 00843 { 00844 bool SyncError :1; //!< SyncWord error on last packet 00845 bool LengthError :1; //!< Length error on last packet 00846 bool CrcError :1; //!< CRC error on last packet 00847 bool AbortError :1; //!< Abort error on last packet 00848 bool HeaderReceived :1; //!< Header received on last packet 00849 bool PacketReceived :1; //!< Packet received 00850 bool PacketControlerBusy :1; //!< Packet controller busy 00851 }ErrorStatus; //!< The error status Byte 00852 struct 00853 { 00854 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 00855 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 00856 }TxRxStatus; //!< The Tx/Rx status Byte 00857 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 00858 }LoRa; 00859 struct 00860 { 00861 int8_t RssiSync; //!< The RSSI of the last packet 00862 struct 00863 { 00864 bool SyncError :1; //!< SyncWord error on last packet 00865 bool LengthError :1; //!< Length error on last packet 00866 bool CrcError :1; //!< CRC error on last packet 00867 bool AbortError :1; //!< Abort error on last packet 00868 bool HeaderReceived :1; //!< Header received on last packet 00869 bool PacketReceived :1; //!< Packet received 00870 bool PacketControlerBusy :1; //!< Packet controller busy 00871 }ErrorStatus; //!< The error status Byte 00872 struct 00873 { 00874 uint8_t RxPid :2; //!< PID of the Rx 00875 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 00876 bool RxPidErr :1; //!< Received PID error 00877 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 00878 }TxRxStatus; //!< The Tx/Rx status Byte 00879 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 00880 }Flrc; 00881 struct 00882 { 00883 int8_t RssiSync; //!< The RSSI of the last packet 00884 struct 00885 { 00886 bool SyncError :1; //!< SyncWord error on last packet 00887 bool LengthError :1; //!< Length error on last packet 00888 bool CrcError :1; //!< CRC error on last packet 00889 bool AbortError :1; //!< Abort error on last packet 00890 bool HeaderReceived :1; //!< Header received on last packet 00891 bool PacketReceived :1; //!< Packet received 00892 bool PacketControlerBusy :1; //!< Packet controller busy 00893 }ErrorStatus; //!< The error status Byte 00894 struct 00895 { 00896 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 00897 }TxRxStatus; //!< The Tx/Rx status Byte 00898 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 00899 }Ble; 00900 }; 00901 }PacketStatus_t; 00902 00903 /*! 00904 * \brief Represents the Rx internal counters values when GFSK or LORA packet type is used 00905 */ 00906 typedef struct 00907 { 00908 RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to. 00909 union 00910 { 00911 struct 00912 { 00913 uint16_t PacketReceived; //!< Number of received packets 00914 uint16_t CrcError; //!< Number of CRC errors 00915 uint16_t LengthError; //!< Number of length errors 00916 uint16_t SyncwordError; //!< Number of sync-word errors 00917 }Gfsk; 00918 struct 00919 { 00920 uint16_t PacketReceived; //!< Number of received packets 00921 uint16_t CrcError; //!< Number of CRC errors 00922 uint16_t HeaderValid; //!< Number of valid headers 00923 }LoRa; 00924 }; 00925 }RxCounter_t; 00926 00927 /*! 00928 * \brief Represents a calibration configuration 00929 */ 00930 typedef struct 00931 { 00932 uint8_t RC64KEnable : 1; //!< Calibrate RC64K clock 00933 uint8_t RC13MEnable : 1; //!< Calibrate RC13M clock 00934 uint8_t PLLEnable : 1; //!< Calibrate PLL 00935 uint8_t ADCPulseEnable : 1; //!< Calibrate ADC Pulse 00936 uint8_t ADCBulkNEnable : 1; //!< Calibrate ADC bulkN 00937 uint8_t ADCBulkPEnable : 1; //!< Calibrate ADC bulkP 00938 }CalibrationParams_t; 00939 00940 /*! 00941 * \brief Represents a sleep mode configuration 00942 */ 00943 typedef struct 00944 { 00945 uint8_t WakeUpRTC : 1; //!< Get out of sleep mode if wakeup signal received from RTC 00946 uint8_t InstructionRamRetention : 1; //!< InstructionRam is conserved during sleep 00947 uint8_t DataBufferRetention : 1; //!< Data buffer is conserved during sleep 00948 uint8_t DataRamRetention : 1; //!< Data ram is conserved during sleep 00949 }SleepParams_t; 00950 00951 /*! 00952 * \brief Represents the SX1280 and its features 00953 * 00954 * It implements the commands the SX1280 can understands 00955 */ 00956 class SX1280 : public Radio 00957 { 00958 public: 00959 /*! 00960 * \brief Instantiates a SX1280 object and provides API functions to communicates with the radio 00961 * 00962 * \param [in] callbacks Pointer to the callbacks structure defining 00963 * all callbacks function pointers 00964 */ 00965 SX1280( RadioCallbacks_t *callbacks ): 00966 Radio( callbacks ) 00967 { 00968 this->dioIrq = &SX1280::OnDioIrq; 00969 this->PacketType = PACKET_TYPE_NONE; 00970 this->LoRaBandwidth = LORA_BW_0200; // This value is not set to the radio! 00971 this->PollingMode = false; 00972 this->IrqState = false; 00973 } 00974 00975 virtual ~SX1280( ) 00976 { 00977 } 00978 00979 private: 00980 /*! 00981 * \brief Holds the internal operating mode of the radio 00982 */ 00983 RadioOperatingModes_t OperatingMode; 00984 00985 /*! 00986 * \brief Stores the current packet type set in the radio 00987 */ 00988 RadioPacketTypes_t PacketType; 00989 00990 /*! 00991 * \brief Stores the current LORA bandwidth set in the radio 00992 */ 00993 RadioLoRaBandwidths_t LoRaBandwidth; 00994 00995 /*! 00996 * \brief Holds a flag raised on radio interrupt 00997 */ 00998 bool IrqState; 00999 01000 /*! 01001 * \brief Hardware DIO IRQ functions 01002 */ 01003 DioIrqHandler dioIrq; 01004 01005 /*! 01006 * \brief Holds the polling state of the driver 01007 */ 01008 bool PollingMode; 01009 01010 /*! 01011 * \brief Compute the two's complement for a register of size lower than 01012 * 32bits 01013 * 01014 * \param [in] num The register to be two's complemented 01015 * \param [in] bitCnt The position of the sign bit 01016 */ 01017 static int32_t complement2( const uint32_t num, const uint8_t bitCnt ); 01018 01019 /*! 01020 * \brief Returns the value of LoRa bandwidth from driver's value 01021 * 01022 * The value is returned in Hz so that it can be represented as an integer 01023 * type. Most computation should be done as integer to reduce floating 01024 * point related errors. 01025 * 01026 * \retval loRaBw The value of the current bandwidth in Hz 01027 */ 01028 int32_t GetLoRaBandwidth( void ); 01029 01030 protected: 01031 /*! 01032 * \brief Sets a function to be triggered on radio interrupt 01033 * 01034 * \param [in] irqHandler A pointer to a function to be run on interrupt 01035 * from the radio 01036 */ 01037 virtual void IoIrqInit( DioIrqHandler irqHandler ) = 0; 01038 01039 /*! 01040 * \brief DIOs interrupt callback 01041 * 01042 * \remark Called to handle all 3 DIOs pins 01043 */ 01044 void OnDioIrq( void ); 01045 01046 /*! 01047 * \brief Set the role of the radio during ranging operations 01048 * 01049 * \param [in] role Role of the radio 01050 */ 01051 void SetRangingRole( RadioRangingRoles_t role ); 01052 01053 public: 01054 /*! 01055 * \brief Initializes the radio driver 01056 */ 01057 void Init( void ); 01058 01059 /*! 01060 * \brief Set the driver in polling mode. 01061 * 01062 * In polling mode the application is responsible to call ProcessIrqs( ) to 01063 * execute callbacks functions. 01064 * The default mode is Interrupt Mode. 01065 * @code 01066 * // Initializations and callbacks declaration/definition 01067 * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks ); 01068 * radio.Init( ); 01069 * radio.SetPollingMode( ); 01070 * 01071 * while( true ) 01072 * { 01073 * // IRQ processing is automatically done 01074 * radio.ProcessIrqs( ); // <-- here, as well as callback functions 01075 * // calls 01076 * // Do some applicative work 01077 * } 01078 * @endcode 01079 * 01080 * \see SX1280::SetInterruptMode 01081 */ 01082 void SetPollingMode( void ); 01083 01084 /*! 01085 * \brief Set the driver in interrupt mode. 01086 * 01087 * In interrupt mode, the driver communicate with the radio during the 01088 * interruption by direct calls to ProcessIrqs( ). The main advantage is 01089 * the possibility to have low power application architecture. 01090 * This is the default mode. 01091 * @code 01092 * // Initializations and callbacks declaration/definition 01093 * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks ); 01094 * radio.Init( ); 01095 * radio.SetInterruptMode( ); // Optionnal. Driver default behavior 01096 * 01097 * while( true ) 01098 * { 01099 * // Do some applicative work 01100 * } 01101 * @endcode 01102 * 01103 * \see SX1280::SetPollingMode 01104 */ 01105 void SetInterruptMode( void ); 01106 01107 /*! 01108 * \brief Initializes the radio registers to the recommended default values 01109 */ 01110 void SetRegistersDefault( void ); 01111 01112 /*! 01113 * \brief Returns the current device firmware version 01114 * 01115 * \retval version Firmware version 01116 */ 01117 virtual uint16_t GetFirmwareVersion( void ); 01118 01119 /*! 01120 * \brief Resets the radio 01121 */ 01122 virtual void Reset( void ) = 0; 01123 01124 /*! 01125 * \brief Wake-ups the radio from Sleep mode 01126 */ 01127 virtual void Wakeup( void ) = 0; 01128 01129 /*! 01130 * \brief Writes the given command to the radio 01131 * 01132 * \param [in] opcode Command opcode 01133 * \param [in] buffer Command parameters byte array 01134 * \param [in] size Command parameters byte array size 01135 */ 01136 virtual void WriteCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size ) = 0; 01137 01138 /*! 01139 * \brief Reads the given command from the radio 01140 * 01141 * \param [in] opcode Command opcode 01142 * \param [in] buffer Command parameters byte array 01143 * \param [in] size Command parameters byte array size 01144 */ 01145 virtual void ReadCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size ) = 0; 01146 01147 /*! 01148 * \brief Writes multiple radio registers starting at address 01149 * 01150 * \param [in] address First Radio register address 01151 * \param [in] buffer Buffer containing the new register's values 01152 * \param [in] size Number of registers to be written 01153 */ 01154 virtual void WriteRegister( uint16_t address, uint8_t *buffer, uint16_t size ) = 0; 01155 01156 /*! 01157 * \brief Writes the radio register at the specified address 01158 * 01159 * \param [in] address Register address 01160 * \param [in] value New register value 01161 */ 01162 virtual void WriteRegister( uint16_t address, uint8_t value ) = 0; 01163 01164 /*! 01165 * \brief Reads multiple radio registers starting at address 01166 * 01167 * \param [in] address First Radio register address 01168 * \param [out] buffer Buffer where to copy the registers data 01169 * \param [in] size Number of registers to be read 01170 */ 01171 virtual void ReadRegister( uint16_t address, uint8_t *buffer, uint16_t size ) = 0; 01172 01173 /*! 01174 * \brief Reads the radio register at the specified address 01175 * 01176 * \param [in] address Register address 01177 * 01178 * \retval data Register value 01179 */ 01180 virtual uint8_t ReadRegister( uint16_t address ) = 0; 01181 01182 /*! 01183 * \brief Writes Radio Data Buffer with buffer of size starting at offset. 01184 * 01185 * \param [in] offset Offset where to start writing 01186 * \param [in] buffer Buffer pointer 01187 * \param [in] size Buffer size 01188 */ 01189 virtual void WriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) = 0; 01190 01191 /*! 01192 * \brief Reads Radio Data Buffer at offset to buffer of size 01193 * 01194 * \param [in] offset Offset where to start reading 01195 * \param [out] buffer Buffer pointer 01196 * \param [in] size Buffer size 01197 */ 01198 virtual void ReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) = 0; 01199 01200 /*! 01201 * \brief Gets the current status of the radio DIOs 01202 * 01203 * \retval status [Bit #3: DIO3, Bit #2: DIO2, 01204 * Bit #1: DIO1, Bit #0: BUSY] 01205 */ 01206 virtual uint8_t GetDioStatus( void ) = 0; 01207 01208 /*! 01209 * \brief Gets the current Operation Mode of the Radio 01210 * 01211 * \retval opMode Last operating mode 01212 */ 01213 virtual RadioOperatingModes_t GetOpMode( void ); 01214 01215 /*! 01216 * \brief Gets the current radio status 01217 * 01218 * \retval status Radio status 01219 */ 01220 virtual RadioStatus_t GetStatus( void ); 01221 01222 /*! 01223 * \brief Sets the radio in sleep mode 01224 * 01225 * \param [in] sleepConfig The sleep configuration describing data 01226 * retention and RTC wake-up 01227 */ 01228 void SetSleep( SleepParams_t sleepConfig ); 01229 01230 /*! 01231 * \brief Sets the radio in configuration mode 01232 * 01233 * \param [in] mode The standby mode to put the radio into 01234 */ 01235 void SetStandby( RadioStandbyModes_t mode ); 01236 01237 /*! 01238 * \brief Sets the radio in FS mode 01239 */ 01240 void SetFs( void ); 01241 01242 /*! 01243 * \brief Sets the radio in transmission mode 01244 * 01245 * \param [in] timeout Structure describing the transmission timeout value 01246 */ 01247 void SetTx( TickTime_t timeout ); 01248 01249 /*! 01250 * \brief Sets the radio in reception mode 01251 * 01252 * \param [in] timeout Structure describing the reception timeout value 01253 */ 01254 void SetRx( TickTime_t timeout ); 01255 01256 /*! 01257 * \brief Sets the Rx duty cycle management parameters 01258 * 01259 * \param [in] step Step time size for Rx and Sleep TickTime sequences 01260 * \param [in] nbStepRx Number of step time size for Rx TickTime sequence 01261 * \param [in] nbStepSleep Number of step time size for Sleep TickTime sequence 01262 */ 01263 void SetRxDutyCycle( RadioTickSizes_t step, uint16_t nbStepRx, uint16_t nbStepSleep ); 01264 01265 /*! 01266 * \brief Sets the radio in CAD mode 01267 * 01268 * \see SX1280::SetCadParams 01269 */ 01270 void SetCad( void ); 01271 01272 /*! 01273 * \brief Sets the radio in continuous wave transmission mode 01274 */ 01275 void SetTxContinuousWave( void ); 01276 01277 /*! 01278 * \brief Sets the radio in continuous preamble transmission mode 01279 */ 01280 void SetTxContinuousPreamble( void ); 01281 01282 /*! 01283 * \brief Sets the radio for the given protocol 01284 * 01285 * \param [in] packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA, 01286 * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC, 01287 * PACKET_TYPE_BLE] 01288 * 01289 * \remark This method has to be called before SetRfFrequency, 01290 * SetModulationParams and SetPacketParams 01291 */ 01292 void SetPacketType( RadioPacketTypes_t packetType ); 01293 01294 /*! 01295 * \brief Gets the current radio protocol 01296 * 01297 * \retval packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA, 01298 * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC, 01299 * PACKET_TYPE_BLE, PACKET_TYPE_NONE] 01300 */ 01301 RadioPacketTypes_t GetPacketType( void ); 01302 01303 /*! 01304 * \brief Sets the RF frequency 01305 * 01306 * \param [in] frequency RF frequency [Hz] 01307 */ 01308 void SetRfFrequency( uint32_t frequency ); 01309 01310 /*! 01311 * \brief Sets the transmission parameters 01312 * 01313 * \param [in] power RF output power [-18..13] dBm 01314 * \param [in] rampTime Transmission ramp up time 01315 */ 01316 void SetTxParams( int8_t power, RadioRampTimes_t rampTime ); 01317 01318 /*! 01319 * \brief Sets the number of symbols to be used for Channel Activity 01320 * Detection operation 01321 * 01322 * \param [in] cadSymbolNum The number of symbol to use for Channel Activity 01323 * Detection operations [LORA_CAD_01_SYMBOL, LORA_CAD_02_SYMBOL, 01324 * LORA_CAD_04_SYMBOL, LORA_CAD_08_SYMBOL, LORA_CAD_16_SYMBOL] 01325 */ 01326 void SetCadParams( RadioLoRaCadSymbols_t cadSymbolNum ); 01327 01328 /*! 01329 * \brief Sets the data buffer base address for transmission and reception 01330 * 01331 * \param [in] txBaseAddress Transmission base address 01332 * \param [in] rxBaseAddress Reception base address 01333 */ 01334 void SetBufferBaseAddresses( uint8_t txBaseAddress, uint8_t rxBaseAddress ); 01335 01336 /*! 01337 * \brief Set the modulation parameters 01338 * 01339 * \param [in] modParams A structure describing the modulation parameters 01340 */ 01341 void SetModulationParams( ModulationParams_t *modParams ); 01342 01343 /*! 01344 * \brief Sets the packet parameters 01345 * 01346 * \param [in] packetParams A structure describing the packet parameters 01347 */ 01348 void SetPacketParams( PacketParams_t *packetParams ); 01349 01350 /*! 01351 * \brief Gets the last received packet buffer status 01352 * 01353 * \param [out] payloadLength Last received packet payload length 01354 * \param [out] rxStartBuffer Last received packet buffer address pointer 01355 */ 01356 void GetRxBufferStatus( uint8_t *payloadLength, uint8_t *rxStartBuffer ); 01357 01358 /*! 01359 * \brief Gets the last received packet payload length 01360 * 01361 * \param [out] pktStatus A structure of packet status 01362 */ 01363 void GetPacketStatus( PacketStatus_t *pktStatus ); 01364 01365 /*! 01366 * \brief Returns the instantaneous RSSI value for the last packet received 01367 * 01368 * \retval rssiInst Instantaneous RSSI 01369 */ 01370 int8_t GetRssiInst( void ); 01371 01372 /*! 01373 * \brief Sets the IRQ mask and DIO masks 01374 * 01375 * \param [in] irqMask General IRQ mask 01376 * \param [in] dio1Mask DIO1 mask 01377 * \param [in] dio2Mask DIO2 mask 01378 * \param [in] dio3Mask DIO3 mask 01379 */ 01380 void SetDioIrqParams( uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask ); 01381 01382 /*! 01383 * \brief Returns the current IRQ status 01384 * 01385 * \retval irqStatus IRQ status 01386 */ 01387 uint16_t GetIrqStatus( void ); 01388 01389 /*! 01390 * \brief Clears the IRQs 01391 * 01392 * \param [in] irq IRQ(s) to be cleared 01393 */ 01394 void ClearIrqStatus( uint16_t irq ); 01395 01396 /*! 01397 * \brief Calibrates the given radio block 01398 * 01399 * \param [in] calibParam The description of blocks to be calibrated 01400 */ 01401 void Calibrate( CalibrationParams_t calibParam ); 01402 01403 /*! 01404 * \brief Sets the power regulators operating mode 01405 * 01406 * \param [in] mode [0: LDO, 1:DC_DC] 01407 */ 01408 void SetRegulatorMode( RadioRegulatorModes_t mode ); 01409 01410 /*! 01411 * \brief Saves the current selected modem configuration into data RAM 01412 */ 01413 void SetSaveContext( void ); 01414 01415 /*! 01416 * \brief Sets the chip to automatically send a packet after the end of a packet reception 01417 * 01418 * \remark The offset is automatically compensated inside the function 01419 * 01420 * \param [in] time The delay in us after which a Tx is done 01421 */ 01422 void SetAutoTx( uint16_t time ); 01423 01424 /*! 01425 * \brief Sets the chip to stay in FS mode after sending a packet 01426 * 01427 * \param [in] enableAutoFs Turn on auto FS 01428 */ 01429 void SetAutoFs( bool enableAutoFs ); 01430 01431 /*! 01432 * \brief Enables or disables long preamble detection mode 01433 * 01434 * \param [in] enable Turn on long preamble mode 01435 */ 01436 void SetLongPreamble( bool enable ); 01437 01438 /*! 01439 * \brief Saves the payload to be send in the radio buffer 01440 * 01441 * \param [in] payload A pointer to the payload 01442 * \param [in] size The size of the payload 01443 * \param [in] offset The address in FIFO where writting first byte (default = 0x00) 01444 */ 01445 void SetPayload( uint8_t *payload, uint8_t size, uint8_t offset = 0x00 ); 01446 01447 /*! 01448 * \brief Reads the payload received. If the received payload is longer 01449 * than maxSize, then the method returns 1 and do not set size and payload. 01450 * 01451 * \param [out] payload A pointer to a buffer into which the payload will be copied 01452 * \param [out] size A pointer to the size of the payload received 01453 * \param [in] maxSize The maximal size allowed to copy into the buffer 01454 */ 01455 uint8_t GetPayload( uint8_t *payload, uint8_t *size, uint8_t maxSize ); 01456 01457 /*! 01458 * \brief Sends a payload 01459 * 01460 * \param [in] payload A pointer to the payload to send 01461 * \param [in] size The size of the payload to send 01462 * \param [in] timeout The timeout for Tx operation 01463 * \param [in] offset The address in FIFO where writting first byte (default = 0x00) 01464 */ 01465 void SendPayload( uint8_t *payload, uint8_t size, TickTime_t timeout, uint8_t offset = 0x00 ); 01466 01467 /*! 01468 * \brief Sets the Sync Word given by index used in GFSK, FLRC and BLE protocols 01469 * 01470 * \remark 5th byte isn't used in FLRC and BLE protocols 01471 * 01472 * \param [in] syncWordIdx Index of SyncWord to be set [1..3] 01473 * \param [in] syncWord SyncWord bytes ( 5 bytes ) 01474 * 01475 * \retval status [0: OK, 1: NOK] 01476 */ 01477 uint8_t SetSyncWord( uint8_t syncWordIdx, uint8_t *syncWord ); 01478 01479 /*! 01480 * \brief Defines how many error bits are tolerated in sync word detection 01481 * 01482 * \param [in] errorBits Number of error bits supported to validate the Sync word detection 01483 * ( default is 4 bit, minimum is 1 bit ) 01484 */ 01485 void SetSyncWordErrorTolerance( uint8_t errorBits ); 01486 01487 /*! 01488 * \brief Sets the Initial value for the LFSR used for the CRC calculation 01489 * 01490 * \param [in] seed Initial LFSR value ( 4 bytes ) 01491 * 01492 */ 01493 void SetCrcSeed( uint16_t seed ); 01494 01495 /*! 01496 * \brief Sets the seed used for the CRC calculation 01497 * 01498 * \param [in] polynomial The seed value 01499 * 01500 */ 01501 void SetCrcPolynomial( uint16_t polynomial ); 01502 01503 /*! 01504 * \brief Sets the Initial value of the LFSR used for the whitening in GFSK, FLRC and BLE protocols 01505 * 01506 * \param [in] seed Initial LFSR value 01507 */ 01508 void SetWhiteningSeed( uint8_t seed ); 01509 01510 /*! 01511 * \brief Sets the number of bits used to check that ranging request match ranging ID 01512 * 01513 * \param [in] length [0: 8 bits, 1: 16 bits, 01514 * 2: 24 bits, 3: 32 bits] 01515 */ 01516 void SetRangingIdLength( RadioRangingIdCheckLengths_t length ); 01517 01518 /*! 01519 * \brief Sets ranging device id 01520 * 01521 * \param [in] address Device address 01522 */ 01523 void SetDeviceRangingAddress( uint32_t address ); 01524 01525 /*! 01526 * \brief Sets the device id to ping in a ranging request 01527 * 01528 * \param [in] address Address of the device to ping 01529 */ 01530 void SetRangingRequestAddress( uint32_t address ); 01531 01532 /*! 01533 * \brief Return the ranging result value 01534 * 01535 * \param [in] resultType Specifies the type of result. 01536 * [0: RAW, 1: Averaged, 01537 * 2: De-biased, 3:Filtered] 01538 * 01539 * \retval ranging The ranging measure filtered according to resultType [m] 01540 */ 01541 double GetRangingResult( RadioRangingResultTypes_t resultType ); 01542 01543 /*! 01544 * \brief Sets the standard processing delay between Master and Slave 01545 * 01546 * \param [in] cal RxTx delay offset for correcting ranging bias. 01547 * 01548 * The calibration value reflects the group delay of the radio front end and 01549 * must be re-performed for each new SX1280 PCB design. The value is obtained 01550 * empirically by either conducted measurement in a known electrical length 01551 * coaxial RF cable (where the design is connectorised) or by radiated 01552 * measurement, at a known distance, where an antenna is present. 01553 * The result of the calibration process is that the SX1280 ranging result 01554 * accurately reflects the physical range, the calibration procedure therefore 01555 * removes the average timing error from the time-of-flight measurement for a 01556 * given design. 01557 * 01558 * The values are Spreading Factor dependents, and depend also of the board 01559 * design. 01560 */ 01561 void SetRangingCalibration( uint16_t cal ); 01562 01563 /*! 01564 * \brief Clears the ranging filter 01565 */ 01566 void RangingClearFilterResult( void ); 01567 01568 /*! 01569 * \brief Set the number of samples considered in the built-in filter 01570 * 01571 * \param [in] numSample The number of samples to use built-in filter 01572 * [8..255] 01573 * 01574 * \remark Value inferior to 8 will be silently set to 8 01575 */ 01576 void RangingSetFilterNumSamples( uint8_t numSample ); 01577 01578 /*! 01579 * \brief Return the Estimated Frequency Error in LORA and RANGING operations 01580 * 01581 * \retval efe The estimated frequency error [Hz] 01582 */ 01583 double GetFrequencyError( ); 01584 01585 /*! 01586 * \brief Process the analysis of radio IRQs and calls callback functions 01587 * depending on radio state 01588 */ 01589 void ProcessIrqs( void ); 01590 }; 01591 01592 #endif // __SX1280_H__
Generated on Thu Jul 21 2022 00:08:48 by
1.7.2
