button3  2.1.0.0
button3.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 BUTTON3_H
29 #define BUTTON3_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_i2c_master.h"
52 
73 #define BUTTON3_REG_INPUT 0x00
74 #define BUTTON3_REG_OUTPUT 0x01
75 #define BUTTON3_REG_POLARITY 0x02
76 #define BUTTON3_REG_CONFIG 0x03
77  // button3_reg
79 
94 #define BUTTON3_PIN_RED_BUTTON 0x01
95 #define BUTTON3_PIN_RED_LED 0x02
96 #define BUTTON3_PIN_GREEN_BUTTON 0x04
97 #define BUTTON3_PIN_GREEN_LED 0x08
98 #define BUTTON3_PIN_BLUE_LED 0x10
99 #define BUTTON3_PIN_BLUE_BUTTON 0x20
100 
105 #define BUTTON3_DEFAULT_PIN_CONFIG 0xE5
106 
111 #define BUTTON3_PIN_STATE_LOW 0
112 #define BUTTON3_PIN_STATE_HIGH 1
113 
118 #define BUTTON3_SWITCH_OFF 0
119 #define BUTTON3_SWITCH_ON 1
120 
125 #define BUTTON3_BUTTON_PRESSED 0
126 #define BUTTON3_BUTTON_RELESED 1
127 
133 #define BUTTON3_DEVICE_ADDRESS_0 0x20
134 #define BUTTON3_DEVICE_ADDRESS_1 0x21
135  // button3_set
137 
152 #define BUTTON3_MAP_MIKROBUS( cfg, mikrobus ) \
153  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
154  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
155  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
156  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
157  // button3_map // button3
160 
165 typedef struct
166 {
167  // Output pins
168  digital_out_t rst;
170  // Input pins
171  digital_in_t int_pin;
173  // Modules
174  i2c_master_t i2c;
176  // I2C slave address
177  uint8_t slave_address;
179 } button3_t;
180 
185 typedef struct
186 {
187  pin_name_t scl;
188  pin_name_t sda;
190  pin_name_t rst;
191  pin_name_t int_pin;
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
196 } button3_cfg_t;
197 
202 typedef enum
203 {
205  BUTTON3_ERROR = -1
206 
208 
225 
239 err_t button3_init ( button3_t *ctx, button3_cfg_t *cfg );
240 
254 
268 err_t button3_write_reg ( button3_t *ctx, uint8_t reg, uint8_t data_in );
269 
282 err_t button3_read_reg ( button3_t *ctx, uint8_t reg, uint8_t *data_out );
283 
293 
304 void button3_set_rst_pin ( button3_t *ctx, uint8_t state );
305 
315 
328 err_t button3_get_red_button ( button3_t *ctx, uint8_t *state );
329 
342 err_t button3_get_green_button ( button3_t *ctx, uint8_t *state );
343 
356 err_t button3_get_blue_button ( button3_t *ctx, uint8_t *state );
357 
370 err_t button3_get_red_led ( button3_t *ctx, uint8_t *state );
371 
384 err_t button3_get_green_led ( button3_t *ctx, uint8_t *state );
385 
398 err_t button3_get_blue_led ( button3_t *ctx, uint8_t *state );
399 
411 
423 
435 
447 
459 
471 
483 
495 
507 
508 #ifdef __cplusplus
509 }
510 #endif
511 #endif // BUTTON3_H
512  // button3
514 
515 // ------------------------------------------------------------------------ END
button3_get_green_button
err_t button3_get_green_button(button3_t *ctx, uint8_t *state)
Button 3 get green button function.
button3_t::i2c
i2c_master_t i2c
Definition: button3.h:174
button3_disable_red_led
err_t button3_disable_red_led(button3_t *ctx)
Button 3 disable red led function.
button3_enable_green_led
err_t button3_enable_green_led(button3_t *ctx)
Button 3 enable green led function.
button3_cfg_t
Button 3 Click configuration object.
Definition: button3.h:186
button3_get_blue_led
err_t button3_get_blue_led(button3_t *ctx, uint8_t *state)
Button 3 get blue led function.
button3_write_reg
err_t button3_write_reg(button3_t *ctx, uint8_t reg, uint8_t data_in)
Button 3 write reg function.
button3_cfg_t::rst
pin_name_t rst
Definition: button3.h:190
button3_get_int_pin
uint8_t button3_get_int_pin(button3_t *ctx)
Button 3 get INT pin function.
button3_toggle_green_led
err_t button3_toggle_green_led(button3_t *ctx)
Button 3 toggle green led function.
button3_return_value_t
button3_return_value_t
Button 3 Click return value data.
Definition: button3.h:203
button3_cfg_t::int_pin
pin_name_t int_pin
Definition: button3.h:191
button3_disable_blue_led
err_t button3_disable_blue_led(button3_t *ctx)
Button 3 disable blue led function.
button3_set_rst_pin
void button3_set_rst_pin(button3_t *ctx, uint8_t state)
Button 3 set RST pin function.
button3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: button3.h:193
button3_get_green_led
err_t button3_get_green_led(button3_t *ctx, uint8_t *state)
Button 3 get green led function.
button3_cfg_t::scl
pin_name_t scl
Definition: button3.h:187
button3_t::slave_address
uint8_t slave_address
Definition: button3.h:177
button3_get_blue_button
err_t button3_get_blue_button(button3_t *ctx, uint8_t *state)
Button 3 get blue button function.
BUTTON3_ERROR
@ BUTTON3_ERROR
Definition: button3.h:205
button3_enable_red_led
err_t button3_enable_red_led(button3_t *ctx)
Button 3 enable red led function.
button3_disable_green_led
err_t button3_disable_green_led(button3_t *ctx)
Button 3 disable green led function.
button3_init
err_t button3_init(button3_t *ctx, button3_cfg_t *cfg)
Button 3 initialization function.
BUTTON3_OK
@ BUTTON3_OK
Definition: button3.h:204
button3_get_red_led
err_t button3_get_red_led(button3_t *ctx, uint8_t *state)
Button 3 get red led function.
button3_get_red_button
err_t button3_get_red_button(button3_t *ctx, uint8_t *state)
Button 3 get red button function.
button3_cfg_t::i2c_address
uint8_t i2c_address
Definition: button3.h:194
button3_toggle_red_led
err_t button3_toggle_red_led(button3_t *ctx)
Button 3 toggle red led function.
button3_t::int_pin
digital_in_t int_pin
Definition: button3.h:171
button3_cfg_setup
void button3_cfg_setup(button3_cfg_t *cfg)
Button 3 configuration object setup function.
button3_reset_device
void button3_reset_device(button3_t *ctx)
Button 3 reset device function.
button3_default_cfg
err_t button3_default_cfg(button3_t *ctx)
Button 3 default configuration function.
button3_cfg_t::sda
pin_name_t sda
Definition: button3.h:188
button3_enable_blue_led
err_t button3_enable_blue_led(button3_t *ctx)
Button 3 enable blue led function.
button3_read_reg
err_t button3_read_reg(button3_t *ctx, uint8_t reg, uint8_t *data_out)
Button 3 read reg function.
button3_t::rst
digital_out_t rst
Definition: button3.h:168
button3_t
Button 3 Click context object.
Definition: button3.h:166
button3_toggle_blue_led
err_t button3_toggle_blue_led(button3_t *ctx)
Button 3 toggle blue led function.