Semtech / SX126xLib

Dependents:   SX126xDevKit SX1262PingPong SX126X_TXonly SX126X_PingPong_Demo ... more

Fork of SX126xLib by Gregory Cristian

Embed: (wiki syntax)

« Back to documentation index

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

sx126x-hal.h

00001 /*
00002   ______                              _
00003  / _____)             _              | |
00004 ( (____  _____ ____ _| |_ _____  ____| |__
00005  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00006  _____) ) ____| | | || |_| ____( (___| | | |
00007 (______/|_____)_|_|_| \__)_____)\____)_| |_|
00008     (C)2015 Semtech
00009 
00010 Description: Handling of the node configuration protocol
00011 
00012 License: Revised BSD License, see LICENSE.TXT file include in the project
00013 
00014 Maintainer: Miguel Luis, Gregory Cristian & Gilbert Menth
00015 */
00016 #ifndef __SX126x_HAL_H__
00017 #define __SX126x_HAL_H__
00018 
00019 #include "sx126x.h"
00020 
00021 /*!
00022  * \brief The default value of SPI clock
00023  */
00024 #define SX126x_SPI_FREQ_DEFAULT                  16000000 
00025 
00026 /*!
00027  * \brief Actual implementation of a SX126x radio
00028  */
00029 class SX126xHal : public SX126x
00030 {
00031 public:
00032     /*!
00033      * \brief Constructor for SX126xHal with SPI support
00034      *
00035      * Represents the physical connectivity with the radio and set callback functions on radio interrupts
00036      */
00037     SX126xHal( PinName mosi, PinName miso, PinName sclk, PinName nss,
00038                PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst,
00039                PinName freqSel, PinName deviceSelect, PinName antSwPower, RadioCallbacks_t *callbacks );
00040 
00041     /*!
00042      * \brief Destructor for SX126xHal
00043      *
00044      * Take care of the correct destruction of the communication objects
00045      */
00046     virtual ~SX126xHal( void );
00047 
00048     /*!
00049      * \brief Soft resets the radio
00050      */
00051     virtual void Reset( void );
00052 
00053     /*!
00054      * \brief Wakes up the radio
00055      */
00056     virtual void Wakeup( void );
00057 
00058     /*!
00059      * \brief Send a command that write data to the radio
00060      *
00061      * \param [in]  opcode        Opcode of the command
00062      * \param [in]  buffer        Buffer to be send to the radio
00063      * \param [in]  size          Size of the buffer to send
00064      */
00065     virtual void WriteCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
00066 
00067     /*!
00068      * \brief Send a command that read data from the radio
00069      *
00070      * \param [in]  opcode        Opcode of the command
00071      * \param [out] buffer        Buffer holding data from the radio
00072      * \param [in]  size          Size of the buffer
00073      */
00074     virtual void ReadCommand( RadioCommands_t opcode, uint8_t *buffer, uint16_t size );
00075 
00076     /*!
00077      * \brief Write data to the radio memory
00078      *
00079      * \param [in]  address       The address of the first byte to write in the radio
00080      * \param [in]  buffer        The data to be written in radio's memory
00081      * \param [in]  size          The number of bytes to write in radio's memory
00082      */
00083     virtual void WriteRegister( uint16_t address, uint8_t *buffer, uint16_t size );
00084 
00085     /*!
00086      * \brief Write a single byte of data to the radio memory
00087      *
00088      * \param [in]  address       The address of the first byte to write in the radio
00089      * \param [in]  value         The data to be written in radio's memory
00090      */
00091     virtual void WriteReg( uint16_t address, uint8_t value );
00092 
00093     /*!
00094      * \brief Read data from the radio memory
00095      *
00096      * \param [in]  address       The address of the first byte to read from the radio
00097      * \param [out] buffer        The buffer that holds data read from radio
00098      * \param [in]  size          The number of bytes to read from radio's memory
00099      */
00100     virtual void ReadRegister( uint16_t address, uint8_t *buffer, uint16_t size );
00101 
00102     /*!
00103      * \brief Read a single byte of data from the radio memory
00104      *
00105      * \param [in]  address       The address of the first byte to write in the
00106      *                            radio
00107      *
00108      * \retval      value         The value of the byte at the given address in
00109      *                            radio's memory
00110      */
00111     virtual uint8_t ReadReg( uint16_t address );
00112 
00113     /*!
00114      * \brief Write data to the buffer holding the payload in the radio
00115      *
00116      * \param [in]  offset        The offset to start writing the payload
00117      * \param [in]  buffer        The data to be written (the payload)
00118      * \param [in]  size          The number of byte to be written
00119      */
00120     virtual void WriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size );
00121 
00122     /*!
00123      * \brief Read data from the buffer holding the payload in the radio
00124      *
00125      * \param [in]  offset        The offset to start reading the payload
00126      * \param [out] buffer        A pointer to a buffer holding the data from the radio
00127      * \param [in]  size          The number of byte to be read
00128      */
00129     virtual void ReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size );
00130 
00131     /*!
00132      * \brief Returns the status of DIOs pins
00133      *
00134      * \retval      dioStatus     A byte where each bit represents a DIO state:
00135      *                            [ DIO3 | DIO2 | DIO1 | BUSY ]
00136      */
00137     virtual uint8_t GetDioStatus( void );
00138 
00139     /*!
00140      * \brief Returns the device type
00141      *
00142      * \retval      0: SX1261, 1: SX1262, 2: SX1268
00143      */
00144     virtual uint8_t GetDeviceType( void );
00145 
00146     /*!
00147      * \brief Returns the matching frequency
00148      *
00149      * \retval      1: 868 MHz
00150      *              0: 915 MHz
00151      */
00152     virtual uint8_t GetFreqSelect( void );
00153 
00154     /*!
00155      * \brief RF Switch power on
00156      */
00157     virtual void AntSwOn( void );
00158 
00159     /*!
00160      * \brief RF Switch power off
00161      */
00162     virtual void AntSwOff( void );
00163 
00164 protected:
00165 
00166     SPI *RadioSpi;                                  //!< The SPI object used to communicate with the radio
00167     DigitalOut RadioNss;                            //!< The pin connected to Radio chip select (active low)
00168     DigitalInOut RadioReset;                        //!< The reset pin connected to the radio
00169 
00170     DigitalIn    BUSY;                              //!< The pin connected to BUSY
00171     InterruptIn *DIO1;                              //!< The pin connected to DIO1
00172     InterruptIn *DIO2;                              //!< The pin connected to DIO2
00173     InterruptIn *DIO3;                              //!< The pin connected to DIO3
00174     AnalogIn     FreqSelect;                        //!< The pin connected to a pull-up/down to select Frequency of the matching
00175     AnalogIn     DeviceSelect;                      //!< The pin connected to a pull-up/down to select device
00176     DigitalOut   antSwitchPower;                    //!< The pin connected to the RF Switch Power
00177 
00178     /*!
00179      * \brief Initializes SPI object used to communicate with the radio
00180      */
00181     virtual void SpiInit( void );
00182 
00183     /*!
00184      * \brief Sets the callback functions to be run on DIO1..3 interrupt
00185      *
00186      * \param [in]  irqHandler    A function pointer of the function to be run on every DIO interrupt
00187      */
00188     virtual void IoIrqInit( DioIrqHandler irqHandler );
00189 };
00190 
00191 #endif // __SX126x_HAL_H__