smartnfc 2.2.0
Loading...
Searching...
No Matches
smartnfc.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
27
28#ifndef SMARTNFC_H
29#define SMARTNFC_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_uart.h"
52
58
63
68
73#define SMARTNFC_FRAME_STX 0xF5
74
79#define SMARTNFC_CMD_ACK 0x00
80#define SMARTNFC_CMD_DUMMY 0x01
81#define SMARTNFC_CMD_GET_TAG_COUNT 0x02
82#define SMARTNFC_CMD_GET_TAG_UID 0x03
83#define SMARTNFC_CMD_ACTIVATE_TAG 0x04
84#define SMARTNFC_CMD_HALT 0x05
85#define SMARTNFC_CMD_SET_POLLING 0x06
86#define SMARTNFC_CMD_SET_KEY 0x07
87#define SMARTNFC_CMD_SAVE_KEYS 0x08
88#define SMARTNFC_CMD_NET_CONFIG 0x09
89#define SMARTNFC_CMD_REBOOT 0x0A
90#define SMARTNFC_CMD_GET_VERSION 0x0B
91#define SMARTNFC_CMD_UART_PASSTHRU 0x0C
92#define SMARTNFC_CMD_SLEEP 0x0D
93#define SMARTNFC_CMD_GPIO 0x0E
94#define SMARTNFC_CMD_SET_ACTIVE_ANT 0x0F
95#define SMARTNFC_CMD_WPAN_PIN 0x10
96#define SMARTNFC_CMD_FACTORY_RESET 0x11
97#define SMARTNFC_CMD_PROTOCOL_AUTH 0x12
98#define SMARTNFC_CMD_PROTOCOL_CFG 0x13
99#define SMARTNFC_CMD_LED 0x14
100#define SMARTNFC_CMD_WPAN_DATA 0x15
101#define SMARTNFC_CMD_POLLING_SETUP 0x16
102#define SMARTNFC_CMD_LOG_FORWARDING 0xE4
103#define SMARTNFC_CMD_ERROR 0xFF
104
109#define SMARTNFC_RSP_TIMEOUT_1000MS 1000
110#define SMARTNFC_RSP_NUM_TRIES 3
111
117#define SMARTNFC_TX_DRV_BUFFER_SIZE 200
118#define SMARTNFC_RX_DRV_BUFFER_SIZE 500
119#define SMARTNFC_PAYLOAD_BUFFER_SIZE 500
120 // smartnfc_cmd
122
127
132
137#define SMARTNFC_MAP_MIKROBUS( cfg, mikrobus ) \
138 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
139 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
140 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
141
142 // smartnfc_map // smartnfc
144
149typedef struct
150{
151 uint8_t cmd;
153 uint16_t payload_len;
154
156
161typedef struct
162{
163 // Output pins
164 digital_out_t rst;
165
166 // Modules
167 uart_t uart;
168
169 // Buffers
172
175
176} smartnfc_t;
177
182typedef struct
183{
184 // Communication gpio pins
185 pin_name_t rx_pin;
186 pin_name_t tx_pin;
187
188 // Additional gpio pins
189 pin_name_t rst;
190
191 // Static variable
192 uint32_t baud_rate;
194 uart_data_bits_t data_bit;
195 uart_parity_t parity_bit;
196 uart_stop_bits_t stop_bit;
197
199
211
217
228
243
256err_t smartnfc_generic_write ( smartnfc_t *ctx, uint8_t *data_in, uint16_t len );
257
270err_t smartnfc_generic_read ( smartnfc_t *ctx, uint8_t *data_out, uint16_t len );
271
281void smartnfc_set_rst_pin ( smartnfc_t *ctx, uint8_t state );
282
293
304
318
330err_t smartnfc_read_ack_frame ( smartnfc_t *ctx, uint8_t cmd );
331
341
342#ifdef __cplusplus
343}
344#endif
345#endif // SMARTNFC_H
346 // smartnfc
348
349// ------------------------------------------------------------------------ END
#define SMARTNFC_TX_DRV_BUFFER_SIZE
Smart NFC driver buffer size.
Definition smartnfc.h:117
#define SMARTNFC_PAYLOAD_BUFFER_SIZE
Definition smartnfc.h:119
#define SMARTNFC_RX_DRV_BUFFER_SIZE
Definition smartnfc.h:118
void smartnfc_set_rst_pin(smartnfc_t *ctx, uint8_t state)
Smart NFC set RST pin function.
err_t smartnfc_send_frame(smartnfc_t *ctx)
Smart NFC send frame function.
err_t smartnfc_generic_write(smartnfc_t *ctx, uint8_t *data_in, uint16_t len)
Smart NFC data writing function.
void smartnfc_cfg_setup(smartnfc_cfg_t *cfg)
Smart NFC configuration object setup function.
err_t smartnfc_init(smartnfc_t *ctx, smartnfc_cfg_t *cfg)
Smart NFC initialization function.
err_t smartnfc_reset_device(smartnfc_t *ctx)
Smart NFC reset device function.
err_t smartnfc_read_ack_frame(smartnfc_t *ctx, uint8_t cmd)
Smart NFC read ack frame function.
void smartnfc_clear_buffers(smartnfc_t *ctx)
Smart NFC clear buffers function.
err_t smartnfc_read_frame(smartnfc_t *ctx)
Smart NFC read frame function.
err_t smartnfc_generic_read(smartnfc_t *ctx, uint8_t *data_out, uint16_t len)
Smart NFC data reading function.
smartnfc_return_value_t
Smart NFC Click return value data.
Definition smartnfc.h:205
@ SMARTNFC_ERROR_TIMEOUT
Definition smartnfc.h:208
@ SMARTNFC_OK
Definition smartnfc.h:206
@ SMARTNFC_ERROR
Definition smartnfc.h:207
Smart NFC Click configuration object.
Definition smartnfc.h:183
uint32_t baud_rate
Definition smartnfc.h:192
bool uart_blocking
Definition smartnfc.h:193
uart_data_bits_t data_bit
Definition smartnfc.h:194
pin_name_t tx_pin
Definition smartnfc.h:186
pin_name_t rx_pin
Definition smartnfc.h:185
uart_stop_bits_t stop_bit
Definition smartnfc.h:196
uart_parity_t parity_bit
Definition smartnfc.h:195
pin_name_t rst
Definition smartnfc.h:189
Smart NFC Click command frame structure object.
Definition smartnfc.h:150
uint16_t payload_len
Definition smartnfc.h:153
uint8_t cmd
Definition smartnfc.h:151
uint8_t payload[SMARTNFC_PAYLOAD_BUFFER_SIZE]
Definition smartnfc.h:152
Smart NFC Click context object.
Definition smartnfc.h:162
smartnfc_frame_t cmd_frame
Definition smartnfc.h:173
smartnfc_frame_t rsp_frame
Definition smartnfc.h:174
uart_t uart
Definition smartnfc.h:167
uint8_t uart_rx_buffer[SMARTNFC_RX_DRV_BUFFER_SIZE]
Definition smartnfc.h:170
uint8_t uart_tx_buffer[SMARTNFC_TX_DRV_BUFFER_SIZE]
Definition smartnfc.h:171
digital_out_t rst
Definition smartnfc.h:164