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 "mikrosdk_version.h"
37 
38 #ifdef __GNUC__
39 #if mikroSDK_GET_VERSION < 20800ul
40 #include "rcu_delays.h"
41 #else
42 #include "delays.h"
43 #endif
44 #endif
45 
46 #include "drv_digital_out.h"
47 #include "drv_digital_in.h"
48 #include "drv_pwm.h"
49 
70 #define BUTTONG_DEF_FREQ 500
71  // buttong_cfg
73 
88 #define BUTTONG_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
90  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
91  // buttong_map // buttong
94 
104 typedef struct
105 {
106  digital_in_t int_pin;
108  // Modules
109  pwm_t pwm;
111  // ctx variable
112  uint32_t pwm_freq;
114 } buttong_t;
115 
120 typedef struct
121 {
122  // Communication gpio pins
123  pin_name_t pwm;
125  pin_name_t int_pin;
127  // Static variable
128  uint32_t dev_pwm_freq;
130 } buttong_cfg_t;
131 
136 typedef enum
137 {
139  BUTTONG_ERROR = -1
140 
142 
159 
174 err_t buttong_init ( buttong_t *ctx, buttong_cfg_t *cfg );
175 
188 err_t buttong_set_duty_cycle ( buttong_t *ctx, float duty_cycle );
189 
202 
215 
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 #endif // BUTTONG_H
233  // buttong
235 
236 // ------------------------------------------------------------------------ END
buttong_cfg_t::int_pin
pin_name_t int_pin
Definition: buttong.h:125
buttong_t::pwm_freq
uint32_t pwm_freq
Definition: buttong.h:112
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:105
buttong_t::pwm
pwm_t pwm
Definition: buttong.h:109
buttong_cfg_t
Button G Click configuration object.
Definition: buttong.h:121
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:137
buttong_cfg_t::pwm
pin_name_t pwm
Definition: buttong.h:123
buttong_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buttong.h:128
BUTTONG_ERROR
@ BUTTONG_ERROR
Definition: buttong.h:139
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:138
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:106