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 "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 DCMOTOR2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
65  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define DCMOTOR2_RETVAL uint8_t
74 
75 #define DCMOTOR2_OK 0x00
76 #define DCMOTOR2_INIT_ERROR 0xFF
77 
83 #define DCMOTOR2_DEF_FREQ 160000
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
96 typedef struct
97 {
98 
99  // Output pins
100 
101  digital_out_t in2;
102  digital_out_t in1;
103  digital_out_t slp;
104 
105  // Modules
106 
107  pwm_t pwm;
108 
109  // ctx variable
110 
111  uint32_t pwm_freq;
112 
113 } dcmotor2_t;
114 
118 typedef struct
119 {
120  // Communication gpio pins
121 
122  pin_name_t pwm;
123 
124  // Additional gpio pins
125 
126  pin_name_t in2;
127  pin_name_t in1;
128  pin_name_t slp;
129 
130  // static variable
131 
132  uint32_t dev_pwm_freq;
133 
135  // End types group
137 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138 
144 #ifdef __cplusplus
145 extern "C"{
146 #endif
147 
157 
166 
176 void dcmotor2_set_duty_cycle ( dcmotor2_t *ctx, float duty_cycle );
177 
186 
195 
204 
213 
222 
232 
241 
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 #endif // _DCMOTOR2_H_
255  // End public_function group
258 
259 // ------------------------------------------------------------------------- END
dcmotor2_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor2.h:111
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:73
dcmotor2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor2.h:132
dcmotor2_cfg_t::in2
pin_name_t in2
Definition: dcmotor2.h:126
dcmotor2_stop_motor
void dcmotor2_stop_motor(dcmotor2_t *ctx)
Stop motor clockwise.
dcmotor2_cfg_t::slp
pin_name_t slp
Definition: dcmotor2.h:128
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:102
dcmotor2_pwm_stop
void dcmotor2_pwm_stop(dcmotor2_t *ctx)
Stop PWM module.
dcmotor2_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor2.h:122
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:103
dcmotor2_t::in2
digital_out_t in2
Definition: dcmotor2.h:101
dcmotor2_cfg_t::in1
pin_name_t in1
Definition: dcmotor2.h:127
dcmotor2_t
Click ctx object definition.
Definition: dcmotor2.h:97
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:119
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:107