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 
40 #ifdef PREINIT_SUPPORTED
41 #include "preinit.h"
42 #endif
43 
44 #ifdef MikroCCoreVersion
45  #if MikroCCoreVersion >= 1
46  #include "delays.h"
47  #endif
48 #endif
49 
50 #include "drv_digital_out.h"
51 #include "drv_digital_in.h"
52 #include "drv_pwm.h"
53 
74 #define BUTTONG_DEF_FREQ 500
75  // buttong_cfg
77 
92 #define BUTTONG_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
94  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
95  // buttong_map // buttong
98 
108 typedef struct
109 {
110  digital_in_t int_pin;
112  // Modules
113  pwm_t pwm;
115  // ctx variable
116  uint32_t pwm_freq;
118 } buttong_t;
119 
124 typedef struct
125 {
126  // Communication gpio pins
127  pin_name_t pwm;
129  pin_name_t int_pin;
131  // Static variable
132  uint32_t dev_pwm_freq;
134 } buttong_cfg_t;
135 
140 typedef enum
141 {
143  BUTTONG_ERROR = -1
144 
146 
163 
178 err_t buttong_init ( buttong_t *ctx, buttong_cfg_t *cfg );
179 
192 err_t buttong_set_duty_cycle ( buttong_t *ctx, float duty_cycle );
193 
206 
219 
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 #endif // BUTTONG_H
237  // buttong
239 
240 // ------------------------------------------------------------------------ END
buttong_cfg_t::int_pin
pin_name_t int_pin
Definition: buttong.h:129
buttong_t::pwm_freq
uint32_t pwm_freq
Definition: buttong.h:116
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:109
buttong_t::pwm
pwm_t pwm
Definition: buttong.h:113
buttong_cfg_t
Button G Click configuration object.
Definition: buttong.h:125
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:141
buttong_cfg_t::pwm
pin_name_t pwm
Definition: buttong.h:127
buttong_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: buttong.h:132
BUTTONG_ERROR
@ BUTTONG_ERROR
Definition: buttong.h:143
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:142
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:110