nfctag5  2.0.0.0
nfctag5.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef NFCTAG5_H
29 #define NFCTAG5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 #include "drv_analog_in.h"
49 
70 #define NFCTAG5_REG_SECTOR_SECURITY_0 0x0000
71 #define NFCTAG5_REG_SECTOR_SECURITY_4 0x0004
72 #define NFCTAG5_REG_SECTOR_SECURITY_8 0x0008
73 #define NFCTAG5_REG_SECTOR_SECURITY_12 0x000C
74 #define NFCTAG5_REG_SECTOR_SECURITY_16 0x0010
75 #define NFCTAG5_REG_SECTOR_SECURITY_20 0x0014
76 #define NFCTAG5_REG_SECTOR_SECURITY_24 0x0018
77 #define NFCTAG5_REG_SECTOR_SECURITY_28 0x001C
78 #define NFCTAG5_REG_SECTOR_SECURITY_32 0x0020
79 #define NFCTAG5_REG_SECTOR_SECURITY_36 0x0024
80 #define NFCTAG5_REG_SECTOR_SECURITY_40 0x0028
81 #define NFCTAG5_REG_SECTOR_SECURITY_44 0x002C
82 #define NFCTAG5_REG_SECTOR_SECURITY_48 0x0030
83 #define NFCTAG5_REG_SECTOR_SECURITY_52 0x0034
84 #define NFCTAG5_REG_SECTOR_SECURITY_56 0x0038
85 #define NFCTAG5_REG_SECTOR_SECURITY_60 0x003C
86 #define NFCTAG5_REG_SECTOR_SECURITY_STATUS_LSB 0x0800
87 #define NFCTAG5_REG_SECTOR_SECURITY_STATUS_MSB 0x0804
88 #define NFCTAG5_REG_I2C_PASSWORD 0x0900
89 #define NFCTAG5_REG_RF_PASSWORD_1 0x0904
90 #define NFCTAG5_REG_RF_PASSWORD_2 0x0908
91 #define NFCTAG5_REG_RF_PASSWORD_3 0x090C
92 #define NFCTAG5_REG_CONFIG 0x0910
93 #define NFCTAG5_REG_UID_LSB 0x0914
94 #define NFCTAG5_REG_UID_MSB 0x0918
95 #define NFCTAG5_REG_IC_REF_MEM_SIZE 0x091C
96 #define NFCTAG5_REG_CONTROL 0x0920
97  // nfctag5_reg
99 
114 #define NFCTAG5_CAPABILITY_CONTAINER_ADDRESS 0x0000
115 #define NFCTAG5_CAPABILITY_CONTAINER 0xE1, 0x40, 0x80, 0x01
116 #define NFCTAG5_NDEF_MESSAGE_START_ADDRESS 0x0004
117 #define NFCTAG5_TYPE_NDEF_MESSAGE 0x03
118 #define NFCTAG5_NDEF_RECORD_HEADER 0xD1
119 #define NFCTAG5_NDEF_TYPE_LENGTH 0x01
120 #define NFCTAG5_NDEF_URI_TYPE 'U'
121 #define NFCTAG5_NDEF_MESSAGE_END_MARK 0xFE
122 
127 #define NFCTAG5_URI_PREFIX_0 0x00
128 #define NFCTAG5_URI_PREFIX_1 0x01
129 #define NFCTAG5_URI_PREFIX_2 0x02
130 #define NFCTAG5_URI_PREFIX_3 0x03
131 #define NFCTAG5_URI_PREFIX_4 0x04
132 #define NFCTAG5_URI_PREFIX_5 0x05
133 #define NFCTAG5_URI_PREFIX_6 0x06
134 #define NFCTAG5_URI_PREFIX_7 0x07
135 #define NFCTAG5_URI_PREFIX_8 0x08
136 #define NFCTAG5_URI_PREFIX_9 0x09
137 #define NFCTAG5_URI_PREFIX_10 0x0A
138 #define NFCTAG5_URI_PREFIX_11 0x0B
139 #define NFCTAG5_URI_PREFIX_12 0x0C
140 #define NFCTAG5_URI_PREFIX_13 0x0D
141 #define NFCTAG5_URI_PREFIX_14 0x0E
142 #define NFCTAG5_URI_PREFIX_15 0x0F
143 #define NFCTAG5_URI_PREFIX_16 0x10
144 #define NFCTAG5_URI_PREFIX_17 0x11
145 #define NFCTAG5_URI_PREFIX_18 0x12
146 #define NFCTAG5_URI_PREFIX_19 0x13
147 #define NFCTAG5_URI_PREFIX_20 0x14
148 #define NFCTAG5_URI_PREFIX_21 0x15
149 #define NFCTAG5_URI_PREFIX_22 0x16
150 #define NFCTAG5_URI_PREFIX_23 0x17
151 #define NFCTAG5_URI_PREFIX_24 0x18
152 #define NFCTAG5_URI_PREFIX_25 0x19
153 #define NFCTAG5_URI_PREFIX_26 0x1A
154 #define NFCTAG5_URI_PREFIX_27 0x1B
155 #define NFCTAG5_URI_PREFIX_28 0x1C
156 #define NFCTAG5_URI_PREFIX_29 0x1D
157 #define NFCTAG5_URI_PREFIX_30 0x1E
158 #define NFCTAG5_URI_PREFIX_31 0x1F
159 #define NFCTAG5_URI_PREFIX_32 0x20
160 #define NFCTAG5_URI_PREFIX_33 0x21
161 #define NFCTAG5_URI_PREFIX_34 0x22
162 #define NFCTAG5_URI_PREFIX_35 0x23
168 #define NFCTAG5_USER_MEMORY_ADDRESS_MIN 0x0000
169 #define NFCTAG5_USER_MEMORY_ADDRESS_MAX 0x1FFF
170 #define NFCTAG5_MEMORY_BLOCK_SIZE 4
171 #define NFCTAG5_MEMORY_BLOCK_MASK 0x1FFC
172 
177 #define NFCTAG5_ADDRESS_MODE_CONFIG 0
178 #define NFCTAG5_ADDRESS_MODE_USER_MEMORY 1
179 
184 #define NFCTAG5_VH_VREF_3V3 3.3
185 #define NFCTAG5_VH_VREF_5V 5.0
186 #define NFCTAG5_VH_VREF NFCTAG5_VH_VREF_3V3
187 
193 #define NFCTAG5_DEVICE_ADDRESS_CONFIG 0x57
194 #define NFCTAG5_DEVICE_ADDRESS_USER_MEMORY 0x53
195  // nfctag5_set
197 
212 #define NFCTAG5_MAP_MIKROBUS( cfg, mikrobus ) \
213  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
214  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
215  cfg.vh = MIKROBUS( mikrobus, MIKROBUS_AN ); \
216  cfg.busy = MIKROBUS( mikrobus, MIKROBUS_INT )
217  // nfctag5_map // nfctag5
220 
225 typedef union
226 {
227  uint8_t value_bytes[ 4 ];
228  uint32_t value;
230 
235 typedef struct
236 {
237  // Input pins
238  digital_in_t busy;
240  // Modules
241  i2c_master_t i2c;
242  analog_in_t adc;
244  // I2C slave address
245  uint8_t slave_address;
247 } nfctag5_t;
248 
253 typedef struct
254 {
255  pin_name_t scl;
256  pin_name_t sda;
258  pin_name_t vh;
259  pin_name_t busy;
261  uint32_t i2c_speed;
262  uint8_t i2c_address;
263  analog_in_resolution_t resolution;
264  float vref;
266 } nfctag5_cfg_t;
267 
272 typedef enum
273 {
275  NFCTAG5_ERROR = -1
276 
278 
295 
309 err_t nfctag5_init ( nfctag5_t *ctx, nfctag5_cfg_t *cfg );
310 
324 
337 err_t nfctag5_set_address_mode ( nfctag5_t *ctx, uint8_t mode );
338 
352 err_t nfctag5_write_memory_block ( nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block );
353 
367 err_t nfctag5_read_memory_block ( nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block );
368 
384 err_t nfctag5_write_multiple_memory_block ( nfctag5_t *ctx, uint16_t block_addr,
385  nfctag5_block_t *block, uint8_t num_blocks );
386 
402 err_t nfctag5_read_multiple_memory_block ( nfctag5_t *ctx, uint16_t block_addr,
403  nfctag5_block_t *block, uint8_t num_blocks );
404 
420 err_t nfctag5_write_ndef_uri_record ( nfctag5_t *ctx, uint8_t uri_prefix, uint8_t *uri_data, uint8_t data_len );
421 
433 
448 err_t nfctag5_write_message_to_memory ( nfctag5_t *ctx, uint16_t block_addr, uint8_t *message, uint16_t message_len );
449 
464 err_t nfctag5_read_message_from_memory ( nfctag5_t *ctx, uint16_t block_addr, uint8_t *message, uint16_t message_len );
465 
477 err_t nfctag5_read_vh_pin_value ( nfctag5_t *ctx, uint16_t *data_out );
478 
492 err_t nfctag5_read_vh_pin_voltage ( nfctag5_t *ctx, float *data_out );
493 
503 
504 #ifdef __cplusplus
505 }
506 #endif
507 #endif // NFCTAG5_H
508  // nfctag5
510 
511 // ------------------------------------------------------------------------ END
nfctag5_block_t
NFC Tag 5 Click memory block union definition.
Definition: nfctag5.h:226
nfctag5_write_memory_block
err_t nfctag5_write_memory_block(nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block)
NFC Tag 5 write memory block function.
nfctag5_t::adc
analog_in_t adc
Definition: nfctag5.h:242
NFCTAG5_ERROR
@ NFCTAG5_ERROR
Definition: nfctag5.h:275
NFCTAG5_OK
@ NFCTAG5_OK
Definition: nfctag5.h:274
nfctag5_write_ndef_uri_record
err_t nfctag5_write_ndef_uri_record(nfctag5_t *ctx, uint8_t uri_prefix, uint8_t *uri_data, uint8_t data_len)
NFC Tag 5 write NDEF URI record function.
nfctag5_read_message_from_memory
err_t nfctag5_read_message_from_memory(nfctag5_t *ctx, uint16_t block_addr, uint8_t *message, uint16_t message_len)
NFC Tag 5 read message from memory function.
nfctag5_cfg_setup
void nfctag5_cfg_setup(nfctag5_cfg_t *cfg)
NFC Tag 5 configuration object setup function.
nfctag5_read_vh_pin_value
err_t nfctag5_read_vh_pin_value(nfctag5_t *ctx, uint16_t *data_out)
NFC Tag 5 read AN pin value function.
nfctag5_t::busy
digital_in_t busy
Definition: nfctag5.h:238
nfctag5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: nfctag5.h:261
nfctag5_cfg_t::vref
float vref
Definition: nfctag5.h:264
nfctag5_write_message_to_memory
err_t nfctag5_write_message_to_memory(nfctag5_t *ctx, uint16_t block_addr, uint8_t *message, uint16_t message_len)
NFC Tag 5 write message to memory function.
nfctag5_cfg_t::vh
pin_name_t vh
Definition: nfctag5.h:258
nfctag5_t
NFC Tag 5 Click context object.
Definition: nfctag5.h:236
nfctag5_cfg_t::sda
pin_name_t sda
Definition: nfctag5.h:256
nfctag5_init
err_t nfctag5_init(nfctag5_t *ctx, nfctag5_cfg_t *cfg)
NFC Tag 5 initialization function.
nfctag5_read_vh_pin_voltage
err_t nfctag5_read_vh_pin_voltage(nfctag5_t *ctx, float *data_out)
NFC Tag 5 read VH pin voltage level function.
nfctag5_default_cfg
err_t nfctag5_default_cfg(nfctag5_t *ctx)
NFC Tag 5 default configuration function.
nfctag5_cfg_t
NFC Tag 5 Click configuration object.
Definition: nfctag5.h:254
nfctag5_read_memory_block
err_t nfctag5_read_memory_block(nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block)
NFC Tag 5 read memory block function.
nfctag5_set_address_mode
err_t nfctag5_set_address_mode(nfctag5_t *ctx, uint8_t mode)
NFC Tag 5 set address mode function.
nfctag5_read_multiple_memory_block
err_t nfctag5_read_multiple_memory_block(nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block, uint8_t num_blocks)
NFC Tag 5 read multiple memory block function.
nfctag5_cfg_t::i2c_address
uint8_t i2c_address
Definition: nfctag5.h:262
nfctag5_format_memory
err_t nfctag5_format_memory(nfctag5_t *ctx)
NFC Tag 5 format memory function.
nfctag5_cfg_t::busy
pin_name_t busy
Definition: nfctag5.h:259
nfctag5_get_busy_pin
uint8_t nfctag5_get_busy_pin(nfctag5_t *ctx)
NFC Tag 5 get busy pin function.
nfctag5_cfg_t::scl
pin_name_t scl
Definition: nfctag5.h:255
nfctag5_block_t::value
uint32_t value
Definition: nfctag5.h:228
nfctag5_t::slave_address
uint8_t slave_address
Definition: nfctag5.h:245
nfctag5_return_value_t
nfctag5_return_value_t
NFC Tag 5 Click return value data.
Definition: nfctag5.h:273
nfctag5_cfg_t::resolution
analog_in_resolution_t resolution
Definition: nfctag5.h:263
nfctag5_t::i2c
i2c_master_t i2c
Definition: nfctag5.h:241
nfctag5_write_multiple_memory_block
err_t nfctag5_write_multiple_memory_block(nfctag5_t *ctx, uint16_t block_addr, nfctag5_block_t *block, uint8_t num_blocks)
NFC Tag 5 write multiple memory block function.