Driver for the SX1272 RF Transceiver

Dependents:   LoRaWAN_mbed_lmic_agriculture_app

Fork of SX1272Lib by Semtech

Committer:
GTsapparellas
Date:
Mon Apr 02 12:06:02 2018 +0000
Revision:
8:60c42278731e
Parent:
7:b988b60083a1
SX1272MB2xAS LoRa shield attached on FRDM-K64F ARM mbed board.

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