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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_pwm.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define DCMOTOR4_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define DCMOTOR4_RETVAL uint8_t
74 
75 #define DCMOTOR4_OK 0x00
76 #define DCMOTOR4_INIT_ERROR 0xFF
77 
83 #define DCMOTOR4_DEF_FREQ 10000
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98 
99  // Output pins
100 
101  digital_out_t dir;
102  digital_out_t en;
103 
104  // Input pins
105 
106  digital_in_t flt;
107 
108  // Modules
109 
110  pwm_t pwm;
111 
112  // ctx variable
113 
114  uint32_t pwm_freq;
115 
116 } dcmotor4_t;
117 
121 typedef struct
122 {
123  // Communication gpio pins
124 
125  pin_name_t pwm;
126 
127  // Additional gpio pins
128 
129  pin_name_t dir;
130  pin_name_t en;
131  pin_name_t flt;
132 
133  // static variable
134 
135  uint32_t dev_pwm_freq;
136 
138  // End types group
140 
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
170 
180 void dcmotor4_set_duty_cycle ( dcmotor4_t *ctx, float duty_cycle );
181 
190 
199 
208 
217 
226 
235 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // _DCMOTOR4_H_
249  // End public_function group
252 
253 // ------------------------------------------------------------------------- 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:106
dcmotor4_t::dir
digital_out_t dir
Definition: dcmotor4.h:101
dcmotor4_t::en
digital_out_t en
Definition: dcmotor4.h:102
dcmotor4_get_diagnostic
uint8_t dcmotor4_get_diagnostic(dcmotor4_t *ctx)
Get diagnostic.
dcmotor4_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor4.h:125
dcmotor4_cfg_t::flt
pin_name_t flt
Definition: dcmotor4.h:131
DCMOTOR4_RETVAL
#define DCMOTOR4_RETVAL
Definition: dcmotor4.h:73
dcmotor4_cfg_t::dir
pin_name_t dir
Definition: dcmotor4.h:129
dcmotor4_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor4.h:135
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:110
dcmotor4_t
Click ctx object definition.
Definition: dcmotor4.h:97
dcmotor4_cfg_t::en
pin_name_t en
Definition: dcmotor4.h:130
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:114
dcmotor4_cfg_t
Click configuration structure definition.
Definition: dcmotor4.h:122
dcmotor4_run_counter_clockwise
void dcmotor4_run_counter_clockwise(dcmotor4_t *ctx)
Run counter clockwise.