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
33extern "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
76 // 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
96 // buttong_map
97 // buttong
98
108typedef 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
124typedef 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;
135
140typedef enum
141{
143 BUTTONG_ERROR = -1
144
146
163
179
192err_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
238 // buttong
239
240// ------------------------------------------------------------------------ END
buttong_return_value_t
Button G Click return value data.
Definition buttong.h:141
@ BUTTONG_OK
Definition buttong.h:142
@ BUTTONG_ERROR
Definition buttong.h:143
err_t buttong_pwm_start(buttong_t *ctx)
Button G start PWM module.
err_t buttong_set_duty_cycle(buttong_t *ctx, float duty_cycle)
Button G sets PWM duty cycle.
void buttong_cfg_setup(buttong_cfg_t *cfg)
Button G configuration object setup function.
err_t buttong_init(buttong_t *ctx, buttong_cfg_t *cfg)
Button G initialization function.
err_t buttong_pwm_stop(buttong_t *ctx)
Button G stop PWM module.
uint8_t buttong_get_button_state(buttong_t *ctx)
Button G get button state function.
Button G Click configuration object.
Definition buttong.h:125
uint32_t dev_pwm_freq
Definition buttong.h:132
pin_name_t int_pin
Definition buttong.h:129
pin_name_t pwm
Definition buttong.h:127
Button G Click driver selector.
Definition buttong.h:109
uint32_t pwm_freq
Definition buttong.h:116
digital_in_t int_pin
Definition buttong.h:110
pwm_t pwm
Definition buttong.h:113