Skip to content

Commit 20a359d

Browse files
committed
Update README.md and fix ndef record tnf name
1 parent 66b2df4 commit 20a359d

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

README.md

+52-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,59 @@ This is a library for ST's [ST25DV-I2C series](https://www.st.com/en/nfc/st25dv-
1313
* [Ndef](#ndef)
1414
* [Example](#example)
1515
### Ndef
16-
The ndef support is not complete, only the external record can be writen. Feel free to improve it and add other records support.
16+
This library contains a basic implementation of ndef to read or write data. However, more specific data types like uri and text require their formats to be added.
17+
18+
For simple write you can use this function `st25dv_ndef_write_content` as shown :
19+
```c
20+
st25dv_config st25dv_config = {
21+
ST25DV_USER_ADDRESS,
22+
ST25DV_SYSTEM_ADDRESS
23+
};
24+
25+
char record_type[] = "android.com:pkg";
26+
char record_payload[] = "fr.ouchat.app";
27+
28+
std25dv_ndef_record record = {
29+
NDEF_ST25DV_TNF_EXTERNAL,
30+
record_type,
31+
record_payload
32+
};
33+
34+
st25dv_ndef_write_content(st25dv_config, &address, mb, me, ndef_record);
35+
```
36+
Arguments of the function :
37+
- `st25dv_config` is your st25dv config
38+
- `address` is the pointer of the value for the memory address, after writing it is updated to the end of what was written
39+
- `mb` stands for "message begin" and should be true is this record is the first one
40+
- `me` stands for "message end" and should be true for the last record
41+
- `ndef_record` contains 3 values:
42+
- `tnf` : Type Name Format, witch describes the content format. Theses are all the values :
43+
- `0x00` : Empty
44+
- `0x01` : Well known
45+
- `0x02` : Mime
46+
- `0x03` : URI
47+
- `0x04` : External
48+
- `0x05` : Unknown
49+
- `0x06` : Unchanged
50+
- `0x07` : Reserved
51+
- `record_type` : The name of your record type
52+
- `record_payload` : The payload
53+
54+
To read data you can use this function `st25dv_ndef_read`
55+
56+
```c
57+
std25dv_ndef_record *read = malloc(sizeof(std25dv_ndef_record));
58+
memset(read, 0 , sizeof(std25dv_ndef_record));
59+
60+
uint8_t record_num = 2;
61+
uint8_t record_count = 0;
62+
st25dv_ndef_read(st25dv_config, record_num,read, &record_count);
63+
64+
//Delete record after use
65+
st25dv_ndef_delete_records(read);
66+
```
1767
### Example
18-
You can find in the `📁 /examples` folder an example project demonstrating the main features of the library.
68+
You can find in the `📁 /examples` folder an example project showcasing the main features of the library to help you understand how it works.
1969

2070
## 📝 License
2171

include/st25dv_ndef.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
#define NDEF_ST25DV_TNF_RESERVED 0x07
3838

3939
typedef struct {
40-
uint8_t ndef_type;
40+
uint8_t tnf;
4141
char *type;
4242
char *payload;
4343
} std25dv_ndef_record;
4444

4545
esp_err_t st25dv_ndef_write_ccfile(uint64_t ccfile);
4646

47-
static esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, std25dv_ndef_record record);
47+
esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, std25dv_ndef_record record);
4848
esp_err_t st25dv_ndef_write_app_launcher_record(st25dv_config st25dv, uint16_t *address, bool mb, bool me, char *app_package);
4949
esp_err_t st25dv_ndef_write_json_record(st25dv_config st25dv, uint16_t *address, bool mb, bool me, cJSON *json_data);
5050

st25dv_ndef.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ esp_err_t st25dv_ndef_write_ccfile(uint64_t ccfile) {
1414
return st25dv_write(ST25DV_USER_ADDRESS, 0x00, ccbyte, sizeof(ccfile));
1515
}
1616

17-
static esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, const std25dv_ndef_record record) {
17+
esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, const std25dv_ndef_record record) {
1818
uint8_t type_size = strlen(record.type);
1919
uint16_t payload_size = strlen(record.payload);
2020

@@ -45,7 +45,7 @@ static esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *addre
4545
tnf |= me ? NDEF_ST25DV_ME : 0;
4646
tnf |= payload_size > 0xFF ? 0 : NDEF_ST25DV_SR;
4747
tnf |= NDEF_ST25DV_IL;
48-
tnf |= record.ndef_type;
48+
tnf |= record.tnf;
4949
*data++ = tnf;
5050

5151
//Type length
@@ -245,7 +245,7 @@ esp_err_t st25dv_ndef_read(st25dv_config st25dv, uint8_t record_num, std25dv_nde
245245

246246
if(*record_count == record_num){
247247
//Add payload type to the output
248-
output_records->ndef_type = payload_type;
248+
output_records->tnf = payload_type;
249249

250250
//Get type and add it to the output
251251
char *type = malloc(type_length + 1);

0 commit comments

Comments
 (0)