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.
sx1278.h
00001 /** 00002 * @brief: Implementation of a SX1278 radio functions 00003 * @author: luk6xff based on SEMTCH code: https://github.com/Lora-net/LoRaMac-node 00004 * @email: luszko@op.pl 00005 * @date: 2019-11-15 00006 */ 00007 00008 #ifndef __SX1278_H__ 00009 #define __SX1278_H__ 00010 00011 00012 #ifdef __cplusplus 00013 extern "C" 00014 { 00015 #endif 00016 00017 #include <stdint.h> 00018 #include <stdbool.h> 00019 00020 #include "registers.h" 00021 00022 /** 00023 * ============================================================================ 00024 * @brief Public defines 00025 * ============================================================================ 00026 */ 00027 00028 /** 00029 * @brief Radio wake-up time from sleep 00030 */ 00031 #define RADIO_WAKEUP_TIME 1 // [ms] 00032 00033 /** 00034 * @brief Sync word for Private LoRa networks 00035 */ 00036 #define LORA_MAC_PRIVATE_SYNCWORD 0x12 00037 00038 /** 00039 * @brief Sync word for Public LoRa networks 00040 */ 00041 #define LORA_MAC_PUBLIC_SYNCWORD 0x34 00042 00043 00044 /** 00045 * @brief SX1278 definitions 00046 */ 00047 #define XTAL_FREQ 32000000 00048 #define FREQ_STEP 61.03515625 00049 00050 #define RX_BUFFER_SIZE 256 00051 00052 /** 00053 * @brief Constant values need to compute the RSSI value 00054 */ 00055 #define RSSI_OFFSET_LF -164.0 00056 #define RSSI_OFFSET_HF -157.0 00057 00058 #define RF_MID_BAND_THRESH 525000000 00059 00060 00061 00062 /** 00063 * ============================================================================ 00064 * @brief Public datatypes declarations 00065 * ============================================================================ 00066 */ 00067 00068 /** 00069 * Timeout timer type 00070 */ 00071 typedef enum 00072 { 00073 RXTimeoutTimer, 00074 TXTimeoutTimer, 00075 RXTimeoutSyncWordTimer 00076 } TimeoutTimer_t; 00077 00078 00079 /** 00080 * Type of the supported board. [RA-01] 00081 */ 00082 typedef enum 00083 { 00084 BOARD_RA01 = 0, 00085 BOARD_UNKNOWN 00086 } BoardType_t; 00087 00088 typedef enum 00089 { 00090 LORA_SF6 = 6, // 64 chips/symbol, SF6 requires an TCXO! 00091 LORA_SF7 = 7, // 128 chips/symbol 00092 LORA_SF8 = 8, // 256 chips/symbol 00093 LORA_SF9 = 9, // 512 chips/symbol 00094 LORA_SF10 = 10, // 1024 chips/symbol 00095 LORA_SF11 = 11, // 2048 chips/symbol 00096 LORA_SF12 = 12, // 4096 chips/symbol 00097 } LoraSpreadingFactor_t; 00098 00099 /** 00100 * Type of the supported lora bandwidths 00101 */ 00102 typedef enum 00103 { 00104 LORA_BANDWIDTH_7kHz = 0, // 7.8 kHz requires TCXO 00105 LORA_BANDWIDTH_10kHz = 1, // 10.4 kHz requires TCXO 00106 LORA_BANDWIDTH_15kHz = 2, // 15.6 kHz requires TCXO 00107 LORA_BANDWIDTH_20kHz = 3, // 20.8 kHz requires TCXO 00108 LORA_BANDWIDTH_31kHz = 4, // 31.2 kHz requires TCXO 00109 LORA_BANDWIDTH_41kHz = 5, // 41.4 kHz requires TCXO 00110 LORA_BANDWIDTH_62kHz = 6, // 62.5 kHz requires TCXO 00111 LORA_BANDWIDTH_125kHz = 7, 00112 LORA_BANDWIDTH_250kHz = 8, 00113 LORA_BANDWIDTH_500kHz = 9, 00114 LORA_BANDWIDTH_RESERVED = 10, 00115 } LoraBandwidth_t; 00116 00117 00118 typedef enum 00119 { // cyclic error coding to perform forward error detection and correction 00120 LORA_ERROR_CODING_RATE_4_5 = 1, // 1.25x overhead 00121 LORA_ERROR_CODING_RATE_4_6 = 2, // 1.50x overhead 00122 LORA_ERROR_CODING_RATE_4_7 = 3, // 1.75x overhead 00123 LORA_ERROR_CODING_RATE_4_8 = 4, // 2.00x overhead 00124 } LoraCodingRate_t; 00125 00126 00127 typedef enum 00128 { 00129 RF_FREQUENCY_434_0 = 434000000, // Hz 00130 RF_FREQUENCY_868_0 = 868000000, // Hz 00131 RF_FREQUENCY_868_1 = 868100000, // Hz 00132 RF_FREQUENCY_868_3 = 868300000, // Hz 00133 RF_FREQUENCY_868_5 = 868500000, // Hz 00134 } RfFrequency_t; 00135 00136 00137 /** 00138 * @brief Radio driver callback functions. 00139 * Reporting functions for upper layers. 00140 * The radio driver reports various vital events to the upper controlling layers 00141 * using callback functions provided by the upper layers at the initialization 00142 * phase. 00143 */ 00144 typedef struct 00145 { 00146 /** 00147 * @brief Callback when Transmission is done. 00148 */ 00149 void (*TxDone)(void); 00150 00151 /** 00152 * @brief Callback when Transmission is timed out. 00153 */ 00154 void (*TxTimeout)(void); 00155 00156 /** 00157 * @brief Rx Done callback prototype. 00158 * 00159 * @param [IN] payload Received buffer pointer 00160 * @param [IN] size Received buffer size 00161 * @param [IN] rssi RSSI value computed while receiving the frame [dBm] 00162 * @param [IN] snr Raw SNR value given by the radio hardware 00163 * FSK : N/A (set to 0) 00164 * LoRa: SNR value in dB 00165 */ 00166 void (*RxDone)(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr); 00167 00168 /** 00169 * @brief Callback when Reception is timed out. 00170 */ 00171 void (*RxTimeout)(void); 00172 00173 /** 00174 * @brief Callback when Reception ends up in error. 00175 */ 00176 void (*RxError)(void); 00177 00178 /** 00179 * @brief FHSS Change Channel callback prototype. 00180 * 00181 * @param [IN] currentChannel Index number of the current channel 00182 */ 00183 void (*FhssChangeChannel)(uint8_t currentChannel); 00184 00185 /** 00186 * @brief CAD Done callback prototype. 00187 * 00188 * @param [IN] channelDetected True, if Channel activity detected. 00189 */ 00190 void (*CadDone) (bool channelActivityDetected); 00191 } RadioEvents_t; 00192 00193 00194 00195 /** 00196 * @brief Radio driver internal state machine states definition 00197 * Helps identify current state of the transceiver. 00198 */ 00199 typedef enum 00200 { 00201 /** @brief IDLE state. 00202 * Radio is in idle state. 00203 */ 00204 RF_IDLE = 0, 00205 00206 /** @brief RX state. 00207 * Radio is receiving. 00208 */ 00209 RF_RX_RUNNING, 00210 00211 /** @brief TX state. 00212 * Radio is transmitting. 00213 */ 00214 RF_TX_RUNNING, 00215 00216 /** @brief CAD state. 00217 * Radio is detecting channel activity. 00218 */ 00219 RF_CAD, 00220 } RadioState_t; 00221 00222 /** 00223 * @brief Type of modem [LORA/FSK] 00224 */ 00225 typedef enum 00226 { 00227 /** 00228 * @brief FSK operation mode. 00229 * Radio is using FSK modulation. 00230 */ 00231 MODEM_FSK = 0, 00232 00233 /** 00234 * @brief LoRa operation mode. 00235 * Radio is using LoRa modulation. 00236 */ 00237 MODEM_LORA 00238 } RadioModems_t; 00239 00240 /** 00241 * @brief Radio FSK modem parameters 00242 * Parameters encompassing FSK modulation. 00243 */ 00244 typedef struct 00245 { 00246 /** 00247 * @brief Transmit power. 00248 */ 00249 int8_t Power; 00250 00251 /** 00252 * @brief Frequency deviation. 00253 */ 00254 uint32_t Fdev; 00255 00256 /** 00257 * @brief Modulation bandwidth. 00258 */ 00259 uint32_t Bandwidth; 00260 00261 /** 00262 * @brief Automated frequency correction bandwidth. 00263 */ 00264 uint32_t BandwidthAfc; 00265 00266 /** 00267 * @brief Data rate (SF). 00268 */ 00269 uint32_t Datarate; 00270 00271 /** 00272 * @brief Expected preamble length. 00273 */ 00274 uint16_t PreambleLen; 00275 00276 /** 00277 * @brief This flag turns on if the TX data size is fixed. 00278 */ 00279 bool FixLen; 00280 00281 /** 00282 * @brief Size of outgoing data. 00283 */ 00284 uint8_t PayloadLen; 00285 00286 /** 00287 * @brief Turn CRC on/off. 00288 */ 00289 bool CrcOn; 00290 00291 /** @deprecated 00292 * @brief Does not apply to FSK. Will be removed. 00293 */ 00294 bool IqInverted; 00295 00296 /** 00297 * @brief Turn continuous reception mode (such as Class C mode) on/off. 00298 */ 00299 bool RxContinuous; 00300 00301 /** 00302 * @brief Timeout value in milliseconds (ms) after which the radio driver reports 00303 * a timeout if the radio was unable to transmit. 00304 */ 00305 uint32_t TxTimeout; 00306 00307 /** 00308 * @brief Timeout value in symbols (symb) after which the radio driver reports a timeout 00309 * if the radio did not receive a Preamble. 00310 */ 00311 uint32_t RxSingleTimeout; 00312 } RadioFskSettings_t; 00313 00314 /** 00315 * @brief Radio FSK packet handler state 00316 * Contains information about an FSK packet and various metadata. 00317 */ 00318 typedef struct 00319 { 00320 /** 00321 * @brief Set to true (1) when a Preamble is detected, otherwise false (0). 00322 */ 00323 uint8_t PreambleDetected; 00324 00325 /** 00326 * @brief Set to true (1) when a SyncWord is detected, otherwise false (0). 00327 */ 00328 uint8_t SyncWordDetected; 00329 00330 /** 00331 * @brief Storage for RSSI value of the received signal. 00332 */ 00333 int8_t RssiValue; 00334 00335 /** 00336 * @brief Automated frequency correction value. 00337 */ 00338 int32_t AfcValue; 00339 00340 /** 00341 * @brief LNA gain value (dbm). 00342 */ 00343 uint8_t RxGain; 00344 00345 /** 00346 * @brief Size of the received data in bytes. 00347 */ 00348 uint16_t Size; 00349 00350 /** 00351 * @brief Keeps track of number of bytes already read from the RX FIFO. 00352 */ 00353 uint16_t NbBytes; 00354 00355 /** 00356 * @brief Stores the FIFO threshold value. 00357 */ 00358 uint8_t FifoThresh; 00359 00360 /** 00361 * @brief Defines the size of a chunk of outgoing buffer written to 00362 * the FIFO at a unit time. For example, if the size of the data exceeds the FIFO 00363 * limit, a certain sized chunk is written to the FIFO. Later, a FIFO-level 00364 * interrupt enables writing of the remaining data to the FIFO chunk by chunk until 00365 * transmission is complete. 00366 */ 00367 uint8_t ChunkSize; 00368 } RadioFskPacketHandler_t; 00369 00370 /** 00371 * @brief Radio LoRa modem parameters 00372 * Parameters encompassing LoRa modulation. 00373 */ 00374 typedef struct 00375 { 00376 /** 00377 * @brief Transmit power. 00378 */ 00379 int8_t Power; 00380 00381 /** 00382 * @brief Modulation bandwidth. 00383 */ 00384 uint32_t Bandwidth; 00385 00386 /** 00387 * @brief Data rate (SF). 00388 */ 00389 uint32_t Datarate; 00390 00391 /** 00392 * @brief Turn low data rate optimization on/off. 00393 */ 00394 bool LowDatarateOptimize; 00395 00396 /** 00397 * @brief Error correction code rate. 00398 */ 00399 uint8_t Coderate; 00400 00401 /** 00402 * @brief Preamble length in symbols. 00403 */ 00404 uint16_t PreambleLen; 00405 00406 /** 00407 * @brief Set to true if the outgoing payload length is fixed. 00408 */ 00409 bool FixLen; 00410 00411 /** 00412 * @brief Size of outgoing payload. 00413 */ 00414 uint8_t PayloadLen; 00415 00416 /** 00417 * @brief Turn CRC on/off. 00418 */ 00419 bool CrcOn; 00420 00421 /** 00422 * @brief Turn frequency hopping on/off. 00423 */ 00424 bool FreqHopOn; 00425 00426 /** 00427 * @brief Number of symbols between two frequency hops. 00428 */ 00429 uint8_t HopPeriod; 00430 00431 /** 00432 * @brief Turn IQ inversion on/off. Usually, the end device sends an IQ inverted 00433 * signal, and the base stations do not invert. We recommended sending an 00434 * IQ inverted signal from the device side, so any transmissions from the 00435 * base stations do not interfere with end device transmission. 00436 */ 00437 bool IqInverted; 00438 00439 /** 00440 * @brief Turn continuous reception mode (such as in Class C) on/off. 00441 */ 00442 bool RxContinuous; 00443 00444 /** 00445 * @brief Timeout in milliseconds (ms) after which the radio driver reports an error 00446 * if the radio was unable to transmit. 00447 */ 00448 uint32_t TxTimeout; 00449 00450 /** 00451 * @brief Change the network mode to Public or Private. 00452 */ 00453 bool PublicNetwork; 00454 } RadioLoRaSettings_t; 00455 00456 /** 00457 * Radio LoRa packet handler state 00458 */ 00459 typedef struct 00460 { 00461 /** 00462 * @brief Signal-to-noise ratio of a received packet. 00463 */ 00464 int8_t SnrValue; 00465 00466 /** 00467 * @brief RSSI value in dBm for the received packet. 00468 */ 00469 int8_t RssiValue; 00470 00471 /** 00472 * @brief Size of the transmitted or received packet. 00473 */ 00474 uint8_t Size; 00475 } RadioLoRaPacketHandler_t; 00476 00477 00478 /** 00479 * @brief Global radio settings. 00480 * Contains settings for the overall transceiver operation. 00481 */ 00482 typedef struct 00483 { 00484 /** 00485 * @brief Current state of the radio, such as RF_IDLE. 00486 */ 00487 RadioState_t State; 00488 00489 /** 00490 * @brief Current modem operation, such as LORA or FSK. 00491 */ 00492 RadioModems_t Modem; 00493 00494 /** 00495 * @brief Current channel of operation. 00496 */ 00497 uint32_t Channel; 00498 00499 /** 00500 * @brief Settings for FSK modem part. 00501 */ 00502 RadioFskSettings_t Fsk; 00503 00504 /** 00505 * @brief FSK packet and meta data. 00506 */ 00507 RadioFskPacketHandler_t FskPacketHandler; 00508 00509 /** 00510 * @brief Settings for LoRa modem part. 00511 */ 00512 RadioLoRaSettings_t LoRa; 00513 00514 /** 00515 * @brief LoRa packet and metadata. 00516 */ 00517 RadioLoRaPacketHandler_t LoRaPacketHandler; 00518 } RadioSettings_t; 00519 00520 00521 /** 00522 * @brief FSK and LORA bandwidth definition 00523 */ 00524 typedef struct 00525 { 00526 uint32_t bandwidth; 00527 uint8_t RegValue; 00528 } BandwidthMap_t; 00529 00530 /** 00531 * @brief Radio registers definition 00532 */ 00533 typedef struct 00534 { 00535 RadioModems_t Modem; 00536 uint8_t Addr; 00537 uint8_t Value; 00538 } RadioRegisters_t; 00539 00540 00541 00542 /** 00543 * @brief Hardware IO IRQ callback function definition 00544 */ 00545 typedef void (*DioIrqHandler)(void); 00546 00547 /** 00548 * @brief Timeout timer callback function definition 00549 */ 00550 typedef void (*timeoutFuncPtr)(void); 00551 00552 /** 00553 * ============================================================================ 00554 * @brief Public functions prototypes 00555 * ============================================================================ 00556 */ 00557 00558 /** 00559 * @brief Actual implementation of a SX1278 radio 00560 */ 00561 00562 //------------------------------------------------------------------------- 00563 // Radio functions 00564 //------------------------------------------------------------------------- 00565 /** 00566 * @brief Initializes the radio 00567 * 00568 * @param [IN] events Structure containing the driver callback functions 00569 */ 00570 bool SX1278Init(RadioEvents_t *events); 00571 00572 /** 00573 * @brief Initializes the radio registers 00574 */ 00575 void SX1278RadioRegistersInit(); 00576 00577 00578 /** 00579 * Return current radio status 00580 * 00581 * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING] 00582 */ 00583 RadioState_t SX1278GetStatus(void); 00584 00585 /** 00586 * @brief Configures the SX1278 with the given modem 00587 * 00588 * @param [IN] modem Modem to be used [0: FSK, 1: LoRa] 00589 */ 00590 void SX1278SetModem(RadioModems_t modem); 00591 00592 /** 00593 * @brief Sets the channel frequency 00594 * 00595 * @param [IN] freq Channel RF frequency 00596 */ 00597 void SX1278SetChannel(uint32_t freq); 00598 00599 /** 00600 * @brief Sets the channels configuration 00601 * 00602 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00603 * @param [IN] freq Channel RF frequency 00604 * @param [IN] rssiThresh RSSI threshold 00605 * @param [IN] maxCarrierSenseTime Max time while the RSSI is measured 00606 * 00607 * @retval isFree [true: Channel is free, false: Channel is not free] 00608 */ 00609 bool SX1278IsChannelFree(RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime); 00610 00611 /** 00612 * @brief Generates a 32 bits random value based on the RSSI readings 00613 * 00614 * @note This function sets the radio in LoRa modem mode and disables 00615 * all interrupts. 00616 * After calling this function either SX1278SetRxConfig or 00617 * SX1278SetTxConfig functions must be called. 00618 * 00619 * @retval randomValue 32 bits random value 00620 */ 00621 uint32_t SX1278Random(void); 00622 00623 /** 00624 * @brief Sets the reception parameters 00625 * 00626 * @note When using LoRa modem only bandwidths 125, 250 and 500 kHz are supported 00627 * 00628 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00629 * @param [IN] bandwidth Sets the bandwidth 00630 * FSK : >= 2600 and <= 250000 Hz 00631 * LoRa: [0: 125 kHz, 1: 250 kHz, 00632 * 2: 500 kHz, 3: Reserved] 00633 * @param [IN] datarate Sets the Datarate 00634 * FSK : 600..300000 bits/s 00635 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00636 * 10: 1024, 11: 2048, 12: 4096 chips] 00637 * @param [IN] coderate Sets the coding rate (LoRa only) 00638 * FSK : N/A (set to 0) 00639 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00640 * @param [IN] bandwidthAfc Sets the AFC Bandwidth (FSK only) 00641 * FSK : >= 2600 and <= 250000 Hz 00642 * LoRa: N/A (set to 0) 00643 * @param [IN] preambleLen Sets the Preamble length (LoRa only) 00644 * FSK : N/A (set to 0) 00645 * LoRa: Length in symbols (the hardware adds 4 more symbols) 00646 * @param [IN] symbTimeout Sets the RxSingle timeout value 00647 * FSK : timeout number of bytes 00648 * LoRa: timeout in symbols 00649 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00650 * @param [IN] payloadLen Sets payload length when fixed lenght is used 00651 * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] 00652 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping 00653 * FSK : N/A ( set to 0 ) 00654 * LoRa: [0: OFF, 1: ON] 00655 * @param [IN] hopPeriod Number of symbols between each hop 00656 * FSK : N/A ( set to 0 ) 00657 * LoRa: Number of symbols 00658 * @param [IN] iqInverted Inverts IQ signals (LoRa only) 00659 * FSK : N/A ( set to 0 ) 00660 * LoRa: [0: not inverted, 1: inverted] 00661 * @param [IN] rxContinuous Sets the reception in continuous mode 00662 * [false: single mode, true: continuous mode] 00663 */ 00664 void SX1278SetRxConfig (RadioModems_t modem, uint32_t bandwidth, 00665 uint32_t datarate, uint8_t coderate, 00666 uint32_t bandwidthAfc, uint16_t preambleLen, 00667 uint16_t symbTimeout, bool fixLen, 00668 uint8_t payloadLen, 00669 bool crcOn, bool freqHopOn, uint8_t hopPeriod, 00670 bool iqInverted, bool rxContinuous); 00671 /** 00672 * @brief Sets the transmission parameters 00673 * 00674 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00675 * @param [IN] power Sets the output power [dBm] 00676 * @param [IN] fdev Sets the frequency deviation (FSK only) 00677 * FSK : [Hz] 00678 * LoRa: 0 00679 * @param [IN] bandwidth Sets the bandwidth (LoRa only) 00680 * FSK : 0 00681 * LoRa: [0: 125 kHz, 1: 250 kHz, 00682 * 2: 500 kHz, 3: Reserved] 00683 * @param [IN] datarate Sets the Datarate 00684 * FSK : 600..300000 bits/s 00685 * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 00686 * 10: 1024, 11: 2048, 12: 4096 chips] 00687 * @param [IN] coderate Sets the coding rate (LoRa only) 00688 * FSK : N/A (set to 0) 00689 * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] 00690 * @param [IN] preambleLen Sets the preamble length 00691 * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] 00692 * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] 00693 * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) 00694 * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) 00695 * @param [IN] iqInverted Inverts IQ signals (LoRa only) 00696 * FSK : N/A (set to 0) 00697 * LoRa: [0: not inverted, 1: inverted] 00698 * @param [IN] timeout Transmission timeout [ms] 00699 */ 00700 void SX1278SetTxConfig(RadioModems_t modem, int8_t power, uint32_t fdev, 00701 uint32_t bandwidth, uint32_t datarate, 00702 uint8_t coderate, uint16_t preambleLen, 00703 bool fixLen, bool crcOn, bool freqHopOn, 00704 uint8_t hopPeriod, bool iqInverted, uint32_t timeout); 00705 00706 /** 00707 * @brief Computes the packet time on air for the given payload 00708 * 00709 * @note Can only be called once SetRxConfig or SetTxConfig have been called 00710 * 00711 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00712 * @param [IN] pktLen Packet payload length 00713 * 00714 * @retval airTime Computed airTime (ms) for the given packet payload length 00715 */ 00716 uint32_t SX1278GetTimeOnAir(RadioModems_t modem, uint8_t pktLen); 00717 00718 /** 00719 * @brief Sends the buffer of size. Prepares the packet to be sent and sets 00720 * the radio in transmission 00721 * 00722 * @param [IN]: buffer Buffer pointer 00723 * @param [IN]: size Buffer size 00724 */ 00725 void SX1278Send(uint8_t *buffer, uint8_t size); 00726 00727 /** 00728 * @brief Sets the radio in sleep mode 00729 */ 00730 void SX1278SetSleep(void); 00731 00732 /** 00733 * @brief Sets the radio in standby mode 00734 */ 00735 void SX1278SetStandby(void); 00736 00737 /** 00738 * @brief Sets the radio in CAD mode (starts a Channel Activity Detection) 00739 */ 00740 void SX1278StartCad(void); 00741 00742 /** 00743 * @brief Sets the radio in reception mode for the given time 00744 * @param [IN] timeout Reception timeout [ms] 00745 * [0: continuous, others timeout] 00746 */ 00747 void SX1278SetRx(uint32_t timeout); 00748 00749 /** 00750 * @brief Sets the radio in transmission mode for the given time 00751 * @param [IN] timeout Transmission timeout [ms] 00752 * [0: continuous, others timeout] 00753 */ 00754 void SX1278SetTx(uint32_t timeout); 00755 00756 /** 00757 * @brief Sets the radio in continuous wave transmission mode 00758 * 00759 * @param [IN]: freq Channel RF frequency 00760 * @param [IN]: power Sets the output power [dBm] 00761 * @param [IN]: time Transmission mode timeout [s] 00762 */ 00763 void SX1278SetTxContinuousWave(uint32_t freq, int8_t power, uint16_t time); 00764 00765 /** 00766 * @brief Reads the current RSSI value 00767 * 00768 * @retval rssiValue Current RSSI value in [dBm] 00769 */ 00770 int16_t SX1278GetRssi(RadioModems_t modem); 00771 00772 /** 00773 * @brief Reads the current frequency error 00774 * 00775 * @retval frequency error value in [Hz] 00776 */ 00777 int32_t SX1278GetFrequencyError(RadioModems_t modem); 00778 00779 /** 00780 * @brief Sets the maximum payload length. 00781 * 00782 * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] 00783 * @param [IN] max Maximum payload length in bytes 00784 */ 00785 void SX1278SetMaxPayloadLength(RadioModems_t modem, uint8_t max); 00786 00787 /** 00788 * @brief Sets the network to public or private. Updates the sync byte. 00789 * 00790 * @note Applies to LoRa modem only 00791 * 00792 * @param [IN] enable if true, it enables a public network 00793 */ 00794 void SX1278SetPublicNetwork(bool enable); 00795 00796 /** 00797 * @brief Gets the time required for the board plus radio to get out of sleep.[ms] 00798 * 00799 * @retval Time Radio plus board wakeup time in ms. 00800 */ 00801 uint32_t SX1278GetWakeupTime(void); 00802 00803 /** 00804 * @brief Sets the SX1278 operating mode 00805 * 00806 * @param [IN] opMode New operating mode 00807 */ 00808 void SX1278SetOpMode(uint8_t opMode); 00809 00810 /** 00811 * @brief Sets the radio output power. 00812 * 00813 * @param [IN] power Sets the RF output power 00814 */ 00815 void SX1278SetRfTxPower(int8_t power); 00816 00817 /** 00818 * @brief Gets the PA selection configuration 00819 * 00820 * @param [IN] channel Channel frequency in Hz 00821 * @retval PaSelect RegPaConfig PaSelect value 00822 */ 00823 uint8_t SX1278GetPaSelect(uint32_t channel); 00824 00825 /** 00826 * @brief Checks if the given RF frequency is supported by the hardware 00827 * 00828 * @param [IN] frequency RF frequency to be checked 00829 * @retval isSupported [true: supported, false: unsupported] 00830 */ 00831 bool SX1278CheckRfFrequency(uint32_t frequency); 00832 00833 /** 00834 * @brief Writes the radio register at the specified address 00835 * 00836 * @param [IN]: addr Register address 00837 * @param [IN]: data New register value 00838 */ 00839 void SX1278Write (uint8_t addr, uint8_t data); 00840 00841 /** 00842 * @brief Reads the radio register at the specified address 00843 * 00844 * @param [IN]: addr Register address 00845 * @retval data Register value 00846 */ 00847 uint8_t SX1278Read(uint8_t addr); 00848 00849 /** 00850 * @brief Writes the buffer contents to the SX1278 FIFO 00851 * 00852 * @param [IN] buffer Buffer containing data to be put on the FIFO. 00853 * @param [IN] size Number of bytes to be written to the FIFO 00854 */ 00855 void SX1278WriteFifo(uint8_t *buffer, uint8_t size); 00856 00857 /** 00858 * @brief Reads the contents of the SX1278 FIFO 00859 * 00860 * @param [OUT] buffer Buffer where to copy the FIFO read data. 00861 * @param [IN] size Number of bytes to be read from the FIFO 00862 */ 00863 void SX1278ReadFifo(uint8_t *buffer, uint8_t size); 00864 00865 00866 00867 //------------------------------------------------------------------------- 00868 // Board/Platform relative (HW dependent) functions, 00869 // Must be implemented in folder platform. 00870 //------------------------------------------------------------------------- 00871 00872 /** 00873 * @brief Initializes the radio I/Os pins interface 00874 */ 00875 extern void SX1278IoInit(void); 00876 00877 /** 00878 * @brief De-initializes the radio I/Os pins interface. 00879 * 00880 * @note Useful when going in MCU lowpower modes 00881 */ 00882 extern void SX1278IoDeInit(void); 00883 00884 /** 00885 * @brief Initializes DIO IRQ handlers 00886 * 00887 * @param [IN] irqHandlers Array containing the IRQ callback functions 00888 */ 00889 extern void SX1278IoIrqInit(DioIrqHandler *irqHandlers); 00890 00891 /** 00892 * @brief Resets the SX1278 00893 */ 00894 extern void SX1278Reset(void); 00895 00896 /** 00897 * @brief Writes multiple radio registers starting at address 00898 * 00899 * @param [IN] addr First Radio register address 00900 * @param [IN] buffer Buffer containing the new register's values 00901 * @param [IN] size Number of registers to be written 00902 */ 00903 extern void SX1278WriteBuffer(uint8_t addr, uint8_t *buffer, uint8_t size); 00904 00905 /** 00906 * @brief Reads multiple radio registers starting at address 00907 * 00908 * @param [IN] addr First Radio register address 00909 * @param [OUT] buffer Buffer where to copy the registers data 00910 * @param [IN] size Number of registers to be read 00911 */ 00912 extern void SX1278ReadBuffer(uint8_t addr, uint8_t *buffer, uint8_t size); 00913 00914 /* 00915 * @brief The the Timeout for a given Timer. 00916 */ 00917 extern void SX1278SetTimeout(TimeoutTimer_t timer, timeoutFuncPtr, int timeout_ms); 00918 00919 /* 00920 * @brief A simple ms sleep 00921 */ 00922 extern void SX1278DelayMs(int ms); 00923 00924 00925 #ifdef __cplusplus 00926 } 00927 #endif 00928 00929 00930 #endif // __SX1278_H__ 00931
Generated on Tue Jul 12 2022 18:29:21 by
