dcmotor4  2.0.0.0
dcmotor4.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 DCMOTOR4_H
36 #define DCMOTOR4_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 DCMOTOR4_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define DCMOTOR4_RETVAL uint8_t
64 
65 #define DCMOTOR4_OK 0x00
66 #define DCMOTOR4_INIT_ERROR 0xFF
67 
73 #define DCMOTOR4_DEF_FREQ 10000
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
86 typedef struct
87 {
88 
89  // Output pins
90 
91  digital_out_t dir;
92  digital_out_t en;
93 
94  // Input pins
95 
96  digital_in_t flt;
97 
98  // Modules
99 
100  pwm_t pwm;
101 
102  // ctx variable
103 
104  uint32_t pwm_freq;
105 
106 } dcmotor4_t;
107 
111 typedef struct
112 {
113  // Communication gpio pins
114 
115  pin_name_t pwm;
116 
117  // Additional gpio pins
118 
119  pin_name_t dir;
120  pin_name_t en;
121  pin_name_t flt;
122 
123  // static variable
124 
125  uint32_t dev_pwm_freq;
126 
128  // End types group
130 
131 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132 
138 #ifdef __cplusplus
139 extern "C"{
140 #endif
141 
151 
160 
170 void dcmotor4_set_duty_cycle ( dcmotor4_t *ctx, float duty_cycle );
171 
180 
189 
198 
207 
216 
225 
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 #endif // _DCMOTOR4_H_
239  // End public_function group
242 
243 // ------------------------------------------------------------------------- END
dcmotor4_set_duty_cycle
void dcmotor4_set_duty_cycle(dcmotor4_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor4_cfg_setup
void dcmotor4_cfg_setup(dcmotor4_cfg_t *cfg)
Config Object Initialization function.
dcmotor4_enable_motor
void dcmotor4_enable_motor(dcmotor4_t *ctx)
Enable motor.
dcmotor4_t::flt
digital_in_t flt
Definition: dcmotor4.h:96
dcmotor4_t::dir
digital_out_t dir
Definition: dcmotor4.h:91
dcmotor4_t::en
digital_out_t en
Definition: dcmotor4.h:92
dcmotor4_get_diagnostic
uint8_t dcmotor4_get_diagnostic(dcmotor4_t *ctx)
Get diagnostic.
dcmotor4_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor4.h:115
dcmotor4_cfg_t::flt
pin_name_t flt
Definition: dcmotor4.h:121
DCMOTOR4_RETVAL
#define DCMOTOR4_RETVAL
Definition: dcmotor4.h:63
dcmotor4_cfg_t::dir
pin_name_t dir
Definition: dcmotor4.h:119
dcmotor4_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor4.h:125
dcmotor4_pwm_stop
void dcmotor4_pwm_stop(dcmotor4_t *ctx)
Stop PWM module.
dcmotor4_run_clockwise
void dcmotor4_run_clockwise(dcmotor4_t *ctx)
Run clockwise.
dcmotor4_pwm_start
void dcmotor4_pwm_start(dcmotor4_t *ctx)
Start PWM module.
dcmotor4_t::pwm
pwm_t pwm
Definition: dcmotor4.h:100
dcmotor4_t
Click ctx object definition.
Definition: dcmotor4.h:87
dcmotor4_cfg_t::en
pin_name_t en
Definition: dcmotor4.h:120
dcmotor4_disable_motor
void dcmotor4_disable_motor(dcmotor4_t *ctx)
Disable motor.
dcmotor4_init
DCMOTOR4_RETVAL dcmotor4_init(dcmotor4_t *ctx, dcmotor4_cfg_t *cfg)
Initialization function.
dcmotor4_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor4.h:104
dcmotor4_cfg_t
Click configuration structure definition.
Definition: dcmotor4.h:112
dcmotor4_run_counter_clockwise
void dcmotor4_run_counter_clockwise(dcmotor4_t *ctx)
Run counter clockwise.