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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "drv_uart.h"
49 
70 #define RFID_SEND_CMD_CRTL 0x00
71 #define RFID_RESET_CTRL 0x01
72 #define RFID_READ_CTRL 0x02
73 #define RFID_POLL_CTRL 0x03
74  // rfid_reg
76 
91 #define RFID_IDN 0x01
92 #define RFID_PROT_SELECT 0x02
93 #define RFID_SEND_RECV 0x04
94 #define RFID_IDLE 0x07
95 #define RFID_RD_WAKEUP_REG 0x08
96 #define RFID_WR_WAKEUP_REG 0x09
97 #define RFID_SET_BAUD 0x0A
98 #define RFID_ECHO 0x55
99 
104 #define RFID_FIELD_OFF 0x00
105 #define RFID_ISO_15693 0x01
106 #define RFID_ISO_14443A 0x02
107 #define RFID_ISO_14443B 0x03
108 #define RFID_ISO_18092NFC 0x04
109 
114 #define RFID_UART 0x00
115 #define RFID_SPI 0x01
116 
121 #define RFID_MAX_DATA_LEN 0xFF
122 
127 #define RFID_DATA_READY 0x08
128 #define RFID_DATA_NOT_READY 0x00
129  // rfid_set
131 
146 #define RFID_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
148  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
149  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
151  cfg.ssi_1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
152  cfg.ssi_0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
153  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
154  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
155  cfg.irq_in = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
156  cfg.irq_out = MIKROBUS( mikrobus, MIKROBUS_INT )
157  // rfid_map // rfid
160 
165 #define DRV_RX_BUFFER_SIZE 500
166 
172 typedef struct
173 {
174  // Output pins
175 
176  digital_out_t ssi_1;
177  digital_out_t ssi_0;
178  digital_out_t irq_in;
180  // Input pins
181 
182  digital_in_t irq_out;
184  // Modules
185 
186  spi_master_t spi;
188  pin_name_t chip_select;
190  uart_t uart;
192  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
193  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
195  // Variables
196 
197  uint8_t com_interface;
198  uint8_t rx_data[ DRV_RX_BUFFER_SIZE ];
200 } rfid_t;
201 
206 typedef struct
207 {
208  // Communication gpio pins
209 
210  pin_name_t miso;
211  pin_name_t mosi;
212  pin_name_t sck;
213  pin_name_t cs;
214  pin_name_t rx_pin;
215  pin_name_t tx_pin;
217  // Additional gpio pins
218 
219  pin_name_t ssi_1;
220  pin_name_t ssi_0;
221  pin_name_t irq_in;
222  pin_name_t irq_out;
224  // static variable
225 
226  uint32_t spi_speed;
227  spi_master_mode_t spi_mode;
228  spi_master_chip_select_polarity_t cs_polarity;
230  uint32_t baud_rate;
232  uart_data_bits_t data_bit;
233  uart_parity_t parity_bit;
234  uart_stop_bits_t stop_bit;
236 } rfid_cfg_t;
237 
242 typedef enum
243 {
244  RFID_OK = 0,
245  RFID_ERROR = -1
246 
248 
265 
280 err_t rfid_init ( rfid_t *ctx, rfid_cfg_t *cfg );
281 
295 err_t rfid_default_cfg ( rfid_t *ctx );
296 
312 err_t rfid_send_command ( rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
313 
326 err_t rfid_read_data ( rfid_t *ctx, uint8_t *data_out );
327 
338 uint8_t rfid_data_ready ( rfid_t *ctx );
339 
351 err_t rfid_reset ( rfid_t *ctx );
352 
364 err_t rfid_check_echo ( rfid_t *ctx );
365 
377 err_t rfid_calibration ( rfid_t *ctx );
378 
391 err_t rfid_get_device_id ( rfid_t *ctx, uint8_t *device_id );
392 
405 err_t rfid_select_communication_interface ( rfid_t* ctx, uint8_t com_interface );
406 
419 err_t rfid_select_rfid_protocol ( rfid_t *ctx, uint8_t rfid_protocol );
420 
433 
446 
461 err_t rfid_get_tag_uid ( rfid_t *ctx, uint8_t rfid_protocol, uint8_t *tag_uid );
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 #endif // RFID_H
467  // rfid
469 
470 // ------------------------------------------------------------------------ END
rfid_t::ssi_1
digital_out_t ssi_1
Definition: rfid.h:176
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rfid.h:165
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:226
rfid_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rfid.h:232
rfid_t::irq_in
digital_out_t irq_in
Definition: rfid.h:178
rfid_return_value_t
rfid_return_value_t
RFID Click return value data.
Definition: rfid.h:243
rfid_cfg_t::irq_in
pin_name_t irq_in
Definition: rfid.h:221
rfid_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rfid.h:234
rfid_t::com_interface
uint8_t com_interface
Definition: rfid.h:197
rfid_t
RFID Click context object.
Definition: rfid.h:173
rfid_t::ssi_0
digital_out_t ssi_0
Definition: rfid.h:177
rfid_cfg_t::mosi
pin_name_t mosi
Definition: rfid.h:211
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:227
rfid_cfg_t::miso
pin_name_t miso
Definition: rfid.h:210
rfid_cfg_t
RFID Click configuration object.
Definition: rfid.h:207
rfid_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rfid.h:215
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:182
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:244
rfid_cfg_t::baud_rate
uint32_t baud_rate
Definition: rfid.h:230
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:186
rfid_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rfid.h:233
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:220
rfid_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rfid.h:228
RFID_ERROR
@ RFID_ERROR
Definition: rfid.h:245
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:222
rfid_t::uart
uart_t uart
Definition: rfid.h:190
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:219
rfid_t::chip_select
pin_name_t chip_select
Definition: rfid.h:188
rfid_cfg_t::sck
pin_name_t sck
Definition: rfid.h:212
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:214
rfid_cfg_t::uart_blocking
bool uart_blocking
Definition: rfid.h:231
rfid_cfg_t::cs
pin_name_t cs
Definition: rfid.h:213