Driver for the SX1276 RF Transceiver

Dependents:   LoRa_PIR LoRaWAN-lmic-app SX1276PingPong LoRaWAN-lmic-app ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sx1276-hal.h Source File

sx1276-hal.h

00001 /*
00002  / _____)             _              | |
00003 ( (____  _____ ____ _| |_ _____  ____| |__
00004  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00005  _____) ) ____| | | || |_| ____( (___| | | |
00006 (______/|_____)_|_|_| \__)_____)\____)_| |_|
00007     (C) 2014 Semtech
00008 
00009 Description: -
00010 
00011 License: Revised BSD License, see LICENSE.TXT file include in the project
00012 
00013 Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
00014 */
00015 #ifndef __SX1276_HAL_H__
00016 #define __SX1276_HAL_H__
00017 #include "sx1276.h"
00018 
00019 /*!
00020  * @brief Radio hardware registers initialization definition
00021  *
00022  * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
00023  */
00024 #define RADIO_INIT_REGISTERS_VALUE                \
00025 {                                                 \
00026     { MODEM_FSK , REG_LNA                , 0x23 },\
00027     { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
00028     { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
00029     { MODEM_FSK , REG_AFCFEI             , 0x01 },\
00030     { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
00031     { MODEM_FSK , REG_OSC                , 0x07 },\
00032     { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
00033     { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
00034     { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
00035     { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
00036     { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
00037     { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
00038     { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
00039     { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
00040     { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
00041     { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
00042 }                                                 \
00043 
00044 /*! 
00045  * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
00046  */
00047 class SX1276MB1xAS  : public SX1276 
00048 {
00049 protected:
00050     /*!
00051      * Antenna switch GPIO pins objects
00052      */
00053     DigitalInOut AntSwitch ;
00054     DigitalIn Fake;
00055 
00056 private:
00057     static const RadioRegisters_t  RadioRegsInit[];
00058 
00059 public:
00060     SX1276MB1xAS ( RadioEvents_t *events,
00061             PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset ,
00062             PinName dio0 , PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
00063             PinName antSwitch ); 
00064 
00065     SX1276MB1xAS ( RadioEvents_t *events );
00066 
00067     virtual ~SX1276MB1xAS ( ) { };
00068 
00069 protected:
00070     /*!
00071      * @brief Initializes the radio I/Os pins interface
00072      */
00073     virtual void IoInit( void );
00074 
00075     /*!
00076      *  @brief Initializes the radio registers
00077      */
00078     virtual void RadioRegistersInit( );
00079     
00080     /*!
00081      * @brief Initializes the radio SPI
00082      */
00083     virtual void SpiInit( void );
00084 
00085     /*!
00086      * @brief Initializes DIO IRQ handlers
00087      *
00088      * @param [IN] irqHandlers Array containing the IRQ callback functions
00089      */
00090     virtual void IoIrqInit( DioIrqHandler *irqHandlers );
00091 
00092     /*!
00093      * @brief De-initializes the radio I/Os pins interface. 
00094      *
00095      * \remark Useful when going in MCU lowpower modes
00096      */
00097     virtual void IoDeInit( void );
00098 
00099     /*!
00100      * \brief Sets the radio output power.
00101      *
00102      * @param [IN] power Sets the RF output power
00103      */
00104     virtual void SetRfTxPower( int8_t power );
00105 
00106     /*!
00107      * @brief Gets the board PA selection configuration
00108      *
00109      * @param [IN] channel Channel frequency in Hz
00110      * @retval PaSelect RegPaConfig PaSelect value
00111      */
00112     virtual uint8_t GetPaSelect( uint32_t channel );
00113 
00114     /*!
00115      * @brief Set the RF Switch I/Os pins in Low Power mode
00116      *
00117      * @param [IN] status enable or disable
00118      */
00119     virtual void SetAntSwLowPower( bool status );
00120 
00121     /*!
00122      * @brief Initializes the RF Switch I/Os pins interface
00123      */
00124     virtual void AntSwInit( void );
00125 
00126     /*!
00127      * @brief De-initializes the RF Switch I/Os pins interface 
00128      *
00129      * @remark Needed to decrease the power consumption in MCU lowpower modes
00130      */
00131     virtual void AntSwDeInit( void );
00132 
00133     /*!
00134      * @brief Controls the antena switch if necessary.
00135      *
00136      * @remark see errata note
00137      *
00138      * @param [IN] opMode Current radio operating mode
00139      */
00140     virtual void SetAntSw( uint8_t opMode );
00141 
00142 public:
00143     /*!
00144      * @brief Detect the board connected by reading the value of the antenna switch pin
00145      */
00146     virtual uint8_t DetectBoardType( void );
00147 
00148     /*!
00149      * @brief Checks if the given RF frequency is supported by the hardware
00150      *
00151      * @param [IN] frequency RF frequency to be checked
00152      * @retval isSupported [true: supported, false: unsupported]
00153      */
00154     virtual bool CheckRfFrequency( uint32_t frequency );
00155 
00156     /*!
00157      * @brief Writes the radio register at the specified address
00158      *
00159      * @param [IN]: addr Register address
00160      * @param [IN]: data New register value
00161      */
00162     virtual void Write ( uint8_t addr, uint8_t data ) ;
00163 
00164     /*!
00165      * @brief Reads the radio register at the specified address
00166      *
00167      * @param [IN]: addr Register address
00168      * @retval data Register value
00169      */
00170     virtual uint8_t Read ( uint8_t addr ) ;
00171 
00172     /*!
00173      * @brief Writes multiple radio registers starting at address
00174      *
00175      * @param [IN] addr   First Radio register address
00176      * @param [IN] buffer Buffer containing the new register's values
00177      * @param [IN] size   Number of registers to be written
00178      */
00179     virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
00180 
00181     /*!
00182      * @brief Reads multiple radio registers starting at address
00183      *
00184      * @param [IN] addr First Radio register address
00185      * @param [OUT] buffer Buffer where to copy the registers data
00186      * @param [IN] size Number of registers to be read
00187      */
00188     virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
00189 
00190     /*!
00191      * @brief Writes the buffer contents to the SX1276 FIFO
00192      *
00193      * @param [IN] buffer Buffer containing data to be put on the FIFO.
00194      * @param [IN] size Number of bytes to be written to the FIFO
00195      */
00196     virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
00197 
00198     /*!
00199      * @brief Reads the contents of the SX1276 FIFO
00200      *
00201      * @param [OUT] buffer Buffer where to copy the FIFO read data.
00202      * @param [IN] size Number of bytes to be read from the FIFO
00203      */
00204     virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
00205 
00206     /*!
00207      * @brief Reset the SX1276
00208      */
00209     virtual void Reset( void );
00210 };
00211 
00212 #endif // __SX1276_HAL_H__