nfcextend  2.0.0.0
nfcextend.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef NFCEXTEND_H
35 #define NFCEXTEND_H
36 
37 #include "drv_digital_out.h"
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define NFCEXTEND_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define NFCEXTEND_RETVAL uint8_t
62 
63 #define NFCEXTEND_OK 0x00
64 #define NFCEXTEND_INIT_ERROR 0xFF
65 
71 #define NFCEXTEND_I2C_SLAVE_ADDRESS 0x53
72 
78 // MEMORY AREAS
79 #define NFCEXTEND_MEMORY_USER 0x01
80 #define NFCEXTEND_MEMORY_DYNAMIC 0x02
81 #define NFCEXTEND_MEMORY_MAILBOX 0x03
82 #define NFCEXTEND_MEMORY_SYSTEM 0x04
83 
84 // SYSTEM REGISTER ADDRESSES
85 #define NFCEXTEND_SYSTEM_REG_GPO 0x0000
86 #define NFCEXTEND_SYSTEM_REG_IT_TIME 0x0001
87 #define NFCEXTEND_SYSTEM_REG_EH_MODE 0x0002
88 #define NFCEXTEND_SYSTEM_REG_RF_MNGT 0x0003
89 #define NFCEXTEND_SYSTEM_REG_RFA1SS 0x0004
90 #define NFCEXTEND_SYSTEM_REG_ENDA1 0x0005
91 #define NFCEXTEND_SYSTEM_REG_RFA2SS 0x0006
92 #define NFCEXTEND_SYSTEM_REG_ENDA2 0x0007
93 #define NFCEXTEND_SYSTEM_REG_RFA3SS 0x0008
94 #define NFCEXTEND_SYSTEM_REG_ENDA3 0x0009
95 #define NFCEXTEND_SYSTEM_REG_RFA4SS 0x000A
96 #define NFCEXTEND_SYSTEM_REG_I2CSS 0x000B
97 #define NFCEXTEND_SYSTEM_REG_LOCK_CCFILE 0x000C
98 #define NFCEXTEND_SYSTEM_REG_MB_MODE 0x000D
99 #define NFCEXTEND_SYSTEM_REG_MB_WDG 0x000E
100 #define NFCEXTEND_SYSTEM_REG_LOCK_CFG 0x000F
101 #define NFCEXTEND_SYSTEM_REG_LOCK_DSFID 0x0010
102 #define NFCEXTEND_SYSTEM_REG_LOCK_AFI 0x0011
103 #define NFCEXTEND_SYSTEM_REG_DSFID 0x0012
104 #define NFCEXTEND_SYSTEM_REG_AFI 0x0013
105 #define NFCEXTEND_SYSTEM_REG_MEM_SIZE_1 0x0014
106 #define NFCEXTEND_SYSTEM_REG_MEM_SIZE_2 0x0015
107 #define NFCEXTEND_SYSTEM_REG_BLK_SIZE 0x0016
108 #define NFCEXTEND_SYSTEM_REG_IC_REF 0x0017
109 #define NFCEXTEND_SYSTEM_REG_UID_1 0x0018
110 #define NFCEXTEND_SYSTEM_REG_UID_2 0x0019
111 #define NFCEXTEND_SYSTEM_REG_UID_3 0x001A
112 #define NFCEXTEND_SYSTEM_REG_UID_4 0x001B
113 #define NFCEXTEND_SYSTEM_REG_UID_5 0x001C
114 #define NFCEXTEND_SYSTEM_REG_UID_6 0x001D
115 #define NFCEXTEND_SYSTEM_REG_UID_7 0x001E
116 #define NFCEXTEND_SYSTEM_REG_UID_8 0x001F
117 #define NFCEXTEND_SYSTEM_REG_IC_REV 0x0020
118 #define NFCEXTEND_SYSTEM_REG_ST_RES_1 0x0021
119 #define NFCEXTEND_SYSTEM_REG_ST_RES_2 0x0022
120 #define NFCEXTEND_SYSTEM_REG_ST_RES_3 0x0023
121 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_1 0x0900
122 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_2 0x0901
123 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_3 0x0902
124 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_4 0x0903
125 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_5 0x0904
126 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_6 0x0905
127 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_7 0x0906
128 #define NFCEXTEND_SYSTEM_REG_I2C_PWD_8 0x0907
129 
130 // DYNAMIC REGISTER ADDRESSES
131 #define NFCEXTEND_DYNAMIC_REG_GPO_CTRL 0x2000
132 #define NFCEXTEND_DYNAMIC_REG_RESERVED_1 0x2001
133 #define NFCEXTEND_DYNAMIC_REG_EH_CTRL 0x2002
134 #define NFCEXTEND_DYNAMIC_REG_RF_MNGT 0x2003
135 #define NFCEXTEND_DYNAMIC_REG_I2C_SSO 0x2004
136 #define NFCEXTEND_DYNAMIC_REG_IT_STS 0x2005
137 #define NFCEXTEND_DYNAMIC_REG_MB_CTRL 0x2006
138 #define NFCEXTEND_DYNAMIC_REG_MB_LEN 0x2007
139 
145 // MAILBOX REGISTER ADDRESSES
146 #define NFCEXTEND_MAILBOX_REG_BYTE_0 0x2008
147 
148 // MAILBOX ENABLE/DISABLE
149 #define NFCEXTEND_MAILBOX_DISABLE 0x00
150 #define NFCEXTEND_MAILBOX_ENABLE 0x01
151 
152 // RF ENABLE/DISABLE
153 #define NFCEXTEND_RF_DISABLE 0x00
154 #define NFCEXTEND_RF_ENABLE 0x01
155 
156 // PASSWORD PRESENT
157 #define NFCEXTEND_PASSWORD_LEN 8
158 #define NFCEXTEND_PASSWORD_BUFFER_SIZE NFCEXTEND_PASSWORD_LEN * 2 + 1
159  // End group macro
162 // --------------------------------------------------------------- PUBLIC TYPES
171 typedef struct
172 {
173  uint8_t memory_area;
174  uint16_t reg_addr;
175  uint8_t *data_buf;
176  uint16_t len;
177 
179 
183 typedef struct
184 {
185  // Input pins
186 
187  digital_in_t int_pin;
188 
189  // Modules
190 
191  i2c_master_t i2c;
192 
193  // ctx variable
194 
195  uint8_t slave_address;
196 
197 } nfcextend_t;
198 
202 typedef struct
203 {
204  // Communication gpio pins
205 
206  pin_name_t scl;
207  pin_name_t sda;
208 
209  // Additional gpio pins
210 
211  pin_name_t int_pin;
212 
213  // static variable
214 
215  uint32_t i2c_speed;
216  uint8_t i2c_address;
217 
219  // End types group
221 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
222 
228 #ifdef __cplusplus
229 extern "C"{
230 #endif
231 
241 
250 
258 uint8_t nfcextend_default_cfg ( nfcextend_t *ctx );
259 
268 uint8_t nfcextend_password_present ( nfcextend_t *ctx, uint8_t *pass_buf );
269 
278 uint8_t nfcextend_i2c_set ( nfcextend_t *ctx, nfcextend_block_t *block );
279 
288 uint8_t nfcextend_i2c_get ( nfcextend_t *ctx, nfcextend_block_t *block );
289 
298 uint8_t nfcextend_digital_read_int ( nfcextend_t *ctx );
299 
300 #ifdef __cplusplus
301 }
302 #endif
303 #endif // _NFCEXTEND_H_
304  // End public_function group
307 
308 // ------------------------------------------------------------------------- END
nfcextend_cfg_t::int_pin
pin_name_t int_pin
Definition: nfcextend.h:211
nfcextend_default_cfg
uint8_t nfcextend_default_cfg(nfcextend_t *ctx)
Click Default Configuration function.
nfcextend_cfg_setup
void nfcextend_cfg_setup(nfcextend_cfg_t *cfg)
Config Object Initialization function.
nfcextend_t::slave_address
uint8_t slave_address
Definition: nfcextend.h:195
nfcextend_t::int_pin
digital_in_t int_pin
Definition: nfcextend.h:187
nfcextend_t
Click ctx object definition.
Definition: nfcextend.h:183
nfcextend_i2c_get
uint8_t nfcextend_i2c_get(nfcextend_t *ctx, nfcextend_block_t *block)
I2C get function.
nfcextend_block_t::memory_area
uint8_t memory_area
Definition: nfcextend.h:173
nfcextend_init
NFCEXTEND_RETVAL nfcextend_init(nfcextend_t *ctx, nfcextend_cfg_t *cfg)
Initialization function.
nfcextend_password_present
uint8_t nfcextend_password_present(nfcextend_t *ctx, uint8_t *pass_buf)
Password present function.
nfcextend_cfg_t
Click configuration structure definition.
Definition: nfcextend.h:202
nfcextend_block_t::reg_addr
uint16_t reg_addr
Definition: nfcextend.h:174
nfcextend_block_t::data_buf
uint8_t * data_buf
Definition: nfcextend.h:175
nfcextend_block_t::len
uint16_t len
Definition: nfcextend.h:176
nfcextend_cfg_t::sda
pin_name_t sda
Definition: nfcextend.h:207
nfcextend_i2c_set
uint8_t nfcextend_i2c_set(nfcextend_t *ctx, nfcextend_block_t *block)
I2C set function.
nfcextend_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: nfcextend.h:215
nfcextend_cfg_t::i2c_address
uint8_t i2c_address
Definition: nfcextend.h:216
NFCEXTEND_RETVAL
#define NFCEXTEND_RETVAL
Definition: nfcextend.h:61
nfcextend_t::i2c
i2c_master_t i2c
Definition: nfcextend.h:191
nfcextend_cfg_t::scl
pin_name_t scl
Definition: nfcextend.h:206
nfcextend_digital_read_int
uint8_t nfcextend_digital_read_int(nfcextend_t *ctx)
Digital read interrupt.
nfcextend_block_t
I2C communication block object definition.
Definition: nfcextend.h:171