-
Notifications
You must be signed in to change notification settings - Fork 7
/
ntag.h
76 lines (73 loc) · 2.75 KB
/
ntag.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef NTAG_H
#define NTAG_H
#include "Arduino.h"
#include <Bounce2.h>
class Ntag
{
public:
typedef enum{
NTAG_I2C_1K,
NTAG_I2C_2K
}DEVICE_TYPE;
typedef enum{
NC_REG,
LAST_NDEF_BLOCK,
SRAM_MIRROR_BLOCK,
WDT_LS,
WDT_MS,
I2C_CLOCK_STR,
NS_REG
}REGISTER_NR;
Ntag(DEVICE_TYPE dt, byte fd_pin, byte vout_pin, byte i2c_address = DEFAULT_I2C_ADDRESS);
void detectI2cDevices();//Comes in handy when you accidentally changed the I²C address of the NTAG.
bool begin();
bool getUid(byte *uid, unsigned int uidLength);
bool getCapabilityContainer(byte* container);
byte getUidLength();
bool isRfBusy();
bool isReaderPresent();
bool setSramMirrorRf(bool bEnable, byte mirrorBaseBlockNr);
bool setFd_ReaderHandshake();
//Address=address of the byte, not address of the 16byte block
bool readEeprom(word address, byte* pdata, byte length);//starts at address 0
//Address=address of the byte, not address of the 16byte block
bool writeEeprom(word address, byte* pdata, byte length);//starts at address 0
bool readSram(word address, byte* pdata, byte length);//starts at address 0
bool writeSram(word address, byte* pdata, byte length);//starts at address 0
bool readRegister(REGISTER_NR regAddr, byte &value);
bool writeRegister(REGISTER_NR regAddr, byte mask, byte regdat);
bool setLastNdefBlock();
void releaseI2c();
private:
typedef enum{
CONFIG=0x1,//BLOCK0 (putting this in a separate block type, because errors here can "brick" the device.)
USERMEM=0x2,//EEPROM
REGISTER=0x4,//Settings registers
SRAM=0x8
}BLOCK_TYPE;
static const byte UID_LENGTH=7;
static const byte DEFAULT_I2C_ADDRESS=0x55;
static const byte NTAG_BLOCK_SIZE=16;
static const word EEPROM_BASE_ADDR=(0x1<<4);
static const word SRAM_BASE_ADDR=(0xF8<<4);
//Address=address of the byte, not address of the 16byte block
bool write(BLOCK_TYPE bt, word byteAddress, byte* pdata, byte length);
//Address=address of the byte, not address of the 16byte block
bool read(BLOCK_TYPE bt, word byteAddress, byte* pdata, byte length);
bool readBlock(BLOCK_TYPE bt, byte memBlockAddress, byte *p_data, byte data_size);
bool writeBlock(BLOCK_TYPE bt, byte memBlockAddress, byte *p_data);
bool writeBlockAddress(BLOCK_TYPE dt, byte addr);
bool end_transmission(void);
bool isAddressValid(BLOCK_TYPE dt, byte blocknr);
bool setLastNdefBlock(byte memBlockAddress);
byte _i2c_address;
DEVICE_TYPE _dt;
byte _fd_pin;
byte _vout_pin;
byte _lastMemBlockWritten;
byte _mirrorBaseBlockNr;
Bounce _debouncer;
unsigned long _rfBusyStartTime;
bool _triggered;
};
#endif // NTAG_H