brushless9  2.0.0.0
brushless9.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 BRUSHLESS9_H
29 #define BRUSHLESS9_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 BRUSHLESS9_DEF_FREQ 5000
74  // brushless9_cfg
76 
91 #define BRUSHLESS9_MAP_MIKROBUS( cfg, mikrobus ) \
92  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
93  cfg.fg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
94  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_RST ); \
95  cfg.brk = MIKROBUS( mikrobus, MIKROBUS_CS ); \
96  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
97  // brushless9_map // brushless9
100 
110 typedef struct
111 {
112  // Output pins
113  digital_out_t dir;
114  digital_out_t brk;
116  // Input pins
117  digital_in_t fg;
118  digital_in_t int_pin;
120  // Modules
121  pwm_t pwm;
123  // ctx variable
124  uint32_t pwm_freq;
126 } brushless9_t;
127 
132 typedef struct
133 {
134  // Communication gpio pins
135  pin_name_t pwm;
137  // Additional gpio pins
138  pin_name_t fg;
139  pin_name_t dir;
140  pin_name_t brk;
141  pin_name_t int_pin;
143  // Static variable
144  uint32_t dev_pwm_freq;
147 
164 
179 
191 err_t brushless9_set_duty_cycle ( brushless9_t *ctx, float duty_cycle );
192 
204 
216 
227 void brushless9_set_dir ( brushless9_t *ctx, uint8_t state );
228 
239 void brushless9_set_brk ( brushless9_t *ctx, uint8_t state );
240 
250 
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // BRUSHLESS9_H
265  // brushless9
267 
268 // ------------------------------------------------------------------------ END
brushless9_t
Brushless 9 Click driver selector.
Definition: brushless9.h:111
brushless9_init
err_t brushless9_init(brushless9_t *ctx, brushless9_cfg_t *cfg)
Brushless 9 initialization function.
brushless9_cfg_t::brk
pin_name_t brk
Definition: brushless9.h:140
brushless9_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless9.h:141
brushless9_t::pwm_freq
uint32_t pwm_freq
Definition: brushless9.h:124
brushless9_t::pwm
pwm_t pwm
Definition: brushless9.h:121
brushless9_cfg_t::pwm
pin_name_t pwm
Definition: brushless9.h:135
brushless9_t::fg
digital_in_t fg
Definition: brushless9.h:117
brushless9_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless9.h:144
brushless9_cfg_t::fg
pin_name_t fg
Definition: brushless9.h:138
brushless9_pwm_start
err_t brushless9_pwm_start(brushless9_t *ctx)
Brushless 9 start PWM module.
brushless9_set_brk
void brushless9_set_brk(brushless9_t *ctx, uint8_t state)
Brushless 9 brk pin setting.
brushless9_cfg_t::dir
pin_name_t dir
Definition: brushless9.h:139
brushless9_t::brk
digital_out_t brk
Definition: brushless9.h:114
brushless9_set_dir
void brushless9_set_dir(brushless9_t *ctx, uint8_t state)
Brushless 9 dir pin setting.
brushless9_pwm_stop
err_t brushless9_pwm_stop(brushless9_t *ctx)
Brushless 9 stop PWM module.
brushless9_get_fg
uint8_t brushless9_get_fg(brushless9_t *ctx)
Brushless 9 fg state.
brushless9_cfg_setup
void brushless9_cfg_setup(brushless9_cfg_t *cfg)
Brushless 9 configuration object setup function.
brushless9_t::int_pin
digital_in_t int_pin
Definition: brushless9.h:118
brushless9_set_duty_cycle
err_t brushless9_set_duty_cycle(brushless9_t *ctx, float duty_cycle)
Brushless 9 sets PWM duty cycle.
brushless9_cfg_t
Brushless 9 Click configuration object.
Definition: brushless9.h:133
brushless9_t::dir
digital_out_t dir
Definition: brushless9.h:113
brushless9_get_int_pin
uint8_t brushless9_get_int_pin(brushless9_t *ctx)
Brushless 9 int_pin state.