SX1261 and sx1262 common library

Dependents:   SX126xDevKit SX1262PingPong SX126X_TXonly SX126X_PingPong_Demo ... more

Fork of SX126xLib by Gregory Cristian

Revision:
4:c6ef863d0b07
Parent:
3:7e3595a9ebe0
Child:
5:e488e6f185f3
--- a/sx126x-hal.h	Wed Oct 12 08:49:58 2016 +0000
+++ b/sx126x-hal.h	Mon Sep 04 15:16:44 2017 +0000
@@ -1,4 +1,5 @@
 /*
+  ______                              _
  / _____)             _              | |
 ( (____  _____ ____ _| |_ _____  ____| |__
  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
@@ -10,7 +11,7 @@
 
 License: Revised BSD License, see LICENSE.TXT file include in the project
 
-Maintainer: Miguel Luis and Gregory Cristian
+Maintainer: Miguel Luis, Gregory Cristian & Gilbert Menth
 */
 #ifndef __SX126x_HAL_H__
 #define __SX126x_HAL_H__
@@ -20,10 +21,10 @@
 /*!
  * \brief The default value of SPI clock
  */
-#define SX126x_SPI_FREQ_DEFAULT                  1000000 // 16000000
+#define SX126x_SPI_FREQ_DEFAULT                  16000000 
 
 /*!
- * \brief Actual implementation of a SX1280 radio
+ * \brief Actual implementation of a SX126x radio
  */
 class SX126xHal : public SX126x
 {
@@ -33,37 +34,16 @@
      *
      * Represents the physical connectivity with the radio and set callback functions on radio interrupts
      */
-    SX126xHal( PinName mosi, PinName miso, PinName sclk, PinName nss, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst,
-                  void ( *txDone )( ), void ( *rxDone )( ), void ( *rxPblSyncWordHeader )( IrqPblSyncHeaderCode_t val ),
-                  void ( *rxTxTimeout )( IrqTimeoutCode_t timeoutCode ),void ( *rxError )( IrqErrorCode_t errorCode ), void ( *cadDone )( bool channelActivityDetected ),
-                  void ( *onDioIrq )( ) );
+    SX126xHal( PinName mosi, PinName miso, PinName sclk, PinName nss,
+               PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst,
+               PinName deviceSelect, PinName antSwPower, RadioCallbacks_t *callbacks );
 
     /*!
-     * \brief Constructor for SX126xHal with UART support
-     *
-     * Represents the physical connectivity with the radio and set callback functions on radio interrupts
-     */
-    SX126xHal( PinName tx, PinName rx, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst,
-                  void ( *txDone )( ), void ( *rxDone )( ), void ( *rxPblSyncWordHeader )( IrqPblSyncHeaderCode_t val ),
-                  void ( *rxTxTimeout )( IrqTimeoutCode_t timeoutCode ), void ( *rxError )( IrqErrorCode_t errorCode ), void ( *cadDone )( bool channelActivityDetected ),
-                  void ( *onDioIrq )( ) );
-
-    /*!
-     * \brief Destructor for SX126xHal with UART support
+     * \brief Destructor for SX126xHal
      *
      * Take care of the correct destruction of the communication objects
      */
-    virtual ~SX126xHal( )
-    {
-        if( this->RadioSpi != 0 )
-        {
-            delete RadioSpi;
-        }
-        if( this->RadioUart != 0 )
-        {
-            delete RadioUart;
-        }
-    };
+    virtual ~SX126xHal( void );
 
     /*!
      * \brief Soft resets the radio
@@ -71,11 +51,6 @@
     virtual void Reset( void );
 
     /*!
-     * \brief Clears the instruction ram memory block
-     */
-    virtual void ClearInstructionRam( void );
-
-    /*!
      * \brief Wakes up the radio
      */
     virtual void Wakeup( void );
@@ -106,9 +81,6 @@
      * \param [in]  size          The number of bytes to write in radio's memory
      */
     virtual void WriteRegister( uint16_t address, uint8_t *buffer, uint16_t size );
-    
-    virtual void WriteRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size );
-    
 
     /*!
      * \brief Write a single byte of data to the radio memory
@@ -116,9 +88,7 @@
      * \param [in]  address       The address of the first byte to write in the radio
      * \param [in]  value         The data to be written in radio's memory
      */
