pwmdriver  2.0.0.0
pwmdriver.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 PWMDRIVER_H
36 #define PWMDRIVER_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 PWMDRIVER_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
54 
60 #define PWMDRIVER_RETVAL uint8_t
61 
62 #define PWMDRIVER_OK 0x00
63 #define PWMDRIVER_INIT_ERROR 0xFF
64 
70 #define PWMDRIVER_DEF_FREQ 20000
71  // End group macro
74 // --------------------------------------------------------------- PUBLIC TYPES
83 typedef struct
84 {
85 
86  // Modules
87 
88  pwm_t pwm;
89 
90  // ctx variable
91 
92  uint16_t pwm_period;
93  uint32_t pwm_freq;
94 
95 } pwmdriver_t;
96 
100 typedef struct
101 {
102  // Communication gpio pins
103 
104  pin_name_t pwm;
105 
106 
107  // static variable
108 
109  uint32_t dev_pwm_freq;
110 
112  // End types group
114 
115 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
116 
122 #ifdef __cplusplus
123 extern "C"{
124 #endif
125 
135 
145 
153 void pwmdriver_default_cfg ( pwmdriver_t *ctx );
154 
164 void pwmdriver_set_duty_cycle ( pwmdriver_t *ctx, float duty_cycle );
165 
173 void pwmdriver_pwm_stop ( pwmdriver_t *ctx );
174 
182 void pwmdriver_pwm_start ( pwmdriver_t *ctx );
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 #endif // _PWMDRIVER_H_
188  // End public_function group
191 
192 // ------------------------------------------------------------------------- END
pin_name_t pwm
Definition: pwmdriver.h:104
void pwmdriver_set_duty_cycle(pwmdriver_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
Click configuration structure definition.
Definition: pwmdriver.h:100
uint16_t pwm_period
Definition: pwmdriver.h:92
uint32_t dev_pwm_freq
Definition: pwmdriver.h:109
PWMDRIVER_RETVAL pwmdriver_init(pwmdriver_t *ctx, pwmdriver_cfg_t *cfg)
Initialization function.
#define PWMDRIVER_RETVAL
Definition: pwmdriver.h:60
Click ctx object definition.
Definition: pwmdriver.h:83
uint32_t pwm_freq
Definition: pwmdriver.h:93
pwm_t pwm
Definition: pwmdriver.h:88
void pwmdriver_pwm_start(pwmdriver_t *ctx)
Start PWM module.
void pwmdriver_pwm_stop(pwmdriver_t *ctx)
Stop PWM module.
void pwmdriver_default_cfg(pwmdriver_t *ctx)
Click Default Configuration function.
void pwmdriver_cfg_setup(pwmdriver_cfg_t *cfg)
Config Object Initialization function.