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
--- a/radio.h	Wed Oct 12 08:49:58 2016 +0000
+++ b/radio.h	Mon Sep 04 15:16:44 2017 +0000
@@ -1,4 +1,5 @@
 /*
+  ______                              _
  / _____)             _              | |
 ( (____  _____ ____ _| |_ _____  ____| |__
  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
@@ -35,32 +36,49 @@
 /*!
  * \brief Structure describing the error codes for callback functions
  */
-enum IrqErrorCode_t
+typedef enum
 {
-    IRQ_HEADER_ERROR_CODE       = 0x01,
-    IRQ_SYNCWORD_ERROR_CODE     = 0x02,
-    IRQ_CRC_ERROR_CODE          = 0x04,
-};
+    IRQ_HEADER_ERROR_CODE                   = 0x01,
+    IRQ_SYNCWORD_ERROR_CODE                 = 0x02,
+    IRQ_CRC_ERROR_CODE                      = 0x04,
+}IrqErrorCode_t;
 
 
 enum IrqPblSyncHeaderCode_t
 {
-    IRQ_PBL_DETECT_CODE         = 0x01,
-    IRQ_SYNCWORD_VALID_CODE     = 0x02,
-    IRQ_HEADER_VALID_CODE       = 0x04,
+    IRQ_PBL_DETECT_CODE                     = 0x01,
+    IRQ_SYNCWORD_VALID_CODE                 = 0x02,
+    IRQ_HEADER_VALID_CODE                   = 0x04,
 };
 
 enum IrqTimeoutCode_t
 {
-    IRQ_RX_TIMEOUT              = 0x00,
-    IRQ_TX_TIMEOUT              = 0x01,
-    IRQ_XYZ                     = 0xFF,
+    IRQ_RX_TIMEOUT                          = 0x00,
+    IRQ_TX_TIMEOUT                          = 0x01,
+    IRQ_XYZ                                 = 0xFF,
 };
 
 /*!
  * \brief The radio command opcodes
  */
-enum RadioCommands_t;
+typedef enum RadioCommands_e RadioCommands_t;
+
+/*!
+ * \brief The radio callbacks structure
+ * Holds function pointers to be called on radio interrupts
+ */
+typedef struct
+{
+    void ( *txDone )( void );                       //!< Pointer to a function run on successful transmission
+    void ( *rxDone )( void );                       //!< Pointer to a function run on successful reception
+    void ( *rxPreambleDetect )( void );             //!< Pointer to a function run on successful Preamble detection
+    void ( *rxSyncWordDone )( void );               //!< Pointer to a function run on successful SyncWord reception
+    void ( *rxHeaderDone )( void );                 //!< Pointer to a function run on successful Header reception
+    void ( *txTimeout )( void );                    //!< Pointer to a function run on transmission timeout
+    void ( *rxTimeout )( void );                    //!< Pointer to a function run on reception timeout
+    void ( *rxError )( IrqErrorCode_t errCode );    //!< Pointer to a function run on reception error
+    void ( *cadDone )( bool cadFlag );              //!< Pointer to a function run on channel activity detected
+}RadioCallbacks_t;
 
 /*!
  * \brief Class holding the basic communications with a radio
@@ -76,29 +94,42 @@
     /*!
      * \brief Callback on Tx done interrupt
      */
-    void ( *txDone )( );
+    void ( *txDone )( void );
 
     /*!
      * \brief Callback on Rx done interrupt
      */
-    void ( *rxDone )( );
+    void ( *rxDone )( void );
+
+    /*!
+     * \brief Callback on Rx preamble detection interrupt
+     */
+    void ( *rxPreambleDetect )( void );
+
+    /*!
+     * \brief Callback on Rx SyncWord interrupt
+     */
+    void ( *rxSyncWordDone )( void );
 
     /*!
-     * \brief Callback on Rx SyncWord done interrupt
+     * \brief Callback on Rx header received interrupt
      */
-    void ( *rxPblSyncWordHeader )( IrqPblSyncHeaderCode_t val );
+    void ( *rxHeaderDone )( void );
 
     /*!
-     * \brief Callback on Rx Tx timeout interrupt
-     *
-     * \param [out] errCode       A code indicating the source of the Timeout interrupt
+     * \brief Callback on Tx timeout interrupt
      */
-    void ( *rxTxTimeout )( IrqTimeoutCode_t timeoutCode );
+    void ( *txTimeout )( void );
+
+    /*!
+     * \brief Callback on Rx timeout interrupt
+     */
+    void ( *rxTimeout )( void );
 
     /*!
      * \brief Callback on Rx error interrupt
      *
-     * \param [out] errCode       A code indicating the type of interrupt ( SyncWord error or CRC error)
+     * \param [out] errCode       A code indicating the type of interrupt (SyncWord error or CRC error)
      */
     void ( *rxError )( IrqErrorCode_t errCode );
 
@@ -112,21 +143,25 @@
 public:
     /*!
      * \brief Constructor for radio class
+     * Sets the callbacks functions pointers
      *
-     * Sets the callbacks functions pointers
+     * \param [in]  callbacks     The structure of callbacks function pointers
+     *                            to be called on radio interrupts
+     *
      */
-    Radio( void ( *txDone )( ), void ( *rxDone )( ), void ( *rxPblSyncWordHeader )(IrqPblSyncHeaderCode_t val ),
-           void ( *rxTxTimeout )( IrqTimeoutCode_t timeoutCode ), void ( *rxError )( IrqErrorCode_t errorCode ),
-           void ( *cadDone )( bool channelActivityDetected ) )
+    Radio( RadioCallbacks_t *callbacks )
     {
-        this->txDone = txDone;
-        this->rxDone = rxDone;
-        this->rxPblSyncWordHeader = rxPblSyncWordHeader;
-        this->rxTxTimeout = rxTxTimeout;
-        this->rxError = rxError;
-        this->cadDone = cadDone;
+        this->txDone = callbacks->txDone;
+        this->rxDone = callbacks->rxDone;
+        this->rxPreambleDetect = callbacks->rxPreambleDetect;
+        this->rxSyncWordDone = callbacks->rxSyncWordDone;
+        this->rxHeaderDone = callbacks->rxHeaderDone;
+        this->txTimeout = callbacks->txTimeout;
+        this->rxTimeout = callbacks->rxTimeout;
+        this->rxError = callbacks->rxError;
+        this->cadDone = callbacks->cadDone;
     }
-    virtual ~Radio( ){ };
+    virtual ~Radio( void ){ };
 
     /*!
      * \brief Resets the radio
@@ -173,7 +208,7 @@
      * \param [in]  address       Register address
      * \param [in]  value         New register value
      */
-    virtual void WriteRegister( uint16_t address, uint8_t value ) = 0;
+    virtual void WriteReg( uint16_t address, uint8_t value ) = 0;
 
     /*!
      * \brief Reads multiple radio registers starting at address
@@ -191,7 +226,7 @@
      *
      * \retval      value         The register value
      */
-    virtual uint8_t ReadRegister( uint16_t address ) = 0;
+    virtual uint8_t ReadReg( uint16_t address ) = 0;
 
     /*!
      * \brief Writes Radio Data Buffer with buffer of size starting at offset.
@@ -210,13 +245,6 @@
      * \param [in]  size          Buffer size
      */
     virtual void ReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) = 0;
-
-    /*!
-     * \brief Return firmware version
-     *
-     * \retval      firmware      The firmware version
-     */
-    virtual uint16_t GetFirmwareVersion( void ) = 0;
 };
 
 #endif // __RADIO_H__