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 )
77#define DCMOTOR2_RETVAL uint8_t
78
79#define DCMOTOR2_OK 0x00
80#define DCMOTOR2_INIT_ERROR 0xFF
87#define DCMOTOR2_DEF_FREQ 160000
90 // End group macro
91// --------------------------------------------------------------- PUBLIC TYPES
100typedef 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
122typedef 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
140 // End types group
141// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
142
148#ifdef __cplusplus
149extern "C"{
150#endif
151
161
170
180void 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
260 // End public_function group
262
263// ------------------------------------------------------------------------- END
#define DCMOTOR2_RETVAL
Definition dcmotor2.h:77
void dcmotor2_pwm_stop(dcmotor2_t *ctx)
Stop PWM module.
void dcmotor2_cfg_setup(dcmotor2_cfg_t *cfg)
Config Object Initialization function.
void dcmotor2_spin_counter_clockwise(dcmotor2_t *ctx)
Spin motor counter clockwise.
void dcmotor2_stop_motor(dcmotor2_t *ctx)
Stop motor clockwise.
DCMOTOR2_RETVAL dcmotor2_init(dcmotor2_t *ctx, dcmotor2_cfg_t *cfg)
Initialization function.
void dcmotor2_pwm_start(dcmotor2_t *ctx)
Start PWM module.
void dcmotor2_spin_clockwise(dcmotor2_t *ctx)
Spin motor clockwise.
void dcmotor2_disable_motor(dcmotor2_t *ctx)
Disable motor.
void dcmotor2_set_duty_cycle(dcmotor2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
void dcmotor2_pull_brake(dcmotor2_t *ctx)
Pull motor brake.
void dcmotor2_enable_motor(dcmotor2_t *ctx)
Enable motor.
Click configuration structure definition.
Definition dcmotor2.h:123
pin_name_t slp
Definition dcmotor2.h:132
pin_name_t in2
Definition dcmotor2.h:130
uint32_t dev_pwm_freq
Definition dcmotor2.h:136
pin_name_t in1
Definition dcmotor2.h:131
pin_name_t pwm
Definition dcmotor2.h:126
Click ctx object definition.
Definition dcmotor2.h:101
digital_out_t in2
Definition dcmotor2.h:105
digital_out_t slp
Definition dcmotor2.h:107
uint32_t pwm_freq
Definition dcmotor2.h:115
digital_out_t in1
Definition dcmotor2.h:106
pwm_t pwm
Definition dcmotor2.h:111