brushless31  2.1.0.0
brushless31.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 BRUSHLESS31_H
29 #define BRUSHLESS31_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 BRUSHLESS31_DIR_CW 0
74 #define BRUSHLESS31_DIR_CCW 1
75 
80 #define BRUSHLESS31_DEF_FREQ 20000
81  // brushless31_cfg
83 
98 #define BRUSHLESS31_MAP_MIKROBUS( cfg, mikrobus ) \
99  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
100  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
101  cfg.start = MIKROBUS( mikrobus, MIKROBUS_RST ); \
102  cfg.brake = MIKROBUS( mikrobus, MIKROBUS_CS ); \
103  cfg.hp = MIKROBUS( mikrobus, MIKROBUS_INT );
104  // brushless31_map // brushless31
107 
112 typedef struct
113 {
114  // Output pins
115  digital_out_t dir;
116  digital_out_t start;
117  digital_out_t brake;
119  // Input pins
120  digital_in_t hp;
122  // Modules
123  pwm_t pwm;
125  // ctx variable
126  uint32_t pwm_freq;
128 } brushless31_t;
129 
134 typedef struct
135 {
136  // Communication gpio pins
137  pin_name_t pwm;
139  // Additional gpio pins
140  pin_name_t dir;
141  pin_name_t start;
142  pin_name_t brake;
143  pin_name_t hp;
145  // Static variable
146  uint32_t dev_pwm_freq;
149 
154 typedef enum
155 {
157  BRUSHLESS31_ERROR = -1
158 
160 
177 
192 
206 
218 err_t brushless31_set_duty_cycle ( brushless31_t *ctx, float duty_cycle );
219 
231 
243 
254 void brushless31_set_direction ( brushless31_t *ctx, uint8_t dir );
255 
265 
275 
285 
295 
305 
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 #endif // BRUSHLESS31_H
320  // brushless31
322 
323 // ------------------------------------------------------------------------ END
brushless31_set_direction
void brushless31_set_direction(brushless31_t *ctx, uint8_t dir)
Brushless 31 set direction function.
BRUSHLESS31_ERROR
@ BRUSHLESS31_ERROR
Definition: brushless31.h:157
brushless31_t::pwm
pwm_t pwm
Definition: brushless31.h:123
brushless31_cfg_t
Brushless 31 Click configuration object.
Definition: brushless31.h:135
brushless31_set_duty_cycle
err_t brushless31_set_duty_cycle(brushless31_t *ctx, float duty_cycle)
Brushless 31 sets PWM duty cycle.
brushless31_cfg_t::dir
pin_name_t dir
Definition: brushless31.h:140
brushless31_pwm_stop
err_t brushless31_pwm_stop(brushless31_t *ctx)
Brushless 31 stop PWM module.
brushless31_get_hp_pin
uint8_t brushless31_get_hp_pin(brushless31_t *ctx)
Brushless 31 get hp pin function.
brushless31_switch_direction
void brushless31_switch_direction(brushless31_t *ctx)
Brushless 31 switch direction function.
brushless31_t::brake
digital_out_t brake
Definition: brushless31.h:117
brushless31_return_value_t
brushless31_return_value_t
Brushless 31 Click return value data.
Definition: brushless31.h:155
brushless31_init
err_t brushless31_init(brushless31_t *ctx, brushless31_cfg_t *cfg)
Brushless 31 initialization function.
brushless31_release_brake
void brushless31_release_brake(brushless31_t *ctx)
Brushless 31 release brake function.
brushless31_default_cfg
err_t brushless31_default_cfg(brushless31_t *ctx)
Brushless 31 default configuration function.
BRUSHLESS31_OK
@ BRUSHLESS31_OK
Definition: brushless31.h:156
brushless31_cfg_t::hp
pin_name_t hp
Definition: brushless31.h:143
brushless31_cfg_setup
void brushless31_cfg_setup(brushless31_cfg_t *cfg)
Brushless 31 configuration object setup function.
brushless31_t
Brushless 31 Click context object.
Definition: brushless31.h:113
brushless31_cfg_t::start
pin_name_t start
Definition: brushless31.h:141
brushless31_t::start
digital_out_t start
Definition: brushless31.h:116
brushless31_t::dir
digital_out_t dir
Definition: brushless31.h:115
brushless31_cfg_t::pwm
pin_name_t pwm
Definition: brushless31.h:137
brushless31_stop
void brushless31_stop(brushless31_t *ctx)
Brushless 31 stop function.
brushless31_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless31.h:146
brushless31_cfg_t::brake
pin_name_t brake
Definition: brushless31.h:142
brushless31_t::pwm_freq
uint32_t pwm_freq
Definition: brushless31.h:126
brushless31_start
void brushless31_start(brushless31_t *ctx)
Brushless 31 start function.
brushless31_t::hp
digital_in_t hp
Definition: brushless31.h:120
brushless31_pull_brake
void brushless31_pull_brake(brushless31_t *ctx)
Brushless 31 pull brake function.
brushless31_pwm_start
err_t brushless31_pwm_start(brushless31_t *ctx)
Brushless 31 start PWM module.