rfid 2.0.0.0
rfid.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 RFID_H
29#define RFID_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 "drv_uart.h"
53
74#define RFID_SEND_CMD_CRTL 0x00
75#define RFID_RESET_CTRL 0x01
76#define RFID_READ_CTRL 0x02
77#define RFID_POLL_CTRL 0x03
78
79 // rfid_reg
80
95#define RFID_IDN 0x01
96#define RFID_PROT_SELECT 0x02
97#define RFID_SEND_RECV 0x04
98#define RFID_IDLE 0x07
99#define RFID_RD_WAKEUP_REG 0x08
100#define RFID_WR_WAKEUP_REG 0x09
101#define RFID_SET_BAUD 0x0A
102#define RFID_ECHO 0x55
103
108#define RFID_FIELD_OFF 0x00
109#define RFID_ISO_15693 0x01
110#define RFID_ISO_14443A 0x02
111#define RFID_ISO_14443B 0x03
112#define RFID_ISO_18092NFC 0x04
113
118#define RFID_UART 0x00
119#define RFID_SPI 0x01
120
125#define RFID_MAX_DATA_LEN 0xFF
126
131#define RFID_DATA_READY 0x08
132#define RFID_DATA_NOT_READY 0x00
133
134 // rfid_set
135
150#define RFID_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
152 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
153 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
154 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
155 cfg.ssi_1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
156 cfg.ssi_0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
157 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159 cfg.irq_in = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
160 cfg.irq_out = MIKROBUS( mikrobus, MIKROBUS_INT )
161
162 // rfid_map
163 // rfid
164
169#define DRV_RX_BUFFER_SIZE 500
176typedef struct
177{
178 // Output pins
179
180 digital_out_t ssi_1;
181 digital_out_t ssi_0;
182 digital_out_t irq_in;
184 // Input pins
185
186 digital_in_t irq_out;
188 // Modules
189
190 spi_master_t spi;
192 pin_name_t chip_select;
194 uart_t uart;
196 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
197 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
199 // Variables
200
202 uint8_t rx_data[ DRV_RX_BUFFER_SIZE ];
204} rfid_t;
205
210typedef struct
211{
212 // Communication gpio pins
213
214 pin_name_t miso;
215 pin_name_t mosi;
216 pin_name_t sck;
217 pin_name_t cs;
218 pin_name_t rx_pin;
219 pin_name_t tx_pin;
221 // Additional gpio pins
222
223 pin_name_t ssi_1;
224 pin_name_t ssi_0;
225 pin_name_t irq_in;
226 pin_name_t irq_out;
228 // static variable
229
230 uint32_t spi_speed;
231 spi_master_mode_t spi_mode;
232 spi_master_chip_select_polarity_t cs_polarity;
234 uint32_t baud_rate;
236 uart_data_bits_t data_bit;
237 uart_parity_t parity_bit;
238 uart_stop_bits_t stop_bit;
240} rfid_cfg_t;
241
246typedef enum
247{
249 RFID_ERROR = -1
250
252
269
284err_t rfid_init ( rfid_t *ctx, rfid_cfg_t *cfg );
285
300
316err_t rfid_send_command ( rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
317
330err_t rfid_read_data ( rfid_t *ctx, uint8_t *data_out );
331
342uint8_t rfid_data_ready ( rfid_t *ctx );
343
355err_t rfid_reset ( rfid_t *ctx );
356
368err_t rfid_check_echo ( rfid_t *ctx );
369
382
395err_t rfid_get_device_id ( rfid_t *ctx, uint8_t *device_id );
396
409err_t rfid_select_communication_interface ( rfid_t* ctx, uint8_t com_interface );
410
423err_t rfid_select_rfid_protocol ( rfid_t *ctx, uint8_t rfid_protocol );
424
437
450
465err_t rfid_get_tag_uid ( rfid_t *ctx, uint8_t rfid_protocol, uint8_t *tag_uid );
466
467#ifdef __cplusplus
468}
469#endif
470#endif // RFID_H
471
472 // rfid
473
474// ------------------------------------------------------------------------ END
#define DRV_RX_BUFFER_SIZE
Definition rfid.h:169
uint8_t rfid_data_ready(rfid_t *ctx)
RFID data ready function.
err_t rfid_auto_detect_filter(rfid_t *ctx)
Configure auto detect filter.
err_t rfid_init(rfid_t *ctx, rfid_cfg_t *cfg)
RFID initialization function.
err_t rfid_select_rfid_protocol(rfid_t *ctx, uint8_t rfid_protocol)
Select RF communication protocol.
err_t rfid_select_communication_interface(rfid_t *ctx, uint8_t com_interface)
Select communication interface.
err_t rfid_set_index_mod_and_gain(rfid_t *ctx)
Configure IndexMod and Gain.
err_t rfid_reset(rfid_t *ctx)
RFID reset function.
err_t rfid_send_command(rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
RFID command writing function.
err_t rfid_default_cfg(rfid_t *ctx)
RFID default configuration function.
err_t rfid_read_data(rfid_t *ctx, uint8_t *data_out)
RFID data reading function.
err_t rfid_get_tag_uid(rfid_t *ctx, uint8_t rfid_protocol, uint8_t *tag_uid)
RFID get RFID tag uid function.
err_t rfid_check_echo(rfid_t *ctx)
RFID check echo response.
err_t rfid_calibration(rfid_t *ctx)
RFID calibration function.
void rfid_cfg_setup(rfid_cfg_t *cfg)
RFID configuration object setup function.
err_t rfid_get_device_id(rfid_t *ctx, uint8_t *device_id)
RFID get device id function.
rfid_return_value_t
RFID Click return value data.
Definition rfid.h:247
@ RFID_ERROR
Definition rfid.h:249
@ RFID_OK
Definition rfid.h:248
RFID Click configuration object.
Definition rfid.h:211
uint32_t baud_rate
Definition rfid.h:234
pin_name_t irq_in
Definition rfid.h:225
pin_name_t ssi_1
Definition rfid.h:223
spi_master_chip_select_polarity_t cs_polarity
Definition rfid.h:232
bool uart_blocking
Definition rfid.h:235
pin_name_t sck
Definition rfid.h:216
uart_data_bits_t data_bit
Definition rfid.h:236
spi_master_mode_t spi_mode
Definition rfid.h:231
pin_name_t tx_pin
Definition rfid.h:219
pin_name_t mosi
Definition rfid.h:215
uint32_t spi_speed
Definition rfid.h:230
pin_name_t rx_pin
Definition rfid.h:218
uart_stop_bits_t stop_bit
Definition rfid.h:238
pin_name_t miso
Definition rfid.h:214
uart_parity_t parity_bit
Definition rfid.h:237
pin_name_t ssi_0
Definition rfid.h:224
pin_name_t irq_out
Definition rfid.h:226
pin_name_t cs
Definition rfid.h:217
RFID Click context object.
Definition rfid.h:177
digital_in_t irq_out
Definition rfid.h:186
spi_master_t spi
Definition rfid.h:190
digital_out_t ssi_0
Definition rfid.h:181
digital_out_t irq_in
Definition rfid.h:182
uart_t uart
Definition rfid.h:194
digital_out_t ssi_1
Definition rfid.h:180
pin_name_t chip_select
Definition rfid.h:192
uint8_t com_interface
Definition rfid.h:201