Tobi's ubw test branch
Dependencies: mavlink_bridge mbed
Fork of AIT_UWB_Range by
Diff: DW1000/DW1000.cpp
- Revision:
- 26:a65c6f26c458
- Parent:
- 25:d58b0595b300
- Child:
- 28:a830131560e8
diff -r d58b0595b300 -r a65c6f26c458 DW1000/DW1000.cpp --- a/DW1000/DW1000.cpp Thu Nov 27 17:51:54 2014 +0000 +++ b/DW1000/DW1000.cpp Thu Nov 27 19:19:35 2014 +0000 @@ -1,8 +1,7 @@ #include "DW1000.h" DW1000::DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ) : irq(IRQ), spi(MOSI, MISO, SCLK), cs(CS) { - callbackRX = NULL; // TODO: setter - callbackTX = NULL; + setCallbacks(NULL, NULL); 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) @@ -13,11 +12,16 @@ // Configuration TODO: make method for that writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error - writeRegister8(DW1000_SYS_CFG, 2, 0x03); // enable 1024 byte frames TODO: doesn't work!! + writeRegister8(DW1000_SYS_CFG, 2, 0x03); // enable 1024 byte frames irq.rise(this, &DW1000::ISR); // attach Interrupt handler to rising edge } +void DW1000::setCallbacks(void (*callbackRX)(int framelength), void (*callbackTX)()) { + DW1000::callbackRX = callbackRX; + DW1000::callbackTX = callbackTX; +} + uint32_t DW1000::getDeviceID() { uint32_t result; readRegister(DW1000_DEV_ID, 0, (uint8_t*)&result, 4); @@ -50,6 +54,18 @@ return readRegister40(DW1000_SYS_STATUS, 0); } +void DW1000::setInterrupt(bool RX, bool TX) { + writeRegister16(DW1000_SYS_MASK, 0, RX*0x4000 | TX*0x0080); // RX good frame 0x4000, TX done 0x0080 +} + +uint64_t DW1000::getRXTimestamp() { + return readRegister40(DW1000_RX_TIME, 0); +} + +uint64_t DW1000::getTXTimestamp() { + return readRegister40(DW1000_TX_TIME, 0); +} + void DW1000::sendString(char* message) { sendFrame((uint8_t*)message, strlen(message)+1); } @@ -74,7 +90,6 @@ } void DW1000::startRX() { - //while(sending); // block until sending finished TODO: the right way?? writeRegister8(DW1000_SYS_CTRL, 0x01, 0x01); // start listening for preamble by setting the RXENAB bit }