brushless2 2.0.0.0
brushless2.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 BRUSHLESS2_H
36#define BRUSHLESS2_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 BRUSHLESS2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68 cfg.cfg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69 cfg.fr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.fgs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define BRUSHLESS2_RETVAL uint8_t
79
80#define BRUSHLESS2_OK 0x00
81#define BRUSHLESS2_INIT_ERROR 0xFF
88#define BRUSHLESS2_DEF_FREQ 5000
91 // End group macro
92// --------------------------------------------------------------- PUBLIC TYPES
101typedef struct
102{
103
104 // Output pins
105
106 digital_out_t fr;
107 digital_out_t fgs;
108
109 // Input pins
110
111 digital_in_t cfg;
112 digital_in_t int_pin;
113
114 // Modules
115
116 pwm_t pwm;
117
118 // ctx variable
119
120 uint32_t pwm_freq;
121
123
127typedef struct
128{
129 // Communication gpio pins
130
131 pin_name_t pwm;
132
133 // Additional gpio pins
134
135 pin_name_t cfg;
136 pin_name_t fr;
137 pin_name_t fgs;
138 pin_name_t int_pin;
139
140 // static variable
141
142 uint32_t dev_pwm_freq;
143
145
146 // End types group
147// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148
154#ifdef __cplusplus
155extern "C"{
156#endif
157
167
176
186void brushless2_set_duty_cycle ( brushless2_t *ctx, float duty_cycle );
187
196
205
215
225
235
248
249#ifdef __cplusplus
250}
251#endif
252#endif // _BRUSHLESS2_H_
253
254 // End public_function group
256
257// ------------------------------------------------------------------------- END
#define BRUSHLESS2_RETVAL
Definition brushless2.h:78
void brushless2_invert_direction(brushless2_t *ctx)
Invert the direction of rotation.
void brushless2_pwm_start(brushless2_t *ctx)
Start PWM module.
void brushless2_cfg_setup(brushless2_cfg_t *cfg)
Config Object Initialization function.
void brushless2_set_duty_cycle(brushless2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
uint8_t brushless2_get_interrupt_status(brushless2_t *ctx)
Get Interrupt pin state function.
void brushless2_pwm_stop(brushless2_t *ctx)
Stop PWM module.
void brushless2_clockwise(brushless2_t *ctx)
Set the direction of rotation in the clockwise direction function.
void brushless2_counter_clockwise(brushless2_t *ctx)
Set the direction of rotation in the counterclockwise direction function.
BRUSHLESS2_RETVAL brushless2_init(brushless2_t *ctx, brushless2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition brushless2.h:128
pin_name_t fgs
Definition brushless2.h:137
pin_name_t cfg
Definition brushless2.h:135
uint32_t dev_pwm_freq
Definition brushless2.h:142
pin_name_t int_pin
Definition brushless2.h:138
pin_name_t pwm
Definition brushless2.h:131
pin_name_t fr
Definition brushless2.h:136
Click ctx object definition.
Definition brushless2.h:102
digital_out_t fgs
Definition brushless2.h:107
digital_in_t cfg
Definition brushless2.h:111
uint32_t pwm_freq
Definition brushless2.h:120
digital_in_t int_pin
Definition brushless2.h:112
pwm_t pwm
Definition brushless2.h:116
digital_out_t fr
Definition brushless2.h:106