1 /* 2 ______ _ 3 / _____) _ | | 4 ( (____ _____ ____ _| |_ _____ ____| |__ 5 \____ \| ___ | (_ _) ___ |/ ___) _ \ 6 _____) ) ____| | | || |_| ____( (___| | | | 7 (______/|_____)_|_|_| \__)_____)\____)_| |_| 8 (C)2016 Semtech 9 10 Description: Driver for SX1280 devices 11 12 License: Revised BSD License, see LICENSE.TXT file include in the project 13 14 Maintainer: Miguel Luis, Gregory Cristian and Matthieu Verdy 15 */ 16 #ifndef __SX1280_H__ 17 #define __SX1280_H__ 18 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include <math.h> 22 23 /*! 24 * \brief Enables/disables driver debug features 25 */ 26 #define SX1280_DEBUG 0 27 28 /*! 29 * \brief Hardware IO IRQ callback function definition 30 */ 31 typedef void ( DioIrqHandler )( void ); 32 33 /*! 34 * \brief Provides the frequency of the chip running on the radio and the frequency step 35 * 36 * \remark These defines are used for computing the frequency divider to set the RF frequency 37 */ 38 #define XTAL_FREQ 52000000 39 #define FREQ_STEP ( ( double )( XTAL_FREQ / pow( 2.0, 18.0 ) ) ) 40 41 /*! 42 * \brief Compensation delay for SetAutoTx/Rx functions in microseconds 43 */ 44 #define AUTO_RX_TX_OFFSET 33 45 46 /*! 47 * \brief The address of the register holding the firmware version MSB 48 */ 49 #define REG_LR_FIRMWARE_VERSION_MSB 0x0153 50 51 /*! 52 * \brief The address of the register holding the first byte defining the CRC seed 53 * 54 * \remark Only used for packet types GFSK and Flrc 55 */ 56 #define REG_LR_CRCSEEDBASEADDR 0x09C8 57 58 /*! 59 * \brief The address of the register holding the first byte defining the CRC polynomial 60 * 61 * \remark Only used for packet types GFSK and Flrc 62 */ 63 #define REG_LR_CRCPOLYBASEADDR 0x09C6 64 65 /*! 66 * \brief The address of the register holding the first byte defining the whitening seed 67 * 68 * \remark Only used for packet types GFSK, FLRC and BLE 69 */ 70 #define REG_LR_WHITSEEDBASEADDR 0x09C5 71 72 /*! 73 * \brief The address of the register holding the ranging id check length 74 * 75 * \remark Only used for packet type Ranging 76 */ 77 #define REG_LR_RANGINGIDCHECKLENGTH 0x0931 78 79 /*! 80 * \brief The address of the register holding the device ranging id 81 * 82 * \remark Only used for packet type Ranging 83 */ 84 #define REG_LR_DEVICERANGINGADDR 0x0916 85 86 /*! 87 * \brief The address of the register holding the device ranging id 88 * 89 * \remark Only used for packet type Ranging 90 */ 91 #define REG_LR_REQUESTRANGINGADDR 0x0912 92 93 /*! 94 * \brief The address of the register holding ranging results configuration 95 * and the corresponding mask 96 * 97 * \remark Only used for packet type Ranging 98 */ 99 #define REG_LR_RANGINGRESULTCONFIG 0x0924 100 #define MASK_RANGINGMUXSEL 0xCF 101 102 /*! 103 * \brief The address of the register holding the first byte of ranging results 104 * Only used for packet type Ranging 105 */ 106 #define REG_LR_RANGINGRESULTBASEADDR 0x0961 107 108 /*! 109 * \brief The address of the register allowing to read ranging results 110 * 111 * \remark Only used for packet type Ranging 112 */ 113 #define REG_LR_RANGINGRESULTSFREEZE 0x097F 114 115 /*! 116 * \brief The address of the register holding the first byte of ranging calibration 117 * 118 * \remark Only used for packet type Ranging 119 */ 120 #define REG_LR_RANGINGRERXTXDELAYCAL 0x092C 121 122 /*! 123 *\brief The address of the register holding the ranging filter window size 124 * 125 * \remark Only used for packet type Ranging 126 */ 127 #define REG_LR_RANGINGFILTERWINDOWSIZE 0x091E 128 129 /*! 130 *\brief The address of the register to reset for clearing ranging filter 131 * 132 * \remark Only used for packet type Ranging 133 */ 134 #define REG_LR_RANGINGRESULTCLEARREG 0x0923 135 136 #define REG_RANGING_RSSI 0x0964 137 138 /*! 139 * \brief The default number of samples considered in built-in ranging filter 140 */ 141 #define DEFAULT_RANGING_FILTER_SIZE 127 142 143 /*! 144 * \brief The address of the register holding LORA packet parameters 145 */ 146 #define REG_LR_PACKETPARAMS 0x903 147 148 /*! 149 * \brief The address of the register holding payload length 150 * 151 * \remark Do NOT try to read it directly. Use GetRxBuffer( ) instead. 152 */ 153 #define REG_LR_PAYLOADLENGTH 0x901 154 155 /*! 156 * \brief The address of the instruction RAM and its size 157 */ 158 #define IRAM_START_ADDRESS 0x8000 159 #define IRAM_SIZE 0x4000 160 161 /*! 162 * \brief The addresses of the registers holding SyncWords values 163 * 164 * \remark The addresses depends on the Packet Type in use, and not all 165 * SyncWords are available for every Packet Type 166 */ 167 #define REG_LR_SYNCWORDBASEADDRESS1 0x09CE 168 #define REG_LR_SYNCWORDBASEADDRESS2 0x09D3 169 #define REG_LR_SYNCWORDBASEADDRESS3 0x09D8 170 171 /*! 172 * \brief The MSB address and mask used to read the estimated frequency 173 * error 174 */ 175 #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MSB 0x0954 176 #define REG_LR_ESTIMATED_FREQUENCY_ERROR_MASK 0x0FFFFF 177 178 /*! 179 * \brief Defines how many bit errors are tolerated in sync word detection 180 */ 181 #define REG_LR_SYNCWORDTOLERANCE 0x09CD 182 183 /*! 184 * \brief Register for MSB Access Address (BLE) 185 */ 186 #define REG_LR_BLE_ACCESS_ADDRESS 0x09CF 187 #define BLE_ADVERTIZER_ACCESS_ADDRESS 0x8E89BED6 188 189 /*! 190 * \brief Register address and mask for LNA regime selection 191 */ 192 #define REG_LNA_REGIME 0x0891 193 #define MASK_LNA_REGIME 0xC0 194 195 /*! 196 * \brief Register and mask enabling manual gain control 197 */ 198 #define REG_ENABLE_MANUAL_GAIN_CONTROL 0x089F 199 #define MASK_MANUAL_GAIN_CONTROL 0x80 200 201 /*! 202 * \brief Register and mask controlling demodulation detection 203 */ 204 #define REG_DEMOD_DETECTION 0x0895 205 #define MASK_DEMOD_DETECTION 0xFE 206 207 /*! 208 * \brief Register and mask setting manual gain value 209 */ 210 #define REG_MANUAL_GAIN_VALUE 0x089E 211 #define MASK_MANUAL_GAIN_VALUE 0xF0 212 213 /*! 214 * \brief Selector values to configure LNA regime 215 */ 216 typedef enum{ 217 LNA_LOW_POWER_MODE, //!< Allow maximum efficiency of sx1280 (default) 218 LNA_HIGH_SENSITIVITY_MODE, //!< Allow to use highest three steps of LNA gain and increase current consumption 219 }RadioLnaSettings_t; 220 221 /*! 222 * \brief Structure describing the radio status 223 */ 224 typedef union 225 { 226 /*! 227 * \brief Structure of the radio status 228 */ 229 struct 230 { 231 uint8_t CpuBusy : 1; //!< Flag for CPU radio busy 232 uint8_t DmaBusy : 1; //!< Flag for DMA busy 233 uint8_t CmdStatus : 3; //!< Command status 234 uint8_t ChipMode : 3; //!< Chip mode 235 }Fields; 236 237 /*! 238 * \brief Serialized radio status 239 */ 240 uint8_t Value; 241 }RadioStatus_t; 242 243 /*! 244 * \brief Represents the states of the radio 245 */ 246 typedef enum 247 { 248 RF_IDLE = 0x00, //!< The radio is idle 249 RF_RX_RUNNING, //!< The radio is in reception state 250 RF_TX_RUNNING, //!< The radio is in transmission state 251 RF_CAD, //!< The radio is doing channel activity detection 252 }RadioStates_t; 253 254 /*! 255 * \brief Represents the operating mode the radio is actually running 256 */ 257 typedef enum 258 { 259 MODE_SLEEP = 0x00, //! The radio is in sleep mode 260 MODE_STDBY_RC, //! The radio is in standby mode with RC oscillator 261 MODE_STDBY_XOSC, //! The radio is in standby mode with XOSC oscillator 262 MODE_FS, //! The radio is in frequency synthesis mode 263 MODE_TX, //! The radio is in transmit mode 264 MODE_RX, //! The radio is in receive mode 265 MODE_CAD //! The radio is in channel activity detection mode 266 }RadioOperatingModes_t; 267 268 /*! 269 * \brief Declares the oscillator in use while in standby mode 270 * 271 * Using the STDBY_RC standby mode allow to reduce the energy consumption 272 * STDBY_XOSC should be used for time critical applications 273 */ 274 typedef enum 275 { 276 STDBY_RC = 0x00, 277 STDBY_XOSC = 0x01, 278 }RadioStandbyModes_t; 279 280 /*! 281 * \brief Declares the power regulation used to power the device 282 * 283 * This command allows the user to specify if DC-DC or LDO is used for power regulation. 284 * Using only LDO implies that the Rx or Tx current is doubled 285 */ 286 typedef enum 287 { 288 USE_LDO = 0x00, //! Use LDO (default value) 289 USE_DCDC = 0x01, //! Use DCDC 290 }RadioRegulatorModes_t; 291 292 /*! 293 * \brief Represents the possible packet type (i.e. modem) used 294 */ 295 typedef enum 296 { 297 PACKET_TYPE_GFSK = 0x00, 298 PACKET_TYPE_LORA, 299 PACKET_TYPE_RANGING, 300 PACKET_TYPE_FLRC, 301 PACKET_TYPE_BLE, 302 PACKET_TYPE_NONE = 0x0F, 303 }RadioPacketTypes_t; 304 305 /*! 306 * \brief Represents the ramping time for power amplifier 307 */ 308 typedef enum 309 { 310 RADIO_RAMP_02_US = 0x00, 311 RADIO_RAMP_04_US = 0x20, 312 RADIO_RAMP_06_US = 0x40, 313 RADIO_RAMP_08_US = 0x60, 314 RADIO_RAMP_10_US = 0x80, 315 RADIO_RAMP_12_US = 0xA0, 316 RADIO_RAMP_16_US = 0xC0, 317 RADIO_RAMP_20_US = 0xE0, 318 }RadioRampTimes_t; 319 320 /*! 321 * \brief Represents the number of symbols to be used for channel activity detection operation 322 */ 323 typedef enum 324 { 325 LORA_CAD_01_SYMBOL = 0x00, 326 LORA_CAD_02_SYMBOL = 0x20, 327 LORA_CAD_04_SYMBOL = 0x40, 328 LORA_CAD_08_SYMBOL = 0x60, 329 LORA_CAD_16_SYMBOL = 0x80, 330 }RadioLoRaCadSymbols_t; 331 332 /*! 333 * \brief Represents the possible combinations of bitrate and bandwidth for 334 * GFSK and BLE packet types 335 * 336 * The bitrate is expressed in Mb/s and the bandwidth in MHz 337 */ 338 typedef enum 339 { 340 GFSK_BLE_BR_2_000_BW_2_4 = 0x04, 341 GFSK_BLE_BR_1_600_BW_2_4 = 0x28, 342 GFSK_BLE_BR_1_000_BW_2_4 = 0x4C, 343 GFSK_BLE_BR_1_000_BW_1_2 = 0x45, 344 GFSK_BLE_BR_0_800_BW_2_4 = 0x70, 345 GFSK_BLE_BR_0_800_BW_1_2 = 0x69, 346 GFSK_BLE_BR_0_500_BW_1_2 = 0x8D, 347 GFSK_BLE_BR_0_500_BW_0_6 = 0x86, 348 GFSK_BLE_BR_0_400_BW_1_2 = 0xB1, 349 GFSK_BLE_BR_0_400_BW_0_6 = 0xAA, 350 GFSK_BLE_BR_0_250_BW_0_6 = 0xCE, 351 GFSK_BLE_BR_0_250_BW_0_3 = 0xC7, 352 GFSK_BLE_BR_0_125_BW_0_3 = 0xEF, 353 }RadioGfskBleBitrates_t; 354 355 /*! 356 * \brief Represents the modulation index used in GFSK and BLE packet 357 * types 358 */ 359 typedef enum 360 { 361 GFSK_BLE_MOD_IND_0_35 = 0, 362 GFSK_BLE_MOD_IND_0_50 = 1, 363 GFSK_BLE_MOD_IND_0_75 = 2, 364 GFSK_BLE_MOD_IND_1_00 = 3, 365 GFSK_BLE_MOD_IND_1_25 = 4, 366 GFSK_BLE_MOD_IND_1_50 = 5, 367 GFSK_BLE_MOD_IND_1_75 = 6, 368 GFSK_BLE_MOD_IND_2_00 = 7, 369 GFSK_BLE_MOD_IND_2_25 = 8, 370 GFSK_BLE_MOD_IND_2_50 = 9, 371 GFSK_BLE_MOD_IND_2_75 = 10, 372 GFSK_BLE_MOD_IND_3_00 = 11, 373 GFSK_BLE_MOD_IND_3_25 = 12, 374 GFSK_BLE_MOD_IND_3_50 = 13, 375 GFSK_BLE_MOD_IND_3_75 = 14, 376 GFSK_BLE_MOD_IND_4_00 = 15, 377 }RadioGfskBleModIndexes_t; 378 379 /*! 380 * \brief Represents the possible combination of bitrate and bandwidth for FLRC 381 * packet type 382 * 383 * The bitrate is in Mb/s and the bitrate in MHz 384 */ 385 typedef enum 386 { 387 FLRC_BR_2_600_BW_2_4 = 0x04, 388 FLRC_BR_2_080_BW_2_4 = 0x28, 389 FLRC_BR_1_300_BW_1_2 = 0x45, 390 FLRC_BR_1_040_BW_1_2 = 0x69, 391 FLRC_BR_0_650_BW_0_6 = 0x86, 392 FLRC_BR_0_520_BW_0_6 = 0xAA, 393 FLRC_BR_0_325_BW_0_3 = 0xC7, 394 FLRC_BR_0_260_BW_0_3 = 0xEB, 395 }RadioFlrcBitrates_t; 396 397 /*! 398 * \brief Represents the possible values for coding rate parameter in FLRC 399 * packet type 400 */ 401 typedef enum 402 { 403 FLRC_CR_1_2 = 0x00, 404 FLRC_CR_3_4 = 0x02, 405 FLRC_CR_1_0 = 0x04, 406 }RadioFlrcCodingRates_t; 407 408 /*! 409 * \brief Represents the modulation shaping parameter for GFSK, FLRC and BLE 410 * packet types 411 */ 412 typedef enum 413 { 414 RADIO_MOD_SHAPING_BT_OFF = 0x00, //! No filtering 415 RADIO_MOD_SHAPING_BT_1_0 = 0x10, 416 RADIO_MOD_SHAPING_BT_0_5 = 0x20, 417 }RadioModShapings_t; 418 419 /*! 420 * \brief Represents the possible spreading factor values in LORA packet types 421 */ 422 typedef enum 423 { 424 LORA_SF5 = 0x50, 425 LORA_SF6 = 0x60, 426 LORA_SF7 = 0x70, 427 LORA_SF8 = 0x80, 428 LORA_SF9 = 0x90, 429 LORA_SF10 = 0xA0, 430 LORA_SF11 = 0xB0, 431 LORA_SF12 = 0xC0, 432 }RadioLoRaSpreadingFactors_t; 433 434 /*! 435 * \brief Represents the bandwidth values for LORA packet type 436 */ 437 typedef enum 438 { 439 LORA_BW_0200 = 0x34, 440 LORA_BW_0400 = 0x26, 441 LORA_BW_0800 = 0x18, 442 LORA_BW_1600 = 0x0A, 443 }RadioLoRaBandwidths_t; 444 445 /*! 446 * \brief Represents the coding rate values for LORA packet type 447 */ 448 typedef enum 449 { 450 LORA_CR_4_5 = 0x01, 451 LORA_CR_4_6 = 0x02, 452 LORA_CR_4_7 = 0x03, 453 LORA_CR_4_8 = 0x04, 454 LORA_CR_LI_4_5 = 0x05, 455 LORA_CR_LI_4_6 = 0x06, 456 LORA_CR_LI_4_7 = 0x07, 457 }RadioLoRaCodingRates_t; 458 459 /*! 460 * \brief Represents the preamble length values for GFSK and FLRC packet 461 * types 462 */ 463 typedef enum 464 { 465 PREAMBLE_LENGTH_04_BITS = 0x00, //!< Preamble length: 04 bits 466 PREAMBLE_LENGTH_08_BITS = 0x10, //!< Preamble length: 08 bits 467 PREAMBLE_LENGTH_12_BITS = 0x20, //!< Preamble length: 12 bits 468 PREAMBLE_LENGTH_16_BITS = 0x30, //!< Preamble length: 16 bits 469 PREAMBLE_LENGTH_20_BITS = 0x40, //!< Preamble length: 20 bits 470 PREAMBLE_LENGTH_24_BITS = 0x50, //!< Preamble length: 24 bits 471 PREAMBLE_LENGTH_28_BITS = 0x60, //!< Preamble length: 28 bits 472 PREAMBLE_LENGTH_32_BITS = 0x70, //!< Preamble length: 32 bits 473 }RadioPreambleLengths_t; 474 475 /*! 476 * \brief Represents the SyncWord length for FLRC packet type 477 */ 478 typedef enum 479 { 480 FLRC_NO_SYNCWORD = 0x00, 481 FLRC_SYNCWORD_LENGTH_4_BYTE = 0x04, 482 }RadioFlrcSyncWordLengths_t; 483 484 /*! 485 * \brief The length of sync words for GFSK packet type 486 */ 487 typedef enum 488 { 489 GFSK_SYNCWORD_LENGTH_1_BYTE = 0x00, //!< Sync word length: 1 byte 490 GFSK_SYNCWORD_LENGTH_2_BYTE = 0x02, //!< Sync word length: 2 bytes 491 GFSK_SYNCWORD_LENGTH_3_BYTE = 0x04, //!< Sync word length: 3 bytes 492 GFSK_SYNCWORD_LENGTH_4_BYTE = 0x06, //!< Sync word length: 4 bytes 493 GFSK_SYNCWORD_LENGTH_5_BYTE = 0x08, //!< Sync word length: 5 bytes 494 }RadioSyncWordLengths_t; 495 496 /*! 497 * \brief Represents the possible combinations of SyncWord correlators 498 * activated for GFSK and FLRC packet types 499 */ 500 typedef enum 501 { 502 RADIO_RX_MATCH_SYNCWORD_OFF = 0x00, //!< No correlator turned on, i.e. do not search for SyncWord 503 RADIO_RX_MATCH_SYNCWORD_1 = 0x10, 504 RADIO_RX_MATCH_SYNCWORD_2 = 0x20, 505 RADIO_RX_MATCH_SYNCWORD_1_2 = 0x30, 506 RADIO_RX_MATCH_SYNCWORD_3 = 0x40, 507 RADIO_RX_MATCH_SYNCWORD_1_3 = 0x50, 508 RADIO_RX_MATCH_SYNCWORD_2_3 = 0x60, 509 RADIO_RX_MATCH_SYNCWORD_1_2_3 = 0x70, 510 }RadioSyncWordRxMatchs_t; 511 512 /*! 513 * \brief Radio packet length mode for GFSK and FLRC packet types 514 */ 515 typedef enum 516 { 517 RADIO_PACKET_FIXED_LENGTH = 0x00, //!< The packet is known on both sides, no header included in the packet 518 RADIO_PACKET_VARIABLE_LENGTH = 0x20, //!< The packet is on variable size, header included 519 }RadioPacketLengthModes_t; 520 521 /*! 522 * \brief Represents the CRC length for GFSK and FLRC packet types 523 * 524 * \warning Not all configurations are available for both GFSK and FLRC 525 * packet type. Refer to the datasheet for possible configuration. 526 */ 527 typedef enum 528 { 529 RADIO_CRC_OFF = 0x00, //!< No CRC in use 530 RADIO_CRC_1_BYTES = 0x10, 531 RADIO_CRC_2_BYTES = 0x20, 532 RADIO_CRC_3_BYTES = 0x30, 533 }RadioCrcTypes_t; 534 535 /*! 536 * \brief Radio whitening mode activated or deactivated for GFSK, FLRC and 537 * BLE packet types 538 */ 539 typedef enum 540 { 541 RADIO_WHITENING_ON = 0x00, 542 RADIO_WHITENING_OFF = 0x08, 543 }RadioWhiteningModes_t; 544 545 /*! 546 * \brief Holds the packet length mode of a LORA packet type 547 */ 548 typedef enum 549 { 550 LORA_PACKET_VARIABLE_LENGTH = 0x00, //!< The packet is on variable size, header included 551 LORA_PACKET_FIXED_LENGTH = 0x80, //!< The packet is known on both sides, no header included in the packet 552 LORA_PACKET_EXPLICIT = LORA_PACKET_VARIABLE_LENGTH, 553 LORA_PACKET_IMPLICIT = LORA_PACKET_FIXED_LENGTH, 554 }RadioLoRaPacketLengthsModes_t; 555 556 /*! 557 * \brief Represents the CRC mode for LORA packet type 558 */ 559 typedef enum 560 { 561 LORA_CRC_ON = 0x20, //!< CRC activated 562 LORA_CRC_OFF = 0x00, //!< CRC not used 563 }RadioLoRaCrcModes_t; 564 565 /*! 566 * \brief Represents the IQ mode for LORA packet type 567 */ 568 typedef enum 569 { 570 LORA_IQ_NORMAL = 0x40, 571 LORA_IQ_INVERTED = 0x00, 572 }RadioLoRaIQModes_t; 573 574 /*! 575 * \brief Represents the length of the ID to check in ranging operation 576 */ 577 typedef enum 578 { 579 RANGING_IDCHECK_LENGTH_08_BITS = 0x00, 580 RANGING_IDCHECK_LENGTH_16_BITS, 581 RANGING_IDCHECK_LENGTH_24_BITS, 582 RANGING_IDCHECK_LENGTH_32_BITS, 583 }RadioRangingIdCheckLengths_t; 584 585 /*! 586 * \brief Represents the result type to be used in ranging operation 587 */ 588 typedef enum 589 { 590 RANGING_RESULT_RAW = 0x00, 591 RANGING_RESULT_AVERAGED = 0x01, 592 RANGING_RESULT_DEBIASED = 0x02, 593 RANGING_RESULT_FILTERED = 0x03, 594 }RadioRangingResultTypes_t; 595 596 /*! 597 * \brief Represents the connection state for BLE packet type 598 */ 599 typedef enum 600 { 601 BLE_PAYLOAD_LENGTH_MAX_31_BYTES = 0x00, 602 BLE_PAYLOAD_LENGTH_MAX_37_BYTES = 0x20, 603 BLE_TX_TEST_MODE = 0x40, 604 BLE_PAYLOAD_LENGTH_MAX_255_BYTES = 0x80, 605 }RadioBleConnectionStates_t; 606 607 /*! 608 * \brief Represents the CRC field length for BLE packet type 609 */ 610 typedef enum 611 { 612 BLE_CRC_OFF = 0x00, 613 BLE_CRC_3B = 0x10, 614 }RadioBleCrcFields_t; 615 616 /*! 617 * \brief Represents the specific packets to use in BLE packet type 618 */ 619 typedef enum 620 { 621 BLE_PRBS_9 = 0x00, //!< Pseudo Random Binary Sequence based on 9th degree polynomial 622 BLE_PRBS_15 = 0x0C, //!< Pseudo Random Binary Sequence based on 15th degree polynomial 623 BLE_EYELONG_1_0 = 0x04, //!< Repeated '11110000' sequence 624 BLE_EYELONG_0_1 = 0x18, //!< Repeated '00001111' sequence 625 BLE_EYESHORT_1_0 = 0x08, //!< Repeated '10101010' sequence 626 BLE_EYESHORT_0_1 = 0x1C, //!< Repeated '01010101' sequence 627 BLE_ALL_1 = 0x10, //!< Repeated '11111111' sequence 628 BLE_ALL_0 = 0x14, //!< Repeated '00000000' sequence 629 }RadioBlePacketTypes_t; 630 631 /*! 632 * \brief Represents the interruption masks available for the radio 633 * 634 * \remark Note that not all these interruptions are available for all packet types 635 */ 636 typedef enum 637 { 638 IRQ_RADIO_NONE = 0x0000, 639 IRQ_TX_DONE = 0x0001, 640 IRQ_RX_DONE = 0x0002, 641 IRQ_SYNCWORD_VALID = 0x0004, 642 IRQ_SYNCWORD_ERROR = 0x0008, 643 IRQ_HEADER_VALID = 0x0010, 644 IRQ_HEADER_ERROR = 0x0020, 645 IRQ_CRC_ERROR = 0x0040, 646 IRQ_RANGING_SLAVE_RESPONSE_DONE = 0x0080, 647 IRQ_RANGING_SLAVE_REQUEST_DISCARDED = 0x0100, 648 IRQ_RANGING_MASTER_RESULT_VALID = 0x0200, 649 IRQ_RANGING_MASTER_RESULT_TIMEOUT = 0x0400, 650 IRQ_RANGING_SLAVE_REQUEST_VALID = 0x0800, 651 IRQ_CAD_DONE = 0x1000, 652 IRQ_CAD_ACTIVITY_DETECTED = 0x2000, 653 IRQ_RX_TX_TIMEOUT = 0x4000, 654 IRQ_PREAMBLE_DETECTED = 0x8000, 655 IRQ_RADIO_ALL = 0xFFFF, 656 }RadioIrqMasks_t; 657 658 /*! 659 * \brief Represents the digital input/output of the radio 660 */ 661 typedef enum 662 { 663 RADIO_DIO1 = 0x02, 664 RADIO_DIO2 = 0x04, 665 RADIO_DIO3 = 0x08, 666 }RadioDios_t; 667 668 /*! 669 * \brief Represents the tick size available for Rx/Tx timeout operations 670 */ 671 typedef enum 672 { 673 RADIO_TICK_SIZE_0015_US = 0x00, 674 RADIO_TICK_SIZE_0062_US = 0x01, 675 RADIO_TICK_SIZE_1000_US = 0x02, 676 RADIO_TICK_SIZE_4000_US = 0x03, 677 }RadioTickSizes_t; 678 679 /*! 680 * \brief Represents the role of the radio during ranging operations 681 */ 682 typedef enum 683 { 684 RADIO_RANGING_ROLE_SLAVE = 0x00, 685 RADIO_RANGING_ROLE_MASTER = 0x01, 686 }RadioRangingRoles_t; 687 688 /*! 689 * \brief Represents all possible opcode understood by the radio 690 */ 691 typedef enum RadioCommands_u 692 { 693 RADIO_GET_STATUS = 0xC0, 694 RADIO_WRITE_REGISTER = 0x18, 695 RADIO_READ_REGISTER = 0x19, 696 RADIO_WRITE_BUFFER = 0x1A, 697 RADIO_READ_BUFFER = 0x1B, 698 RADIO_SET_SLEEP = 0x84, 699 RADIO_SET_STANDBY = 0x80, 700 RADIO_SET_FS = 0xC1, 701 RADIO_SET_TX = 0x83, 702 RADIO_SET_RX = 0x82, 703 RADIO_SET_RXDUTYCYCLE = 0x94, 704 RADIO_SET_CAD = 0xC5, 705 RADIO_SET_TXCONTINUOUSWAVE = 0xD1, 706 RADIO_SET_TXCONTINUOUSPREAMBLE = 0xD2, 707 RADIO_SET_PACKETTYPE = 0x8A, 708 RADIO_GET_PACKETTYPE = 0x03, 709 RADIO_SET_RFFREQUENCY = 0x86, 710 RADIO_SET_TXPARAMS = 0x8E, 711 RADIO_SET_CADPARAMS = 0x88, 712 RADIO_SET_BUFFERBASEADDRESS = 0x8F, 713 RADIO_SET_MODULATIONPARAMS = 0x8B, 714 RADIO_SET_PACKETPARAMS = 0x8C, 715 RADIO_GET_RXBUFFERSTATUS = 0x17, 716 RADIO_GET_PACKETSTATUS = 0x1D, 717 RADIO_GET_RSSIINST = 0x1F, 718 RADIO_SET_DIOIRQPARAMS = 0x8D, 719 RADIO_GET_IRQSTATUS = 0x15, 720 RADIO_CLR_IRQSTATUS = 0x97, 721 RADIO_CALIBRATE = 0x89, 722 RADIO_SET_REGULATORMODE = 0x96, 723 RADIO_SET_SAVECONTEXT = 0xD5, 724 RADIO_SET_AUTOTX = 0x98, 725 RADIO_SET_AUTOFS = 0x9E, 726 RADIO_SET_LONGPREAMBLE = 0x9B, 727 RADIO_SET_UARTSPEED = 0x9D, 728 RADIO_SET_RANGING_ROLE = 0xA3, 729 }RadioCommands_t; 730 731 /*! 732 * \brief Represents an amount of time measurable by the radio clock 733 * 734 * @code 735 * Time = Step * NbSteps 736 * Example: 737 * Step = RADIO_TICK_SIZE_4000_US( 4 ms ) 738 * NbSteps = 1000 739 * Time = 4e-3 * 1000 = 4 seconds 740 * @endcode 741 */ 742 typedef struct TickTime_s 743 { 744 RadioTickSizes_t Step; //!< The step of ticktime 745 /*! 746 * \brief The number of steps for ticktime 747 * Special values are: 748 * - 0x0000 for single mode 749 * - 0xFFFF for continuous mode 750 */ 751 uint16_t NbSteps; 752 }TickTime_t; 753 754 /*! 755 * \brief RX_TX_CONTINUOUS and RX_TX_SINGLE are two particular values for TickTime. 756 * The former keep the radio in Rx or Tx mode, even after successfull reception 757 * or transmission. It should never generate Timeout interrupt. 758 * The later let the radio enought time to make one reception or transmission. 759 * No Timeout interrupt is generated, and the radio fall in StandBy mode after 760 * reception or transmission. 761 */ 762 #define RX_TX_CONTINUOUS ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0xFFFF } 763 #define RX_TX_SINGLE ( TickTime_t ){ RADIO_TICK_SIZE_0015_US, 0 } 764 765 /*! 766 * \brief The type describing the modulation parameters for every packet types 767 */ 768 typedef struct 769 { 770 RadioPacketTypes_t PacketType; //!< Packet to which the modulation parameters are referring to. 771 // union 772 struct 773 { 774 /*! 775 * \brief Holds the GFSK modulation parameters 776 * 777 * In GFSK modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 778 */ 779 struct 780 { 781 RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations 782 RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations 783 RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations 784 }Gfsk; 785 /*! 786 * \brief Holds the LORA modulation parameters 787 * 788 * LORA modulation is defined by Spreading Factor (SF), Bandwidth and Coding Rate 789 */ 790 struct 791 { 792 RadioLoRaSpreadingFactors_t SpreadingFactor; //!< Spreading Factor for the LORA modulation 793 RadioLoRaBandwidths_t Bandwidth; //!< Bandwidth for the LORA modulation 794 RadioLoRaCodingRates_t CodingRate; //!< Coding rate for the LORA modulation 795 }LoRa; 796 /*! 797 * \brief Holds the FLRC modulation parameters 798 * 799 * In FLRC modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 800 */ 801 struct 802 { 803 RadioFlrcBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for FLRC modulation 804 RadioFlrcCodingRates_t CodingRate; //!< The coding rate for FLRC modulation 805 RadioModShapings_t ModulationShaping; //!< The modulation shaping for FLRC modulation 806 }Flrc; 807 /*! 808 * \brief Holds the BLE modulation parameters 809 * 810 * In BLE modulation, the bit-rate and bandwidth are linked together. In this structure, its values are set using the same token. 811 */ 812 struct 813 { 814 RadioGfskBleBitrates_t BitrateBandwidth; //!< The bandwidth and bit-rate values for BLE and GFSK modulations 815 RadioGfskBleModIndexes_t ModulationIndex; //!< The coding rate for BLE and GFSK modulations 816 RadioModShapings_t ModulationShaping; //!< The modulation shaping for BLE and GFSK modulations 817 }Ble; 818 }Params; //!< Holds the modulation parameters structure 819 }ModulationParams_t; 820 821 /*! 822 * \brief Structure describing the error codes for callback functions 823 */ 824 typedef enum 825 { 826 IRQ_HEADER_ERROR_CODE = 0x00, 827 IRQ_SYNCWORD_ERROR_CODE, 828 IRQ_CRC_ERROR_CODE, 829 IRQ_RANGING_ON_LORA_ERROR_CODE, 830 }IrqErrorCode_t; 831 832 /*! 833 * \brief Structure describing the ranging codes for callback functions 834 */ 835 typedef enum 836 { 837 IRQ_RANGING_SLAVE_ERROR_CODE = 0x00, 838 IRQ_RANGING_SLAVE_VALID_CODE, 839 IRQ_RANGING_MASTER_ERROR_CODE, 840 IRQ_RANGING_MASTER_VALID_CODE, 841 }IrqRangingCode_t; 842 843 /*! 844 * \brief The radio callbacks structure 845 * Holds function pointers to be called on radio interrupts 846 */ 847 typedef struct 848 { 849 void ( *txDone )( void ); //!< Pointer to a function run on successful transmission 850 void ( *rxDone )( void ); //!< Pointer to a function run on successful reception 851 void ( *rxSyncWordDone )( void ); //!< Pointer to a function run on successful SyncWord reception 852 void ( *rxHeaderDone )( void ); //!< Pointer to a function run on successful Header reception 853 void ( *txTimeout )( void ); //!< Pointer to a function run on transmission timeout 854 void ( *rxTimeout )( void ); //!< Pointer to a function run on reception timeout 855 void ( *rxError )( IrqErrorCode_t errCode ); //!< Pointer to a function run on reception error 856 void ( *rangingDone )( IrqRangingCode_t val ); //!< Pointer to a function run on ranging terminated 857 void ( *cadDone )( bool cadFlag ); //!< Pointer to a function run on channel activity detected 858 }RadioCallbacks_t; 859 860 /*! 861 * \brief The type describing the packet parameters for every packet types 862 */ 863 typedef struct 864 { 865 RadioPacketTypes_t PacketType; //!< Packet to which the packet parameters are referring to. 866 // union 867 struct 868 { 869 /*! 870 * \brief Holds the GFSK packet parameters 871 */ 872 struct 873 { 874 RadioPreambleLengths_t PreambleLength; //!< The preamble length for GFSK packet type 875 RadioSyncWordLengths_t SyncWordLength; //!< The synchronization word length for GFSK packet type 876 RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word 877 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 878 uint8_t PayloadLength; //!< Size of the payload in the GFSK packet 879 RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the GFSK packet 880 RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable 881 }Gfsk; 882 /*! 883 * \brief Holds the LORA packet parameters 884 */ 885 struct 886 { 887 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 888 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 889 uint8_t PayloadLength; //!< Size of the payload in the LORA packet 890 RadioLoRaCrcModes_t CrcMode; //!< Size of CRC block in LORA packet 891 RadioLoRaIQModes_t InvertIQ; //!< Allows to swap IQ for LORA packet 892 }LoRa; 893 /*! 894 * \brief Holds the FLRC packet parameters 895 */ 896 struct 897 { 898 RadioPreambleLengths_t PreambleLength; //!< The preamble length for FLRC packet type 899 RadioFlrcSyncWordLengths_t SyncWordLength; //!< The synchronization word length for FLRC packet type 900 RadioSyncWordRxMatchs_t SyncWordMatch; //!< The synchronization correlator to use to check synchronization word 901 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. 902 uint8_t PayloadLength; //!< Size of the payload in the FLRC packet 903 RadioCrcTypes_t CrcLength; //!< Size of the CRC block in the FLRC packet 904 RadioWhiteningModes_t Whitening; //!< Usage of whitening on payload and CRC blocks plus header block if header type is variable 905 }Flrc; 906 /*! 907 * \brief Holds the BLE packet parameters 908 */ 909 struct 910 { 911 RadioBleConnectionStates_t ConnectionState; //!< The BLE state 912 RadioBleCrcFields_t CrcField; //!< Size of the CRC block in the BLE packet 913 RadioBlePacketTypes_t BlePacketType; //!< Special BLE packet types 914 RadioWhiteningModes_t Whitening; //!< Usage of whitening on PDU and CRC blocks of BLE packet 915 }Ble; 916 }Params; //!< Holds the packet parameters structure 917 }PacketParams_t; 918 919 /*! 920 * \brief Represents the packet status for every packet type 921 */ 922 typedef struct 923 { 924 RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to. 925 union 926 { 927 struct 928 { 929 int8_t RssiAvg; //!< The averaged RSSI 930 int8_t RssiSync; //!< The RSSI measured on last packet 931 struct 932 { 933 bool SyncError :1; //!< SyncWord error on last packet 934 bool LengthError :1; //!< Length error on last packet 935 bool CrcError :1; //!< CRC error on last packet 936 bool AbortError :1; //!< Abort error on last packet 937 bool HeaderReceived :1; //!< Header received on last packet 938 bool PacketReceived :1; //!< Packet received 939 bool PacketControlerBusy :1; //!< Packet controller busy 940 }ErrorStatus; //!< The error status Byte 941 struct 942 { 943 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 944 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 945 }TxRxStatus; //!< The Tx/Rx status Byte 946 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 947 }Gfsk; 948 struct 949 { 950 int8_t RssiPkt; //!< The RSSI of the last packet 951 int8_t SnrPkt; //!< The SNR of the last packet 952 struct 953 { 954 bool SyncError :1; //!< SyncWord error on last packet 955 bool LengthError :1; //!< Length error on last packet 956 bool CrcError :1; //!< CRC error on last packet 957 bool AbortError :1; //!< Abort error on last packet 958 bool HeaderReceived :1; //!< Header received on last packet 959 bool PacketReceived :1; //!< Packet received 960 bool PacketControlerBusy :1; //!< Packet controller busy 961 }ErrorStatus; //!< The error status Byte 962 struct 963 { 964 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 965 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 966 }TxRxStatus; //!< The Tx/Rx status Byte 967 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 968 }LoRa; 969 struct 970 { 971 int8_t RssiAvg; //!< The averaged RSSI 972 int8_t RssiSync; //!< The RSSI of the last packet 973 struct 974 { 975 bool SyncError :1; //!< SyncWord error on last packet 976 bool LengthError :1; //!< Length error on last packet 977 bool CrcError :1; //!< CRC error on last packet 978 bool AbortError :1; //!< Abort error on last packet 979 bool HeaderReceived :1; //!< Header received on last packet 980 bool PacketReceived :1; //!< Packet received 981 bool PacketControlerBusy :1; //!< Packet controller busy 982 }ErrorStatus; //!< The error status Byte 983 struct 984 { 985 uint8_t RxPid :2; //!< PID of the Rx 986 bool RxNoAck :1; //!< No acknowledgment received for Rx with variable length packets 987 bool RxPidErr :1; //!< Received PID error 988 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 989 }TxRxStatus; //!< The Tx/Rx status Byte 990 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 991 }Flrc; 992 struct 993 { 994 int8_t RssiAvg; //!< The averaged RSSI 995 int8_t RssiSync; //!< The RSSI of the last packet 996 struct 997 { 998 bool SyncError :1; //!< SyncWord error on last packet 999 bool LengthError :1; //!< Length error on last packet 1000 bool CrcError :1; //!< CRC error on last packet 1001 bool AbortError :1; //!< Abort error on last packet 1002 bool HeaderReceived :1; //!< Header received on last packet 1003 bool PacketReceived :1; //!< Packet received 1004 bool PacketControlerBusy :1; //!< Packet controller busy 1005 }ErrorStatus; //!< The error status Byte 1006 struct 1007 { 1008 bool PacketSent :1; //!< Packet sent, only relevant in Tx mode 1009 }TxRxStatus; //!< The Tx/Rx status Byte 1010 uint8_t SyncAddrStatus :3; //!< The id of the correlator who found the packet 1011 }Ble; 1012 }Params; 1013 }PacketStatus_t; 1014 1015 /*! 1016 * \brief Represents the Rx internal counters values when GFSK or LORA packet type is used 1017 */ 1018 typedef struct 1019 { 1020 RadioPacketTypes_t packetType; //!< Packet to which the packet status are referring to. 1021 union 1022 { 1023 struct 1024 { 1025 uint16_t PacketReceived; //!< Number of received packets 1026 uint16_t CrcError; //!< Number of CRC errors 1027 uint16_t LengthError; //!< Number of length errors 1028 uint16_t SyncwordError; //!< Number of sync-word errors 1029 }Gfsk; 1030 struct 1031 { 1032 uint16_t PacketReceived; //!< Number of received packets 1033 uint16_t CrcError; //!< Number of CRC errors 1034 uint16_t HeaderValid; //!< Number of valid headers 1035 }LoRa; 1036 }Params; 1037 }RxCounter_t; 1038 1039 /*! 1040 * \brief Represents a calibration configuration 1041 */ 1042 typedef struct 1043 { 1044 uint8_t RC64KEnable : 1; //!< Calibrate RC64K clock 1045 uint8_t RC13MEnable : 1; //!< Calibrate RC13M clock 1046 uint8_t PLLEnable : 1; //!< Calibrate PLL 1047 uint8_t ADCPulseEnable : 1; //!< Calibrate ADC Pulse 1048 uint8_t ADCBulkNEnable : 1; //!< Calibrate ADC bulkN 1049 uint8_t ADCBulkPEnable : 1; //!< Calibrate ADC bulkP 1050 }CalibrationParams_t; 1051 1052 /*! 1053 * \brief Represents a sleep mode configuration 1054 */ 1055 typedef struct 1056 { 1057 uint8_t WakeUpRTC : 1; //!< Get out of sleep mode if wakeup signal received from RTC 1058 uint8_t InstructionRamRetention : 1; //!< InstructionRam is conserved during sleep 1059 uint8_t DataBufferRetention : 1; //!< Data buffer is conserved during sleep 1060 uint8_t DataRamRetention : 1; //!< Data ram is conserved during sleep 1061 }SleepParams_t; 1062 1063 /*! 1064 * \brief Compute the two's complement for a register of size lower than 1065 * 32bits 1066 * 1067 * \param [in] num The register to be two's complemented 1068 * \param [in] bitCnt The position of the sign bit 1069 */ 1070 int32_t SX1280complement2( const uint32_t num, const uint8_t bitCnt ); 1071 1072 /*! 1073 * \brief Returns the value of LoRa bandwidth from driver's value 1074 * 1075 * The value is returned in Hz so that it can be represented as an integer 1076 * type. Most computation should be done as integer to reduce floating 1077 * point related errors. 1078 * 1079 * \retval loRaBw The value of the current bandwidth in Hz 1080 */ 1081 int32_t SX1280GetLoRaBandwidth( void ); 1082 1083 /*! 1084 * \brief Returns the corrected raw value of ranging 1085 * 1086 * \retval correction Corrected ranging raw value 1087 */ 1088 double SX1280GetRangingCorrectionPerSfBwGain( const RadioLoRaSpreadingFactors_t sf, const RadioLoRaBandwidths_t bw, const int8_t gain); 1089 1090 /*! 1091 * \brief Returns the short range corrected distance 1092 * 1093 * \retval Corrected Distance corrected ditance 1094 */ 1095 double SX1280ComputeRangingCorrectionPolynome(const RadioLoRaSpreadingFactors_t sf, const RadioLoRaBandwidths_t bw, const double median); 1096 1097 /*! 1098 * \brief DIOs interrupt callback 1099 * 1100 * \remark Called to handle all 3 DIOs pins 1101 */ 1102 void SX1280OnDioIrq( void ); 1103 1104 /*! 1105 * \brief Set the role of the radio during ranging operations 1106 * 1107 * \param [in] role Role of the radio 1108 */ 1109 void SX1280SetRangingRole( RadioRangingRoles_t role ); 1110 1111 /*! 1112 * \brief Initializes the radio driver 1113 */ 1114 void SX1280Init( RadioCallbacks_t *callbacks ); 1115 1116 /*! 1117 * \brief Set the driver in polling mode. 1118 * 1119 * In polling mode the application is responsible to call ProcessIrqs( ) to 1120 * execute callbacks functions. 1121 * The default mode is Interrupt Mode. 1122 * @code 1123 * // Initializations and callbacks declaration/definition 1124 * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks ); 1125 * radio.Init( ); 1126 * radio.SetPollingMode( ); 1127 * 1128 * while( true ) 1129 * { 1130 * // IRQ processing is automatically done 1131 * radio.ProcessIrqs( ); // <-- here, as well as callback functions 1132 * // calls 1133 * // Do some applicative work 1134 * } 1135 * @endcode 1136 * 1137 * \see SX1280SetInterruptMode 1138 */ 1139 void SX1280SetPollingMode( void ); 1140 1141 /*! 1142 * \brief Set the driver in interrupt mode. 1143 * 1144 * In interrupt mode, the driver communicate with the radio during the 1145 * interruption by direct calls to ProcessIrqs( ). The main advantage is 1146 * the possibility to have low power application architecture. 1147 * This is the default mode. 1148 * @code 1149 * // Initializations and callbacks declaration/definition 1150 * radio = SX1280( mosi, miso, sclk, nss, busy, int1, int2, int3, rst, &callbacks ); 1151 * radio.Init( ); 1152 * radio.SetInterruptMode( ); // Optionnal. Driver default behavior 1153 * 1154 * while( true ) 1155 * { 1156 * // Do some applicative work 1157 * } 1158 * @endcode 1159 * 1160 * \see SX1280SetPollingMode 1161 */ 1162 void SX1280SetInterruptMode( void ); 1163 1164 /*! 1165 * \brief Initializes the radio registers to the recommended default values 1166 */ 1167 void SX1280SetRegistersDefault( void ); 1168 1169 /*! 1170 * \brief Returns the current device firmware version 1171 * 1172 * \retval version Firmware version 1173 */ 1174 uint16_t SX1280GetFirmwareVersion( void ); 1175 1176 /*! 1177 * \brief Gets the current Operation Mode of the Radio 1178 * 1179 * \retval RadioOperatingModes_t last operating mode 1180 */ 1181 RadioOperatingModes_t SX1280GetOpMode( void ); 1182 1183 /*! 1184 * \brief Gets the current radio status 1185 * 1186 * \retval status Radio status 1187 */ 1188 RadioStatus_t SX1280GetStatus( void ); 1189 1190 /*! 1191 * \brief Sets the radio in sleep mode 1192 * 1193 * \param [in] sleepConfig The sleep configuration describing data 1194 * retention and RTC wake-up 1195 */ 1196 void SX1280SetSleep( SleepParams_t sleepConfig ); 1197 1198 /*! 1199 * \brief Sets the radio in configuration mode 1200 * 1201 * \param [in] mode The standby mode to put the radio into 1202 */ 1203 void SX1280SetStandby( RadioStandbyModes_t mode ); 1204 1205 /*! 1206 * \brief Sets the radio in FS mode 1207 */ 1208 void SX1280SetFs( void ); 1209 1210 /*! 1211 * \brief Sets the radio in transmission mode 1212 * 1213 * \param [in] timeout Structure describing the transmission timeout value 1214 */ 1215 void SX1280SetTx( TickTime_t timeout ); 1216 1217 /*! 1218 * \brief Sets the radio in reception mode 1219 * 1220 * \param [in] timeout Structure describing the reception timeout value 1221 */ 1222 void SX1280SetRx( TickTime_t timeout ); 1223 1224 /*! 1225 * \brief Sets the Rx duty cycle management parameters 1226 * 1227 * \param [in] rxTime Structure describing reception timeout value 1228 * \param [in] sleepTime Structure describing sleep timeout value 1229 */ 1230 void SX1280SetRxDutyCycle( RadioTickSizes_t Step, uint16_t NbStepRx, uint16_t RxNbStepSleep ); 1231 1232 /*! 1233 * \brief Sets the radio in CAD mode 1234 * 1235 * \see SX1280::SetCadParams 1236 */ 1237 void SX1280SetCad( void ); 1238 1239 /*! 1240 * \brief Sets the radio in continuous wave transmission mode 1241 */ 1242 void SX1280SetTxContinuousWave( void ); 1243 1244 /*! 1245 * \brief Sets the radio in continuous preamble transmission mode 1246 */ 1247 void SX1280SetTxContinuousPreamble( void ); 1248 1249 /*! 1250 * \brief Sets the radio for the given protocol 1251 * 1252 * \param [in] packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA, 1253 * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC, 1254 * PACKET_TYPE_BLE] 1255 * 1256 * \remark This method has to be called before SetRfFrequency, 1257 * SetModulationParams and SetPacketParams 1258 */ 1259 void SX1280SetPacketType( RadioPacketTypes_t packetType ); 1260 1261 /*! 1262 * \brief Gets the current radio protocol 1263 * 1264 * \retval packetType [PACKET_TYPE_GFSK, PACKET_TYPE_LORA, 1265 * PACKET_TYPE_RANGING, PACKET_TYPE_FLRC, 1266 * PACKET_TYPE_BLE, PACKET_TYPE_NONE] 1267 */ 1268 RadioPacketTypes_t SX1280GetPacketType( void ); 1269 1270 /*! 1271 * \brief Sets the RF frequency 1272 * 1273 * \param [in] frequency RF frequency [Hz] 1274 */ 1275 void SX1280SetRfFrequency( uint32_t frequency ); 1276 1277 /*! 1278 * \brief Sets the transmission parameters 1279 * 1280 * \param [in] power RF output power [-18..13] dBm 1281 * \param [in] rampTime Transmission ramp up time 1282 */ 1283 void SX1280SetTxParams( int8_t power, RadioRampTimes_t rampTime ); 1284 1285 /*! 1286 * \brief Sets the number of symbols to be used for Channel Activity 1287 * Detection operation 1288 * 1289 * \param [in] cadSymbolNum The number of symbol to use for Channel Activity 1290 * Detection operations [LORA_CAD_01_SYMBOL, LORA_CAD_02_SYMBOL, 1291 * LORA_CAD_04_SYMBOL, LORA_CAD_08_SYMBOL, LORA_CAD_16_SYMBOL] 1292 */ 1293 void SX1280SetCadParams( RadioLoRaCadSymbols_t cadSymbolNum ); 1294 1295 /*! 1296 * \brief Sets the data buffer base address for transmission and reception 1297 * 1298 * \param [in] txBaseAddress Transmission base address 1299 * \param [in] rxBaseAddress Reception base address 1300 */ 1301 void SX1280SetBufferBaseAddresses( uint8_t txBaseAddress, uint8_t rxBaseAddress ); 1302 1303 /*! 1304 * \brief Set the modulation parameters 1305 * 1306 * \param [in] modParams A structure describing the modulation parameters 1307 */ 1308 void SX1280SetModulationParams( ModulationParams_t *modParams ); 1309 1310 /*! 1311 * \brief Sets the packet parameters 1312 * 1313 * \param [in] packetParams A structure describing the packet parameters 1314 */ 1315 void SX1280SetPacketParams( PacketParams_t *packetParams ); 1316 1317 /*! 1318 * \brief Gets the last received packet buffer status 1319 * 1320 * \param [out] payloadLength Last received packet payload length 1321 * \param [out] rxStartBuffer Last received packet buffer address pointer 1322 */ 1323 void SX1280GetRxBufferStatus( uint8_t *payloadLength, uint8_t *rxStartBuffer ); 1324 1325 /*! 1326 * \brief Gets the last received packet payload length 1327 * 1328 * \param [out] pktStatus A structure of packet status 1329 */ 1330 void SX1280GetPacketStatus( PacketStatus_t *pktStatus ); 1331 1332 /*! 1333 * \brief Returns the instantaneous RSSI value for the last packet received 1334 * 1335 * \retval rssiInst Instantaneous RSSI 1336 */ 1337 int8_t SX1280GetRssiInst( void ); 1338 1339 /*! 1340 * \brief Sets the IRQ mask and DIO masks 1341 * 1342 * \param [in] irqMask General IRQ mask 1343 * \param [in] dio1Mask DIO1 mask 1344 * \param [in] dio2Mask DIO2 mask 1345 * \param [in] dio3Mask DIO3 mask 1346 */ 1347 void SX1280SetDioIrqParams( uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask ); 1348 1349 /*! 1350 * \brief Returns the current IRQ status 1351 * 1352 * \retval irqStatus IRQ status 1353 */ 1354 uint16_t SX1280GetIrqStatus( void ); 1355 1356 /*! 1357 * \brief Clears the IRQs 1358 * 1359 * \param [in] irq IRQ(s) to be cleared 1360 */ 1361 void SX1280ClearIrqStatus( uint16_t irq ); 1362 1363 /*! 1364 * \brief Calibrates the given radio block 1365 * 1366 * \param [in] calibParam The description of blocks to be calibrated 1367 */ 1368 void SX1280Calibrate( CalibrationParams_t calibParam ); 1369 1370 /*! 1371 * \brief Sets the power regulators operating mode 1372 * 1373 * \param [in] mode [0: LDO, 1:DC_DC] 1374 */ 1375 void SX1280SetRegulatorMode( RadioRegulatorModes_t mode ); 1376 1377 /*! 1378 * \brief Saves the current selected modem configuration into data RAM 1379 */ 1380 void SX1280SetSaveContext( void ); 1381 1382 /*! 1383 * \brief Sets the chip to automatically send a packet after the end of a packet reception 1384 * 1385 * \remark The offset is automatically compensated inside the function 1386 * 1387 * \param [in] time The delay in us after which a Tx is done 1388 */ 1389 void SX1280SetAutoTx( uint16_t time ); 1390 1391 /*! 1392 * \brief Stop the chip from automatically sending a packet after the end of a packet reception 1393 * if previously activated with SX1280SetAutoTx command 1394 * 1395 * \see SX1280SetAutoTx 1396 */ 1397 void SX1280StopAutoTx( void ); 1398 1399 /*! 1400 * \brief Sets the chip to automatically receive a packet after the end of a packet transmission 1401 * 1402 * \remark The offset is automatically compensated inside the function 1403 * 1404 * \param [in] time The delay in us after which a Rx is done 1405 */ 1406 void SX1280SetAutoFS( uint8_t enable ); 1407 1408 /*! 1409 * \brief Enables or disables long preamble detection mode 1410 * 1411 * \param [in] enable [0: Disable, 1: Enable] 1412 */ 1413 void SX1280SetLongPreamble( uint8_t enable ); 1414 1415 /*! 1416 * \brief Saves the payload to be send in the radio buffer 1417 * 1418 * \param [in] payload A pointer to the payload 1419 * \param [in] size The size of the payload 1420 */ 1421 void SX1280SetPayload( uint8_t *payload, uint8_t size ); 1422 1423 /*! 1424 * \brief Reads the payload received. If the received payload is longer 1425 * than maxSize, then the method returns 1 and do not set size and payload. 1426 * 1427 * \param [out] payload A pointer to a buffer into which the payload will be copied 1428 * \param [out] size A pointer to the size of the payload received 1429 * \param [in] maxSize The maximal size allowed to copy into the buffer 1430 */ 1431 uint8_t SX1280GetPayload( uint8_t *payload, uint8_t *size, uint8_t maxSize ); 1432 1433 /*! 1434 * \brief Sends a payload 1435 * 1436 * \param [in] payload A pointer to the payload to send 1437 * \param [in] size The size of the payload to send 1438 * \param [in] timeout The timeout for Tx operation 1439 */ 1440 void SX1280SendPayload( uint8_t *payload, uint8_t size, TickTime_t timeout ); 1441 1442 /*! 1443 * \brief Sets the Sync Word given by index used in GFSK, FLRC and BLE protocols 1444 * 1445 * \remark 5th byte isn't used in FLRC and BLE protocols 1446 * 1447 * \param [in] syncWordIdx Index of SyncWord to be set [1..3] 1448 * \param [in] syncWord SyncWord bytes ( 5 bytes ) 1449 * 1450 * \retval status [0: OK, 1: NOK] 1451 */ 1452 uint8_t SX1280SetSyncWord( uint8_t syncWordIdx, uint8_t *syncWord ); 1453 1454 /*! 1455 * \brief Defines how many error bits are tolerated in sync word detection 1456 * 1457 * \param [in] errorBits Number of error bits supported to validate the Sync word detection 1458 * ( default is 4 bit, minimum is 1 bit ) 1459 */ 1460 void SX1280SetSyncWordErrorTolerance( uint8_t errorBits ); 1461 1462 /*! 1463 * \brief Sets the Initial value for the LFSR used for the CRC calculation 1464 * 1465 * \param [in] seed Initial LFSR value ( 4 bytes ) 1466 * 1467 */ 1468 void SX1280SetCrcSeed( uint16_t seed ); 1469 1470 /*! 1471 * \brief Set the Access Address field of BLE packet 1472 * 1473 * \param [in] accessAddress The access address to be used for next BLE packet sent 1474 */ 1475 void SX1280SetBleAccessAddress( uint32_t accessAddress ); 1476 1477 /*! 1478 * \brief Set the Access Address for Advertizer BLE packets 1479 * 1480 * All advertizer BLE packets must use a particular value for Access 1481 * Address field. This method sets it. 1482 * 1483 * \see SX1280::SetBleAccessAddress 1484 */ 1485 void SX1280SetBleAdvertizerAccessAddress( void ); 1486 1487 /*! 1488 * \brief Sets the seed used for the CRC calculation 1489 * 1490 * \param [in] seed The seed value 1491 * 1492 */ 1493 void SX1280SetCrcPolynomial( uint16_t seed ); 1494 1495 /*! 1496 * \brief Sets the Initial value of the LFSR used for the whitening in GFSK, FLRC and BLE protocols 1497 * 1498 * \param [in] seed Initial LFSR value 1499 */ 1500 void SX1280SetWhiteningSeed( uint8_t seed ); 1501 1502 /*! 1503 * \brief Enable manual gain and disable AGC 1504 * 1505 * \see SX1280SetManualGainValue, SX1280DisableManualGain 1506 */ 1507 void SX1280EnableManualGain( void ); 1508 1509 /*! 1510 * \brief Disable the manual gain control and enable AGC 1511 * 1512 * \see SX1280EnableManualGain 1513 */ 1514 void SX1280DisableManualGain( void ); 1515 1516 /*! 1517 * \brief Set the gain for LNA 1518 * 1519 * SX1280EnableManualGain must be call before using this function 1520 * 1521 * \param [in] gain The value of gain to set, refer to datasheet for value meaning 1522 * 1523 * \see SX1280EnableManualGain, SX1280DisableManualGain 1524 */ 1525 void SX1280SetManualGainValue( uint8_t gain ); 1526 1527 /*! 1528 * \brief Configure the LNA regime of operation 1529 * 1530 * \param [in] lnaSetting The LNA setting. Possible values are 1531 * LNA_LOW_POWER_MODE and 1532 * LNA_HIGH_SENSITIVITY_MODE 1533 */ 1534 void SX1280SetLNAGainSetting( const RadioLnaSettings_t lnaSetting ); 1535 1536 /*! 1537 * \brief Sets the number of bits used to check that ranging request match ranging ID 1538 * 1539 * \param [in] length [0: 8 bits, 1: 16 bits, 1540 * 2: 24 bits, 3: 32 bits] 1541 */ 1542 void SX1280SetRangingIdLength( RadioRangingIdCheckLengths_t length ); 1543 1544 /*! 1545 * \brief Sets ranging device id 1546 * 1547 * \param [in] address Device address 1548 */ 1549 void SX1280SetDeviceRangingAddress( uint32_t address ); 1550 1551 /*! 1552 * \brief Sets the device id to ping in a ranging request 1553 * 1554 * \param [in] address Address of the device to ping 1555 */ 1556 void SX1280SetRangingRequestAddress( uint32_t address ); 1557 1558 /*! 1559 * \brief Return the ranging result value 1560 * 1561 * \param [in] resultType Specifies the type of result. 1562 * [0: RAW, 1: Averaged, 1563 * 2: De-biased, 3:Filtered] 1564 * 1565 * \retval ranging The ranging measure filtered according to resultType [m] 1566 */ 1567 double SX1280GetRangingResult( RadioRangingResultTypes_t resultType ); 1568 1569 /*! 1570 * \brief Sets the standard processing delay between Master and Slave 1571 * 1572 * \param [in] cal RxTx delay offset for correcting ranging bias. 1573 * 1574 * The calibration value reflects the group delay of the radio front end and 1575 * must be re-performed for each new SX1280 PCB design. The value is obtained 1576 * empirically by either conducted measurement in a known electrical length 1577 * coaxial RF cable (where the design is connectorised) or by radiated 1578 * measurement, at a known distance, where an antenna is present. 1579 * The result of the calibration process is that the SX1280 ranging result 1580 * accurately reflects the physical range, the calibration procedure therefore 1581 * removes the average timing error from the time-of-flight measurement for a 1582 * given design. 1583 * 1584 * The values are Spreading Factor dependents, and depend also of the board 1585 * design. Some typical values are provided in the next table. 1586 * 1587 * Spreading Factor | Calibration Value 1588 * ---------------- | ----------------- 1589 * SF5 | 12200 1590 * SF6 | 12200 1591 * SF7 | 12400 1592 * SF8 | 12650 1593 * SF9 | 12940 1594 * SF10 | 13000 1595 * SF11 | 13060 1596 * SF12 | 13120 1597 */ 1598 void SX1280SetRangingCalibration( uint16_t cal ); 1599 1600 /*! 1601 * \brief Return the last ranging result power indicator 1602 * 1603 * The value returned is not an absolute power measurement. It is 1604 * a relative power measurement. 1605 * 1606 * \retval deltaThreshold A relative power indicator 1607 */ 1608 uint8_t SX1280GetRangingPowerDeltaThresholdIndicator( void ); 1609 1610 /*! 1611 * \brief Clears the ranging filter 1612 */ 1613 void SX1280RangingClearFilterResult( void ); 1614 1615 /*! 1616 * \brief Set the number of samples considered in the built-in filter 1617 * 1618 * \param [in] numSample The number of samples to use built-in filter 1619 * [8..255] 1620 * 1621 * \remark Value inferior to 8 will be silently set to 8 1622 */ 1623 void SX1280RangingSetFilterNumSamples( uint8_t numSample ); 1624 1625 /*! 1626 * \brief Return the Estimated Frequency Error in LORA and RANGING operations 1627 * 1628 * \retval efe The estimated frequency error [Hz] 1629 */ 1630 double SX1280GetFrequencyError( void ); 1631 1632 /*! 1633 * \brief Process the analysis of radio IRQs and calls callback functions 1634 * depending on radio state 1635 */ 1636 void SX1280ProcessIrqs( void ); 1637 1638 /*! 1639 * \brief Clears the instruction RAM 1640 */ 1641 void SX1280ClearInstructionRam( void ); 1642 1643 /*! 1644 * \brief Parses 1 HEX file line and writes the content to the instruction memory 1645 * 1646 * \param [in] line HEX file line string 1647 * 1648 * \retval status [0: ERROR, 1:OK] 1649 */ 1650 int8_t SX1280ParseHexFileLine( char* line ); 1651 1652 /*! 1653 * \brief Gets individual fields for the given HEX file line 1654 * 1655 * \param [in] line HEX file line string 1656 * \param [out] bytes Bytes array to be written to the instruction memory 1657 * \param [out] addr Instruction memory address where to write the bytes array 1658 * \param [out] num Number of bytes in Bytes array 1659 * \param [out] code HEX file line type [0: instruction, 1: end of file, 2: begin of file] 1660 * 1661 * \retval status [0: ERROR, 1:OK] 1662 */ 1663 int8_t SX1280GetHexFileLineFields( char* line, uint8_t *bytes, uint16_t *addr, uint16_t *num, uint8_t *code ); 1664 1665 /*! 1666 * /\brief Update operating mode to tx - used to let SX1280ProcessIrqs know that TX is/was active and call the correct handlers 1667 */ 1668 void SX1280AutoTxWillStart(void); 1669 1670 #endif // __SX1280_H__ 1671