r g / SX1276GenericLib-us915

Dependents:   DISCO-L072CZ-LRWAN1_LoRa_PingPong

Fork of SX1276GenericLib by Helmut Tschemernjak

Files at this revision

API Documentation at this revision

Comitter:
Helmut Tschemernjak
Date:
Sun May 07 18:09:10 2017 +0200
Parent:
37:21fa0615e993
Child:
39:706c32eda7e7
Commit message:
Migrated typedefs.h into the sx1276 source.
Migrated radio init register values and settings into sx1276.cpp
where it belongs to.

Changed in this revision

LoRa_TODO.txt Show annotated file Show diff for this revision Revisions of this file
enums/enums.h Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276-mbed-hal.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276-mbed-hal.h Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.h Show annotated file Show diff for this revision Revisions of this file
typedefs/typedefs.h Show diff for this revision Revisions of this file
--- a/LoRa_TODO.txt	Sat May 06 12:12:29 2017 +0000
+++ b/LoRa_TODO.txt	Sun May 07 18:09:10 2017 +0200
@@ -7,6 +7,8 @@
 - add support for Arduino - add sx1276-Arduino-hal.h/cpp
 - add support for Linux - add sx1276-Linux-hal.h/cpp
 
+- Migrate enum code into sx1276.h
+
 
 
 
@@ -25,4 +27,6 @@
 
 
 Done:
-- Started a Generic SX1276 drive to support multiple SX1276 based modules (My-2017 Helmut Tsch)
+- Started a Generic SX1276 drive to support multiple SX1276 based modules (May-2017 Helmut Tsch)
+- Migrated typedefs code into sx1276.h (7-May-2017 Helmut Tsch)
+
--- a/enums/enums.h	Sat May 06 12:12:29 2017 +0000
+++ b/enums/enums.h	Sun May 07 18:09:10 2017 +0200
@@ -113,7 +113,7 @@
     int8_t SnrValue;
     int8_t RssiValue;
     uint8_t Size;
-}RadioLoRaPacketHandler_t;
+ }RadioLoRaPacketHandler_t;
 
 /*!
  * Radio Settings
@@ -129,5 +129,11 @@
     RadioLoRaPacketHandler_t LoRaPacketHandler;
 }RadioSettings_t;
 
+typedef enum {
+    RXTimeout,
+    TXTimeout,
+    RXTimeoutSyncWorld
+} Timeout_t;
+
 
 #endif //__ENUMS_H__
--- a/sx1276/sx1276-mbed-hal.cpp	Sat May 06 12:12:29 2017 +0000
+++ b/sx1276/sx1276-mbed-hal.cpp	Sun May 07 18:09:10 2017 +0200
@@ -14,14 +14,14 @@
 */
 
 /*
- * additional development to make it more generic across multiple os versions
+ * additional development to make it more generic across multiple OS versions
  * (c) 2017 Helmut Tschemernjak
  * 30826 Garbsen (Hannover) Germany
  */
 
 #include "sx1276-mbed-hal.h"
 
-const RadioRegisters_t SX1276Generic::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
+
 
 SX1276Generic::SX1276Generic( RadioEvents_t *events, BoardType_t board,
                             PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
@@ -127,6 +127,7 @@
     	delete _dio5;
 }
 
+
 //-------------------------------------------------------------------------
 //                      Board relative functions
 //-------------------------------------------------------------------------
@@ -143,15 +144,6 @@
     SpiInit( );
 }
 
-void SX1276Generic::RadioRegistersInit( )
-{
-    uint8_t i = 0;
-    for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
-    {
-        SetModem( RadioRegsInit[i].Modem );
-        Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
-    }    
-}
 
 void SX1276Generic::SpiInit( void )
 {
@@ -351,6 +343,11 @@
     }
 }
 
