|
| 1 | +/* |
| 2 | + This is a library written for the ST25DV64KC Dynamic RFID Tag. |
| 3 | + SparkFun sells these at its website: |
| 4 | + https://www.sparkfun.com/products/ |
| 5 | +
|
| 6 | + Do you like this library? Help support open source hardware. Buy a board! |
| 7 | +
|
| 8 | + Written by Paul CLark @ SparkFun Electronics, August 5th, 2021 |
| 9 | + This file declares the additional functions used to read/write NDEF |
| 10 | + records from/to the ST25DV64KC Dynamic RFID Tag. |
| 11 | +
|
| 12 | + This program is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "SparkFun_ST25DV64KC_NDEF.h" |
| 21 | + |
| 22 | +bool SFE_ST25DV64KC_NDEF::writeCCFile4Byte(uint32_t val) |
| 23 | +{ |
| 24 | + uint8_t CCFile[4]; |
| 25 | + CCFile[0] = val >> 24; |
| 26 | + CCFile[1] = (val >> 16) & 0xFF; |
| 27 | + CCFile[2] = (val >> 8) & 0xFF; |
| 28 | + CCFile[3] = val & 0xFF; |
| 29 | + |
| 30 | + return writeEEPROM(0x0, CCFile, 0x4); |
| 31 | +} |
| 32 | + |
| 33 | +/* |
| 34 | + The Capacity Container File is written to the first eight bytes of user memory: |
| 35 | +
|
| 36 | + 0xE2 0x40 0x00 0x01 0x00 0x00 0x03 0xFF |
| 37 | +
|
| 38 | + Byte 0: Magic Number |
| 39 | + The ST25DV64KC has 8kBytes of user memory so we need to select 0xE2 to select two-byte addressing |
| 40 | + Byte 1: Version and Access Condition |
| 41 | + b7 b6 = 0b01 Major Version |
| 42 | + b5 b4 = 0b00 Minor Version |
| 43 | + b3 b2 = 0x00 Read Access: Always |
| 44 | + b1 b0 = 0x00 Write Access: Always |
| 45 | + Byte 2: 0x00 |
| 46 | + Byte 3: Additional Feature Information |
| 47 | + b7 b6 b5 = 0b000 RFU (Reserved Future Use) |
| 48 | + b4 = 0b0 Special Frame |
| 49 | + b3 = 0b0 Lock Block |
| 50 | + b2 b1 = 0b00 RFU |
| 51 | + b0 = 0b1 MBREAD: Read Multiple Block is supported |
| 52 | + Byte 4: 0x00 RFU (Reserved Future Use) |
| 53 | + Byte 5: 0x00 RFU (Reserved Future Use) |
| 54 | + Byte 6 + Byte 7: MLEN Encoded Memory Length |
| 55 | + MLEN = T5T_Area / 8 |
| 56 | + MLEN encoding for a ST25DV64K (8192 bytes memory size) and 8 bytes capability container (CC): |
| 57 | + If the entire user memory full, user memory is used to store NDEF, T5T_Area=8192-8 |
| 58 | + MLEN = (8192 – 8) / 8 = 1023 (0x03FF) |
| 59 | +*/ |
| 60 | + |
| 61 | +bool SFE_ST25DV64KC_NDEF::writeCCFile8Byte(uint32_t val1, uint32_t val2) |
| 62 | +{ |
| 63 | + uint8_t CCFile[8]; |
| 64 | + CCFile[0] = val1 >> 24; |
| 65 | + CCFile[1] = (val1 >> 16) & 0xFF; |
| 66 | + CCFile[2] = (val1 >> 8) & 0xFF; |
| 67 | + CCFile[3] = val1 & 0xFF; |
| 68 | + CCFile[4] = val2 >> 24; |
| 69 | + CCFile[5] = (val2 >> 16) & 0xFF; |
| 70 | + CCFile[6] = (val2 >> 8) & 0xFF; |
| 71 | + CCFile[7] = val2 & 0xFF; |
| 72 | + |
| 73 | + return writeEEPROM(0x0, CCFile, 0x8); |
| 74 | +} |
0 commit comments