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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_one_wire.h"
48 
69 #define IBUTTON_CMD_WRITE_SCRATCHPAD 0x4E
70 #define IBUTTON_CMD_READ_SCRATCHPAD 0xBE
71  // ibutton_cmd
73 
88 #define IBUTTON_FAMILY_CODE 0x01
89 
94 #define IBUTTON_MAX_KEY_NUMBER 5
95  // ibutton_set
97 
112 #define IBUTTON_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
114  cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
115  cfg.st1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
116  cfg.st2 = MIKROBUS( mikrobus, MIKROBUS_CS );
117  // ibutton_map // ibutton
120 
125 typedef enum
126 {
131 
136 typedef struct
137 {
138  // Output pins
139  digital_out_t st2;
140  digital_out_t st1;
142  // Modules
143  one_wire_t ow;
145  one_wire_rom_address_t key_rom[ IBUTTON_MAX_KEY_NUMBER ];
146  uint8_t num_keys;
148 } ibutton_t;
149 
154 typedef struct
155 {
156  // Communication gpio pins
157  pin_name_t gp0;
158  pin_name_t gp1;
160  // Additional gpio pins
161  pin_name_t st2;
162  pin_name_t st1;
166 } ibutton_cfg_t;
167 
172 typedef enum
173 {
178 
180 
185 typedef enum
186 {
191 
193 
210 
226 
240 err_t ibutton_init ( ibutton_t *ctx, ibutton_cfg_t *cfg );
241 
254 err_t ibutton_add_key ( ibutton_t *ctx );
255 
265 
279 
289 
299 
309 
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 #endif // IBUTTON_H
324  // ibutton
326 
327 // ------------------------------------------------------------------------ END
ibutton_led_state_t
ibutton_led_state_t
iButton Click led indication state.
Definition: ibutton.h:186
ibutton_cfg_t::st2
pin_name_t st2
Definition: ibutton.h:161
ibutton_cfg_t
iButton Click configuration object.
Definition: ibutton.h:155
IBUTTON_MAX_KEY_NUMBER
#define IBUTTON_MAX_KEY_NUMBER
iButton max key number.
Definition: ibutton.h:94
IBUTTON_LED_SUCCESS
@ IBUTTON_LED_SUCCESS
Definition: ibutton.h:189
IBUTTON_KEY_ALREADY_EXIST
@ IBUTTON_KEY_ALREADY_EXIST
Definition: ibutton.h:176
ibutton_enable_green_led
void ibutton_enable_green_led(ibutton_t *ctx)
iButton enable green led function.
ibutton_cfg_t::gp1
pin_name_t gp1
Definition: ibutton.h:158
IBUTTON_LED_WRONG_KEY
@ IBUTTON_LED_WRONG_KEY
Definition: ibutton.h:190
IBUTTON_LED_DISABLE
@ IBUTTON_LED_DISABLE
Definition: ibutton.h:187
ibutton_cfg_t::gpio_sel
ibutton_gpio_sel_t gpio_sel
Definition: ibutton.h:164
ibutton_return_value_t
ibutton_return_value_t
iButton Click return value data.
Definition: ibutton.h:173
IBUTTON_GPIO_1
@ IBUTTON_GPIO_1
Definition: ibutton.h:128
IBUTTON_OK
@ IBUTTON_OK
Definition: ibutton.h:174
ibutton_check_key
err_t ibutton_check_key(ibutton_t *ctx)
iButton check key function.
ibutton_cfg_setup
void ibutton_cfg_setup(ibutton_cfg_t *cfg)
iButton configuration object setup function.
IBUTTON_GPIO_0
@ IBUTTON_GPIO_0
Definition: ibutton.h:127
ibutton_gpio_sel_t
ibutton_gpio_sel_t
iButton Click gpio selector.
Definition: ibutton.h:126
ibutton_cfg_t::st1
pin_name_t st1
Definition: ibutton.h:162
ibutton_disable_red_led
void ibutton_disable_red_led(ibutton_t *ctx)
iButton disable red led function.
IBUTTON_ERROR
@ IBUTTON_ERROR
Definition: ibutton.h:175
ibutton_disable_green_led
void ibutton_disable_green_led(ibutton_t *ctx)
iButton disable green led function.
ibutton_add_key
err_t ibutton_add_key(ibutton_t *ctx)
iButton add key function.
IBUTTON_KEY_NO_MATCH
@ IBUTTON_KEY_NO_MATCH
Definition: ibutton.h:177
ibutton_gpio_selection
void ibutton_gpio_selection(ibutton_cfg_t *cfg, ibutton_gpio_sel_t gpio_sel)
iButton driver interface setup function.
ibutton_t::st2
digital_out_t st2
Definition: ibutton.h:139
IBUTTON_LED_WAIT_KEY
@ IBUTTON_LED_WAIT_KEY
Definition: ibutton.h:188
ibutton_t::num_keys
uint8_t num_keys
Definition: ibutton.h:146
ibutton_cfg_t::gp0
pin_name_t gp0
Definition: ibutton.h:157
ibutton_t
iButton Click context object.
Definition: ibutton.h:137
ibutton_enable_red_led
void ibutton_enable_red_led(ibutton_t *ctx)
iButton enable red led function.
ibutton_init
err_t ibutton_init(ibutton_t *ctx, ibutton_cfg_t *cfg)
iButton initialization function.
ibutton_t::st1
digital_out_t st1
Definition: ibutton.h:140
ibutton_remove_keys
void ibutton_remove_keys(ibutton_t *ctx)
iButton remove keys function.
ibutton_t::ow
one_wire_t ow
Definition: ibutton.h:143