DW1000 UWB driver based on work of Matthias Grob & Manuel Stalder - ETH Zürich - 2015

Dependencies:   BurstSPI

Revision:
4:5f1025df5530
Parent:
3:1459d2aa6b97
Child:
5:68ffaa5962d1
--- a/DW1000.h	Thu Apr 07 14:31:28 2016 +0000
+++ b/DW1000.h	Thu Apr 07 16:25:31 2016 +0000
@@ -167,8 +167,137 @@
 */
 
 
+/** Class for holding DW1000 config options
+*
+*/
+class DW1000Setup
+{
+public:
+
+/// Constructor - default settings are close to hardware defaults.
+    DW1000Setup() {
+        channel = 5;
+        prf =prf16MHz;
+        dataRate = kbps850;
+        sfd = standard;
+        preamble = pre128;
+        preambleCode = 3;
+        enableSmartPower = true;
+    }
+
+/// enum for PRF options
+    enum prf_e {prf16MHz,prf64MHz};
+
+/// enum for data rate options    
+    enum dataRate_e {kbps110,kbps850,kbps6800};
+    
+/// enum for SFD options    
+    enum sfd_e {standard, decaWave, user};
+    
+/// enum for preamble length options    
+    enum preamble_e { pre64, pre128, pre256, pre512, pre1024, pre1536, pre2048, pre4096};
+
+/** Set the PRF
+* @return true if a valid option
+*/
+    bool setPRF(enum prf_e newSetting) {
+        prf = newSetting;
+        return true;
+    };
+
+/** Set the Channel
+* @return true if a valid option
+*/
+    bool setChannel(unsigned char newChannel) {
+        if ((channel > 0) && ((channel <= 5) || (channel == 7))) {
+            channel = newChannel;
+            return true;
+        }
+        return false;
+    };
+/** Set the SFD
+* @return true if a valid option
+*/
+    bool setSfd(enum sfd_e newSetting) {
+        sfd = newSetting;
+        return true;
+    };
+/** Set the Preamble length
+* @return true if a valid option
+*/
+    bool setPreambleLength(enum preamble_e newSetting) {
+        preamble = newSetting;
+        return true;
+    };
+/** Set the Data rate
+* @return true if a valid option
+*/
+    bool setDataRate(enum dataRate_e newSetting)  {
+        dataRate = newSetting;
+        return true;
+    };
+/** Set the Preamble code
+* @return true if a valid option
+*
+* note - not all codes are valid for all channels. Set the channel first.
+* TODO - enforce code restrictions
+*/
+    bool setPreambleCode(unsigned char newCode) {
+        if ((newCode > 0) && (newCode <= 24)) {
+            preambleCode = newCode;
+            return true;
+        }
+        return false;
+    };
+/** Set the smartpower state
+* @return true if a valid option
+*
+* only takes effect at 6.8Mb/s
+*/
+    bool setSmartPower(bool enable) {
+        enableSmartPower = enable;
+        return true;
+    };
+
+/** Get the current channel
+* @return the channel number
+*/
+    unsigned char getChannel() {
+        return channel;
+    };
+    enum prf_e getPRF() {
+        return prf;
+    };
+    enum dataRate_e getDataRate() {
+        return dataRate;
+    };
+    
+    enum sfd_e getSfd() {return sfd;};
+    enum preamble_e getPreambleLength() {
+        return preamble;
+    };
+    unsigned char getPreambleCode() {
+        return preambleCode;
+    };
+    bool getSmartPower() {
+        return  enableSmartPower;
+    };
+
+private:
+    unsigned char channel; // 1-5 , 7
+    enum prf_e prf;
+    enum dataRate_e dataRate;
+    enum sfd_e sfd;
+    enum preamble_e preamble;
+    unsigned char preambleCode; // 1-24. See section 10.5 of user manual for details.
+    bool enableSmartPower;
+};
+
+
 typedef enum {minPacketSize, tunedDefault, user110k} UWBMode;
 
+/** A DW1000 driver
+*/
 class DW1000
 {
 public:
@@ -215,6 +344,15 @@
     uint32_t readOTP (uint16_t word_address);
     bool writeOTP(uint16_t word_address,uint32_t data);                                          // program a value in the OTP. It is recommended to reset afterwards.
 
+    /** Get setup description
+    *
+    * @param buffer Data buffer to place description in
+    * @param len Length of data buffer
+    *
+    * Places a text string describing the current setup into the suppled buffer.
+    */
+    void getSetup(char *buffer, int len);
+
 protected:
     void resetRX();                                                                         // soft reset only the tranciever part of DW1000
     void setInterrupt(bool RX, bool TX);                                                    // set Interrupt for received a good frame (CRC ok) or transmission done
@@ -237,7 +375,7 @@
 
     void setupRadio();
 
-   // system register setup functions
+    // system register setup functions
     void setupAGC();
     void setupRxConfig();
     void setupLDE();
@@ -249,23 +387,10 @@
     void setupSystemConfig();
     void loadLDE();                                                                         // load the leading edge detection algorithm to RAM, [IMPORTANT because receiving malfunction may occur] see User Manual LDELOAD on p22 & p158
     void loadLDOTUNE();                                                                     // load the LDO tuning as set in the factory
-    
+
     uint8_t powerToRegValue(uint16_t powercB);
 
-    enum prf_e {prf16MHz,prf64MHz};
-    enum dataRate_e {kbps110,kbps850,kbps6800};
-    enum sfd_e {standard, nonStandard};
-    enum preamble_e { pre64, pre128, pre256, pre512, pre1024, pre1536, pre2048, pre4096};
-
-    struct {
-        unsigned char channel; // 1-5 , 7
-        enum prf_e prf;
-        enum dataRate_e dataRate;
-        enum sfd_e sfd;
-        enum preamble_e preamble;
-        unsigned char preambleCode; // 1-24. See section 10.5 of user manual for details.
-        bool enableSmartPower;
-    } systemConfig;
+    DW1000Setup systemConfig;