+void SX1276Generic::SetTimeout(Timeout_t timer, int timeout_ms)
+{
+    
+}
+
 bool SX1276Generic::CheckRfFrequency( uint32_t frequency )
 {
     // Implement check. Currently all frequencies are supported
--- a/sx1276/sx1276-mbed-hal.h	Sat May 06 12:12:29 2017 +0000
+++ b/sx1276/sx1276-mbed-hal.h	Sun May 07 18:09:10 2017 +0200
@@ -14,7 +14,7 @@
 */
 
 /*
- * additional development to make it more generic across multiple os versions
+ * additional development to make it more generic across multiple OS versions
  * (c) 2017 Helmut Tschemernjak
  * 30826 Garbsen (Hannover) Germany
  */
@@ -23,32 +23,15 @@
 #define __SX1276_HAL_H__
 #include "sx1276.h"
 
+
 /*!
- * @brief Radio hardware registers initialization definition
- *
- * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
+ * triggers definition
  */
-#define RADIO_INIT_REGISTERS_VALUE                \
-{                                                 \
-    { MODEM_FSK , REG_LNA                , 0x23 },\
-    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
-    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
-    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
-    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
-    { MODEM_FSK , REG_OSC                , 0x07 },\
-    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
-    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
-    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
-    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
-    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
-    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
-    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
-    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
-    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
-    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
-}                                                 \
+typedef void ( SX1276::*Trigger )( void );
+typedef void ( SX1276Generic::*TriggerMB1xAS )( void );
 
-/*! 
+
+/*!
  * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
  */
 class SX1276Generic : public SX1276
@@ -87,8 +70,10 @@
     InterruptIn *_dio4;
     DigitalIn *_dio5;
     
+    Timeout txTimeoutTimer;
+    
+    
 private:
-    static const RadioRegisters_t RadioRegsInit[];
 
 public:
     SX1276Generic( RadioEvents_t *events, BoardType_t board,
@@ -108,11 +93,6 @@
     virtual void IoInit( void );
 
     /*!
-     *  @brief Initializes the radio registers
-     */
-    virtual void RadioRegistersInit( );
-    
-    /*!
      * @brief Initializes the radio SPI
      */
     virtual void SpiInit( void );
@@ -173,8 +153,14 @@
      * @param [IN] opMode Current radio operating mode
      */
     virtual void SetAntSw( uint8_t opMode );
+    
+    /*
+     * The the Timeout for a given Timer.
+     */
+    virtual void SetTimeout(Timeout_t timer, int timeout_ms);
 
 public:
+    
     /*!
      * @brief Detect the board connected by reading the value of the antenna switch pin
      */
--- a/sx1276/sx1276.cpp	Sat May 06 12:12:29 2017 +0000
+++ b/sx1276/sx1276.cpp	Sun May 07 18:09:10 2017 +0200
@@ -14,13 +14,15 @@
 */
 
 /*
- * additional development to make it more generic across multiple os versions
+ * additional development to make it more generic across multiple OS versions
  * (c) 2017 Helmut Tschemernjak
  * 30826 Garbsen (Hannover) Germany
  */
 
 #include "sx1276.h"
 
+
+
 const FskBandwidth_t SX1276::FskBandwidths[] =
 {
     { 2600  , 0x17 },   
@@ -48,6 +50,34 @@
 };
 
 
+
+/*!
+ * @brief Radio hardware registers initialization definition
+ *
+ * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
+ */
+
+const RadioRegisters_t SX1276::RadioRegsInit[] = {
+    { MODEM_FSK , REG_LNA                , 0x23 },
+    { MODEM_FSK , REG_RXCONFIG           , 0x1E },
+    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },
+    { MODEM_FSK , REG_AFCFEI             , 0x01 },
+    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },
+    { MODEM_FSK , REG_OSC                , 0x07 },
+    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },
+    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },
+    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },
+    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },
+    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },
+    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },
+    { MODEM_FSK , REG_IMAGECAL           , 0x02 },
+    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },
+    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },
+    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },
+    
+};
+
+
 SX1276::SX1276( RadioEvents_t *events) : Radio( events ), isRadioActive( false )
 {
     wait_ms( 10 );
@@ -78,6 +108,18 @@
     this->RadioEvents = events;
 }
 
