ibutton 2.1.0.0
ibutton.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 IBUTTON_H
29#define IBUTTON_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_one_wire.h"
52
73#define IBUTTON_CMD_WRITE_SCRATCHPAD 0x4E
74#define IBUTTON_CMD_READ_SCRATCHPAD 0xBE
75
76 // ibutton_cmd
77
92#define IBUTTON_FAMILY_CODE 0x01
93
98#define IBUTTON_MAX_KEY_NUMBER 5
99
100 // ibutton_set
101
116#define IBUTTON_MAP_MIKROBUS( cfg, mikrobus ) \
117 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
118 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
119 cfg.st1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
120 cfg.st2 = MIKROBUS( mikrobus, MIKROBUS_CS );
121
122 // ibutton_map
123 // ibutton
124
135
140typedef struct
141{
142 // Output pins
143 digital_out_t st2;
144 digital_out_t st1;
146 // Modules
147 one_wire_t ow;
149 one_wire_rom_address_t key_rom[ IBUTTON_MAX_KEY_NUMBER ];
150 uint8_t num_keys;
152} ibutton_t;
153
158typedef struct
159{
160 // Communication gpio pins
161 pin_name_t gp0;
162 pin_name_t gp1;
164 // Additional gpio pins
165 pin_name_t st2;
166 pin_name_t st1;
171
184
197
214
230
245
259
269
283
293
303
313
323
324#ifdef __cplusplus
325}
326#endif
327#endif // IBUTTON_H
328
329 // ibutton
330
331// ------------------------------------------------------------------------ END
#define IBUTTON_MAX_KEY_NUMBER
iButton max key number.
Definition ibutton.h:98
void ibutton_remove_keys(ibutton_t *ctx)
iButton remove keys function.
void ibutton_disable_green_led(ibutton_t *ctx)
iButton disable green led function.
void ibutton_enable_red_led(ibutton_t *ctx)
iButton enable red led function.
void ibutton_gpio_selection(ibutton_cfg_t *cfg, ibutton_gpio_sel_t gpio_sel)
iButton driver interface setup function.
void ibutton_disable_red_led(ibutton_t *ctx)
iButton disable red led function.
err_t ibutton_add_key(ibutton_t *ctx)
iButton add key function.
err_t ibutton_check_key(ibutton_t *ctx)
iButton check key function.
void ibutton_enable_green_led(ibutton_t *ctx)
iButton enable green led function.
err_t ibutton_init(ibutton_t *ctx, ibutton_cfg_t *cfg)
iButton initialization function.
void ibutton_cfg_setup(ibutton_cfg_t *cfg)
iButton configuration object setup function.
ibutton_return_value_t
iButton Click return value data.
Definition ibutton.h:177
@ IBUTTON_ERROR
Definition ibutton.h:179
@ IBUTTON_KEY_ALREADY_EXIST
Definition ibutton.h:180
@ IBUTTON_KEY_NO_MATCH
Definition ibutton.h:181
@ IBUTTON_OK
Definition ibutton.h:178
ibutton_led_state_t
iButton Click led indication state.
Definition ibutton.h:190
@ IBUTTON_LED_SUCCESS
Definition ibutton.h:193
@ IBUTTON_LED_WAIT_KEY
Definition ibutton.h:192
@ IBUTTON_LED_DISABLE
Definition ibutton.h:191
@ IBUTTON_LED_WRONG_KEY
Definition ibutton.h:194
ibutton_gpio_sel_t
iButton Click gpio selector.
Definition ibutton.h:130
@ IBUTTON_GPIO_0
Definition ibutton.h:131
@ IBUTTON_GPIO_1
Definition ibutton.h:132
iButton Click configuration object.
Definition ibutton.h:159
pin_name_t gp0
Definition ibutton.h:161
ibutton_gpio_sel_t gpio_sel
Definition ibutton.h:168
pin_name_t st1
Definition ibutton.h:166
pin_name_t st2
Definition ibutton.h:165
pin_name_t gp1
Definition ibutton.h:162
iButton Click context object.
Definition ibutton.h:141
digital_out_t st2
Definition ibutton.h:143
uint8_t num_keys
Definition ibutton.h:150
digital_out_t st1
Definition ibutton.h:144
one_wire_t ow
Definition ibutton.h:147