pin pong

Dependents:   SX1272PingPong

Fork of SX1276Lib by Semtech

Committer:
tmulrooney
Date:
Tue Feb 09 02:05:06 2016 +0000
Revision:
23:273a2f93ae99
Child:
24:9100348e6c28
ping pong

Who changed what in which revision?

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