-    virtual void WriteRegister( uint16_t address, uint8_t value );
-    
-    virtual void WriteRegisterNoBusy( uint16_t address, uint8_t value );
+    virtual void WriteReg( uint16_t address, uint8_t value );
 
     /*!
      * \brief Read data from the radio memory
@@ -128,7 +98,6 @@
      * \param [in]  size          The number of bytes to read from radio's memory
      */
     virtual void ReadRegister( uint16_t address, uint8_t *buffer, uint16_t size );
-    virtual void ReadRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size );
 
     /*!
      * \brief Read a single byte of data from the radio memory
@@ -139,15 +108,13 @@
      * \retval      value         The value of the byte at the given address in
      *                            radio's memory
      */
-    virtual uint8_t ReadRegister( uint16_t address );
-    virtual uint8_t ReadRegisterNoBusy( uint16_t address );
-    
+    virtual uint8_t ReadReg( uint16_t address );
 
     /*!
      * \brief Write data to the buffer holding the payload in the radio
      *
      * \param [in]  offset        The offset to start writing the payload
-     * \param [in]  buffer        The data to be written (aka payload)
+     * \param [in]  buffer        The data to be written (the payload)
      * \param [in]  size          The number of byte to be written
      */
     virtual void WriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size );
@@ -165,21 +132,39 @@
      * \brief Returns the status of DIOs pins
      *
      * \retval      dioStatus     A byte where each bit represents a DIO state:
-     *                            [ DIO3 | DIO2 | DIO1 | DIO0 ]
+     *                            [ DIO3 | DIO2 | DIO1 | BUSY ]
      */
     virtual uint8_t GetDioStatus( void );
 
+    /*!
+     * \brief Returns the device type
+     *
+     * \retval      1: SX1261, 0: sx1262     
+     */
+    virtual uint8_t GetDeviceType( void );
+
+    /*!
+     * \brief RF Switch power on
+     */
+    virtual void AntSwOn( void );
+
+    /*!
+     * \brief RF Switch power off
+     */
+    virtual void AntSwOff( void );
+
 protected:
 
     SPI *RadioSpi;                                  //!< The SPI object used to communicate with the radio
-    Serial *RadioUart;                              //!< The UART object used to communicate with the radio
-    DigitalOut RadioNss;                            //!< The pin connected to Radio chip select
-    DigitalOut RadioReset;                          //!< The reset pin connected to the radio
-    DigitalIn BUSY;                                 //!< The pin connected to DIO0 of the radio (aka busy pin)
+    DigitalOut RadioNss;                            //!< The pin connected to Radio chip select (active low)
+    DigitalInOut RadioReset;                        //!< The reset pin connected to the radio
 
-    InterruptIn DIO1;                               //!< The pin connected to DIO1
-    InterruptIn DIO2;                               //!< The pin connected to DIO2
-    InterruptIn DIO3;                               //!< The pin connected to DIO3
+    DigitalIn    BUSY;                              //!< The pin connected to BUSY
+    InterruptIn *DIO1;                              //!< The pin connected to DIO1
+    InterruptIn *DIO2;                              //!< The pin connected to DIO2
+    InterruptIn *DIO3;                              //!< The pin connected to DIO3
+    DigitalIn    DeviceSelect;                      //!< The pin connected to a pull-up/down to select device
+    DigitalOut   antSwitchPower;                    //!< The pin connected to the RF Switch Power
 
     /*!
      * \brief Initializes SPI object used to communicate with the radio
@@ -187,11 +172,6 @@
     virtual void SpiInit( void );
 
     /*!
-     * \brief Initializes UART object used to communicate with the radio
-     */
-    virtual void UartInit( void );
-
-    /*!
      * \brief Sets the callback functions to be run on DIO1..3 interrupt
      *
      * \param [in]  irqHandler    A function pointer of the function to be run on every DIO interrupt