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