brushless15 2.0.0.0

brushless15.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22
28 #ifndef BRUSHLESS15_H
29 #define BRUSHLESS15_H
30
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42
43 #ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47 #endif
48
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_pwm.h"
52
73 #define BRUSHLESS15_DEF_FREQ 1000
74
79 #define BRUSHLESS15_DIR_CW 0
80 #define BRUSHLESS15_DIR_CCW 1
81 // brushless15_cfg
83
98 #define BRUSHLESS15_MAP_MIKROBUS( cfg, mikrobus ) \
99 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
100 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
101 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
102 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
103 // brushless15_map // brushless15
106
116 typedef struct
117 {
118 // Output pins
119 digital_out_t dir;
120 digital_out_t en;
122 // Input pins
123 digital_in_t int_pin;
125 // Modules
126 pwm_t pwm;
128 // ctx variable
129 uint32_t pwm_freq;
131 } brushless15_t;
132
137 typedef struct
138 {
139 // Communication gpio pins
140 pin_name_t pwm;
142 // Additional gpio pins
143 pin_name_t dir;
144 pin_name_t en;
145 pin_name_t int_pin;
147 // Static variable
148 uint32_t dev_pwm_freq;
150 } brushless15_cfg_t;
151
156 typedef enum
157 {
158 BRUSHLESS15_OK = 0,
159 BRUSHLESS15_ERROR = -1
160
161 } brushless15_return_value_t;
162
178 void brushless15_cfg_setup ( brushless15_cfg_t *cfg );
179
194 err_t brushless15_init ( brushless15_t *ctx, brushless15_cfg_t *cfg );
195
209 err_t brushless15_default_cfg ( brushless15_t *ctx );
210
223 err_t brushless15_set_duty_cycle ( brushless15_t *ctx, float duty_cycle );
224
236 err_t brushless15_pwm_stop ( brushless15_t *ctx );
237
249 err_t brushless15_pwm_start ( brushless15_t *ctx );
250
259 void brushless15_enable_device ( brushless15_t *ctx );
260
269 void brushless15_disable_device ( brushless15_t *ctx );
270
279 uint8_t brushless15_get_int_pin ( brushless15_t *ctx );
280
291 void brushless15_set_direction ( brushless15_t *ctx, uint8_t direction );
292
301 void brushless15_switch_direction ( brushless15_t *ctx );
302
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // BRUSHLESS15_H
307 // brushless15
309
310 // ------------------------------------------------------------------------ END
brushless15_cfg_t
Brushless 15 Click configuration object.
Definition: brushless15.h:138
brushless15_cfg_t::en
pin_name_t en
Definition: brushless15.h:144
BRUSHLESS15_ERROR
@ BRUSHLESS15_ERROR
Definition: brushless15.h:159
brushless15_pwm_stop
err_t brushless15_pwm_stop(brushless15_t *ctx)
Brushless 15 stop PWM module.
brushless15_enable_device
void brushless15_enable_device(brushless15_t *ctx)
Brushless 15 enable device function.
brushless15_return_value_t
brushless15_return_value_t
Brushless 15 Click return value data.
Definition: brushless15.h:157
brushless15_t::pwm_freq
uint32_t pwm_freq
Definition: brushless15.h:129
brushless15_set_duty_cycle
err_t brushless15_set_duty_cycle(brushless15_t *ctx, float duty_cycle)
Brushless 15 sets PWM duty cycle.
brushless15_pwm_start
err_t brushless15_pwm_start(brushless15_t *ctx)
Brushless 15 start PWM module.
brushless15_default_cfg
err_t brushless15_default_cfg(brushless15_t *ctx)
Brushless 15 default configuration function.
brushless15_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless15.h:148
brushless15_t::pwm
pwm_t pwm
Definition: brushless15.h:126
brushless15_t
Brushless 15 Click driver selector.
Definition: brushless15.h:117
brushless15_set_direction
void brushless15_set_direction(brushless15_t *ctx, uint8_t direction)
Brushless 15 set direction function.
brushless15_cfg_t::pwm
pin_name_t pwm
Definition: brushless15.h:140
brushless15_cfg_setup
void brushless15_cfg_setup(brushless15_cfg_t *cfg)
Brushless 15 configuration object setup function.
brushless15_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless15.h:145
BRUSHLESS15_OK
@ BRUSHLESS15_OK
Definition: brushless15.h:158
brushless15_init
err_t brushless15_init(brushless15_t *ctx, brushless15_cfg_t *cfg)
Brushless 15 initialization function.
brushless15_cfg_t::dir
pin_name_t dir
Definition: brushless15.h:143
brushless15_t::int_pin
digital_in_t int_pin
Definition: brushless15.h:123
brushless15_t::en
digital_out_t en
Definition: brushless15.h:120
brushless15_switch_direction
void brushless15_switch_direction(brushless15_t *ctx)
Brushless 15 switch direction function.
brushless15_disable_device
void brushless15_disable_device(brushless15_t *ctx)
Brushless 15 disable device function.
brushless15_t::dir
digital_out_t dir
Definition: brushless15.h:119
brushless15_get_int_pin
uint8_t brushless15_get_int_pin(brushless15_t *ctx)
Brushless 15 get int pin function.