I made a fork of a generic library that was developed with support for RFM95 LoRa module that I found online. I Made a few changes and made it compatible with hardware limitations of the MAX32620FTHR and MAX32630FTHR module.
Dependents: MAX326xxFTHR_LoRa_RFM95 MAX326xxFTHR_LoRa_PingPong MAX326xxFTHR_RFM95_LoRa_PingPong MAX326xxFTHR_LoRa_RFM95_PingPong_Example ... more
Fork of SX1276GenericLib by
sx1276/sx1276.h@27:1a9d7dadb593, 2017-04-23 (annotated)
- Committer:
- Helmut64
- Date:
- Sun Apr 23 19:17:13 2017 +0000
- Revision:
- 27:1a9d7dadb593
- Parent:
- 26:87796ee62589
- Child:
- 28:6d83af9f8563
Only the STM L0 Board uses the Murata antenna switch. This is not ; completely clean, however I don't like to include out PinMap.h; in the Semtech mbed library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:e6ceb13d2d05 | 1 | /* |
GregCr | 0:e6ceb13d2d05 | 2 | / _____) _ | | |
GregCr | 0:e6ceb13d2d05 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
GregCr | 0:e6ceb13d2d05 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
GregCr | 0:e6ceb13d2d05 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
GregCr | 0:e6ceb13d2d05 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
mluis | 22:7f3aab69cca9 | 7 | (C) 2014 Semtech |
GregCr | 0:e6ceb13d2d05 | 8 | |
GregCr | 0:e6ceb13d2d05 | 9 | Description: Actual implementation of a SX1276 radio, inherits Radio |
GregCr | 0:e6ceb13d2d05 | 10 | |
GregCr | 0:e6ceb13d2d05 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
GregCr | 0:e6ceb13d2d05 | 12 | |
GregCr | 0:e6ceb13d2d05 | 13 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
GregCr | 0:e6ceb13d2d05 | 14 | */ |
GregCr | 0:e6ceb13d2d05 | 15 | #ifndef __SX1276_H__ |
GregCr | 0:e6ceb13d2d05 | 16 | #define __SX1276_H__ |
GregCr | 0:e6ceb13d2d05 | 17 | |
GregCr | 0:e6ceb13d2d05 | 18 | #include "radio.h" |
GregCr | 0:e6ceb13d2d05 | 19 | #include "./registers/sx1276Regs-Fsk.h" |
GregCr | 0:e6ceb13d2d05 | 20 | #include "./registers/sx1276Regs-LoRa.h" |
GregCr | 0:e6ceb13d2d05 | 21 | #include "./typedefs/typedefs.h" |
GregCr | 0:e6ceb13d2d05 | 22 | |
mluis | 16:d447f8d2d2d6 | 23 | /*! |
mluis | 16:d447f8d2d2d6 | 24 | * Radio wakeup time from SLEEP mode |
mluis | 16:d447f8d2d2d6 | 25 | */ |
mluis | 25:3778e6204cc1 | 26 | #define RADIO_OSC_STARTUP 1000 // [us] |
mluis | 25:3778e6204cc1 | 27 | |
mluis | 25:3778e6204cc1 | 28 | /*! |
mluis | 25:3778e6204cc1 | 29 | * Radio PLL lock and Mode Ready delay which can vary with the temperature |
mluis | 25:3778e6204cc1 | 30 | */ |
mluis | 25:3778e6204cc1 | 31 | #define RADIO_SLEEP_TO_RX 2000 // [us] |
mluis | 25:3778e6204cc1 | 32 | |
mluis | 25:3778e6204cc1 | 33 | /*! |
mluis | 25:3778e6204cc1 | 34 | * Radio complete Wake-up Time with margin for temperature compensation |
mluis | 25:3778e6204cc1 | 35 | */ |
mluis | 25:3778e6204cc1 | 36 | #define RADIO_WAKEUP_TIME ( RADIO_OSC_STARTUP + RADIO_SLEEP_TO_RX ) |
mluis | 25:3778e6204cc1 | 37 | |
mluis | 16:d447f8d2d2d6 | 38 | |
mluis | 16:d447f8d2d2d6 | 39 | /*! |
mluis | 16:d447f8d2d2d6 | 40 | * SX1276 definitions |
mluis | 16:d447f8d2d2d6 | 41 | */ |
GregCr | 0:e6ceb13d2d05 | 42 | #define XTAL_FREQ 32000000 |
GregCr | 0:e6ceb13d2d05 | 43 | #define FREQ_STEP 61.03515625 |
GregCr | 0:e6ceb13d2d05 | 44 | |
GregCr | 0:e6ceb13d2d05 | 45 | #define RX_BUFFER_SIZE 256 |
GregCr | 0:e6ceb13d2d05 | 46 | |
GregCr | 0:e6ceb13d2d05 | 47 | /*! |
GregCr | 0:e6ceb13d2d05 | 48 | * Constant values need to compute the RSSI value |
GregCr | 0:e6ceb13d2d05 | 49 | */ |
GregCr | 0:e6ceb13d2d05 | 50 | #define RSSI_OFFSET_LF -164.0 |
GregCr | 0:e6ceb13d2d05 | 51 | #define RSSI_OFFSET_HF -157.0 |
GregCr | 0:e6ceb13d2d05 | 52 | |
GregCr | 0:e6ceb13d2d05 | 53 | #define RF_MID_BAND_THRESH 525000000 |
GregCr | 0:e6ceb13d2d05 | 54 | |
Helmut64 | 27:1a9d7dadb593 | 55 | #ifdef TARGET_STM32L0 |
Helmut64 | 26:87796ee62589 | 56 | #define MURTA_ANT_SWITCH 1 // STM B-L072Z-LRWAN1 device |
Helmut64 | 27:1a9d7dadb593 | 57 | #endif |
Helmut64 | 26:87796ee62589 | 58 | |
GregCr | 0:e6ceb13d2d05 | 59 | /*! |
GregCr | 0:e6ceb13d2d05 | 60 | * Actual implementation of a SX1276 radio, inherits Radio |
GregCr | 0:e6ceb13d2d05 | 61 | */ |
GregCr | 0:e6ceb13d2d05 | 62 | class SX1276 : public Radio |
GregCr | 0:e6ceb13d2d05 | 63 | { |
GregCr | 0:e6ceb13d2d05 | 64 | protected: |
GregCr | 0:e6ceb13d2d05 | 65 | /*! |
GregCr | 0:e6ceb13d2d05 | 66 | * SPI Interface |
GregCr | 0:e6ceb13d2d05 | 67 | */ |
GregCr | 0:e6ceb13d2d05 | 68 | SPI spi; // mosi, miso, sclk |
GregCr | 0:e6ceb13d2d05 | 69 | DigitalOut nss; |
GregCr | 0:e6ceb13d2d05 | 70 | |
GregCr | 0:e6ceb13d2d05 | 71 | /*! |
GregCr | 0:e6ceb13d2d05 | 72 | * SX1276 Reset pin |
GregCr | 0:e6ceb13d2d05 | 73 | */ |
GregCr | 4:f0ce52e94d3f | 74 | DigitalInOut reset; |
GregCr | 0:e6ceb13d2d05 | 75 | |
GregCr | 0:e6ceb13d2d05 | 76 | /*! |
GregCr | 0:e6ceb13d2d05 | 77 | * SX1276 DIO pins |
GregCr | 0:e6ceb13d2d05 | 78 | */ |
mluis | 13:618826a997e2 | 79 | InterruptIn dio0; |
mluis | 13:618826a997e2 | 80 | InterruptIn dio1; |
mluis | 13:618826a997e2 | 81 | InterruptIn dio2; |
mluis | 13:618826a997e2 | 82 | InterruptIn dio3; |
mluis | 13:618826a997e2 | 83 | InterruptIn dio4; |
mluis | 13:618826a997e2 | 84 | DigitalIn dio5; |
mluis | 25:3778e6204cc1 | 85 | |
mluis | 13:618826a997e2 | 86 | bool isRadioActive; |
mluis | 25:3778e6204cc1 | 87 | |
mluis | 13:618826a997e2 | 88 | uint8_t boardConnected; //1 = SX1276MB1LAS; 0 = SX1276MB1MAS |
mluis | 25:3778e6204cc1 | 89 | |
GregCr | 23:1e143575df0f | 90 | uint8_t *rxtxBuffer; |
mluis | 13:618826a997e2 | 91 | |
mluis | 25:3778e6204cc1 | 92 | uint8_t currentOpMode; |
mluis | 25:3778e6204cc1 | 93 | |
mluis | 13:618826a997e2 | 94 | /*! |
mluis | 13:618826a997e2 | 95 | * Hardware DIO IRQ functions |
mluis | 13:618826a997e2 | 96 | */ |
mluis | 13:618826a997e2 | 97 | DioIrqHandler *dioIrq; |
mluis | 25:3778e6204cc1 | 98 | |
mluis | 13:618826a997e2 | 99 | /*! |
mluis | 13:618826a997e2 | 100 | * Tx and Rx timers |
mluis | 13:618826a997e2 | 101 | */ |
mluis | 13:618826a997e2 | 102 | Timeout txTimeoutTimer; |
mluis | 13:618826a997e2 | 103 | Timeout rxTimeoutTimer; |
mluis | 13:618826a997e2 | 104 | Timeout rxTimeoutSyncWord; |
mluis | 25:3778e6204cc1 | 105 | |
mluis | 13:618826a997e2 | 106 | /*! |
mluis | 13:618826a997e2 | 107 | * rxTx: [1: Tx, 0: Rx] |
mluis | 13:618826a997e2 | 108 | */ |
mluis | 13:618826a997e2 | 109 | uint8_t rxTx; |
mluis | 25:3778e6204cc1 | 110 | |
mluis | 13:618826a997e2 | 111 | RadioSettings_t settings; |
mluis | 25:3778e6204cc1 | 112 | |
mluis | 13:618826a997e2 | 113 | static const FskBandwidth_t FskBandwidths[] ; |
GregCr | 0:e6ceb13d2d05 | 114 | protected: |
GregCr | 0:e6ceb13d2d05 | 115 | |
mluis | 13:618826a997e2 | 116 | /*! |
mluis | 13:618826a997e2 | 117 | * Performs the Rx chain calibration for LF and HF bands |
mluis | 13:618826a997e2 | 118 | * \remark Must be called just after the reset so all registers are at their |
mluis | 13:618826a997e2 | 119 | * default values |
mluis | 13:618826a997e2 | 120 | */ |
mluis | 13:618826a997e2 | 121 | void RxChainCalibration( void ); |
GregCr | 0:e6ceb13d2d05 | 122 | |
GregCr | 0:e6ceb13d2d05 | 123 | public: |
mluis | 21:2e496deb7858 | 124 | SX1276( RadioEvents_t *events, |
mluis | 13:618826a997e2 | 125 | PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, |
GregCr | 0:e6ceb13d2d05 | 126 | PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5 ); |
mluis | 21:2e496deb7858 | 127 | SX1276( RadioEvents_t *events ); |
mluis | 13:618826a997e2 | 128 | virtual ~SX1276( ); |
mluis | 13:618826a997e2 | 129 | |
mluis | 13:618826a997e2 | 130 | //------------------------------------------------------------------------- |
mluis | 13:618826a997e2 | 131 | // Redefined Radio functions |
mluis | 13:618826a997e2 | 132 | //------------------------------------------------------------------------- |
mluis | 13:618826a997e2 | 133 | /*! |
mluis | 21:2e496deb7858 | 134 | * @brief Initializes the radio |
mluis | 21:2e496deb7858 | 135 | * |
mluis | 21:2e496deb7858 | 136 | * @param [IN] events Structure containing the driver callback functions |
mluis | 21:2e496deb7858 | 137 | */ |
mluis | 21:2e496deb7858 | 138 | virtual void Init( RadioEvents_t *events ); |
mluis | 21:2e496deb7858 | 139 | /*! |
GregCr | 0:e6ceb13d2d05 | 140 | * Return current radio status |
GregCr | 0:e6ceb13d2d05 | 141 | * |
mluis | 21:2e496deb7858 | 142 | * @param status Radio status. [RF_IDLE, RX_RUNNING, TX_RUNNING] |
GregCr | 0:e6ceb13d2d05 | 143 | */ |
GregCr | 19:71a47bb03fbb | 144 | virtual RadioState GetStatus( void ); |
mluis | 25:3778e6204cc1 | 145 | |
mluis | 13:618826a997e2 | 146 | /*! |
mluis | 13:618826a997e2 | 147 | * @brief Configures the SX1276 with the given modem |
mluis | 13:618826a997e2 | 148 | * |
mluis | 13:618826a997e2 | 149 | * @param [IN] modem Modem to be used [0: FSK, 1: LoRa] |
mluis | 13:618826a997e2 | 150 | */ |
mluis | 22:7f3aab69cca9 | 151 | virtual void SetModem( RadioModems_t modem ); |
mluis | 13:618826a997e2 | 152 | |
mluis | 13:618826a997e2 | 153 | /*! |
GregCr | 0:e6ceb13d2d05 | 154 | * @brief Sets the channel frequency |
GregCr | 0:e6ceb13d2d05 | 155 | * |
GregCr | 0:e6ceb13d2d05 | 156 | * @param [IN] freq Channel RF frequency |
GregCr | 0:e6ceb13d2d05 | 157 | */ |
GregCr | 0:e6ceb13d2d05 | 158 | virtual void SetChannel( uint32_t freq ); |
mluis | 25:3778e6204cc1 | 159 | |
mluis | 13:618826a997e2 | 160 | /*! |
GregCr | 0:e6ceb13d2d05 | 161 | * @brief Sets the channels configuration |
GregCr | 0:e6ceb13d2d05 | 162 | * |
GregCr | 0:e6ceb13d2d05 | 163 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
GregCr | 0:e6ceb13d2d05 | 164 | * @param [IN] freq Channel RF frequency |
GregCr | 0:e6ceb13d2d05 | 165 | * @param [IN] rssiThresh RSSI threshold |
GregCr | 0:e6ceb13d2d05 | 166 | * |
GregCr | 0:e6ceb13d2d05 | 167 | * @retval isFree [true: Channel is free, false: Channel is not free] |
GregCr | 0:e6ceb13d2d05 | 168 | */ |
mluis | 22:7f3aab69cca9 | 169 | virtual bool IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh ); |
mluis | 25:3778e6204cc1 | 170 | |
mluis | 13:618826a997e2 | 171 | /*! |
GregCr | 0:e6ceb13d2d05 | 172 | * @brief Generates a 32 bits random value based on the RSSI readings |
GregCr | 0:e6ceb13d2d05 | 173 | * |
GregCr | 0:e6ceb13d2d05 | 174 | * \remark This function sets the radio in LoRa modem mode and disables |
GregCr | 0:e6ceb13d2d05 | 175 | * all interrupts. |
GregCr | 0:e6ceb13d2d05 | 176 | * After calling this function either Radio.SetRxConfig or |
GregCr | 0:e6ceb13d2d05 | 177 | * Radio.SetTxConfig functions must be called. |
GregCr | 0:e6ceb13d2d05 | 178 | * |
GregCr | 0:e6ceb13d2d05 | 179 | * @retval randomValue 32 bits random value |
GregCr | 0:e6ceb13d2d05 | 180 | */ |
GregCr | 0:e6ceb13d2d05 | 181 | virtual uint32_t Random( void ); |
mluis | 25:3778e6204cc1 | 182 | |
mluis | 13:618826a997e2 | 183 | /*! |
GregCr | 0:e6ceb13d2d05 | 184 | * @brief Sets the reception parameters |
GregCr | 0:e6ceb13d2d05 | 185 | * |
GregCr | 0:e6ceb13d2d05 | 186 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
GregCr | 0:e6ceb13d2d05 | 187 | * @param [IN] bandwidth Sets the bandwidth |
GregCr | 0:e6ceb13d2d05 | 188 | * FSK : >= 2600 and <= 250000 Hz |
GregCr | 0:e6ceb13d2d05 | 189 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
GregCr | 0:e6ceb13d2d05 | 190 | * 2: 500 kHz, 3: Reserved] |
GregCr | 0:e6ceb13d2d05 | 191 | * @param [IN] datarate Sets the Datarate |
GregCr | 0:e6ceb13d2d05 | 192 | * FSK : 600..300000 bits/s |
GregCr | 0:e6ceb13d2d05 | 193 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
GregCr | 0:e6ceb13d2d05 | 194 | * 10: 1024, 11: 2048, 12: 4096 chips] |
GregCr | 0:e6ceb13d2d05 | 195 | * @param [IN] coderate Sets the coding rate ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 196 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 197 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
GregCr | 0:e6ceb13d2d05 | 198 | * @param [IN] bandwidthAfc Sets the AFC Bandwidth ( FSK only ) |
GregCr | 0:e6ceb13d2d05 | 199 | * FSK : >= 2600 and <= 250000 Hz |
GregCr | 0:e6ceb13d2d05 | 200 | * LoRa: N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 201 | * @param [IN] preambleLen Sets the Preamble length ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 202 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 203 | * LoRa: Length in symbols ( the hardware adds 4 more symbols ) |
GregCr | 0:e6ceb13d2d05 | 204 | * @param [IN] symbTimeout Sets the RxSingle timeout value ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 205 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 206 | * LoRa: timeout in symbols |
GregCr | 0:e6ceb13d2d05 | 207 | * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] |
mluis | 13:618826a997e2 | 208 | * @param [IN] payloadLen Sets payload length when fixed lenght is used |
GregCr | 0:e6ceb13d2d05 | 209 | * @param [IN] crcOn Enables/Disables the CRC [0: OFF, 1: ON] |
mluis | 13:618826a997e2 | 210 | * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
mluis | 13:618826a997e2 | 211 | * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) |
GregCr | 0:e6ceb13d2d05 | 212 | * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 213 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 214 | * LoRa: [0: not inverted, 1: inverted] |
GregCr | 0:e6ceb13d2d05 | 215 | * @param [IN] rxContinuous Sets the reception in continuous mode |
GregCr | 0:e6ceb13d2d05 | 216 | * [false: single mode, true: continuous mode] |
GregCr | 0:e6ceb13d2d05 | 217 | */ |
mluis | 22:7f3aab69cca9 | 218 | virtual void SetRxConfig ( RadioModems_t modem, uint32_t bandwidth, |
GregCr | 0:e6ceb13d2d05 | 219 | uint32_t datarate, uint8_t coderate, |
GregCr | 0:e6ceb13d2d05 | 220 | uint32_t bandwidthAfc, uint16_t preambleLen, |
GregCr | 0:e6ceb13d2d05 | 221 | uint16_t symbTimeout, bool fixLen, |
mluis | 13:618826a997e2 | 222 | uint8_t payloadLen, |
mluis | 13:618826a997e2 | 223 | bool crcOn, bool freqHopOn, uint8_t hopPeriod, |
GregCr | 6:e7f02929cd3d | 224 | bool iqInverted, bool rxContinuous ); |
mluis | 25:3778e6204cc1 | 225 | |
mluis | 13:618826a997e2 | 226 | /*! |
GregCr | 0:e6ceb13d2d05 | 227 | * @brief Sets the transmission parameters |
GregCr | 0:e6ceb13d2d05 | 228 | * |
GregCr | 0:e6ceb13d2d05 | 229 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
GregCr | 0:e6ceb13d2d05 | 230 | * @param [IN] power Sets the output power [dBm] |
GregCr | 0:e6ceb13d2d05 | 231 | * @param [IN] fdev Sets the frequency deviation ( FSK only ) |
GregCr | 0:e6ceb13d2d05 | 232 | * FSK : [Hz] |
GregCr | 0:e6ceb13d2d05 | 233 | * LoRa: 0 |
GregCr | 0:e6ceb13d2d05 | 234 | * @param [IN] bandwidth Sets the bandwidth ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 235 | * FSK : 0 |
GregCr | 0:e6ceb13d2d05 | 236 | * LoRa: [0: 125 kHz, 1: 250 kHz, |
GregCr | 0:e6ceb13d2d05 | 237 | * 2: 500 kHz, 3: Reserved] |
GregCr | 0:e6ceb13d2d05 | 238 | * @param [IN] datarate Sets the Datarate |
GregCr | 0:e6ceb13d2d05 | 239 | * FSK : 600..300000 bits/s |
GregCr | 0:e6ceb13d2d05 | 240 | * LoRa: [6: 64, 7: 128, 8: 256, 9: 512, |
GregCr | 0:e6ceb13d2d05 | 241 | * 10: 1024, 11: 2048, 12: 4096 chips] |
GregCr | 0:e6ceb13d2d05 | 242 | * @param [IN] coderate Sets the coding rate ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 243 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 244 | * LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8] |
GregCr | 0:e6ceb13d2d05 | 245 | * @param [IN] preambleLen Sets the preamble length |
GregCr | 0:e6ceb13d2d05 | 246 | * @param [IN] fixLen Fixed length packets [0: variable, 1: fixed] |
GregCr | 0:e6ceb13d2d05 | 247 | * @param [IN] crcOn Enables disables the CRC [0: OFF, 1: ON] |
mluis | 13:618826a997e2 | 248 | * @param [IN] freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) |
mluis | 13:618826a997e2 | 249 | * @param [IN] hopPeriod Number of symbols bewteen each hop (LoRa only) |
GregCr | 0:e6ceb13d2d05 | 250 | * @param [IN] iqInverted Inverts IQ signals ( LoRa only ) |
GregCr | 0:e6ceb13d2d05 | 251 | * FSK : N/A ( set to 0 ) |
GregCr | 0:e6ceb13d2d05 | 252 | * LoRa: [0: not inverted, 1: inverted] |
GregCr | 0:e6ceb13d2d05 | 253 | * @param [IN] timeout Transmission timeout [us] |
GregCr | 0:e6ceb13d2d05 | 254 | */ |
mluis | 22:7f3aab69cca9 | 255 | virtual void SetTxConfig( RadioModems_t modem, int8_t power, uint32_t fdev, |
GregCr | 0:e6ceb13d2d05 | 256 | uint32_t bandwidth, uint32_t datarate, |
GregCr | 0:e6ceb13d2d05 | 257 | uint8_t coderate, uint16_t preambleLen, |
mluis | 13:618826a997e2 | 258 | bool fixLen, bool crcOn, bool freqHopOn, |
mluis | 13:618826a997e2 | 259 | uint8_t hopPeriod, bool iqInverted, uint32_t timeout ); |
mluis | 25:3778e6204cc1 | 260 | |
mluis | 13:618826a997e2 | 261 | /*! |
GregCr | 0:e6ceb13d2d05 | 262 | * @brief Computes the packet time on air for the given payload |
GregCr | 0:e6ceb13d2d05 | 263 | * |
GregCr | 0:e6ceb13d2d05 | 264 | * \Remark Can only be called once SetRxConfig or SetTxConfig have been called |
GregCr | 0:e6ceb13d2d05 | 265 | * |
GregCr | 0:e6ceb13d2d05 | 266 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
GregCr | 0:e6ceb13d2d05 | 267 | * @param [IN] pktLen Packet payload length |
GregCr | 0:e6ceb13d2d05 | 268 | * |
GregCr | 0:e6ceb13d2d05 | 269 | * @retval airTime Computed airTime for the given packet payload length |
GregCr | 0:e6ceb13d2d05 | 270 | */ |
mluis | 22:7f3aab69cca9 | 271 | virtual double TimeOnAir ( RadioModems_t modem, uint8_t pktLen ); |
mluis | 25:3778e6204cc1 | 272 | |
mluis | 13:618826a997e2 | 273 | /*! |
GregCr | 0:e6ceb13d2d05 | 274 | * @brief Sends the buffer of size. Prepares the packet to be sent and sets |
GregCr | 0:e6ceb13d2d05 | 275 | * the radio in transmission |
GregCr | 0:e6ceb13d2d05 | 276 | * |
GregCr | 0:e6ceb13d2d05 | 277 | * @param [IN]: buffer Buffer pointer |
GregCr | 0:e6ceb13d2d05 | 278 | * @param [IN]: size Buffer size |
GregCr | 0:e6ceb13d2d05 | 279 | */ |
GregCr | 0:e6ceb13d2d05 | 280 | virtual void Send( uint8_t *buffer, uint8_t size ); |
mluis | 25:3778e6204cc1 | 281 | |
mluis | 13:618826a997e2 | 282 | /*! |
GregCr | 0:e6ceb13d2d05 | 283 | * @brief Sets the radio in sleep mode |
GregCr | 0:e6ceb13d2d05 | 284 | */ |
GregCr | 0:e6ceb13d2d05 | 285 | virtual void Sleep( void ); |
GregCr | 0:e6ceb13d2d05 | 286 | |
mluis | 13:618826a997e2 | 287 | /*! |
GregCr | 0:e6ceb13d2d05 | 288 | * @brief Sets the radio in standby mode |
GregCr | 0:e6ceb13d2d05 | 289 | */ |
GregCr | 0:e6ceb13d2d05 | 290 | virtual void Standby( void ); |
mluis | 25:3778e6204cc1 | 291 | |
mluis | 13:618826a997e2 | 292 | /*! |
GregCr | 0:e6ceb13d2d05 | 293 | * @brief Sets the radio in reception mode for the given time |
GregCr | 0:e6ceb13d2d05 | 294 | * @param [IN] timeout Reception timeout [us] |
GregCr | 0:e6ceb13d2d05 | 295 | * [0: continuous, others timeout] |
GregCr | 0:e6ceb13d2d05 | 296 | */ |
GregCr | 0:e6ceb13d2d05 | 297 | virtual void Rx( uint32_t timeout ); |
mluis | 25:3778e6204cc1 | 298 | |
mluis | 13:618826a997e2 | 299 | /*! |
GregCr | 0:e6ceb13d2d05 | 300 | * @brief Sets the radio in transmission mode for the given time |
GregCr | 0:e6ceb13d2d05 | 301 | * @param [IN] timeout Transmission timeout [us] |
GregCr | 0:e6ceb13d2d05 | 302 | * [0: continuous, others timeout] |
GregCr | 0:e6ceb13d2d05 | 303 | */ |
GregCr | 0:e6ceb13d2d05 | 304 | virtual void Tx( uint32_t timeout ); |
mluis | 25:3778e6204cc1 | 305 | |
mluis | 13:618826a997e2 | 306 | /*! |
GregCr | 7:2b555111463f | 307 | * @brief Start a Channel Activity Detection |
GregCr | 7:2b555111463f | 308 | */ |
mluis | 13:618826a997e2 | 309 | virtual void StartCad( void ); |
mluis | 25:3778e6204cc1 | 310 | |
mluis | 13:618826a997e2 | 311 | /*! |
GregCr | 0:e6ceb13d2d05 | 312 | * @brief Reads the current RSSI value |
GregCr | 0:e6ceb13d2d05 | 313 | * |
GregCr | 0:e6ceb13d2d05 | 314 | * @retval rssiValue Current RSSI value in [dBm] |
GregCr | 0:e6ceb13d2d05 | 315 | */ |
mluis | 22:7f3aab69cca9 | 316 | virtual int16_t GetRssi ( RadioModems_t modem ); |
mluis | 25:3778e6204cc1 | 317 | |
mluis | 13:618826a997e2 | 318 | /*! |
GregCr | 0:e6ceb13d2d05 | 319 | * @brief Writes the radio register at the specified address |
GregCr | 0:e6ceb13d2d05 | 320 | * |
GregCr | 0:e6ceb13d2d05 | 321 | * @param [IN]: addr Register address |
GregCr | 0:e6ceb13d2d05 | 322 | * @param [IN]: data New register value |
GregCr | 0:e6ceb13d2d05 | 323 | */ |
GregCr | 0:e6ceb13d2d05 | 324 | virtual void Write ( uint8_t addr, uint8_t data ) = 0; |
mluis | 25:3778e6204cc1 | 325 | |
mluis | 13:618826a997e2 | 326 | /*! |
GregCr | 0:e6ceb13d2d05 | 327 | * @brief Reads the radio register at the specified address |
GregCr | 0:e6ceb13d2d05 | 328 | * |
GregCr | 0:e6ceb13d2d05 | 329 | * @param [IN]: addr Register address |
GregCr | 0:e6ceb13d2d05 | 330 | * @retval data Register value |
GregCr | 0:e6ceb13d2d05 | 331 | */ |
GregCr | 0:e6ceb13d2d05 | 332 | virtual uint8_t Read ( uint8_t addr ) = 0; |
mluis | 25:3778e6204cc1 | 333 | |
mluis | 13:618826a997e2 | 334 | /*! |
GregCr | 0:e6ceb13d2d05 | 335 | * @brief Writes multiple radio registers starting at address |
GregCr | 0:e6ceb13d2d05 | 336 | * |
GregCr | 0:e6ceb13d2d05 | 337 | * @param [IN] addr First Radio register address |
GregCr | 0:e6ceb13d2d05 | 338 | * @param [IN] buffer Buffer containing the new register's values |
GregCr | 0:e6ceb13d2d05 | 339 | * @param [IN] size Number of registers to be written |
GregCr | 0:e6ceb13d2d05 | 340 | */ |
GregCr | 0:e6ceb13d2d05 | 341 | virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; |
mluis | 25:3778e6204cc1 | 342 | |
mluis | 13:618826a997e2 | 343 | /*! |
GregCr | 0:e6ceb13d2d05 | 344 | * @brief Reads multiple radio registers starting at address |
GregCr | 0:e6ceb13d2d05 | 345 | * |
GregCr | 0:e6ceb13d2d05 | 346 | * @param [IN] addr First Radio register address |
GregCr | 0:e6ceb13d2d05 | 347 | * @param [OUT] buffer Buffer where to copy the registers data |
GregCr | 0:e6ceb13d2d05 | 348 | * @param [IN] size Number of registers to be read |
GregCr | 0:e6ceb13d2d05 | 349 | */ |
GregCr | 0:e6ceb13d2d05 | 350 | virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) = 0; |
mluis | 25:3778e6204cc1 | 351 | |
mluis | 13:618826a997e2 | 352 | /*! |
mluis | 13:618826a997e2 | 353 | * @brief Writes the buffer contents to the SX1276 FIFO |
mluis | 13:618826a997e2 | 354 | * |
mluis | 13:618826a997e2 | 355 | * @param [IN] buffer Buffer containing data to be put on the FIFO. |
mluis | 13:618826a997e2 | 356 | * @param [IN] size Number of bytes to be written to the FIFO |
mluis | 13:618826a997e2 | 357 | */ |
mluis | 13:618826a997e2 | 358 | virtual void WriteFifo( uint8_t *buffer, uint8_t size ) = 0; |
GregCr | 0:e6ceb13d2d05 | 359 | |
mluis | 13:618826a997e2 | 360 | /*! |
mluis | 13:618826a997e2 | 361 | * @brief Reads the contents of the SX1276 FIFO |
mluis | 13:618826a997e2 | 362 | * |
mluis | 13:618826a997e2 | 363 | * @param [OUT] buffer Buffer where to copy the FIFO read data. |
mluis | 13:618826a997e2 | 364 | * @param [IN] size Number of bytes to be read from the FIFO |
mluis | 13:618826a997e2 | 365 | */ |
mluis | 13:618826a997e2 | 366 | virtual void ReadFifo( uint8_t *buffer, uint8_t size ) = 0; |
mluis | 13:618826a997e2 | 367 | /*! |
mluis | 13:618826a997e2 | 368 | * @brief Resets the SX1276 |
mluis | 13:618826a997e2 | 369 | */ |
mluis | 13:618826a997e2 | 370 | virtual void Reset( void ) = 0; |
mluis | 25:3778e6204cc1 | 371 | |
mluis | 20:e05596ba4166 | 372 | /*! |
mluis | 20:e05596ba4166 | 373 | * @brief Sets the maximum payload length. |
mluis | 20:e05596ba4166 | 374 | * |
mluis | 20:e05596ba4166 | 375 | * @param [IN] modem Radio modem to be used [0: FSK, 1: LoRa] |
mluis | 20:e05596ba4166 | 376 | * @param [IN] max Maximum payload length in bytes |
mluis | 20:e05596ba4166 | 377 | */ |
mluis | 22:7f3aab69cca9 | 378 | virtual void SetMaxPayloadLength( RadioModems_t modem, uint8_t max ); |
mluis | 25:3778e6204cc1 | 379 | |
mluis | 13:618826a997e2 | 380 | //------------------------------------------------------------------------- |
mluis | 13:618826a997e2 | 381 | // Board relative functions |
mluis | 13:618826a997e2 | 382 | //------------------------------------------------------------------------- |
mluis | 25:3778e6204cc1 | 383 | |
GregCr | 0:e6ceb13d2d05 | 384 | protected: |
mluis | 13:618826a997e2 | 385 | /*! |
mluis | 13:618826a997e2 | 386 | * @brief Initializes the radio I/Os pins interface |
mluis | 13:618826a997e2 | 387 | */ |
mluis | 13:618826a997e2 | 388 | virtual void IoInit( void ) = 0; |
mluis | 13:618826a997e2 | 389 | |
mluis | 13:618826a997e2 | 390 | /*! |
mluis | 13:618826a997e2 | 391 | * @brief Initializes the radio registers |
mluis | 13:618826a997e2 | 392 | */ |
mluis | 13:618826a997e2 | 393 | virtual void RadioRegistersInit( ) = 0; |
mluis | 13:618826a997e2 | 394 | |
mluis | 13:618826a997e2 | 395 | /*! |
mluis | 13:618826a997e2 | 396 | * @brief Initializes the radio SPI |
mluis | 13:618826a997e2 | 397 | */ |
mluis | 13:618826a997e2 | 398 | virtual void SpiInit( void ) = 0; |
mluis | 25:3778e6204cc1 | 399 | |
mluis | 13:618826a997e2 | 400 | /*! |
mluis | 13:618826a997e2 | 401 | * @brief Initializes DIO IRQ handlers |
mluis | 13:618826a997e2 | 402 | * |
mluis | 13:618826a997e2 | 403 | * @param [IN] irqHandlers Array containing the IRQ callback functions |
mluis | 13:618826a997e2 | 404 | */ |
mluis | 13:618826a997e2 | 405 | virtual void IoIrqInit( DioIrqHandler *irqHandlers ) = 0; |
GregCr | 0:e6ceb13d2d05 | 406 | |
mluis | 13:618826a997e2 | 407 | /*! |
mluis | 13:618826a997e2 | 408 | * @brief De-initializes the radio I/Os pins interface. |
mluis | 13:618826a997e2 | 409 | * |
mluis | 13:618826a997e2 | 410 | * \remark Useful when going in MCU lowpower modes |
mluis | 13:618826a997e2 | 411 | */ |
mluis | 13:618826a997e2 | 412 | virtual void IoDeInit( void ) = 0; |
GregCr | 0:e6ceb13d2d05 | 413 | |
mluis | 13:618826a997e2 | 414 | /*! |
mluis | 13:618826a997e2 | 415 | * @brief Gets the board PA selection configuration |
mluis | 13:618826a997e2 | 416 | * |
mluis | 13:618826a997e2 | 417 | * @param [IN] channel Channel frequency in Hz |
mluis | 13:618826a997e2 | 418 | * @retval PaSelect RegPaConfig PaSelect value |
mluis | 13:618826a997e2 | 419 | */ |
mluis | 13:618826a997e2 | 420 | virtual uint8_t GetPaSelect( uint32_t channel ) = 0; |
GregCr | 0:e6ceb13d2d05 | 421 | |
mluis | 13:618826a997e2 | 422 | /*! |
mluis | 13:618826a997e2 | 423 | * @brief Set the RF Switch I/Os pins in Low Power mode |
mluis | 13:618826a997e2 | 424 | * |
mluis | 13:618826a997e2 | 425 | * @param [IN] status enable or disable |
mluis | 13:618826a997e2 | 426 | */ |
mluis | 13:618826a997e2 | 427 | virtual void SetAntSwLowPower( bool status ) = 0; |
GregCr | 0:e6ceb13d2d05 | 428 | |
mluis | 13:618826a997e2 | 429 | /*! |
mluis | 13:618826a997e2 | 430 | * @brief Initializes the RF Switch I/Os pins interface |
mluis | 13:618826a997e2 | 431 | */ |
mluis | 13:618826a997e2 | 432 | virtual void AntSwInit( void ) = 0; |
GregCr | 0:e6ceb13d2d05 | 433 | |
mluis | 13:618826a997e2 | 434 | /*! |
mluis | 13:618826a997e2 | 435 | * @brief De-initializes the RF Switch I/Os pins interface |
mluis | 13:618826a997e2 | 436 | * |
mluis | 13:618826a997e2 | 437 | * \remark Needed to decrease the power consumption in MCU lowpower modes |
mluis | 13:618826a997e2 | 438 | */ |
mluis | 13:618826a997e2 | 439 | virtual void AntSwDeInit( void ) = 0; |
GregCr | 0:e6ceb13d2d05 | 440 | |
mluis | 13:618826a997e2 | 441 | /*! |
mluis | 13:618826a997e2 | 442 | * @brief Controls the antena switch if necessary. |
mluis | 13:618826a997e2 | 443 | * |
mluis | 13:618826a997e2 | 444 | * \remark see errata note |
mluis | 13:618826a997e2 | 445 | * |
mluis | 13:618826a997e2 | 446 | * @param [IN] rxTx [1: Tx, 0: Rx] |
mluis | 13:618826a997e2 | 447 | */ |
mluis | 13:618826a997e2 | 448 | virtual void SetAntSw( uint8_t rxTx ) = 0; |
mluis | 25:3778e6204cc1 | 449 | |
mluis | 13:618826a997e2 | 450 | /*! |
GregCr | 0:e6ceb13d2d05 | 451 | * @brief Checks if the given RF frequency is supported by the hardware |
GregCr | 0:e6ceb13d2d05 | 452 | * |
GregCr | 0:e6ceb13d2d05 | 453 | * @param [IN] frequency RF frequency to be checked |
GregCr | 0:e6ceb13d2d05 | 454 | * @retval isSupported [true: supported, false: unsupported] |
GregCr | 0:e6ceb13d2d05 | 455 | */ |
GregCr | 0:e6ceb13d2d05 | 456 | virtual bool CheckRfFrequency( uint32_t frequency ) = 0; |
GregCr | 0:e6ceb13d2d05 | 457 | protected: |
GregCr | 0:e6ceb13d2d05 | 458 | |
mluis | 13:618826a997e2 | 459 | /*! |
mluis | 13:618826a997e2 | 460 | * @brief Sets the SX1276 operating mode |
mluis | 13:618826a997e2 | 461 | * |
mluis | 13:618826a997e2 | 462 | * @param [IN] opMode New operating mode |
mluis | 13:618826a997e2 | 463 | */ |
mluis | 13:618826a997e2 | 464 | virtual void SetOpMode( uint8_t opMode ); |
GregCr | 0:e6ceb13d2d05 | 465 | |
mluis | 13:618826a997e2 | 466 | /* |
mluis | 13:618826a997e2 | 467 | * SX1276 DIO IRQ callback functions prototype |
mluis | 13:618826a997e2 | 468 | */ |
GregCr | 0:e6ceb13d2d05 | 469 | |
mluis | 13:618826a997e2 | 470 | /*! |
mluis | 13:618826a997e2 | 471 | * @brief DIO 0 IRQ callback |
mluis | 13:618826a997e2 | 472 | */ |
mluis | 13:618826a997e2 | 473 | virtual void OnDio0Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 474 | |
mluis | 13:618826a997e2 | 475 | /*! |
mluis | 13:618826a997e2 | 476 | * @brief DIO 1 IRQ callback |
mluis | 13:618826a997e2 | 477 | */ |
mluis | 13:618826a997e2 | 478 | virtual void OnDio1Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 479 | |
mluis | 13:618826a997e2 | 480 | /*! |
mluis | 13:618826a997e2 | 481 | * @brief DIO 2 IRQ callback |
mluis | 13:618826a997e2 | 482 | */ |
mluis | 13:618826a997e2 | 483 | virtual void OnDio2Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 484 | |
mluis | 13:618826a997e2 | 485 | /*! |
mluis | 13:618826a997e2 | 486 | * @brief DIO 3 IRQ callback |
mluis | 13:618826a997e2 | 487 | */ |
mluis | 13:618826a997e2 | 488 | virtual void OnDio3Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 489 | |
mluis | 13:618826a997e2 | 490 | /*! |
mluis | 13:618826a997e2 | 491 | * @brief DIO 4 IRQ callback |
mluis | 13:618826a997e2 | 492 | */ |
mluis | 13:618826a997e2 | 493 | virtual void OnDio4Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 494 | |
mluis | 13:618826a997e2 | 495 | /*! |
mluis | 13:618826a997e2 | 496 | * @brief DIO 5 IRQ callback |
mluis | 13:618826a997e2 | 497 | */ |
mluis | 13:618826a997e2 | 498 | virtual void OnDio5Irq( void ); |
GregCr | 0:e6ceb13d2d05 | 499 | |
mluis | 13:618826a997e2 | 500 | /*! |
mluis | 13:618826a997e2 | 501 | * @brief Tx & Rx timeout timer callback |
mluis | 13:618826a997e2 | 502 | */ |
mluis | 13:618826a997e2 | 503 | virtual void OnTimeoutIrq( void ); |
mluis | 25:3778e6204cc1 | 504 | |
mluis | 13:618826a997e2 | 505 | /*! |
mluis | 13:618826a997e2 | 506 | * Returns the known FSK bandwidth registers value |
mluis | 13:618826a997e2 | 507 | * |
mluis | 13:618826a997e2 | 508 | * \param [IN] bandwidth Bandwidth value in Hz |
mluis | 13:618826a997e2 | 509 | * \retval regValue Bandwidth register value. |
mluis | 13:618826a997e2 | 510 | */ |
mluis | 13:618826a997e2 | 511 | static uint8_t GetFskBandwidthRegValue( uint32_t bandwidth ); |
GregCr | 0:e6ceb13d2d05 | 512 | }; |
GregCr | 0:e6ceb13d2d05 | 513 | |
mluis | 22:7f3aab69cca9 | 514 | #endif // __SX1276_H__ |