diff --git a/README.md b/README.md index 3d8c08b..14b6226 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/include/st25dv_ndef.h b/include/st25dv_ndef.h index 35adfe5..2719de7 100644 --- a/include/st25dv_ndef.h +++ b/include/st25dv_ndef.h @@ -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); diff --git a/st25dv_ndef.c b/st25dv_ndef.c index bf0e04c..16c0fba 100644 --- a/st25dv_ndef.c +++ b/st25dv_ndef.c @@ -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); @@ -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 @@ -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);