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

Dependencies:   BurstSPI

Revision:
8:0b408e77b701
Parent:
7:b13881dbb09d
Child:
9:326bf149c8bc
--- a/DW1000.cpp	Wed Apr 13 09:07:14 2016 +0000
+++ b/DW1000.cpp	Mon Apr 18 16:58:27 2016 +0000
@@ -6,128 +6,28 @@
 DW1000::DW1000(UWBMode setup, PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ) : irq(IRQ), spi(MOSI, MISO, SCLK), cs(CS)
 {
     setCallbacks(NULL, NULL);
+    DW1000Setup newSetup(DW1000Setup::fastLocationC5);
+    systemConfig.applyConfig(&newSetup);
 
     deselect();                         // Chip must be deselected first
     spi.format(8,0);                    // Setup the spi for standard 8 bit data and SPI-Mode 0 (GPIO5, GPIO6 open circuit or ground on DW1000)
     spi.frequency(SPIRATE_PLL);             // with a 1MHz clock rate (worked up to 49MHz in our Test)
 
     resetAll();                         // we do a soft reset of the DW1000 everytime the driver starts
-
-    switch (setup) {
-        case user110k:  // values from Matthias Grob & Manuel Stalder - ETH Zürich - library
-
-            systemConfig.setChannel(5);
-            systemConfig.setPRF(DW1000Setup::prf16MHz);
-            systemConfig.setDataRate(DW1000Setup::kbps110);
-            systemConfig.setSfd(DW1000Setup::standard);
-            systemConfig.setPreambleLength(DW1000Setup::pre1024);
-            systemConfig.setPreambleCode(3);
-            systemConfig.setSmartPower(false);
-
-            setupRadio();
-
-            setTxPower(230); // power = 23dB gain
-
-            setRxDelay(1<<14); // set delays to 2^14 (1/4 of max)
-            setTxDelay(1<<14);
-            break;
-
-        case tunedDefault:    // User Manual "2.5.5 Default Configurations that should be modified" p. 22
-        default:
-
-            systemConfig.setChannel(5);
-            systemConfig.setPRF(DW1000Setup::prf16MHz);
-            systemConfig.setDataRate(DW1000Setup::kbps6800);
-            systemConfig.setSfd(DW1000Setup::standard);
-            systemConfig.setPreambleLength(DW1000Setup::pre128);
-            systemConfig.setPreambleCode(3);
-            systemConfig.setSmartPower(false);
-
-            setupRadio();
-
-            setTxPower(230,260,290); // power = 23dB gain
-            setRxDelay(0);
-            setTxDelay(0);
-
-            break;
-        case minPacketSize:
-            systemConfig.setChannel(5);
-            systemConfig.setPRF(DW1000Setup::prf64MHz);
-            systemConfig.setDataRate(DW1000Setup::kbps6800);
-            systemConfig.setSfd(DW1000Setup::standard);
-            systemConfig.setPreambleLength(DW1000Setup::pre64);
-            systemConfig.setPreambleCode(10);
-            systemConfig.setSmartPower(true);
-
-            setupRadio();
-            uint16_t txPower = 25*10; // 25dB gain.
-            // 2 packets per ms max. So can increase TX power of 250us packets by 10log(4/2) dB and 125us packets by 10log(8/2) dB
-            setTxPower(txPower,txPower,txPower+30,txPower+60); // power = 23dB gain
+setupRadio();
+            setTxPower(250,250,250+30,250+60); // power = 23dB gain
 
             setRxDelay(0);
             setTxDelay(0);
 
-            break;
-    }
-
-
     irq.rise(this, &DW1000::ISR);       // attach interrupt handler to rising edge of interrupt pin from DW1000
 }
 
-void DW1000::getSetup(char *buffer, int len)
-{
 
-    char dataRateString[10];
-    if (systemConfig.getDataRate() == DW1000Setup::kbps6800)
-        strcpy(dataRateString,"6.8 Mbps");
-    else if (systemConfig.getDataRate() == DW1000Setup::kbps850)
-        strcpy(dataRateString,"850 kbps");
-    else
-        strcpy(dataRateString,"110 kbps");
-
-    char preambleString[8];
-    switch (systemConfig.getPreambleLength()) {
-        default:
-            strcpy(preambleString,"error");
-            break;
-        case DW1000Setup::pre64:
-            strcpy(preambleString,"64");
-            break;
-        case DW1000Setup::pre128:
-            strcpy(preambleString,"128");
-            break;
-        case DW1000Setup::pre256:
-            strcpy(preambleString,"256");
-            break;
-        case DW1000Setup::pre512:
-            strcpy(preambleString,"512");
-            break;
-        case DW1000Setup::pre1024:
-            strcpy(preambleString,"1024");
-            break;
-        case DW1000Setup::pre1536:
-            strcpy(preambleString,"1536");
-            break;
-        case DW1000Setup::pre2048:
-            strcpy(preambleString,"2048");
-            break;
-        case DW1000Setup::pre4096:
-            strcpy(preambleString,"4096");
-            break;
+DW1000Setup* DW1000::getSetup() {
+    return &systemConfig;
     }
 
-    snprintf(buffer,len,"Channel:\t%u\r\nPRF:\t%s\r\nData Rate:\t%s\r\nPreamble length:\t%s\r\nPreamble code:\t%u\r\nSmart power:\t%s\r\nSFD:\t%s\r\n",
-             systemConfig.getChannel(),
-             (systemConfig.getPRF() == DW1000Setup::prf16MHz)?"16 MHz":"64 MHz",
-             dataRateString,
-             preambleString,
-             systemConfig.getPreambleCode(),
-             systemConfig.getSmartPower()?"Enabled":"Disabled",
-             (systemConfig.getSfd() == DW1000Setup::standard)?"Standard":"Non-standard");
-
-}
-
-
 void DW1000::setupRadio()
 {
     setupAGC();
@@ -363,10 +263,10 @@
     else
         registerValue |= 0x02 << 18;
 
-    if (systemConfig.getSfd() == DW1000Setup::decaWave) 
+    if (systemConfig.getSfd() == DW1000Setup::decaWave)
         registerValue |= 0x01 << 17; // enable DW own SFD
 
-    if (systemConfig.getSfd() == DW1000Setup::user) {     
+    if (systemConfig.getSfd() == DW1000Setup::user) {
         registerValue |= 0x01 << 20; // enable user set SFD Tx
         registerValue |= 0x01 << 21; // enable user set SFD Rx
     }
@@ -435,6 +335,8 @@
     powerReg |= powerToRegValue(boost500) << 8;
     powerReg |= powerToRegValue(boost250) << 16;
     powerReg |= powerToRegValue(boost125) << 24;
+    writeRegister32(DW1000_TX_POWER, 0, powerReg);
+
 }
 
 void DW1000::setupAnalogRF()