nfc 2.1.0.0
nfc.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2021 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 NFC_H
29#define NFC_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_i2c_master.h"
38
59#define NFC_RF_DISCOVER_MAP_CMD 0x00
60#define NFC_RF_DISCOVER_MAP_RSP 0x00
61#define NFC_RF_SET_LISTEN_MODE_ROUTING_CMD 0x01
62#define NFC_RF_SET_LISTEN_MODE_ROUTING_RSP 0x01
63#define NFC_RF_GET_LISTEN_MODE_ROUTING_CMD 0x02
64#define NFC_RF_GET_LISTEN_MODE_ROUTING_RSP 0x02
65#define NFC_RF_GET_LISTEN_MODE_ROUTING_NTF 0x02
66#define NFC_RF_DISCOVER_CMD 0x03
67#define NFC_RF_DISCOVER_RSP 0x03
68#define NFC_RF_DISCOVER_NTF 0x03
69#define NFC_RF_DISCOVER_SELECT_CMD 0x04
70#define NFC_RF_DISCOVER_SELECT_RSP 0x04
71#define NFC_RF_INTF_ACTIVATED_NTF 0x05
72#define NFC_RF_DEACTIVATE_CMD 0x06
73#define NFC_RF_DEACTIVATE_RSP 0x06
74#define NFC_RF_DEACTIVATE_NTF 0x06
75#define NFC_RF_FIELD_INFO_NTF 0x07
76#define NFC_RF_T3T_POLLING_CMD 0x08
77#define NFC_RF_T3T_POLLING_RSP 0x08
78#define NFC_RF_T3T_POLLING_NTF 0x08
79#define NFC_RF_NFCEE_ACTION_NTF 0x09
80#define NFC_RF_NFCEE_DISCOVERY_REQ_NTF 0x0A
81#define NFC_RF_PARAMETER_UPDATE_CMD 0x0B
82#define NFC_RF_PARAMETER_UPDATE_RSP 0x0B
83
84#define NFC_NFCEE_DISCOVER_CMD 0x00
85#define NFC_NFCEE_DISCOVER_RSP 0x00
86#define NFC_NFCEE_DISCOVER_NTF 0x00
87#define NFC_NFCEE_MODE_SET_CMD 0x01
88#define NFC_NFCEE_MODE_SET_RSP 0x01
89
90#define NFC_NCI_PROPRIETARY_ACT_CMD 0x02
91#define NFC_NCI_PROPRIETARY_ACT_RSP 0x02
92#define NFC_RESET_KEEP_CONFIG 0x00
93#define NFC_RESET_CLEAR_CONFIG 0x01
94
99#define NFC_STATUS_OK 0x00
100#define NFC_STATUS_REJECTED 0x01
101#define NFC_STATUS_RF_FRAME_CORRUPTED 0x02
102#define NFC_STATUS_FAILED 0x03
103#define NFC_STATUS_NOT_INITIALIZED 0x04
104#define NFC_STATUS_SYNTAX_ERROR 0x05
105#define NFC_STATUS_SEMANTIC_ERROR 0x06
106
107#define NFC_STATUS_INVALID_PARAM 0x09
108#define NFC_STATUS_MESSAGE_SIZE_EXCEEDED 0x0A
109
110#define NFC_DISCOVERY_ALREADY_STARTED 0xA0
111#define NFC_DISCOVERY_TARGET_ACTIVATION_FAILED 0xA1
112#define NFC_DISCOVERY_TEAR_DOWN 0xA2
113
114#define NFC_RF_TRANSMISSION_ERROR 0xB0
115#define NFC_RF_PROTOCOL_ERROR 0xB1
116#define NFC_RF_TIMEOUT_ERROR 0xB2
117
118#define NFC_NFCEE_INTERFACE_ACTIVATION_FAILED 0xC0
119#define NFC_NFCEE_TRANSMISSION_ERROR 0xC1
120#define NFC_NFCEE_PROTOCOL_ERROR 0xC2
121#define NFC_NFCEE_TIMEOUT_ERROR 0xC3
122
123#define NFC_NFC_RF_TECHNOLOGY_A 0x00
124#define NFC_NFC_RF_TECHNOLOGY_B 0x01
125#define NFC_NFC_RF_TECHNOLOGY_F 0x02
126#define NFC_NFC_RF_TECHNOLOGY_15693 0x03
127
132#define NFC_NFC_A_PASSIVE_POLL_MODE 0x00
133#define NFC_NFC_B_PASSIVE_POLL_MODE 0x01
134#define NFC_NFC_F_PASSIVE_POLL_MODE 0x02
135#define NFC_NFC_A_ACTIVE_POLL_MODE 0x03
136#define NFC_NFC_F_ACTIVE_POLL_MODE 0x05
137#define NFC_NFC_15693_PASSIVE_POLL_MODE 0x06
138
139#define NFC_NFC_A_PASSIVE_LISTEN_MODE 0x80
140#define NFC_NFC_B_PASSIVE_LISTEN_MODE 0x81
141#define NFC_NFC_F_PASSIVE_LISTEN_MODE 0x82
142#define NFC_NFC_A_ACTIVE_LISTEN_MODE 0x83
143#define NFC_NFC_F_ACTIVE_LISTEN_MODE 0x85
144#define NFC_NFC_15693_PASSIVE_LISTEN_MODE 0x86
145
150#define NFC_PROTOCOL_UNDETERMINED 0x00
151#define NFC_PROTOCOL_T1T 0x01
152#define NFC_PROTOCOL_T2T 0x02
153#define NFC_PROTOCOL_T3T 0x03
154#define NFC_PROTOCOL_ISO_DEP 0x04
155#define NFC_PROTOCOL_NFC_DEP 0x05
156
157#define NFC_NFCEE_DIRECT_RF_INTERFACE 0x00
158#define NFC_FRAME_RF_INTERFACE 0x01
159#define NFC_ISO_DEP_RF_INTERFACE 0x02
160#define NFC_NFC_DEP_RF_INTERFACE 0x03
161
166#define NFC_APDU 0x00
167#define NFC_HCI_ACCES 0x01
168#define NFC_TYPE_3_TAG_COMMAND_SET 0x02
169#define NFC_TRANSPARENT 0x03
170
175#define NFC_NFC_BIT_RATE_106 0x00
176#define NFC_NFC_BIT_RATE_212 0x01
177#define NFC_NFC_BIT_RATE_424 0x02
178#define NFC_NFC_BIT_RATE_848 0x03
179#define NFC_NFC_BIT_RATE_1695 0x04
180#define NFC_NFC_BIT_RATE_3390 0x05
181#define NFC_NFC_BIT_RATE_6780 0x06
182
187#define NFC_IRQ_STATE_LOW 0x00
188#define NFC_IRQ_STATE_HIGH 0x01
189
194#define NFC_GROUP_ID_CORE 0x00
195#define NFC_GROUP_ID_RF_MANAGEMENT 0x01
196#define NFC_GROUP_ID_NFC_MANAGEMENT 0x02
197#define NFC_GROUP_ID_PROPRIETARY 0x0F
198
203#define NFC_CORE_RESET_CMD 0x00
204#define NFC_CORE_RESET_RSP 0x00
205#define NFC_CORE_RESET_NTF 0x00
206#define NFC_CORE_INIT_CMD 0x01
207#define NFC_CORE_INIT_RSP 0x01
208#define NFC_CORE_SET_CONFIG_CMD 0x02
209#define NFC_CORE_SET_CONFIG_RSP 0x02
210#define NFC_CORE_GET_CONFIG_CMD 0x03
211#define NFC_CORE_GET_CONFIG_RSP 0x03
212#define NFC_CORE_CONN_CREATE_CMD 0x04
213#define NFC_CORE_CONN_CREATE_RSP 0x04
214#define NFC_CORE_CONN_CLOSE_CMD 0x05
215#define NFC_CORE_CONN_CLOSE_RSP 0x05
216#define NFC_CORE_CONN_CREDITS_NTF 0x06
217#define NFC_CORE_GENERIC_ERROR_NTF 0x07
218#define NFC_CORE_INTERFACE_ERROR_NTF 0x08
219
225#define NFC_I2C_ADDR_0 0x28
226#define NFC_I2C_ADDR_1 0x29
227 // nfc_set
229
244#define NFC_MAP_MIKROBUS( cfg, mikrobus ) \
245 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
246 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
247 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
248 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
249 // nfc_map // nfc
252
257typedef struct
258{
259 // Output pins
260 digital_out_t rst;
262 // Input pins
263 digital_in_t int_pin;
265 // Modules
266 i2c_master_t i2c;
268 // I2C slave address
271} nfc_t;
272
277typedef struct
278{
279 pin_name_t scl;
280 pin_name_t sda;
282 pin_name_t rst;
283 pin_name_t int_pin;
285 uint32_t i2c_speed;
286 uint8_t i2c_address;
288} nfc_cfg_t;
289
294typedef struct
295{
298 uint8_t group_ident;
301 uint8_t payload[ 256 ];
303
308typedef struct
309{
312 uint8_t conn_ident;
314 uint8_t payload[ 256 ];
316
321typedef enum
322{
324 NFC_ERROR = -1
325
327
344
358err_t nfc_init ( nfc_t *ctx, nfc_cfg_t *cfg );
359
371void nfc_default_cfg ( nfc_t *ctx, control_packet_t *ctrl_pck );
372
386err_t nfc_generic_write ( nfc_t *ctx, uint8_t *p_tx_data, uint8_t n_bytes );
387
401err_t nfc_generic_read ( nfc_t *ctx, uint8_t *p_rx_h_data, uint8_t *p_rx_p_data );
402
411void nfc_hw_reset( nfc_t *ctx );
412
422uint8_t nfc_get_data ( nfc_t *ctx, uint8_t *p_rx_data );
423
434
445
456uint8_t nfc_check_irq ( nfc_t *ctx );
457
467
477
486
496void nfc_cmd_antenna_test ( nfc_t *ctx, uint8_t sel_ant );
497
507
516void nfc_core_reset ( nfc_t *ctx );
517
526void nfc_init_core ( nfc_t *ctx );
527
537
547
557
567
577void nfc_cmd_authenticate_sector ( nfc_t *ctx, uint8_t sel_sect_addr );
578
588
589#ifdef __cplusplus
590}
591#endif
592#endif // NFC_H
593 // nfc
595
596// ------------------------------------------------------------------------ END
void nfc_read_ctrl_packet_data(nfc_t *ctx, control_packet_t *ctrl_pck)
Read control packet data function.
uint8_t nfc_get_data(nfc_t *ctx, uint8_t *p_rx_data)
Get data function.
err_t nfc_generic_read(nfc_t *ctx, uint8_t *p_rx_h_data, uint8_t *p_rx_p_data)
NFC I2C reading function.
void nfc_hw_reset(nfc_t *ctx)
HW reset function.
void nfc_cmd_disable_standby_mode(nfc_t *ctx)
Disable standby mode command function.
void nfc_default_cfg(nfc_t *ctx, control_packet_t *ctrl_pck)
NFC default configuration function.
void nfc_cmd_core_reset(nfc_t *ctx)
Core reset command function.
void nfc_activate_rmt_mifare_card(nfc_t *ctx)
Activate remote mifare card command function.
void nfc_core_set_default_config(nfc_t *ctx)
Set default configuration function.
void nfc_write_ctrl_packet_data(nfc_t *ctx, control_packet_t ctrl_pck)
Write control packet data function.
void nfc_init_core(nfc_t *ctx)
Core initialization command function.
void nfc_core_set_protocol_config(nfc_t *ctx)
Set protocol configuration function.
void nfc_cmd_card_disconnected(nfc_t *ctx)
Card disconnected command function.
void nfc_cmd_start_discovery(nfc_t *ctx)
Start discovery command function.
err_t nfc_generic_write(nfc_t *ctx, uint8_t *p_tx_data, uint8_t n_bytes)
NFC I2C writing function.
void nfc_cmd_antenna_test(nfc_t *ctx, uint8_t sel_ant)
Antenna test function.
void nfc_cmd_core_init(nfc_t *ctx)
Core init command function.
uint8_t nfc_check_irq(nfc_t *ctx)
Check IRQ ststus function.
void nfc_core_reset(nfc_t *ctx)
Core reset command function.
void nfc_cmd_test_procedure(nfc_t *ctx)
NFC test procedure command function.
void nfc_cmd_authenticate_sector(nfc_t *ctx, uint8_t sel_sect_addr)
Authenticate sector command function.
void nfc_cfg_setup(nfc_cfg_t *cfg)
NFC configuration object setup function.
err_t nfc_init(nfc_t *ctx, nfc_cfg_t *cfg)
NFC initialization function.
nfc_return_value_t
NFC Click return value data.
Definition: nfc.h:322
@ NFC_OK
Definition: nfc.h:323
@ NFC_ERROR
Definition: nfc.h:324
NFC Click control packet object.
Definition: nfc.h:295
uint8_t pck_bound_flag
Definition: nfc.h:297
uint8_t payload_length
Definition: nfc.h:300
uint8_t opcode_ident
Definition: nfc.h:299
uint8_t message_type
Definition: nfc.h:296
uint8_t group_ident
Definition: nfc.h:298
NFC Click data packet object.
Definition: nfc.h:309
uint8_t pck_bound_flag
Definition: nfc.h:311
uint8_t conn_ident
Definition: nfc.h:312
uint8_t payload_length
Definition: nfc.h:313
uint8_t message_type
Definition: nfc.h:310
NFC Click configuration object.
Definition: nfc.h:278
uint32_t i2c_speed
Definition: nfc.h:285
pin_name_t scl
Definition: nfc.h:279
pin_name_t int_pin
Definition: nfc.h:283
pin_name_t sda
Definition: nfc.h:280
pin_name_t rst
Definition: nfc.h:282
uint8_t i2c_address
Definition: nfc.h:286
NFC Click context object.
Definition: nfc.h:258
digital_in_t int_pin
Definition: nfc.h:263
i2c_master_t i2c
Definition: nfc.h:266
digital_out_t rst
Definition: nfc.h:260
uint8_t slave_address
Definition: nfc.h:269