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
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define NFC_RF_DISCOVER_MAP_CMD 0x00
74#define NFC_RF_DISCOVER_MAP_RSP 0x00
75#define NFC_RF_SET_LISTEN_MODE_ROUTING_CMD 0x01
76#define NFC_RF_SET_LISTEN_MODE_ROUTING_RSP 0x01
77#define NFC_RF_GET_LISTEN_MODE_ROUTING_CMD 0x02
78#define NFC_RF_GET_LISTEN_MODE_ROUTING_RSP 0x02
79#define NFC_RF_GET_LISTEN_MODE_ROUTING_NTF 0x02
80#define NFC_RF_DISCOVER_CMD 0x03
81#define NFC_RF_DISCOVER_RSP 0x03
82#define NFC_RF_DISCOVER_NTF 0x03
83#define NFC_RF_DISCOVER_SELECT_CMD 0x04
84#define NFC_RF_DISCOVER_SELECT_RSP 0x04
85#define NFC_RF_INTF_ACTIVATED_NTF 0x05
86#define NFC_RF_DEACTIVATE_CMD 0x06
87#define NFC_RF_DEACTIVATE_RSP 0x06
88#define NFC_RF_DEACTIVATE_NTF 0x06
89#define NFC_RF_FIELD_INFO_NTF 0x07
90#define NFC_RF_T3T_POLLING_CMD 0x08
91#define NFC_RF_T3T_POLLING_RSP 0x08
92#define NFC_RF_T3T_POLLING_NTF 0x08
93#define NFC_RF_NFCEE_ACTION_NTF 0x09
94#define NFC_RF_NFCEE_DISCOVERY_REQ_NTF 0x0A
95#define NFC_RF_PARAMETER_UPDATE_CMD 0x0B
96#define NFC_RF_PARAMETER_UPDATE_RSP 0x0B
97
98#define NFC_NFCEE_DISCOVER_CMD 0x00
99#define NFC_NFCEE_DISCOVER_RSP 0x00
100#define NFC_NFCEE_DISCOVER_NTF 0x00
101#define NFC_NFCEE_MODE_SET_CMD 0x01
102#define NFC_NFCEE_MODE_SET_RSP 0x01
103
104#define NFC_NCI_PROPRIETARY_ACT_CMD 0x02
105#define NFC_NCI_PROPRIETARY_ACT_RSP 0x02
106#define NFC_RESET_KEEP_CONFIG 0x00
107#define NFC_RESET_CLEAR_CONFIG 0x01
108
113#define NFC_STATUS_OK 0x00
114#define NFC_STATUS_REJECTED 0x01
115#define NFC_STATUS_RF_FRAME_CORRUPTED 0x02
116#define NFC_STATUS_FAILED 0x03
117#define NFC_STATUS_NOT_INITIALIZED 0x04
118#define NFC_STATUS_SYNTAX_ERROR 0x05
119#define NFC_STATUS_SEMANTIC_ERROR 0x06
120
121#define NFC_STATUS_INVALID_PARAM 0x09
122#define NFC_STATUS_MESSAGE_SIZE_EXCEEDED 0x0A
123
124#define NFC_DISCOVERY_ALREADY_STARTED 0xA0
125#define NFC_DISCOVERY_TARGET_ACTIVATION_FAILED 0xA1
126#define NFC_DISCOVERY_TEAR_DOWN 0xA2
127
128#define NFC_RF_TRANSMISSION_ERROR 0xB0
129#define NFC_RF_PROTOCOL_ERROR 0xB1
130#define NFC_RF_TIMEOUT_ERROR 0xB2
131
132#define NFC_NFCEE_INTERFACE_ACTIVATION_FAILED 0xC0
133#define NFC_NFCEE_TRANSMISSION_ERROR 0xC1
134#define NFC_NFCEE_PROTOCOL_ERROR 0xC2
135#define NFC_NFCEE_TIMEOUT_ERROR 0xC3
136
137#define NFC_NFC_RF_TECHNOLOGY_A 0x00
138#define NFC_NFC_RF_TECHNOLOGY_B 0x01
139#define NFC_NFC_RF_TECHNOLOGY_F 0x02
140#define NFC_NFC_RF_TECHNOLOGY_15693 0x03
141
146#define NFC_NFC_A_PASSIVE_POLL_MODE 0x00
147#define NFC_NFC_B_PASSIVE_POLL_MODE 0x01
148#define NFC_NFC_F_PASSIVE_POLL_MODE 0x02
149#define NFC_NFC_A_ACTIVE_POLL_MODE 0x03
150#define NFC_NFC_F_ACTIVE_POLL_MODE 0x05
151#define NFC_NFC_15693_PASSIVE_POLL_MODE 0x06
152
153#define NFC_NFC_A_PASSIVE_LISTEN_MODE 0x80
154#define NFC_NFC_B_PASSIVE_LISTEN_MODE 0x81
155#define NFC_NFC_F_PASSIVE_LISTEN_MODE 0x82
156#define NFC_NFC_A_ACTIVE_LISTEN_MODE 0x83
157#define NFC_NFC_F_ACTIVE_LISTEN_MODE 0x85
158#define NFC_NFC_15693_PASSIVE_LISTEN_MODE 0x86
159
164#define NFC_PROTOCOL_UNDETERMINED 0x00
165#define NFC_PROTOCOL_T1T 0x01
166#define NFC_PROTOCOL_T2T 0x02
167#define NFC_PROTOCOL_T3T 0x03
168#define NFC_PROTOCOL_ISO_DEP 0x04
169#define NFC_PROTOCOL_NFC_DEP 0x05
170
171#define NFC_NFCEE_DIRECT_RF_INTERFACE 0x00
172#define NFC_FRAME_RF_INTERFACE 0x01
173#define NFC_ISO_DEP_RF_INTERFACE 0x02
174#define NFC_NFC_DEP_RF_INTERFACE 0x03
175
180#define NFC_APDU 0x00
181#define NFC_HCI_ACCES 0x01
182#define NFC_TYPE_3_TAG_COMMAND_SET 0x02
183#define NFC_TRANSPARENT 0x03
184
189#define NFC_NFC_BIT_RATE_106 0x00
190#define NFC_NFC_BIT_RATE_212 0x01
191#define NFC_NFC_BIT_RATE_424 0x02
192#define NFC_NFC_BIT_RATE_848 0x03
193#define NFC_NFC_BIT_RATE_1695 0x04
194#define NFC_NFC_BIT_RATE_3390 0x05
195#define NFC_NFC_BIT_RATE_6780 0x06
196
201#define NFC_IRQ_STATE_LOW 0x00
202#define NFC_IRQ_STATE_HIGH 0x01
203
208#define NFC_GROUP_ID_CORE 0x00
209#define NFC_GROUP_ID_RF_MANAGEMENT 0x01
210#define NFC_GROUP_ID_NFC_MANAGEMENT 0x02
211#define NFC_GROUP_ID_PROPRIETARY 0x0F
212
217#define NFC_CORE_RESET_CMD 0x00
218#define NFC_CORE_RESET_RSP 0x00
219#define NFC_CORE_RESET_NTF 0x00
220#define NFC_CORE_INIT_CMD 0x01
221#define NFC_CORE_INIT_RSP 0x01
222#define NFC_CORE_SET_CONFIG_CMD 0x02
223#define NFC_CORE_SET_CONFIG_RSP 0x02
224#define NFC_CORE_GET_CONFIG_CMD 0x03
225#define NFC_CORE_GET_CONFIG_RSP 0x03
226#define NFC_CORE_CONN_CREATE_CMD 0x04
227#define NFC_CORE_CONN_CREATE_RSP 0x04
228#define NFC_CORE_CONN_CLOSE_CMD 0x05
229#define NFC_CORE_CONN_CLOSE_RSP 0x05
230#define NFC_CORE_CONN_CREDITS_NTF 0x06
231#define NFC_CORE_GENERIC_ERROR_NTF 0x07
232#define NFC_CORE_INTERFACE_ERROR_NTF 0x08
233
239#define NFC_I2C_ADDR_0 0x28
240#define NFC_I2C_ADDR_1 0x29
241
242 // nfc_set
243
258#define NFC_MAP_MIKROBUS( cfg, mikrobus ) \
259 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
260 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
261 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
262 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
263
264 // nfc_map
265 // nfc
266
271typedef struct
272{
273 // Output pins
274 digital_out_t rst;
276 // Input pins
277 digital_in_t int_pin;
279 // Modules
280 i2c_master_t i2c;
282 // I2C slave address
285} nfc_t;
286
291typedef struct
292{
293 pin_name_t scl;
294 pin_name_t sda;
296 pin_name_t rst;
297 pin_name_t int_pin;
299 uint32_t i2c_speed;
300 uint8_t i2c_address;
302} nfc_cfg_t;
303
308typedef struct
309{
312 uint8_t group_ident;
315 uint8_t payload[ 256 ];
317
322typedef struct
323{
326 uint8_t conn_ident;
328 uint8_t payload[ 256 ];
330
335typedef enum
336{
338 NFC_ERROR = -1
339
341
358
372err_t nfc_init ( nfc_t *ctx, nfc_cfg_t *cfg );
373
385void nfc_default_cfg ( nfc_t *ctx, control_packet_t *ctrl_pck );
386
400err_t nfc_generic_write ( nfc_t *ctx, uint8_t *p_tx_data, uint8_t n_bytes );
401
415err_t nfc_generic_read ( nfc_t *ctx, uint8_t *p_rx_h_data, uint8_t *p_rx_p_data );
416
425void nfc_hw_reset( nfc_t *ctx );
426
436uint8_t nfc_get_data ( nfc_t *ctx, uint8_t *p_rx_data );
437
448
459
470uint8_t nfc_check_irq ( nfc_t *ctx );
471
481
491
500
510void nfc_cmd_antenna_test ( nfc_t *ctx, uint8_t sel_ant );
511
521
530void nfc_core_reset ( nfc_t *ctx );
531
540void nfc_init_core ( nfc_t *ctx );
541
551
561
571
581
591void nfc_cmd_authenticate_sector ( nfc_t *ctx, uint8_t sel_sect_addr );
592
602
603#ifdef __cplusplus
604}
605#endif
606#endif // NFC_H
607
608 // nfc
609
610// ------------------------------------------------------------------------ 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:336
@ NFC_OK
Definition nfc.h:337
@ NFC_ERROR
Definition nfc.h:338
NFC Click control packet object.
Definition nfc.h:309
uint8_t pck_bound_flag
Definition nfc.h:311
uint8_t payload_length
Definition nfc.h:314
uint8_t opcode_ident
Definition nfc.h:313
uint8_t message_type
Definition nfc.h:310
uint8_t group_ident
Definition nfc.h:312
NFC Click data packet object.
Definition nfc.h:323
uint8_t pck_bound_flag
Definition nfc.h:325
uint8_t conn_ident
Definition nfc.h:326
uint8_t payload_length
Definition nfc.h:327
uint8_t message_type
Definition nfc.h:324
NFC Click configuration object.
Definition nfc.h:292
uint32_t i2c_speed
Definition nfc.h:299
pin_name_t scl
Definition nfc.h:293
pin_name_t int_pin
Definition nfc.h:297
pin_name_t sda
Definition nfc.h:294
pin_name_t rst
Definition nfc.h:296
uint8_t i2c_address
Definition nfc.h:300
NFC Click context object.
Definition nfc.h:272
digital_in_t int_pin
Definition nfc.h:277
i2c_master_t i2c
Definition nfc.h:280
digital_out_t rst
Definition nfc.h:274
uint8_t slave_address
Definition nfc.h:283