Added support to TARGET_NUCLEO_L073RZ

Dependents:   SX1272PingPong

Fork of SX1272Lib by Semtech

Committer:
mluis
Date:
Tue Jan 05 16:43:48 2016 +0000
Revision:
0:45c4f0364ca4
Child:
3:5baff45eb3c5
Child:
7:b988b60083a1
Library creation based on SX1276Lib and https://github.com/Lora-net/LoRaMac-node

Who changed what in which revision?

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