use with LoRa Access Point

Fork of SX1276Lib by Semtech

Committer:
GregCr
Date:
Thu Sep 04 14:03:20 2014 +0000
Revision:
6:e7f02929cd3d
Parent:
4:f0ce52e94d3f
Child:
7:2b555111463f
Added support for FHSS

Who changed what in which revision?

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