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 
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  // 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  // 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  // rfid_map // rfid
164 
169 #define DRV_RX_BUFFER_SIZE 500
170 
176 typedef 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 
201  uint8_t com_interface;
202  uint8_t rx_data[ DRV_RX_BUFFER_SIZE ];
204 } rfid_t;
205 
210 typedef 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 
246 typedef enum
247 {
248  RFID_OK = 0,
249  RFID_ERROR = -1
250 
252 
269 
284 err_t rfid_init ( rfid_t *ctx, rfid_cfg_t *cfg );
285 
299 err_t rfid_default_cfg ( rfid_t *ctx );
300 
316 err_t rfid_send_command ( rfid_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
317 
330 err_t rfid_read_data ( rfid_t *ctx, uint8_t *data_out );
331 
342 uint8_t rfid_data_ready ( rfid_t *ctx );
343 
355 err_t rfid_reset ( rfid_t *ctx );
356 
368 err_t rfid_check_echo ( rfid_t *ctx );
369 
381 err_t rfid_calibration ( rfid_t *ctx );
382 
395 err_t rfid_get_device_id ( rfid_t *ctx, uint8_t *device_id );
396 
409 err_t rfid_select_communication_interface ( rfid_t* ctx, uint8_t com_interface );
410 
423 err_t rfid_select_rfid_protocol ( rfid_t *ctx, uint8_t rfid_protocol );
424 
437 
450 
465 err_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  // rfid
473 
474 // ------------------------------------------------------------------------ END
rfid_t::ssi_1
digital_out_t ssi_1
Definition: rfid.h:180
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rfid.h:169
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:230
rfid_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rfid.h:236
rfid_t::irq_in
digital_out_t irq_in
Definition: rfid.h:182
rfid_return_value_t
rfid_return_value_t
RFID Click return value data.
Definition: rfid.h:247
rfid_cfg_t::irq_in
pin_name_t irq_in
Definition: rfid.h:225
rfid_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rfid.h:238
rfid_t::com_interface
uint8_t com_interface
Definition: rfid.h:201
rfid_t
RFID Click context object.
Definition: rfid.h:177
rfid_t::ssi_0
digital_out_t ssi_0
Definition: rfid.h:181
rfid_cfg_t::mosi
pin_name_t mosi
Definition: rfid.h:215
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:231
rfid_cfg_t::miso
pin_name_t miso
Definition: rfid.h:214
rfid_cfg_t
RFID Click configuration object.
Definition: rfid.h:211
rfid_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rfid.h:219
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:186
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:248
rfid_cfg_t::baud_rate
uint32_t baud_rate
Definition: rfid.h:234
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:190
rfid_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rfid.h:237
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:224
rfid_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: rfid.h:232
RFID_ERROR
@ RFID_ERROR
Definition: rfid.h:249
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:226
rfid_t::uart
uart_t uart
Definition: rfid.h:194
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:223
rfid_t::chip_select
pin_name_t chip_select
Definition: rfid.h:192
rfid_cfg_t::sck
pin_name_t sck
Definition: rfid.h:216
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:218
rfid_cfg_t::uart_blocking
bool uart_blocking
Definition: rfid.h:235
rfid_cfg_t::cs
pin_name_t cs
Definition: rfid.h:217