1272 driver for lorawan, which is compatible with current mbed-os

Dependents:   LoRaWAN-demo-72-bootcamp

Fork of SX1272Lib by Semtech

Committer:
dudmuck
Date:
Tue Jan 30 22:44:23 2018 +0000
Revision:
8:3f3d884e05ad
Parent:
7:b988b60083a1
debug() symbol in mbed-os library

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