NFC API for mbed using the MicroNFCBoard as a peripheral

Dependents:   MicroNFCBoardAPI_P2P_Client MicroNFCBoardAPI_Blink MicroNFCBoardAPI_Tag_Emulator MicroNFCBoardAPI_Tag_Reader ... more

Revision:
2:9b0733b8fa95
Parent:
1:1d246e0872c6
diff -r 1d246e0872c6 -r 9b0733b8fa95 transport.cpp
--- a/transport.cpp	Fri Apr 24 12:59:31 2015 +0000
+++ b/transport.cpp	Thu May 14 16:41:27 2015 +0000
@@ -28,8 +28,8 @@
                                            *(((uint8_t*)(addr)) + 1) = ((val) >> 0 ) & 0xFF; } while(0)
 
 //MSB first
-#define READ_UINT32( addr, val ) do{ val = (*(((uint8_t*)(addr)) + 0) << 24 ) \
-                                              | (*(((uint8_t*)(addr)) + 1) << 16 ) \
+#define READ_UINT32( addr, val ) do{ val = (*(uint32_t*)(((uint8_t*)(addr)) + 0) << 24 ) \
+                                              | (*(uint32_t*)(((uint8_t*)(addr)) + 1) << 16 ) \
                                               | (*(((uint8_t*)(addr)) + 2) << 8 ) \
                                               | (*(((uint8_t*)(addr)) + 3) << 0 ); } while(0)
 #define READ_UINT16( addr, val ) do{ val = (*(((uint8_t*)(addr)) + 0) << 8 ) \
@@ -76,9 +76,9 @@
   return status;
 }
 
-void Transport::nfcPoll(bool enable)
+void Transport::nfcPoll(bool readerWriter, bool emulator, bool p2p)
 {
-  uint8_t out[] = {enable?1:0};
+  uint8_t out[] = {(readerWriter?1:0) | (emulator?2:0) | (p2p?4:0)};
   command(Transport::NFC_POLL, out, sizeof(out), NULL, 0);
 }
 
@@ -137,7 +137,7 @@
   }
 }
 
-void Transport::nfcSetRecordInfo(size_t recordNumber, uint16_t type, uint16_t* info, size_t infoCount)
+void Transport::nfcSetRecordInfo(size_t recordNumber, uint16_t type, const uint16_t* info, size_t infoCount)
 {
   uint8_t out[2+2+2*infoCount];
   WRITE_UINT16(&out[0], recordNumber);
@@ -159,7 +159,7 @@
   command(Transport::NFC_GET_RECORD_DATA, out, sizeof(out), data, length);
 }
 
-void Transport::nfcSetRecordData(size_t recordNumber, size_t item, size_t offset, uint8_t* data, size_t length)
+void Transport::nfcSetRecordData(size_t recordNumber, size_t item, size_t offset, const uint8_t* data, size_t length)
 {
   uint8_t out[7+length];
   WRITE_UINT16(&out[0], recordNumber);
@@ -185,7 +185,7 @@
   {
     out[0] = 0;
   }
-  command(Transport::NFC_POLL, out, sizeof(out), NULL, 0);
+  command(Transport::NFC_PREPARE_MESSAGE, out, sizeof(out), NULL, 0);
 }
 
 void Transport::nfcDecodePrefix(uint8_t prefix, char* data, size_t* pDataLength)
@@ -202,17 +202,15 @@
   memcpy(data, &in[2], *pDataLength);
 }
 
-void Transport::nfcEncodePrefix(uint8_t* pPrefix, char* data, size_t dataLength)
+void Transport::nfcEncodePrefix(uint8_t* pPrefix, const char* data, size_t* pDataLength)
 {
-  uint8_t out[2 + dataLength];
-  uint8_t in[1];
-
-  WRITE_UINT16(&out[0], dataLength);
-  memcpy(data, &out[2], dataLength);
-
+  uint8_t out[2 + *pDataLength];
+  uint8_t in[3];
+  WRITE_UINT16(&out[0], *pDataLength);
+  memcpy(&out[2], data, *pDataLength);
   command(Transport::NFC_ENCODE_PREFIX, out, sizeof(out), in, sizeof(in));
-
   *pPrefix = in[0];
+  READ_UINT16(&in[1], *pDataLength);
 }
 
 void Transport::leds(bool led1, bool led2)