vibromotor  2.0.0.0
vibromotor.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 VIBROMOTOR_H
36 #define VIBROMOTOR_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 VIBROMOTOR_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM );
54 
60 #define VIBROMOTOR_RETVAL uint8_t
61 
62 #define VIBROMOTOR_OK 0x00
63 #define VIBROMOTOR_INIT_ERROR 0xFF
64 
70 #define VIBROMOTOR_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 } vibromotor_t;
96 
100 typedef struct
101 {
102  // Communication gpio pins
103 
104  pin_name_t pwm;
105 
106  // Additional gpio pins
107 
108  // static variable
109 
110  uint32_t dev_pwm_freq;
111 
113  // End types group
115 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
116 
122 #ifdef __cplusplus
123 extern "C"{
124 #endif
125 
135 
144 
153 
163 void vibromotor_set_duty_cycle ( vibromotor_t *ctx, float duty_cycle );
164 
172 void vibromotor_pwm_stop ( vibromotor_t *ctx );
173 
181 void vibromotor_pwm_start ( vibromotor_t *ctx );
182 
183 #ifdef __cplusplus
184 }
185 #endif
186 #endif // _VIBROMOTOR_H_
187  // End public_function group
190 
191 // ------------------------------------------------------------------------- END
uint32_t pwm_freq
Definition: vibromotor.h:93
void vibromotor_set_duty_cycle(vibromotor_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
pwm_t pwm
Definition: vibromotor.h:88
uint16_t pwm_period
Definition: vibromotor.h:92
uint32_t dev_pwm_freq
Definition: vibromotor.h:110
void vibromotor_default_cfg(vibromotor_t *ctx)
Click Default Configuration function.
void vibromotor_pwm_start(vibromotor_t *ctx)
Start PWM module.
Click ctx object definition.
Definition: vibromotor.h:83
void vibromotor_cfg_setup(vibromotor_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition: vibromotor.h:100
pin_name_t pwm
Definition: vibromotor.h:104
void vibromotor_pwm_stop(vibromotor_t *ctx)
Stop PWM module.
#define VIBROMOTOR_RETVAL
Definition: vibromotor.h:60
VIBROMOTOR_RETVAL vibromotor_init(vibromotor_t *ctx, vibromotor_cfg_t *cfg)
Initialization function.