vreg2  2.0.0.0
vreg2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef VREG2_H
36 #define VREG2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_pwm.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define VREG2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
55 
61 #define VREG2_RETVAL uint8_t
62 
63 #define VREG2_OK 0x00
64 #define VREG2_INIT_ERROR 0xFF
65 
71 #define VREG2_DEF_FREQ 20000
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef struct
85 {
86  // Input pins
87 
88  digital_in_t an;
89 
90  // Modules
91 
92  pwm_t pwm;
93 
94  // ctx variable
95 
96  uint16_t pwm_period;
97  uint32_t pwm_freq;
98 
99 } vreg2_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t pwm;
109 
110  // Additional gpio pins
111 
112  pin_name_t an;
113 
114  // static variable
115 
116  uint32_t dev_pwm_freq;
117 
118 } vreg2_cfg_t;
119  // End types group
121 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
122 
128 #ifdef __cplusplus
129 extern "C"{
130 #endif
131 
140 void vreg2_cfg_setup ( vreg2_cfg_t *cfg );
141 
150 
158 void vreg2_default_cfg ( vreg2_t *ctx );
159 
169 void vreg2_set_duty_cycle ( vreg2_t *ctx, float duty_cycle );
170 
178 void vreg2_pwm_stop ( vreg2_t *ctx );
179 
187 void vreg2_pwm_start ( vreg2_t *ctx );
188 
189 #ifdef __cplusplus
190 }
191 #endif
192 #endif // _VREG2_H_
193  // End public_function group
196 
197 // ------------------------------------------------------------------------- END
VREG2_RETVAL vreg2_init(vreg2_t *ctx, vreg2_cfg_t *cfg)
Initialization function.
pwm_t pwm
Definition: vreg2.h:92
uint32_t dev_pwm_freq
Definition: vreg2.h:116
#define VREG2_RETVAL
Definition: vreg2.h:61
void vreg2_default_cfg(vreg2_t *ctx)
Click Default Configuration function.
Click configuration structure definition.
Definition: vreg2.h:104
void vreg2_set_duty_cycle(vreg2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void vreg2_pwm_start(vreg2_t *ctx)
Start PWM module.
pin_name_t an
Definition: vreg2.h:112
void vreg2_pwm_stop(vreg2_t *ctx)
Stop PWM module.
void vreg2_cfg_setup(vreg2_cfg_t *cfg)
Config Object Initialization function.
pin_name_t pwm
Definition: vreg2.h:108
uint32_t pwm_freq
Definition: vreg2.h:97
uint16_t pwm_period
Definition: vreg2.h:96
Click ctx object definition.
Definition: vreg2.h:84
digital_in_t an
Definition: vreg2.h:88