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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_pwm.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define DCMOTOR2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
69  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define DCMOTOR2_RETVAL uint8_t
78 
79 #define DCMOTOR2_OK 0x00
80 #define DCMOTOR2_INIT_ERROR 0xFF
81 
87 #define DCMOTOR2_DEF_FREQ 160000
88  // End group macro
91 // --------------------------------------------------------------- PUBLIC TYPES
100 typedef struct
101 {
102 
103  // Output pins
104 
105  digital_out_t in2;
106  digital_out_t in1;
107  digital_out_t slp;
108 
109  // Modules
110 
111  pwm_t pwm;
112 
113  // ctx variable
114 
115  uint32_t pwm_freq;
116 
117 } dcmotor2_t;
118 
122 typedef struct
123 {
124  // Communication gpio pins
125 
126  pin_name_t pwm;
127 
128  // Additional gpio pins
129 
130  pin_name_t in2;
131  pin_name_t in1;
132  pin_name_t slp;
133 
134  // static variable
135 
136  uint32_t dev_pwm_freq;
137 
139  // End types group
141 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142 
148 #ifdef __cplusplus
149 extern "C"{
150 #endif
151 
161 
170 
180 void dcmotor2_set_duty_cycle ( dcmotor2_t *ctx, float duty_cycle );
181 
190 
199 
208 
217 
226 
236 
245 
254 
255 #ifdef __cplusplus
256 }
257 #endif
258 #endif // _DCMOTOR2_H_
259  // End public_function group
262 
263 // ------------------------------------------------------------------------- END
dcmotor2_t::pwm_freq
uint32_t pwm_freq
Definition: dcmotor2.h:115
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:77
dcmotor2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: dcmotor2.h:136
dcmotor2_cfg_t::in2
pin_name_t in2
Definition: dcmotor2.h:130
dcmotor2_stop_motor
void dcmotor2_stop_motor(dcmotor2_t *ctx)
Stop motor clockwise.
dcmotor2_cfg_t::slp
pin_name_t slp
Definition: dcmotor2.h:132
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:106
dcmotor2_pwm_stop
void dcmotor2_pwm_stop(dcmotor2_t *ctx)
Stop PWM module.
dcmotor2_cfg_t::pwm
pin_name_t pwm
Definition: dcmotor2.h:126
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:107
dcmotor2_t::in2
digital_out_t in2
Definition: dcmotor2.h:105
dcmotor2_cfg_t::in1
pin_name_t in1
Definition: dcmotor2.h:131
dcmotor2_t
Click ctx object definition.
Definition: dcmotor2.h:101
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:123
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:111