LoRa node acquiring random float value and sending to LoRa Server - Working ok

Fork of SX1276GenericLib by Helmut Tschemernjak

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