1 #ifndef NT3H_H_ 2 #define NT3H_H_ 3 4 #include <stdint.h> 5 #include "stdbool.h" 6 7 #define NT3H1X_ADDRESS 0x55 8 9 #define MANUFACTORING_DATA_REG 0x0 10 #define USER_START_REG 0x1 11 12 #define NT3H1X_WRITE_TIMEOUT_US 300000 13 14 // NT3H1201 // for th 2K 15 #define USER_END_REG 0x77 16 #define CONFIG_REG 0x7A 17 18 #define SERIAL_NUM_LEN 16 19 20 #define SRAM_START_REG 0xF8 21 #define SRAM_END_REG 0xFB // just the first 8 bytes 22 23 #define SESSION_REG 0xFE 24 25 #define NFC_PAGE_SIZE 16 26 27 typedef enum { 28 NT3HERROR_NO_ERROR, 29 NT3HERROR_READ_HEADER, 30 NT3HERROR_WRITE_HEADER, 31 NT3HERROR_INVALID_USER_MEMORY_PAGE, 32 NT3HERROR_READ_USER_MEMORY_PAGE, 33 NT3HERROR_WRITE_USER_MEMORY_PAGE, 34 NT3HERROR_ERASE_USER_MEMORY_PAGE, 35 NT3HERROR_READ_NDEF_TEXT, 36 NT3HERROR_WRITE_NDEF_TEXT, 37 NT3HERROR_TYPE_NOT_SUPPORTED 38 }NT3HerrNo; 39 40 typedef enum { 41 EndRecordsPtr = 1, 42 NDEFHeader = 2, 43 } HeardPosEnu; 44 45 typedef enum { 46 NDEFFirstPos, 47 NDEFMiddlePos, 48 NDEFLastPos 49 } RecordPosEnu; 50 /* 51 * This strucure is used in the ADD record functionality 52 * to store the last nfc page information, in order to continue from that point. 53 */ 54 typedef struct { 55 uint8_t page; 56 uint8_t usedBytes; 57 } UncompletePageStr; 58 59 60 typedef struct { 61 RecordPosEnu ndefPosition; 62 uint8_t rtdType; 63 uint8_t *rtdPayload; 64 uint8_t rtdPayloadlength; 65 void *specificRtdData; 66 }NDEFDataStr; 67 68 69 void NT3HGetNxpSerialNumber(char *buffer); 70 71 /* 72 * read the user data from the requested page 73 * first page is 0 74 * 75 * the NT3H1201 has 119 PAges 76 * the NT3H1101 has 56 PAges (but the 56th page has only 8 Bytes) 77 */ 78 bool NT3HReadUserData(uint8_t page); 79 80 /* 81 * Write data information from the starting requested page. 82 * If the dataLen is bigger of NFC_PAGE_SIZE, the consecuiteve needed 83 * pages will be automatically used. 84 * 85 * The functions stops to the latest available page. 86 * 87 first page is 0 88 * the NT3H1201 has 119 PAges 89 * the NT3H1101 has 56 PAges (but the 56th page has only 8 Bytes) 90 */ 91 bool NT3HWriteUserData(uint8_t page, const uint8_t *data); 92 93 /* 94 * The function read the first page of user data where is stored the NFC Header. 95 * It is important because it contains the total size of all the stored records. 96 * 97 * param endRecordsPtr return the value of the total size excluding the NDEF_END_BYTE 98 * param ndefHeader Store the NDEF Header of the first record 99 */ 100 bool NT3HReadHeaderNfc(uint8_t *endRecordsPtr, uint8_t *ndefHeader); 101 102 /* 103 * The function write the first page of user data where is stored the NFC Header. 104 * update the bytes that contains the payload Length and the first NDEF Header 105 * 106 * param endRecordsPtr The value of the total size excluding the NDEF_END_BYTE 107 * param ndefHeader The NDEF Header of the first record 108 */ 109 bool NT3HWriteHeaderNfc(uint8_t endRecordsPtr, uint8_t ndefHeader); 110 111 bool getSessionReg(void); 112 bool getNxpUserData(char *buffer); 113 bool NT3HReadSram(void); 114 bool NT3HReadSession(void); 115 bool NT3HReadConfiguration(uint8_t *configuration); 116 117 bool NT3HEraseAllTag(void); 118 119 bool NT3HReaddManufactoringData(uint8_t *manuf); 120 121 bool NT3HResetUserData(void); 122 123 bool NT3HwriteRecord(const NDEFDataStr *data); 124 125 #endif /* NFC_H_ */ 126