Walter Luu / SX1276GenericLib

Dependents:   mbed-os-example-mbed5-blinky-zchen409 NonPingPong_PICO_LoRa NonPingPong_PICO_LoRa_LP0 NonPingPong_PICO_LoRa_LP1 ... more

Embed: (wiki syntax)

« Back to documentation index

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

sx1276-mbed-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 
00016 /*
00017  * additional development to make it more generic across multiple OS versions
00018  * (c) 2017 Helmut Tschemernjak
00019  * 30826 Garbsen (Hannover) Germany
00020  */
00021 
00022 #ifndef __SX1276_MBED_HAL_H__
00023 #define __SX1276_MBED_HAL_H__
00024 
00025 
00026 #include "sx1276.h"
00027 
00028 
00029 #ifdef __MBED__
00030 #define XSPI    SPI
00031 #endif
00032 
00033 #ifdef DEVICE_LOWPOWERTIMER
00034  #define MyTimeout LowPowerTimeout
00035 #else
00036  #define MyTimeout Timeout
00037 #endif
00038 
00039 /*!
00040  * Actual implementation of a SX1276 radio, includes some modifications to make it
00041  * compatible with the MB1 LAS board
00042  */
00043 class SX1276Generic  : public SX1276 
00044 {
00045 protected:          // can be accessible by derived class or inheritance
00046     /*!
00047      * Antenna switch GPIO pins objects
00048      */
00049     DigitalOut *_antSwitch ;                 // declaration of _antSwitch pin
00050     DigitalOut *_antSwitchTX;               // declaration of _antSwitchTX pin
00051     DigitalOut *_antSwitchTXBoost;          // declaration of _antSwitchTXBoost pin
00052 
00053     /*!
00054      * SX1276 Reset pin
00055      */
00056     DigitalInOut *_reset ;                   // declaration of _reset pin
00057     
00058     /*!
00059      * TCXO being used with the Murata Module
00060      */
00061     DigitalOut *_tcxo ;                      // declaration of _tcxo pin, only for Murata module
00062 
00063     /*!
00064      * SPI Interface
00065      */
00066     XSPI *_spi ; // mosi, miso, sclk     // declaration of SPI pins
00067     DigitalOut *_nss;                   // declaration of _nss pin
00068     
00069     /*!
00070      * SX1276 DIO pins
00071      */
00072     InterruptIn *_dio0 ;                 // declaration of interrupt in _dio0
00073     InterruptIn *_dio1;                 // declaration of interrupt in _dio1
00074     InterruptIn *_dio2;                 // declaration of interrupt in _dio2
00075     InterruptIn *_dio3;                 // declaration of interrupt in _dio3
00076     InterruptIn *_dio4;                 // declaration of interrupt in _dio4
00077     DigitalIn *_dio5;                   // declaration of digital input _dio5
00078     
00079     /*!
00080      * Tx and Rx timers
00081      */
00082     MyTimeout txTimeoutTimer ;           // declaration of txTimeoutTimer
00083     MyTimeout rxTimeoutTimer;           // declaration of rxTimeoutTimer
00084     MyTimeout rxTimeoutSyncWord;        // declaration of rxTimeoutSyncWord
00085     
00086     
00087 private:
00088     /*!
00089      * triggers definition
00090      */
00091     typedef void (SX1276Generic ::*Trigger)(void);
00092 
00093 
00094 public:
00095     SX1276Generic ( RadioEvents_t *events, BoardType_t board,
00096             PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
00097             PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
00098             PinName antSwitch = NC, PinName antSwitchTX = NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC);
00099 
00100     
00101     SX1276Generic ( RadioEvents_t *events );
00102 
00103     virtual ~SX1276Generic ();
00104 
00105 protected:
00106     /*!
00107      * @brief Initializes the radio I/Os pins interface
00108      */
00109     virtual void IoInit( void );
00110 
00111     /*!
00112      * @brief Initializes the radio SPI
00113      */
00114     virtual void SpiInit( void );
00115 
00116     /*!
00117      * @brief Initializes DIO IRQ handlers
00118      *
00119      * @param [IN] irqHandlers Array containing the IRQ callback functions
00120      */
00121     virtual void IoIrqInit( DioIrqHandler  *irqHandlers );
00122 
00123     /*!
00124      * @brief De-initializes the radio I/Os pins interface. 
00125      *
00126      * \remark Useful when going in MCU lowpower modes
00127      */
00128     virtual void IoDeInit( void );
00129 
00130     /*!
00131      * @brief Gets the board PA selection configuration
00132      *
00133      * @param [IN] channel Channel frequency in Hz
00134      * @retval PaSelect RegPaConfig PaSelect value
00135      */
00136     virtual uint8_t GetPaSelect( uint32_t channel );
00137 
00138     /*!
00139      * @brief Set the RF Switch I/Os pins in Low Power mode
00140      *
00141      * @param [IN] status enable or disable
00142      */
00143     virtual void SetAntSwLowPower( bool status );
00144 
00145     /*!
00146      * @brief Initializes the RF Switch I/Os pins interface
00147      */
00148     virtual void AntSwInit( void );
00149 
00150     /*!
00151      * @brief De-initializes the RF Switch I/Os pins interface 
00152      *
00153      * @remark Needed to decrease the power consumption in MCU lowpower modes
00154      */
00155     virtual void AntSwDeInit( void );
00156 
00157     /*!
00158      * @brief Controls the antena switch if necessary.
00159      *
00160      * @remark see errata note
00161      *
00162      * @param [IN] opMode Current radio operating mode
00163      */
00164     virtual void SetAntSw( uint8_t opMode );
00165     
00166     /*
00167      * The the Timeout for a given Timer.
00168      */
00169     virtual void SetTimeout(TimeoutTimer_t timer, timeoutFuncPtr, int timeout_ms = 0);
00170 
00171     /*
00172      * A simple ms sleep
00173      */
00174     virtual void Sleep_ms(int ms);
00175 
00176 
00177 public:
00178     
00179     /*!
00180      * @brief Detect the board connected by reading the value of the antenna switch pin
00181      */
00182     virtual uint8_t DetectBoardType( void );
00183 
00184     /*!
00185      * @brief Checks if the given RF frequency is supported by the hardware
00186      *
00187      * @param [IN] frequency RF frequency to be checked
00188      * @retval isSupported [true: supported, false: unsupported]
00189      */
00190     virtual bool CheckRfFrequency( uint32_t frequency );
00191 
00192     /*!
00193      * @brief Writes the radio register at the specified address
00194      *
00195      * @param [IN]: addr Register address
00196      * @param [IN]: data New register value
00197      */
00198     virtual void Write ( uint8_t addr, uint8_t data ) ;
00199 
00200     /*!
00201      * @brief Reads the radio register at the specified address
00202      *
00203      * @param [IN]: addr Register address
00204      * @retval data Register value
00205      */
00206     virtual uint8_t Read ( uint8_t addr ) ;
00207 
00208     /*!
00209      * @brief Writes multiple radio registers starting at address
00210      *
00211      * @param [IN] addr   First Radio register address
00212      * @param [IN] buffer Buffer containing the new register's values
00213      * @param [IN] size   Number of registers to be written
00214      */
00215     virtual void Write( uint8_t addr, void *buffer, uint8_t size ) ;
00216 
00217     /*!
00218      * @brief Reads multiple radio registers starting at address
00219      *
00220      * @param [IN] addr First Radio register address
00221      * @param [OUT] buffer Buffer where to copy the registers data
00222      * @param [IN] size Number of registers to be read
00223      */
00224     virtual void Read ( uint8_t addr, void *buffer, uint8_t size ) ;
00225 
00226     /*!
00227      * @brief Writes the buffer contents to the SX1276 FIFO
00228      *
00229      * @param [IN] buffer Buffer containing data to be put on the FIFO.
00230      * @param [IN] size Number of bytes to be written to the FIFO
00231      */
00232     virtual void WriteFifo( void *buffer, uint8_t size ) ;
00233 
00234     /*!
00235      * @brief Reads the contents of the SX1276 FIFO
00236      *
00237      * @param [OUT] buffer Buffer where to copy the FIFO read data.
00238      * @param [IN] size Number of bytes to be read from the FIFO
00239      */
00240     virtual void ReadFifo( void *buffer, uint8_t size ) ;
00241 
00242     /*!
00243      * @brief Reset the SX1276
00244      */
00245     virtual void Reset( void );
00246     
00247     /*!
00248      * \brief Sets the radio output power.
00249      *
00250      * @param [IN] power Sets the RF output power
00251      */
00252     virtual void SetRfTxPower( int8_t power );
00253     
00254 };
00255 
00256 #endif // __SX1276_MBED_HAL_H__