nfc6 2.1.0.0
nfc6.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 NFC6_H
29#define NFC6_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define NFC6_CONTROL_SEND_COMMAND 0x00
75#define NFC6_CONTROL_READ_DATA 0x02
76#define NFC6_CONTROL_POLL_READY 0x03
77#define NFC6_CONTROL_RESET_DEVICE 0x01
78#define NFC6_CONTROL_POLL_READY_FLAG 0x08
79
84#define NFC6_CMD_IDN 0x01
85#define NFC6_CMD_PROTOCOL_SELECT 0x02
86#define NFC6_CMD_POLL_FIELD 0x03
87#define NFC6_CMD_SEND_RECV 0x04
88#define NFC6_CMD_LISTEN 0x05
89#define NFC6_CMD_SEND 0x06
90#define NFC6_CMD_IDLE 0x07
91#define NFC6_CMD_RD_REG 0x08
92#define NFC6_CMD_WR_REG 0x09
93#define NFC6_CMD_SUB_FREQ_RES 0x0B
94#define NFC6_CMD_AC_FILTER 0x0D
95#define NFC6_CMD_ECHO 0x55
96
97 // nfc6_reg
98
113#define NFC6_RSP_FIXED_BYTES 0x80
114#define NFC6_RSP_FIXED_BYTES_MASK 0x8F
115#define NFC6_RSP_LONG_FRAME_MASK 0x60
116#define NFC6_RSP_OK 0x00
117#define NFC6_RSP_ECHO 0x55
118#define NFC6_RSP_MAX_DATA_LEN 528u
119#define NFC6_RSP_READY_TIMEOUT_MS 5000ul
120
125#define NFC6_IDLE_CMD_LENGTH 14
126#define NFC6_IDLE_CMD_WU_SOURCE 0x03
127#define NFC6_IDLE_CMD_ENTER_CTRL_L 0xA1
128#define NFC6_IDLE_CMD_ENTER_CTRL_H 0x00
129#define NFC6_IDLE_CMD_WU_CTRL_L 0xF8
130#define NFC6_IDLE_CMD_WU_CTRL_H 0x01
131#define NFC6_IDLE_CMD_LEAVE_CTRL_L 0x18
132#define NFC6_IDLE_CMD_LEAVE_CTRL_H 0x00
133#define NFC6_IDLE_CMD_WU_PERIOD 0x20
134#define NFC6_IDLE_CMD_OSC_START 0x60
135#define NFC6_IDLE_CMD_DAC_START 0x60
136#define NFC6_IDLE_CMD_DAC_DATA_L 0x00
137#define NFC6_IDLE_CMD_DAC_DATA_H 0x00
138#define NFC6_IDLE_CMD_DAC_DATA_H_MIN 0x00
139#define NFC6_IDLE_CMD_DAC_DATA_H_MAX 0xFC
140#define NFC6_IDLE_CMD_SWINGS_CNT 0x3F
141#define NFC6_IDLE_CMD_MAX_SLEEP 0x01
142#define NFC6_IDLE_RSP_TIMEOUT 0x01
143#define NFC6_IDLE_RSP_TAG_DETECT 0x02
144#define NFC6_IDLE_RSP_LENGTH 1
145#define NFC6_IDLE_CALIB_START 0x80
146
151#define NFC6_PROTOCOL_FIELD_OFF 0
152#define NFC6_PROTOCOL_ISO_15693 1
153#define NFC6_PROTOCOL_ISO_14443A 2
154#define NFC6_PROTOCOL_ISO_14443B 3
155#define NFC6_PROTOCOL_FELICA 4
156
161#define NFC6_TAG_UID_RSP_MAX_DATA_LEN 10
162#define NFC6_TAG_UID_MAX_LEN 7
163#define NFC6_MIFARE_REQA 0x26
164#define NFC6_MIFARE_REQA_LEN 0x07
165#define NFC6_MIFARE_WUPA 0x52
166#define NFC6_MIFARE_CL1 0x93
167#define NFC6_MIFARE_CL2 0x95
168#define NFC6_MIFARE_ANTICOLLISION 0x20
169#define NFC6_MIFARE_ANTICOLLISION_LEN 0x08
170#define NFC6_MIFARE_SELECT 0x70
171#define NFC6_MIFARE_CASCADE_TAG 0x88
172#define NFC6_MIFARE_READ 0x30
173#define NFC6_MIFARE_WRITE 0xA0
174
183#define NFC6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
184#define NFC6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
185
186 // nfc6_set
187
202#define NFC6_MAP_MIKROBUS( cfg, mikrobus ) \
203 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
204 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
205 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
206 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
207 cfg.irq_in = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
208 cfg.irq_out = MIKROBUS( mikrobus, MIKROBUS_INT )
209
210 // nfc6_map
211 // nfc6
212
217typedef struct
218{
219 // Output pins
220 digital_out_t irq_in;
222 // Input pins
223 digital_in_t irq_out;
225 // Modules
226 spi_master_t spi;
228 pin_name_t chip_select;
232} nfc6_t;
233
238typedef struct
239{
240 // Communication gpio pins
241 pin_name_t miso;
242 pin_name_t mosi;
243 pin_name_t sck;
244 pin_name_t cs;
246 // Additional gpio pins
247 pin_name_t irq_in;
248 pin_name_t irq_out;
250 // static variable
251 uint32_t spi_speed;
252 spi_master_mode_t spi_mode;
253 spi_master_chip_select_polarity_t cs_polarity;
255} nfc6_cfg_t;
256
261typedef enum
262{
264 NFC6_ERROR = -1
265
267
284
298err_t nfc6_init ( nfc6_t *ctx, nfc6_cfg_t *cfg );
299
313
327err_t nfc6_send_command ( nfc6_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
328
343err_t nfc6_read_data ( nfc6_t *ctx, uint8_t *data_out, uint16_t buffer_size, uint16_t *rx_len );
344
355err_t nfc6_poll_ready ( nfc6_t *ctx );
356
368
380
393
403
413void nfc6_set_irq_in_pin ( nfc6_t *ctx, uint8_t state );
414
424
436
453err_t nfc6_select_protocol ( nfc6_t *ctx, uint8_t protocol );
454
467err_t nfc6_read_mifare_tag_uid ( nfc6_t *ctx, uint8_t *tag_uid, uint8_t *tag_uid_len );
468
469#ifdef __cplusplus
470}
471#endif
472#endif // NFC6_H
473
474 // nfc6
475
476// ------------------------------------------------------------------------ END
err_t nfc6_init(nfc6_t *ctx, nfc6_cfg_t *cfg)
NFC 6 initialization function.
err_t nfc6_select_protocol(nfc6_t *ctx, uint8_t protocol)
NFC 6 select protocol function.
err_t nfc6_send_command(nfc6_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
NFC 6 send command function.
err_t nfc6_poll_ready_irq(nfc6_t *ctx)
NFC 6 poll ready irq function.
void nfc6_pulse_irq_in(nfc6_t *ctx)
NFC 6 pulse irq in function.
err_t nfc6_reset_device(nfc6_t *ctx)
NFC 6 reset device function.
uint8_t nfc6_get_irq_out_pin(nfc6_t *ctx)
NFC 6 get irq out pin function.
void nfc6_cfg_setup(nfc6_cfg_t *cfg)
NFC 6 configuration object setup function.
void nfc6_set_irq_in_pin(nfc6_t *ctx, uint8_t state)
NFC 6 set irq in pin function.
err_t nfc6_default_cfg(nfc6_t *ctx)
NFC 6 default configuration function.
err_t nfc6_check_command_echo(nfc6_t *ctx)
NFC 6 check command echo function.
err_t nfc6_read_mifare_tag_uid(nfc6_t *ctx, uint8_t *tag_uid, uint8_t *tag_uid_len)
NFC 6 read MIFARE tag UID function.
err_t nfc6_read_data(nfc6_t *ctx, uint8_t *data_out, uint16_t buffer_size, uint16_t *rx_len)
NFC 6 read data function.
err_t nfc6_calibrate_device(nfc6_t *ctx)
NFC 6 calibrate device function.
err_t nfc6_poll_ready(nfc6_t *ctx)
NFC 6 poll ready function.
nfc6_return_value_t
NFC 6 Click return value data.
Definition nfc6.h:262
@ NFC6_ERROR
Definition nfc6.h:264
@ NFC6_OK
Definition nfc6.h:263
This file contains SPI specific macros, functions, etc.
NFC 6 Click configuration object.
Definition nfc6.h:239
pin_name_t irq_in
Definition nfc6.h:247
spi_master_chip_select_polarity_t cs_polarity
Definition nfc6.h:253
pin_name_t sck
Definition nfc6.h:243
spi_master_mode_t spi_mode
Definition nfc6.h:252
pin_name_t mosi
Definition nfc6.h:242
uint32_t spi_speed
Definition nfc6.h:251
pin_name_t miso
Definition nfc6.h:241
pin_name_t irq_out
Definition nfc6.h:248
pin_name_t cs
Definition nfc6.h:244
NFC 6 Click context object.
Definition nfc6.h:218
digital_in_t irq_out
Definition nfc6.h:223
spi_master_t spi
Definition nfc6.h:226
digital_out_t irq_in
Definition nfc6.h:220
pin_name_t chip_select
Definition nfc6.h:228
uint8_t cal_dac_data_h
Definition nfc6.h:230