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 
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  // ibutton_cmd
77 
92 #define IBUTTON_FAMILY_CODE 0x01
93 
98 #define IBUTTON_MAX_KEY_NUMBER 5
99  // 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  // ibutton_map // ibutton
124 
129 typedef enum
130 {
135 
140 typedef 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 
158 typedef 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;
170 } ibutton_cfg_t;
171 
176 typedef enum
177 {
182 
184 
189 typedef enum
190 {
195 
197 
214 
230 
244 err_t ibutton_init ( ibutton_t *ctx, ibutton_cfg_t *cfg );
245 
258 err_t ibutton_add_key ( ibutton_t *ctx );
259 
269 
283 
293 
303 
313 
323 
324 #ifdef __cplusplus
325 }
326 #endif
327 #endif // IBUTTON_H
328  // ibutton
330 
331 // ------------------------------------------------------------------------ END
ibutton_led_state_t
ibutton_led_state_t
iButton Click led indication state.
Definition: ibutton.h:190
ibutton_cfg_t::st2
pin_name_t st2
Definition: ibutton.h:165
ibutton_cfg_t
iButton Click configuration object.
Definition: ibutton.h:159
IBUTTON_MAX_KEY_NUMBER
#define IBUTTON_MAX_KEY_NUMBER
iButton max key number.
Definition: ibutton.h:98
IBUTTON_LED_SUCCESS
@ IBUTTON_LED_SUCCESS
Definition: ibutton.h:193
IBUTTON_KEY_ALREADY_EXIST
@ IBUTTON_KEY_ALREADY_EXIST
Definition: ibutton.h:180
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:162
IBUTTON_LED_WRONG_KEY
@ IBUTTON_LED_WRONG_KEY
Definition: ibutton.h:194
IBUTTON_LED_DISABLE
@ IBUTTON_LED_DISABLE
Definition: ibutton.h:191
ibutton_cfg_t::gpio_sel
ibutton_gpio_sel_t gpio_sel
Definition: ibutton.h:168
ibutton_return_value_t
ibutton_return_value_t
iButton Click return value data.
Definition: ibutton.h:177
IBUTTON_GPIO_1
@ IBUTTON_GPIO_1
Definition: ibutton.h:132
IBUTTON_OK
@ IBUTTON_OK
Definition: ibutton.h:178
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:131
ibutton_gpio_sel_t
ibutton_gpio_sel_t
iButton Click gpio selector.
Definition: ibutton.h:130
ibutton_cfg_t::st1
pin_name_t st1
Definition: ibutton.h:166
ibutton_disable_red_led
void ibutton_disable_red_led(ibutton_t *ctx)
iButton disable red led function.
IBUTTON_ERROR
@ IBUTTON_ERROR
Definition: ibutton.h:179
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:181
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:143
IBUTTON_LED_WAIT_KEY
@ IBUTTON_LED_WAIT_KEY
Definition: ibutton.h:192
ibutton_t::num_keys
uint8_t num_keys
Definition: ibutton.h:150
ibutton_cfg_t::gp0
pin_name_t gp0
Definition: ibutton.h:161
ibutton_t
iButton Click context object.
Definition: ibutton.h:141
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:144
ibutton_remove_keys
void ibutton_remove_keys(ibutton_t *ctx)
iButton remove keys function.
ibutton_t::ow
one_wire_t ow
Definition: ibutton.h:147