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
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 "drv_uart.h"
39 
60 #define RFID_SEND_CMD_CRTL 0x00
61 #define RFID_RESET_CTRL 0x01
62 #define RFID_READ_CTRL 0x02
63 #define RFID_POLL_CTRL 0x03
64  // rfid_reg
66 
81 #define RFID_IDN 0x01
82 #define RFID_PROT_SELECT 0x02
83 #define RFID_SEND_RECV 0x04
84 #define RFID_IDLE 0x07
85 #define RFID_RD_WAKEUP_REG 0x08
86 #define RFID_WR_WAKEUP_REG 0x09
87 #define RFID_SET_BAUD 0x0A
88 #define RFID_ECHO 0x55
89 
94 #define RFID_FIELD_OFF 0x00
95 #define RFID_ISO_15693 0x01
96 #define RFID_ISO_14443A 0x02
97 #define RFID_ISO_14443B 0x03
98 #define RFID_ISO_18092NFC 0x04
99 
104 #define RFID_UART 0x00
105 #define RFID_SPI 0x01
106 
111 #define RFID_MAX_DATA_LEN 0xFF
112 
117 #define RFID_DATA_READY 0x08
118 #define RFID_DATA_NOT_READY 0x00
119  // rfid_set
121 
136 #define RFID_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
141  cfg.ssi_1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
142  cfg.ssi_0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
143  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
144  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
145  cfg.irq_in = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
146  cfg.irq_out = MIKROBUS( mikrobus, MIKROBUS_INT )
147  // rfid_map // rfid
150 
155 #define DRV_RX_BUFFER_SIZE 500
156 
162 typedef struct
163 {
164  // Output pins
165 
166  digital_out_t ssi_1;
167  digital_out_t ssi_0;
168  digital_out_t irq_in;
170  // Input pins
171 
172  digital_in_t irq_out;
174  // Modules
175 
176  spi_master_t spi;
178  pin_name_t chip_select;
180  uart_t uart;
182  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
183  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
185  // Variables
186 
187  uint8_t com_interface;
188  uint8_t rx_data[ DRV_RX_BUFFER_SIZE ];
190 } rfid_t;
191 
196 typedef struct
197 {
198  // Communication gpio pins
199 
200  pin_name_t miso;
201  pin_name_t mosi;
202  pin_name_t sck;
203  pin_name_t cs;
204  pin_name_t rx_pin;
205  pin_name_t tx_pin;
207  // Additional gpio pins
208 
209  pin_name_t ssi_1;
210  pin_name_t ssi_0;
211  pin_name_t irq_in;
212  pin_name_t irq_out;
214  // static variable
215 
216  uint32_t spi_speed;
217  spi_master_mode_t spi_mode;
218  spi_master_chip_select_polarity_t cs_polarity;
220  uint32_t baud_rate;
222  uart_data_bits_t data_bit;
223  uart_parity_t parity_bit;
224  uart_stop_bits_t stop_bit;
226 } rfid_cfg_t;
227 
232 typedef enum
233 {
234  RFID_OK = 0,
235  RFID_ERROR = -1
236 
238 
255 
270 err_t rfid_init ( rfid_t *ctx, rfid_cfg_t *cfg );
271 
285 err_t rfid_default_cfg ( rfid_t *ctx );
286 
302 err_t rfid_send_command ( rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
303 
316 err_t rfid_read_data ( rfid_t *ctx, uint8_t *data_out );
317 
328 uint8_t rfid_data_ready ( rfid_t *ctx );
329 
341 err_t rfid_reset ( rfid_t *ctx );
342 
354 err_t rfid_check_echo ( rfid_t *ctx );
355 
367 err_t rfid_calibration ( rfid_t *ctx );
368 
381 err_t rfid_get_device_id ( rfid_t *ctx, uint8_t *device_id );
382 
395 err_t rfid_select_communication_interface ( rfid_t* ctx, uint8_t com_interface );
396 
409 err_t rfid_select_rfid_protocol ( rfid_t *ctx, uint8_t rfid_protocol );
410 
423 
436 
451 err_t rfid_get_tag_uid ( rfid_t *ctx, uint8_t rfid_protocol, uint8_t *tag_uid );
452 
453 #ifdef __cplusplus
454 }
455 #endif
456 #endif // RFID_H
457  // rfid
459 
460 // ------------------------------------------------------------------------ END
rfid_t::ssi_1
digital_out_t ssi_1
Definition: rfid.h:166
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rfid.h:155
rfid_reset
err_t rfid_reset(rfid_t *ctx)
RFID reset function.
rfid_select_communication_interface
err_t rfid_select_communication_interface(rfid_t *ctx, uint8_t com_interface)
Select communication interface.
rfid_cfg_setup
void rfid_cfg_setup(rfid_cfg_t *cfg)
RFID configuration object setup function.
rfid_auto_detect_filter
err_t rfid_auto_detect_filter(rfid_t *ctx)
Configure auto detect filter.
rfid_cfg_t::spi_speed
uint32_t spi_speed
Definition: rfid.h:216
rfid_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rfid.h:222
rfid_t::irq_in
digital_out_t irq_in
Definition: rfid.h:168
rfid_return_value_t
rfid_return_value_t
RFID Click return value data.
Definition: rfid.h:233
rfid_cfg_t::irq_in
pin_name_t irq_in
Definition: rfid.h:211
rfid_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rfid.h:224
rfid_t::com_interface
uint8_t com_interface
Definition: rfid.h:187
rfid_t
RFID Click context object.
Definition: rfid.h:163
rfid_t::ssi_0
digital_out_t ssi_0
Definition: rfid.h:167
rfid_cfg_t::mosi
pin_name_t mosi
Definition: rfid.h:201
rfid_data_ready
uint8_t rfid_data_ready(rfid_t *ctx)
RFID data ready function.
rfid_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: rfid.h:217
rfid_cfg_t::miso
pin_name_t miso
Definition: rfid.h:200
rfid_cfg_t
RFID Click configuration object.
Definition: rfid.h:197
rfid_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rfid.h:205
rfid_select_rfid_protocol
err_t rfid_select_rfid_protocol(rfid_t *ctx, uint8_t rfid_protocol)
Select RF communication protocol.
rfid_t::irq_out
digital_in_t irq_out
Definition: rfid.h:172
rfid_read_data
err_t rfid_read_data(rfid_t *ctx, uint8_t *data_out)
RFID data reading function.
rfid_init
err_t rfid_init(rfid_t *ctx, rfid_cfg_t *cfg)
RFID initialization function.
RFID_OK
@ RFID_OK
Definition: rfid.h:234
rfid_cfg_t::baud_rate
uint32_t baud_rate
Definition: rfid.h:220
rfid_set_index_mod_and_gain
err_t rfid_set_index_mod_and_gain(rfid_t *ctx)
Configure IndexMod and Gain.
rfid_t::spi
spi_master_t spi
Definition: rfid.h:176
rfid_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rfid.h:223
rfid_get_device_id
err_t rfid_get_device_id(rfid_t *ctx, uint8_t *device_id)
RFID get device id function.
rfid_cfg_t::ssi_0
pin_name_t ssi_0
Definition: rfid.h:210
rfid_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rfid.h:218
RFID_ERROR
@ RFID_ERROR
Definition: rfid.h:235
rfid_calibration
err_t rfid_calibration(rfid_t *ctx)
RFID calibration function.
rfid_get_tag_uid
err_t rfid_get_tag_uid(rfid_t *ctx, uint8_t rfid_protocol, uint8_t *tag_uid)
RFID get RFID tag uid function.
rfid_default_cfg
err_t rfid_default_cfg(rfid_t *ctx)
RFID default configuration function.
rfid_cfg_t::irq_out
pin_name_t irq_out
Definition: rfid.h:212
rfid_t::uart
uart_t uart
Definition: rfid.h:180
rfid_check_echo
err_t rfid_check_echo(rfid_t *ctx)
RFID check echo response.
rfid_cfg_t::ssi_1
pin_name_t ssi_1
Definition: rfid.h:209
rfid_t::chip_select
pin_name_t chip_select
Definition: rfid.h:178
rfid_cfg_t::sck
pin_name_t sck
Definition: rfid.h:202
rfid_send_command
err_t rfid_send_command(rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
RFID command writing function.
rfid_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rfid.h:204
rfid_cfg_t::uart_blocking
bool uart_blocking
Definition: rfid.h:221
rfid_cfg_t::cs
pin_name_t cs
Definition: rfid.h:203