first draft

Dependents:   LoRaWAN-demo-72_tjm frdm_LoRa_Connect_Woodstream_Demo_tjm frdm_LoRa_Connect_Woodstream_Demo_jlc

Fork of SX1272Lib by Semtech

Embed: (wiki syntax)

« Back to documentation index

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

sx1272-hal.h

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