clickid  2.1.0.0
clickid.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 CLICKID_H
29 #define CLICKID_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_one_wire.h"
52 
73 #define CLICKID_CMD_WRITE_MEMORY 0x96
74 #define CLICKID_CMD_READ_MEMORY 0x69
75 #define CLICKID_CMD_RELEASE 0xAA
76  // clickid_cmd
78 
93 #define CLICKID_MEM_ACCESS_SUCCESS 0xAA
94 #define CLICKID_MEM_ACCESS_FAIL 0x55
95 
100 #define CLICKID_USER_EEPROM_START 0x0000
101 #define CLICKID_USER_EEPROM_END 0x01FF
102 #define CLICKID_PAGE_START 0x00
103 #define CLICKID_PAGE_END 0x1F
104 #define CLICKID_PAGE_SIZE 32
105 #define CLICKID_MANIFEST_START_ADDRESS 0x0020
106 
111 #define CLICKID_FAMILY_CODE 0xCC
112  // clickid_set
114 
129 #define CLICKID_MAP_MIKROBUS( cfg, mikrobus ) \
130  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
131  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
132  // clickid_map // clickid
135 
140 typedef struct
141 {
142  uint8_t major;
143  uint8_t minor;
144 
146 
151 typedef struct
152 {
154  uint16_t serial;
155  uint16_t type;
156  uint8_t custom;
157  uint8_t name[ 20 ];
160 
165 typedef struct
166 {
167  // Output pins
168  digital_out_t rst;
170  // Modules
171  one_wire_t ow;
173  one_wire_rom_address_t rom_addr;
175 } clickid_t;
176 
181 typedef struct
182 {
183  // Communication gpio pins
184  pin_name_t cs;
186  // Additional gpio pins
187  pin_name_t rst;
189 } clickid_cfg_t;
190 
195 typedef enum
196 {
198  CLICKID_ERROR = -1
199 
201 
218 
232 err_t clickid_init ( clickid_t *ctx, clickid_cfg_t *cfg );
233 
242 void clickid_deinit ( clickid_t *ctx );
243 
256 
271 err_t clickid_read_memory ( clickid_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len );
272 
287 err_t clickid_write_memory ( clickid_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len );
288 
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // CLICKID_H
307  // clickid
309 
310 // ------------------------------------------------------------------------ END
clickid_information_t
ClickID information.
Definition: clickid.h:152
clickid_write_memory
err_t clickid_write_memory(clickid_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len)
ClickID write memory function.
clickid_cfg_t
ClickID configuration object.
Definition: clickid.h:182
CLICKID_OK
@ CLICKID_OK
Definition: clickid.h:197
clickid_version_t::minor
uint8_t minor
Definition: clickid.h:143
clickid_deinit
void clickid_deinit(clickid_t *ctx)
ClickID de-initialization function.
clickid_cfg_setup
void clickid_cfg_setup(clickid_cfg_t *cfg)
ClickID configuration object setup function.
clickid_cfg_t::rst
pin_name_t rst
Definition: clickid.h:187
clickid_check_communication
err_t clickid_check_communication(clickid_t *ctx)
ClickID check communication function.
clickid_read_memory
err_t clickid_read_memory(clickid_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len)
ClickID read memory function.
clickid_information_t::custom
uint8_t custom
Definition: clickid.h:156
clickid_information_t::hw_rev
clickid_version_t hw_rev
Definition: clickid.h:153
CLICKID_ERROR
@ CLICKID_ERROR
Definition: clickid.h:198
clickid_return_value_t
clickid_return_value_t
ClickID return value data.
Definition: clickid.h:196
clickid_t::ow
one_wire_t ow
Definition: clickid.h:171
clickid_information_t::type
uint16_t type
Definition: clickid.h:155
clickid_read_information
err_t clickid_read_information(clickid_t *ctx, clickid_information_t *info)
ClickID read information function.
clickid_version_t
ClickID version.
Definition: clickid.h:141
clickid_information_t::serial
uint16_t serial
Definition: clickid.h:154
clickid_cfg_t::cs
pin_name_t cs
Definition: clickid.h:184
clickid_version_t::major
uint8_t major
Definition: clickid.h:142
clickid_init
err_t clickid_init(clickid_t *ctx, clickid_cfg_t *cfg)
ClickID initialization function.
clickid_t::rom_addr
one_wire_rom_address_t rom_addr
Definition: clickid.h:173
clickid_t::rst
digital_out_t rst
Definition: clickid.h:168
clickid_t
ClickID context object.
Definition: clickid.h:166