buttong  2.0.0.0
buttong.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 
29 #ifndef BUTTONG_H
30 #define BUTTONG_H
31 
32 #ifdef __cplusplus
33 extern "C"{
34 #endif
35 
36 #include "drv_digital_out.h"
37 #include "drv_digital_in.h"
38 #include "drv_pwm.h"
39 
60 #define BUTTONG_DEF_FREQ 500
61  // buttong_cfg
63 
78 #define BUTTONG_MAP_MIKROBUS( cfg, mikrobus ) \
79  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
80  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
81  // buttong_map // buttong
84 
94 typedef struct
95 {
96  digital_in_t int_pin;
98  // Modules
99  pwm_t pwm;
101  // ctx variable
102  uint32_t pwm_freq;
104 } buttong_t;
105 
110 typedef struct
111 {
112  // Communication gpio pins
113  pin_name_t pwm;
115  pin_name_t int_pin;
117  // Static variable
118  uint32_t dev_pwm_freq;
120 } buttong_cfg_t;
121 
126 typedef enum
127 {
129  BUTTONG_ERROR = -1
130 
132 
149 
164 err_t buttong_init ( buttong_t *ctx, buttong_cfg_t *cfg );
165 
178 err_t buttong_set_duty_cycle ( buttong_t *ctx, float duty_cycle );
179 
192 
205 
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 #endif // BUTTONG_H
223  // buttong
225 
226 // ------------------------------------------------------------------------ END
buttong_cfg_t::int_pin
pin_name_t int_pin
Definition: buttong.h:115
buttong_t::pwm_freq
uint32_t pwm_freq
Definition: buttong.h:102
buttong_set_duty_cycle
err_t buttong_set_duty_cycle(buttong_t *ctx, float duty_cycle)
Button G sets PWM duty cycle.
buttong_t
Button G Click driver selector.
Definition: buttong.h:95
buttong_t::pwm
pwm_t pwm
Definition: buttong.h:99
buttong_cfg_t
Button G Click configuration object.
Definition: buttong.h:111
buttong_pwm_start
err_t buttong_pwm_start(buttong_t *ctx)
Button G start PWM module.
buttong_return_value_t
buttong_return_value_t
Button G Click return value data.
Definition: buttong.h:127
buttong_cfg_t::pwm
pin_name_t pwm
Definition: buttong.h:113
buttong_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buttong.h:118
BUTTONG_ERROR
@ BUTTONG_ERROR
Definition: buttong.h:129
buttong_get_button_state
uint8_t buttong_get_button_state(buttong_t *ctx)
Button G get button state function.
buttong_init
err_t buttong_init(buttong_t *ctx, buttong_cfg_t *cfg)
Button G initialization function.
BUTTONG_OK
@ BUTTONG_OK
Definition: buttong.h:128
buttong_cfg_setup
void buttong_cfg_setup(buttong_cfg_t *cfg)
Button G configuration object setup function.
buttong_pwm_stop
err_t buttong_pwm_stop(buttong_t *ctx)
Button G stop PWM module.
buttong_t::int_pin
digital_in_t int_pin
Definition: buttong.h:96