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: -
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_HAL_H__
mluis 0:45c4f0364ca4 25 #define __SX1272_HAL_H__
mluis 0:45c4f0364ca4 26 #include "sx1272.h"
mluis 0:45c4f0364ca4 27
mluis 0:45c4f0364ca4 28 /*!
mluis 7:b988b60083a1 29 * @brief Radio hardware registers initialization definition
mluis 0:45c4f0364ca4 30 *
mluis 7:b988b60083a1 31 * @remark Can be automatically generated by the SX1272 GUI (not yet implemented)
mluis 0:45c4f0364ca4 32 */
mluis 0:45c4f0364ca4 33 #define RADIO_INIT_REGISTERS_VALUE \
mluis 0:45c4f0364ca4 34 { \
mluis 0:45c4f0364ca4 35 { MODEM_FSK , REG_LNA , 0x23 },\
mluis 0:45c4f0364ca4 36 { MODEM_FSK , REG_RXCONFIG , 0x1E },\
mluis 0:45c4f0364ca4 37 { MODEM_FSK , REG_RSSICONFIG , 0xD2 },\
mluis 7:b988b60083a1 38 { MODEM_FSK , REG_AFCFEI , 0x01 },\
mluis 0:45c4f0364ca4 39 { MODEM_FSK , REG_PREAMBLEDETECT , 0xAA },\
mluis 0:45c4f0364ca4 40 { MODEM_FSK , REG_OSC , 0x07 },\
mluis 0:45c4f0364ca4 41 { MODEM_FSK , REG_SYNCCONFIG , 0x12 },\
mluis 0:45c4f0364ca4 42 { MODEM_FSK , REG_SYNCVALUE1 , 0xC1 },\
mluis 0:45c4f0364ca4 43 { MODEM_FSK , REG_SYNCVALUE2 , 0x94 },\
mluis 0:45c4f0364ca4 44 { MODEM_FSK , REG_SYNCVALUE3 , 0xC1 },\
mluis 0:45c4f0364ca4 45 { MODEM_FSK , REG_PACKETCONFIG1 , 0xD8 },\
mluis 0:45c4f0364ca4 46 { MODEM_FSK , REG_FIFOTHRESH , 0x8F },\
mluis 0:45c4f0364ca4 47 { MODEM_FSK , REG_IMAGECAL , 0x02 },\
mluis 0:45c4f0364ca4 48 { MODEM_FSK , REG_DIOMAPPING1 , 0x00 },\
mluis 0:45c4f0364ca4 49 { MODEM_FSK , REG_DIOMAPPING2 , 0x30 },\
mluis 0:45c4f0364ca4 50 { MODEM_LORA, REG_LR_DETECTOPTIMIZE , 0x43 },\
mluis 0:45c4f0364ca4 51 { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
mluis 0:45c4f0364ca4 52 } \
mluis 0:45c4f0364ca4 53
mluis 0:45c4f0364ca4 54 /*!
mluis 0:45c4f0364ca4 55 * Actual implementation of a SX1272 radio, includes some modifications to make it compatible with the MB1 LAS board
mluis 0:45c4f0364ca4 56 */
GregCr 2:cd1093b6676f 57 class SX1272MB2xAS : public SX1272
mluis 0:45c4f0364ca4 58 {
mluis 0:45c4f0364ca4 59 protected:
mluis 0:45c4f0364ca4 60 /*!
mluis 0:45c4f0364ca4 61 * Antenna switch GPIO pins objects
mluis 0:45c4f0364ca4 62 */
mluis 0:45c4f0364ca4 63 #if defined ( TARGET_MOTE_L152RC )
mluis 0:45c4f0364ca4 64 DigitalOut RfSwitchCntr1;
mluis 0:45c4f0364ca4 65 DigitalOut RfSwitchCntr2;
mluis 0:45c4f0364ca4 66 DigitalOut PwrAmpCntr;
dudmuck 1:b0372ef620d0 67 #elif defined ( TARGET_MTS_MDOT_F411RE )
dudmuck 1:b0372ef620d0 68 DigitalOut TxCtl;
dudmuck 1:b0372ef620d0 69 DigitalOut RxCtl;
mluis 0:45c4f0364ca4 70 #else
mluis 0:45c4f0364ca4 71 DigitalInOut AntSwitch;
mluis 0:45c4f0364ca4 72 DigitalIn Fake;
mluis 0:45c4f0364ca4 73 #endif
mluis 7:b988b60083a1 74
mluis 0:45c4f0364ca4 75 private:
mluis 0:45c4f0364ca4 76 static const RadioRegisters_t RadioRegsInit[];
mluis 7:b988b60083a1 77
mluis 0:45c4f0364ca4 78 public:
GregCr 2:cd1093b6676f 79 SX1272MB2xAS( RadioEvents_t *events,
mluis 0:45c4f0364ca4 80 PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
mluis 0:45c4f0364ca4 81 PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
mluis 0:45c4f0364ca4 82 #if defined ( TARGET_MOTE_L152RC )
mluis 0:45c4f0364ca4 83 PinName rfSwitchCntr1, PinName rfSwitchCntr2 );
dudmuck 1:b0372ef620d0 84 #elif defined ( TARGET_MTS_MDOT_F411RE )
dudmuck 1:b0372ef620d0 85 PinName txctl, PinName rxctl );
mluis 0:45c4f0364ca4 86 #else
mluis 0:45c4f0364ca4 87 PinName antSwitch );
mluis 0:45c4f0364ca4 88 #endif
mluis 7:b988b60083a1 89
GregCr 2:cd1093b6676f 90 SX1272MB2xAS( RadioEvents_t *events );
mluis 7:b988b60083a1 91
GregCr 2:cd1093b6676f 92 virtual ~SX1272MB2xAS( ) { };
mluis 7:b988b60083a1 93
mluis 7:b988b60083a1 94 protected:
mluis 0:45c4f0364ca4 95 /*!
mluis 0:45c4f0364ca4 96 * @brief Initializes the radio I/Os pins interface
mluis 0:45c4f0364ca4 97 */
mluis 0:45c4f0364ca4 98 virtual void IoInit( void );
mluis 7:b988b60083a1 99
mluis 0:45c4f0364ca4 100 /*!
mluis 0:45c4f0364ca4 101 * @brief Initializes the radio registers
mluis 0:45c4f0364ca4 102 */
mluis 0:45c4f0364ca4 103 virtual void RadioRegistersInit( );
mluis 0:45c4f0364ca4 104
mluis 0:45c4f0364ca4 105 /*!
mluis 0:45c4f0364ca4 106 * @brief Initializes the radio SPI
mluis 0:45c4f0364ca4 107 */
mluis 0:45c4f0364ca4 108 virtual void SpiInit( void );
mluis 7:b988b60083a1 109
mluis 0:45c4f0364ca4 110 /*!
mluis 0:45c4f0364ca4 111 * @brief Initializes DIO IRQ handlers
mluis 0:45c4f0364ca4 112 *
mluis 0:45c4f0364ca4 113 * @param [IN] irqHandlers Array containing the IRQ callback functions
mluis 0:45c4f0364ca4 114 */
mluis 0:45c4f0364ca4 115 virtual void IoIrqInit( DioIrqHandler *irqHandlers );
mluis 0:45c4f0364ca4 116
mluis 0:45c4f0364ca4 117 /*!
mluis 0:45c4f0364ca4 118 * @brief De-initializes the radio I/Os pins interface.
mluis 0:45c4f0364ca4 119 *
mluis 0:45c4f0364ca4 120 * \remark Useful when going in MCU lowpower modes
mluis 0:45c4f0364ca4 121 */
mluis 0:45c4f0364ca4 122 virtual void IoDeInit( void );
mluis 0:45c4f0364ca4 123
mluis 0:45c4f0364ca4 124 /*!
mluis 7:b988b60083a1 125 * \brief Sets the radio output power.
mluis 7:b988b60083a1 126 *
mluis 7:b988b60083a1 127 * @param [IN] power Sets the RF output power
mluis 7:b988b60083a1 128 */
mluis 7:b988b60083a1 129 virtual void SetRfTxPower( int8_t power );
mluis 7:b988b60083a1 130
mluis 7:b988b60083a1 131 /*!
mluis 0:45c4f0364ca4 132 * @brief Gets the board PA selection configuration
mluis 0:45c4f0364ca4 133 *
mluis 0:45c4f0364ca4 134 * @param [IN] channel Channel frequency in Hz
mluis 0:45c4f0364ca4 135 * @retval PaSelect RegPaConfig PaSelect value
mluis 0:45c4f0364ca4 136 */
mluis 0:45c4f0364ca4 137 virtual uint8_t GetPaSelect( uint32_t channel );
mluis 0:45c4f0364ca4 138
mluis 0:45c4f0364ca4 139 /*!
mluis 0:45c4f0364ca4 140 * @brief Set the RF Switch I/Os pins in Low Power mode
mluis 0:45c4f0364ca4 141 *
mluis 0:45c4f0364ca4 142 * @param [IN] status enable or disable
mluis 0:45c4f0364ca4 143 */
mluis 0:45c4f0364ca4 144 virtual void SetAntSwLowPower( bool status );
mluis 0:45c4f0364ca4 145
mluis 0:45c4f0364ca4 146 /*!
mluis 0:45c4f0364ca4 147 * @brief Initializes the RF Switch I/Os pins interface
mluis 0:45c4f0364ca4 148 */
mluis 0:45c4f0364ca4 149 virtual void AntSwInit( void );
mluis 0:45c4f0364ca4 150
mluis 0:45c4f0364ca4 151 /*!
mluis 0:45c4f0364ca4 152 * @brief De-initializes the RF Switch I/Os pins interface
mluis 0:45c4f0364ca4 153 *
mluis 7:b988b60083a1 154 * @remark Needed to decrease the power consumption in MCU lowpower modes
mluis 0:45c4f0364ca4 155 */
mluis 0:45c4f0364ca4 156 virtual void AntSwDeInit( void );
mluis 0:45c4f0364ca4 157
mluis 0:45c4f0364ca4 158 /*!
mluis 0:45c4f0364ca4 159 * @brief Controls the antena switch if necessary.
mluis 0:45c4f0364ca4 160 *
mluis 7:b988b60083a1 161 * @remark see errata note
mluis 0:45c4f0364ca4 162 *
mluis 7:b988b60083a1 163 * @param [IN] opMode Current radio operating mode
mluis 0:45c4f0364ca4 164 */
mluis 7:b988b60083a1 165 virtual void SetAntSw( uint8_t opMode );
mluis 7:b988b60083a1 166
mluis 7:b988b60083a1 167 public:
mluis 0:45c4f0364ca4 168 /*!
mluis 0:45c4f0364ca4 169 * @brief Detect the board connected by reading the value of the antenna switch pin
mluis 0:45c4f0364ca4 170 */
mluis 7:b988b60083a1 171 virtual uint8_t DetectBoardType( void );
mluis 7:b988b60083a1 172
mluis 0:45c4f0364ca4 173 /*!
mluis 0:45c4f0364ca4 174 * @brief Checks if the given RF frequency is supported by the hardware
mluis 0:45c4f0364ca4 175 *
mluis 0:45c4f0364ca4 176 * @param [IN] frequency RF frequency to be checked
mluis 0:45c4f0364ca4 177 * @retval isSupported [true: supported, false: unsupported]
mluis 0:45c4f0364ca4 178 */
mluis 0:45c4f0364ca4 179 virtual bool CheckRfFrequency( uint32_t frequency );
mluis 7:b988b60083a1 180
mluis 7:b988b60083a1 181 /*!
mluis 0:45c4f0364ca4 182 * @brief Writes the radio register at the specified address
mluis 0:45c4f0364ca4 183 *
mluis 0:45c4f0364ca4 184 * @param [IN]: addr Register address
mluis 0:45c4f0364ca4 185 * @param [IN]: data New register value
mluis 0:45c4f0364ca4 186 */
mluis 0:45c4f0364ca4 187 virtual void Write ( uint8_t addr, uint8_t data ) ;
mluis 7:b988b60083a1 188
mluis 0:45c4f0364ca4 189 /*!
mluis 0:45c4f0364ca4 190 * @brief Reads the radio register at the specified address
mluis 0:45c4f0364ca4 191 *
mluis 0:45c4f0364ca4 192 * @param [IN]: addr Register address
mluis 0:45c4f0364ca4 193 * @retval data Register value
mluis 0:45c4f0364ca4 194 */
mluis 0:45c4f0364ca4 195 virtual uint8_t Read ( uint8_t addr ) ;
mluis 7:b988b60083a1 196
mluis 0:45c4f0364ca4 197 /*!
mluis 0:45c4f0364ca4 198 * @brief Writes multiple radio registers starting at address
mluis 0:45c4f0364ca4 199 *
mluis 0:45c4f0364ca4 200 * @param [IN] addr First Radio register address
mluis 0:45c4f0364ca4 201 * @param [IN] buffer Buffer containing the new register's values
mluis 0:45c4f0364ca4 202 * @param [IN] size Number of registers to be written
mluis 0:45c4f0364ca4 203 */
mluis 0:45c4f0364ca4 204 virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
mluis 7:b988b60083a1 205
mluis 0:45c4f0364ca4 206 /*!
mluis 0:45c4f0364ca4 207 * @brief Reads multiple radio registers starting at address
mluis 0:45c4f0364ca4 208 *
mluis 0:45c4f0364ca4 209 * @param [IN] addr First Radio register address
mluis 0:45c4f0364ca4 210 * @param [OUT] buffer Buffer where to copy the registers data
mluis 0:45c4f0364ca4 211 * @param [IN] size Number of registers to be read
mluis 0:45c4f0364ca4 212 */
mluis 0:45c4f0364ca4 213 virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
mluis 7:b988b60083a1 214
mluis 0:45c4f0364ca4 215 /*!
mluis 0:45c4f0364ca4 216 * @brief Writes the buffer contents to the SX1272 FIFO
mluis 0:45c4f0364ca4 217 *
mluis 0:45c4f0364ca4 218 * @param [IN] buffer Buffer containing data to be put on the FIFO.
mluis 0:45c4f0364ca4 219 * @param [IN] size Number of bytes to be written to the FIFO
mluis 0:45c4f0364ca4 220 */
mluis 0:45c4f0364ca4 221 virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
mluis 0:45c4f0364ca4 222
mluis 0:45c4f0364ca4 223 /*!
mluis 0:45c4f0364ca4 224 * @brief Reads the contents of the SX1272 FIFO
mluis 0:45c4f0364ca4 225 *
mluis 0:45c4f0364ca4 226 * @param [OUT] buffer Buffer where to copy the FIFO read data.
mluis 0:45c4f0364ca4 227 * @param [IN] size Number of bytes to be read from the FIFO
mluis 0:45c4f0364ca4 228 */
mluis 0:45c4f0364ca4 229 virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
mluis 7:b988b60083a1 230
mluis 0:45c4f0364ca4 231 /*!
mluis 0:45c4f0364ca4 232 * @brief Reset the SX1272
mluis 0:45c4f0364ca4 233 */
mluis 0:45c4f0364ca4 234 virtual void Reset( void );
mluis 0:45c4f0364ca4 235 };
mluis 0:45c4f0364ca4 236
mluis 0:45c4f0364ca4 237 #endif // __SX1272_HAL_H__