+
+void SX1276::RadioRegistersInit( )
+{
+    uint8_t i = 0;
+    for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
+    {
+        SetModem( RadioRegsInit[i].Modem );
+        Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
+    }
+}
+
+
 RadioState SX1276::GetStatus( void )
 {
     return this->settings.State;
--- a/sx1276/sx1276.h	Sat May 06 12:12:29 2017 +0000
+++ b/sx1276/sx1276.h	Sun May 07 18:09:10 2017 +0200
@@ -14,7 +14,7 @@
 */
 
 /*
- * additional development to make it more generic across multiple os versions
+ * additional development to make it more generic across multiple OS versions
  * (c) 2017 Helmut Tschemernjak
  * 30826 Garbsen (Hannover) Germany
  */
@@ -25,7 +25,11 @@
 #include "radio.h"
 #include "./registers/sx1276Regs-Fsk.h"
 #include "./registers/sx1276Regs-LoRa.h"
-#include "./typedefs/typedefs.h"
+
+class SX1276;
+class SX1276Generic;
+
+
 
 /*!
  * Radio wake-up time from sleep
@@ -68,6 +72,33 @@
 #endif
 
 
+/*!
+ * FSK bandwidth definition
+ */
+typedef struct
+{
+    uint32_t bandwidth;
+    uint8_t  RegValue;
+}FskBandwidth_t;
+
+
+
+/*!
+ * Radio registers definition
+ */
+typedef struct
+{
+    ModemType   Modem;
+    uint8_t     Addr;
+    uint8_t     Value;
+}RadioRegisters_t;
+
+/*!
+ * Hardware IO IRQ callback function definition
+ */
+typedef void ( SX1276::*DioIrqHandler )( void );
+
+
 typedef enum {
     LORA_BANKWIDTH_7kHz  = 0, //  7.8 kHz requires TCXO
     LORA_BANKWIDTH_10kHz = 1, // 10.4 kHz requires TCXO
@@ -141,6 +172,7 @@
     RadioSettings_t settings;
 
     static const FskBandwidth_t FskBandwidths[];
+    
 protected:
 
     /*!
@@ -163,6 +195,12 @@
      * @param [IN] events Structure containing the driver callback functions
      */
     virtual void Init( RadioEvents_t *events );
+
+    /*!
+     *  @brief Initializes the radio registers
+     */
+    virtual void RadioRegistersInit(void);
+
     /*!
      * Return current radio status
      *
@@ -285,6 +323,7 @@
                               bool fixLen, bool crcOn, bool freqHopOn,
                               uint8_t hopPeriod, bool iqInverted, uint32_t timeout );
 
+    
     /*!
      * @brief Checks if the given RF frequency is supported by the hardware
      *
@@ -435,7 +474,9 @@
     //-------------------------------------------------------------------------
     //                        Board relative functions
     //-------------------------------------------------------------------------
-
+    static const RadioRegisters_t RadioRegsInit[];
+private:
+    
 protected:
     /*!
      * @brief Initializes the radio I/Os pins interface
@@ -443,11 +484,6 @@
     virtual void IoInit( void ) = 0;
     
     /*!
-     *    @brief Initializes the radio registers
-     */
-    virtual void RadioRegistersInit( ) = 0;
-    
-    /*!
      * @brief Initializes the radio SPI
      */
     virtual void SpiInit( void ) = 0;
@@ -509,6 +545,12 @@
      */
     virtual void SetAntSw( uint8_t opMode ) = 0;
     
+    /*
+     * The the Timeout for a given Timer.
+     */
+    virtual void SetTimeout(Timeout_t timer, int timeout_ms) = 0;
+    
+    
 protected:
 
     /*!
--- a/typedefs/typedefs.h	Sat May 06 12:12:29 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C) 2014 Semtech
-
-Description: -
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
-*/
-#ifndef __TYPEDEFS_H__
-#define __TYPEDEFS_H__
-
-#include "mbed.h"
-#include "./enums/enums.h"
-
-class SX1276;
-class SX1276Generic;
-/*!
- * Hardware IO IRQ callback function definition
- */
-typedef void ( SX1276::*DioIrqHandler )( void );
-
-/*!
- * triggers definition
- */
-typedef void ( SX1276::*Trigger )( void );
-typedef void ( SX1276Generic::*TriggerMB1xAS )( void );
-
-/*!
- * FSK bandwidth definition
- */
-typedef struct
-{
-    uint32_t bandwidth;
-    uint8_t  RegValue;
-}FskBandwidth_t;
-
-/*!
- * Radio registers definition
- */
-typedef struct
-{
-    ModemType   Modem;
-    uint8_t     Addr;
-    uint8_t     Value;
-}RadioRegisters_t;
-
-#endif //__TYPEDEFS_H__