Driver for the SX1276 RF Transceiver

Dependents:   LoRaWAN_actility LoRaWAN_MBED LoRaWANSharedTest

Committer:
GregCr
Date:
Mon Oct 13 07:06:55 2014 +0000
Revision:
11:ce0cdab5137a
Parent:
9:b420e9c3d6fe
Child:
13:618826a997e2
Added LICENSE.txt; Minor corrections;

Who changed what in which revision?

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