This Library is to establish communication between a transmitter and receivers formed by the combination of SX1272MB2DAS shield and FRDM kl25z board that uses Cortex M0+ architecture.

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