Modtronix inAir9 driver based on SX1276 standard driver

Dependents:   SX1276PingPong_inAir Sensors LoRaTerminal

Fork of SX1276Lib by Semtech

Committer:
mluis
Date:
Tue Dec 16 10:02:45 2014 +0000
Revision:
13:618826a997e2
Parent:
12:aa5b3bf7fdf4
Child:
16:d447f8d2d2d6
Cosmetics; Added LICENSE text.; Added the possibility to specify the payload length for receiving fixed length frames.; Added SetModem function to radio interface.; Added LoRa syncword register definition

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