dcmotor2  2.0.0.0
dcmotor2.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 DCMOTOR2_H
36 #define DCMOTOR2_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 DCMOTOR2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define DCMOTOR2_RETVAL uint8_t
64 
65 #define DCMOTOR2_OK 0x00
66 #define DCMOTOR2_INIT_ERROR 0xFF
67 
73 #define DCMOTOR2_DEF_FREQ 160000
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
86 typedef struct
87 {
88 
89  // Output pins
90 
91  digital_out_t in2;
92  digital_out_t in1;
93  digital_out_t slp;
94 
95  // Modules
96 
97  pwm_t pwm;
98 
99  // ctx variable
100 
101  uint32_t pwm_freq;
102 
103 } dcmotor2_t;
104 
108 typedef struct
109 {
110  // Communication gpio pins
111 
112  pin_name_t pwm;
113 
114  // Additional gpio pins
115 
116  pin_name_t in2;
117  pin_name_t in1;
118  pin_name_t slp;
119 
120  // static variable
121 
122  uint32_t dev_pwm_freq;
123 
125  // End types group
127 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
128 
134 #ifdef __cplusplus
135 extern "C"{
136 #endif
137 
146 void dcmotor2_cfg_setup ( dcmotor2_cfg_t *cfg );
147 
156 
166 void dcmotor2_set_duty_cycle ( dcmotor2_t *ctx, float duty_cycle );
167 
175 void dcmotor2_pwm_stop ( dcmotor2_t *ctx );
176 
184 void dcmotor2_pwm_start ( dcmotor2_t *ctx );
185 
193 void dcmotor2_enable_motor ( dcmotor2_t *ctx );
194 
202 void dcmotor2_disable_motor ( dcmotor2_t *ctx );
203 
211 void dcmotor2_spin_clockwise ( dcmotor2_t *ctx );
212 
222 
230 void dcmotor2_pull_brake ( dcmotor2_t *ctx );
231 
239 void dcmotor2_stop_motor ( dcmotor2_t *ctx );
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 #endif // _DCMOTOR2_H_
245  // End public_function group
248 
249 // ------------------------------------------------------------------------- END
dcmotor2_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor2.h:101
dcmotor2_init
DCMOTOR2_RETVAL dcmotor2_init(dcmotor2_t *ctx, dcmotor2_cfg_t *cfg)
Initialization function.
dcmotor2_pwm_start
void dcmotor2_pwm_start(dcmotor2_t *ctx)
Start PWM module.
DCMOTOR2_RETVAL
#define DCMOTOR2_RETVAL
Definition: dcmotor2.h:63
dcmotor2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor2.h:122
dcmotor2_cfg_t::in2
pin_name_t in2
Definition: dcmotor2.h:116
dcmotor2_stop_motor
void dcmotor2_stop_motor(dcmotor2_t *ctx)
Stop motor clockwise.
dcmotor2_cfg_t::slp
pin_name_t slp
Definition: dcmotor2.h:118
dcmotor2_enable_motor
void dcmotor2_enable_motor(dcmotor2_t *ctx)
Enable motor.
dcmotor2_spin_counter_clockwise
void dcmotor2_spin_counter_clockwise(dcmotor2_t *ctx)
Spin motor counter clockwise.
dcmotor2_t::in1
digital_out_t in1
Definition: dcmotor2.h:92
dcmotor2_pwm_stop
void dcmotor2_pwm_stop(dcmotor2_t *ctx)
Stop PWM module.
dcmotor2_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor2.h:112
dcmotor2_disable_motor
void dcmotor2_disable_motor(dcmotor2_t *ctx)
Disable motor.
dcmotor2_spin_clockwise
void dcmotor2_spin_clockwise(dcmotor2_t *ctx)
Spin motor clockwise.
dcmotor2_t::slp
digital_out_t slp
Definition: dcmotor2.h:93
dcmotor2_t::in2
digital_out_t in2
Definition: dcmotor2.h:91
dcmotor2_cfg_t::in1
pin_name_t in1
Definition: dcmotor2.h:117
dcmotor2_t
Click ctx object definition.
Definition: dcmotor2.h:86
dcmotor2_cfg_setup
void dcmotor2_cfg_setup(dcmotor2_cfg_t *cfg)
Config Object Initialization function.
dcmotor2_cfg_t
Click configuration structure definition.
Definition: dcmotor2.h:108
dcmotor2_pull_brake
void dcmotor2_pull_brake(dcmotor2_t *ctx)
Pull motor brake.
dcmotor2_set_duty_cycle
void dcmotor2_set_duty_cycle(dcmotor2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
dcmotor2_t::pwm
pwm_t pwm
Definition: dcmotor2.h:97