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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define NFC6_CONTROL_SEND_COMMAND 0x00
61 #define NFC6_CONTROL_READ_DATA 0x02
62 #define NFC6_CONTROL_POLL_READY 0x03
63 #define NFC6_CONTROL_RESET_DEVICE 0x01
64 #define NFC6_CONTROL_POLL_READY_FLAG 0x08
65 
70 #define NFC6_CMD_IDN 0x01
71 #define NFC6_CMD_PROTOCOL_SELECT 0x02
72 #define NFC6_CMD_POLL_FIELD 0x03
73 #define NFC6_CMD_SEND_RECV 0x04
74 #define NFC6_CMD_LISTEN 0x05
75 #define NFC6_CMD_SEND 0x06
76 #define NFC6_CMD_IDLE 0x07
77 #define NFC6_CMD_RD_REG 0x08
78 #define NFC6_CMD_WR_REG 0x09
79 #define NFC6_CMD_SUB_FREQ_RES 0x0B
80 #define NFC6_CMD_AC_FILTER 0x0D
81 #define NFC6_CMD_ECHO 0x55
82  // nfc6_reg
84 
99 #define NFC6_RSP_FIXED_BYTES 0x80
100 #define NFC6_RSP_FIXED_BYTES_MASK 0x8F
101 #define NFC6_RSP_LONG_FRAME_MASK 0x60
102 #define NFC6_RSP_OK 0x00
103 #define NFC6_RSP_ECHO 0x55
104 #define NFC6_RSP_MAX_DATA_LEN 528u
105 #define NFC6_RSP_READY_TIMEOUT_MS 5000ul
106 
111 #define NFC6_IDLE_CMD_LENGTH 14
112 #define NFC6_IDLE_CMD_WU_SOURCE 0x03
113 #define NFC6_IDLE_CMD_ENTER_CTRL_L 0xA1
114 #define NFC6_IDLE_CMD_ENTER_CTRL_H 0x00
115 #define NFC6_IDLE_CMD_WU_CTRL_L 0xF8
116 #define NFC6_IDLE_CMD_WU_CTRL_H 0x01
117 #define NFC6_IDLE_CMD_LEAVE_CTRL_L 0x18
118 #define NFC6_IDLE_CMD_LEAVE_CTRL_H 0x00
119 #define NFC6_IDLE_CMD_WU_PERIOD 0x20
120 #define NFC6_IDLE_CMD_OSC_START 0x60
121 #define NFC6_IDLE_CMD_DAC_START 0x60
122 #define NFC6_IDLE_CMD_DAC_DATA_L 0x00
123 #define NFC6_IDLE_CMD_DAC_DATA_H 0x00
124 #define NFC6_IDLE_CMD_DAC_DATA_H_MIN 0x00
125 #define NFC6_IDLE_CMD_DAC_DATA_H_MAX 0xFC
126 #define NFC6_IDLE_CMD_SWINGS_CNT 0x3F
127 #define NFC6_IDLE_CMD_MAX_SLEEP 0x01
128 #define NFC6_IDLE_RSP_TIMEOUT 0x01
129 #define NFC6_IDLE_RSP_TAG_DETECT 0x02
130 #define NFC6_IDLE_RSP_LENGTH 1
131 #define NFC6_IDLE_CALIB_START 0x80
132 
137 #define NFC6_PROTOCOL_FIELD_OFF 0
138 #define NFC6_PROTOCOL_ISO_15693 1
139 #define NFC6_PROTOCOL_ISO_14443A 2
140 #define NFC6_PROTOCOL_ISO_14443B 3
141 #define NFC6_PROTOCOL_FELICA 4
142 
147 #define NFC6_TAG_UID_RSP_MAX_DATA_LEN 10
148 #define NFC6_TAG_UID_MAX_LEN 7
149 #define NFC6_MIFARE_REQA 0x26
150 #define NFC6_MIFARE_REQA_LEN 0x07
151 #define NFC6_MIFARE_WUPA 0x52
152 #define NFC6_MIFARE_CL1 0x93
153 #define NFC6_MIFARE_CL2 0x95
154 #define NFC6_MIFARE_ANTICOLLISION 0x20
155 #define NFC6_MIFARE_ANTICOLLISION_LEN 0x08
156 #define NFC6_MIFARE_SELECT 0x70
157 #define NFC6_MIFARE_CASCADE_TAG 0x88
158 #define NFC6_MIFARE_READ 0x30
159 #define NFC6_MIFARE_WRITE 0xA0
160 
169 #define NFC6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
170 #define NFC6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
171  // nfc6_set
173 
188 #define NFC6_MAP_MIKROBUS( cfg, mikrobus ) \
189  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
190  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
191  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
192  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
193  cfg.irq_in = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
194  cfg.irq_out = MIKROBUS( mikrobus, MIKROBUS_INT )
195  // nfc6_map // nfc6
198 
203 typedef struct
204 {
205  // Output pins
206  digital_out_t irq_in;
208  // Input pins
209  digital_in_t irq_out;
211  // Modules
212  spi_master_t spi;
214  pin_name_t chip_select;
216  uint8_t cal_dac_data_h;
218 } nfc6_t;
219 
224 typedef struct
225 {
226  // Communication gpio pins
227  pin_name_t miso;
228  pin_name_t mosi;
229  pin_name_t sck;
230  pin_name_t cs;
232  // Additional gpio pins
233  pin_name_t irq_in;
234  pin_name_t irq_out;
236  // static variable
237  uint32_t spi_speed;
238  spi_master_mode_t spi_mode;
239  spi_master_chip_select_polarity_t cs_polarity;
241 } nfc6_cfg_t;
242 
247 typedef enum
248 {
249  NFC6_OK = 0,
250  NFC6_ERROR = -1
251 
253 
270 
284 err_t nfc6_init ( nfc6_t *ctx, nfc6_cfg_t *cfg );
285 
298 err_t nfc6_default_cfg ( nfc6_t *ctx );
299 
313 err_t nfc6_send_command ( nfc6_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
314 
329 err_t nfc6_read_data ( nfc6_t *ctx, uint8_t *data_out, uint16_t buffer_size, uint16_t *rx_len );
330 
341 err_t nfc6_poll_ready ( nfc6_t *ctx );
342 
354 
365 err_t nfc6_reset_device ( nfc6_t *ctx );
366 
379 
388 void nfc6_pulse_irq_in ( nfc6_t *ctx );
389 
399 void nfc6_set_irq_in_pin ( nfc6_t *ctx, uint8_t state );
400 
409 uint8_t nfc6_get_irq_out_pin ( nfc6_t *ctx );
410 
422 
439 err_t nfc6_select_protocol ( nfc6_t *ctx, uint8_t protocol );
440 
453 err_t nfc6_read_mifare_tag_uid ( nfc6_t *ctx, uint8_t *tag_uid, uint8_t *tag_uid_len );
454 
455 #ifdef __cplusplus
456 }
457 #endif
458 #endif // NFC6_H
459  // nfc6
461 
462 // ------------------------------------------------------------------------ END
nfc6_cfg_t::irq_in
pin_name_t irq_in
Definition: nfc6.h:233
nfc6_select_protocol
err_t nfc6_select_protocol(nfc6_t *ctx, uint8_t protocol)
NFC 6 select protocol function.
nfc6_t::irq_in
digital_out_t irq_in
Definition: nfc6.h:206
nfc6_get_irq_out_pin
uint8_t nfc6_get_irq_out_pin(nfc6_t *ctx)
NFC 6 get irq out pin function.
NFC6_OK
@ NFC6_OK
Definition: nfc6.h:249
nfc6_t::irq_out
digital_in_t irq_out
Definition: nfc6.h:209
nfc6_cfg_t::sck
pin_name_t sck
Definition: nfc6.h:229
nfc6_cfg_t
NFC 6 Click configuration object.
Definition: nfc6.h:225
spi_specifics.h
This file contains SPI specific macros, functions, etc.
nfc6_cfg_t::cs
pin_name_t cs
Definition: nfc6.h:230
nfc6_poll_ready
err_t nfc6_poll_ready(nfc6_t *ctx)
NFC 6 poll ready function.
nfc6_return_value_t
nfc6_return_value_t
NFC 6 Click return value data.
Definition: nfc6.h:248
nfc6_send_command
err_t nfc6_send_command(nfc6_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
NFC 6 send command function.
nfc6_reset_device
err_t nfc6_reset_device(nfc6_t *ctx)
NFC 6 reset device function.
nfc6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: nfc6.h:239
nfc6_read_mifare_tag_uid
err_t nfc6_read_mifare_tag_uid(nfc6_t *ctx, uint8_t *tag_uid, uint8_t *tag_uid_len)
NFC 6 get MIFARE tag UID function.
nfc6_t
NFC 6 Click context object.
Definition: nfc6.h:204
nfc6_read_data
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.
nfc6_cfg_t::miso
pin_name_t miso
Definition: nfc6.h:227
nfc6_t::chip_select
pin_name_t chip_select
Definition: nfc6.h:214
nfc6_pulse_irq_in
void nfc6_pulse_irq_in(nfc6_t *ctx)
NFC 6 pulse irq in function.
NFC6_ERROR
@ NFC6_ERROR
Definition: nfc6.h:250
nfc6_calibrate_device
err_t nfc6_calibrate_device(nfc6_t *ctx)
NFC 6 calibrate device function.
nfc6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: nfc6.h:238
nfc6_check_command_echo
err_t nfc6_check_command_echo(nfc6_t *ctx)
NFC 6 check command echo function.
nfc6_set_irq_in_pin
void nfc6_set_irq_in_pin(nfc6_t *ctx, uint8_t state)
NFC 6 set irq in pin function.
nfc6_init
err_t nfc6_init(nfc6_t *ctx, nfc6_cfg_t *cfg)
NFC 6 initialization function.
nfc6_t::cal_dac_data_h
uint8_t cal_dac_data_h
Definition: nfc6.h:216
nfc6_cfg_t::mosi
pin_name_t mosi
Definition: nfc6.h:228
nfc6_poll_ready_irq
err_t nfc6_poll_ready_irq(nfc6_t *ctx)
NFC 6 poll ready irq function.
nfc6_default_cfg
err_t nfc6_default_cfg(nfc6_t *ctx)
NFC 6 default configuration function.
nfc6_cfg_t::irq_out
pin_name_t irq_out
Definition: nfc6.h:234
nfc6_t::spi
spi_master_t spi
Definition: nfc6.h:212
nfc6_cfg_setup
void nfc6_cfg_setup(nfc6_cfg_t *cfg)
NFC 6 configuration object setup function.
nfc6_cfg_t::spi_speed
uint32_t spi_speed
Definition: nfc6.h:237