Skip to content

Commit

Permalink
Update README.md and fix ndef record tnf name
Browse files Browse the repository at this point in the history
  • Loading branch information
RJRP44 committed Oct 31, 2023
1 parent 66b2df4 commit 20a359d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,59 @@ This is a library for ST's [ST25DV-I2C series](https://www.st.com/en/nfc/st25dv-
* [Ndef](#ndef)
* [Example](#example)
### Ndef
The ndef support is not complete, only the external record can be writen. Feel free to improve it and add other records support.
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.

For simple write you can use this function `st25dv_ndef_write_content` as shown :
```c
st25dv_config st25dv_config = {
ST25DV_USER_ADDRESS,
ST25DV_SYSTEM_ADDRESS
};

char record_type[] = "android.com:pkg";
char record_payload[] = "fr.ouchat.app";

std25dv_ndef_record record = {
NDEF_ST25DV_TNF_EXTERNAL,
record_type,
record_payload
};

st25dv_ndef_write_content(st25dv_config, &address, mb, me, ndef_record);
```
Arguments of the function :
- `st25dv_config` is your st25dv config
- `address` is the pointer of the value for the memory address, after writing it is updated to the end of what was written
- `mb` stands for "message begin" and should be true is this record is the first one
- `me` stands for "message end" and should be true for the last record
- `ndef_record` contains 3 values:
- `tnf` : Type Name Format, witch describes the content format. Theses are all the values :
- `0x00` : Empty
- `0x01` : Well known
- `0x02` : Mime
- `0x03` : URI
- `0x04` : External
- `0x05` : Unknown
- `0x06` : Unchanged
- `0x07` : Reserved
- `record_type` : The name of your record type
- `record_payload` : The payload
To read data you can use this function `st25dv_ndef_read`
```c
std25dv_ndef_record *read = malloc(sizeof(std25dv_ndef_record));
memset(read, 0 , sizeof(std25dv_ndef_record));
uint8_t record_num = 2;
uint8_t record_count = 0;
st25dv_ndef_read(st25dv_config, record_num,read, &record_count);
//Delete record after use
st25dv_ndef_delete_records(read);
```
### Example
You can find in the `📁 /examples` folder an example project demonstrating the main features of the library.
You can find in the `📁 /examples` folder an example project showcasing the main features of the library to help you understand how it works.

## 📝 License

Expand Down
4 changes: 2 additions & 2 deletions include/st25dv_ndef.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
#define NDEF_ST25DV_TNF_RESERVED 0x07

typedef struct {
uint8_t ndef_type;
uint8_t tnf;
char *type;
char *payload;
} std25dv_ndef_record;

esp_err_t st25dv_ndef_write_ccfile(uint64_t ccfile);

static esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, std25dv_ndef_record record);
esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *address, bool mb, bool me, std25dv_ndef_record record);
esp_err_t st25dv_ndef_write_app_launcher_record(st25dv_config st25dv, uint16_t *address, bool mb, bool me, char *app_package);
esp_err_t st25dv_ndef_write_json_record(st25dv_config st25dv, uint16_t *address, bool mb, bool me, cJSON *json_data);

Expand Down
6 changes: 3 additions & 3 deletions st25dv_ndef.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ esp_err_t st25dv_ndef_write_ccfile(uint64_t ccfile) {
return st25dv_write(ST25DV_USER_ADDRESS, 0x00, ccbyte, sizeof(ccfile));
}

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

Expand Down Expand Up @@ -45,7 +45,7 @@ static esp_err_t st25dv_ndef_write_content(st25dv_config st25dv, uint16_t *addre
tnf |= me ? NDEF_ST25DV_ME : 0;
tnf |= payload_size > 0xFF ? 0 : NDEF_ST25DV_SR;
tnf |= NDEF_ST25DV_IL;
tnf |= record.ndef_type;
tnf |= record.tnf;
*data++ = tnf;

//Type length
Expand Down Expand Up @@ -245,7 +245,7 @@ esp_err_t st25dv_ndef_read(st25dv_config st25dv, uint8_t record_num, std25dv_nde

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

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

0 comments on commit 20a359d

Please sign in to comment.