Simple driver for DWM1000 modules.

Revision:
5:c34ebc7f650c
Parent:
4:faf802b4af85
diff -r faf802b4af85 -r c34ebc7f650c DW1000.h
--- a/DW1000.h	Tue Mar 29 10:00:23 2016 +0000
+++ b/DW1000.h	Thu Mar 31 15:36:39 2016 +0000
@@ -58,7 +58,7 @@
         const static float US_TO_TIMEUNITS = (128*499.2f);      // conversion between microseconds to the decawave timeunits (ca 15.65ps).
         const static uint64_t CONST_2POWER40 = 1099511627776;  // Time register in DW1000 is 40 bit so this is needed to detect overflows.
 
-        DW1000(SPI& spi, InterruptIn& irq, PinName CS, PinName RESET = NC);              // constructor, uses SPI class
+        DW1000(SPI& spi, InterruptIn* irq, PinName CS, PinName RESET = NC);              // constructor, uses SPI class
 
         void setCallbacks(void (*callbackRX)(void), void (*callbackTX)(void));                  // setter for callback functions, automatically enables interrupt, if NULL is passed the coresponding interrupt gets disabled
         template<typename T>
@@ -102,28 +102,14 @@
         void receiveString(char* message);                                                      // to receive char string (length of the buffer must be 1021 to be safe)
         void sendFrame(uint8_t* message, uint16_t length);                                      // send a raw frame (length in bytes)
         void sendDelayedFrame(uint8_t* message, uint16_t length, uint64_t TxTimestamp);
+        uint16_t getFramelength();                                                              // to get the framelength of the received frame from the PHY header
         void startRX();                                                                         // start listening for frames
         void stopTRX();                                                                         // disable tranceiver go back to idle mode
-        
-    //private:
-        void loadLDE();                                                                         // load the leading edge detection algorithm to RAM, [IMPORTANT because receiving malfunction may occur] see User Manual LDELOAD on p22 & p158
-        void resetRX();                                                                         // soft reset only the tranciever part of DW1000
-        static void hardwareReset(PinName reset_pin);
-        void resetAll();                                                                        // soft reset the entire DW1000 (some registers stay as they were see User Manual)
 
-        // Interrupt
-        InterruptIn& irq;
-        FunctionPointer callbackRX;                                                             // function pointer to callback which is called when successfull RX took place
-        FunctionPointer callbackTX;                                                             // function pointer to callback which is called when successfull TX took place
-        void setInterrupt(bool RX, bool TX);                                                    // set Interrupt for received a good frame (CRC ok) or transmission done
-        void ISR();                                                                             // interrupt handling method (also calls according callback methods)
-        uint16_t getFramelength();                                                              // to get the framelength of the received frame from the PHY header
-        
-        // SPI Inteface
-        SPI& spi;                                                                                // SPI Bus
-        DigitalOut cs;                                                                          // Slave selector for SPI-Bus (here explicitly needed to start and end SPI transactions also usable to wake up DW1000)
-        DigitalOut reset;
-        
+        static void hardwareReset(PinName reset_pin);
+        static void hardwareReset(DigitalInOut& reset_pin);
+        void softwareReset();
+
         uint8_t readRegister8(uint8_t reg, uint16_t subaddress);                                // expressive methods to read or write the number of bits written in the name
         uint16_t readRegister16(uint8_t reg, uint16_t subaddress);
         uint32_t readRegister32(uint8_t reg, uint16_t subaddress);
@@ -132,9 +118,26 @@
         void writeRegister16(uint8_t reg, uint16_t subaddress, uint16_t buffer);
         void writeRegister32(uint8_t reg, uint16_t subaddress, uint32_t buffer);
         void writeRegister40(uint8_t reg, uint16_t subaddress, uint64_t buffer);
-
         void readRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length);       // reads the selected part of a slave register into the buffer memory
         void writeRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length);      // writes the buffer memory to the selected slave register
+
+    private:
+        void loadLDE();                                                                         // load the leading edge detection algorithm to RAM, [IMPORTANT because receiving malfunction may occur] see User Manual LDELOAD on p22 & p158
+        void resetRX();                                                                         // soft reset only the tranciever part of DW1000
+        void resetAll();                                                                        // soft reset the entire DW1000 (some registers stay as they were see User Manual)
+
+        // Interrupt
+        InterruptIn* irq;
+        FunctionPointer callbackRX;                                                             // function pointer to callback which is called when successfull RX took place
+        FunctionPointer callbackTX;                                                             // function pointer to callback which is called when successfull TX took place
+        void setInterrupt(bool RX, bool TX);                                                    // set Interrupt for received a good frame (CRC ok) or transmission done
+        void ISR();                                                                             // interrupt handling method (also calls according callback methods)
+        
+        // SPI Inteface
+        SPI& spi;                                                                                // SPI Bus
+        DigitalOut cs;                                                                          // Slave selector for SPI-Bus (here explicitly needed to start and end SPI transactions also usable to wake up DW1000)
+        DigitalInOut reset;
+
         void setupTransaction(uint8_t reg, uint16_t subaddress, bool write);                    // sets up an SPI read or write transaction with correct register address and offset
         void select();                                                                          // selects the only slave for a transaction
         void deselect();