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
32extern "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
75 // 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
98 // brushless9_map
99 // brushless9
100
110typedef 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;
127
132typedef 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
191err_t brushless9_set_duty_cycle ( brushless9_t *ctx, float duty_cycle );
192
204
216
227void brushless9_set_dir ( brushless9_t *ctx, uint8_t state );
228
239void brushless9_set_brk ( brushless9_t *ctx, uint8_t state );
240
250
260
261#ifdef __cplusplus
262}
263#endif
264#endif // BRUSHLESS9_H
265
266 // brushless9
267
268// ------------------------------------------------------------------------ END
err_t brushless9_init(brushless9_t *ctx, brushless9_cfg_t *cfg)
Brushless 9 initialization function.
uint8_t brushless9_get_fg(brushless9_t *ctx)
Brushless 9 fg state.
void brushless9_set_dir(brushless9_t *ctx, uint8_t state)
Brushless 9 dir pin setting.
err_t brushless9_pwm_stop(brushless9_t *ctx)
Brushless 9 stop PWM module.
err_t brushless9_pwm_start(brushless9_t *ctx)
Brushless 9 start PWM module.
void brushless9_set_brk(brushless9_t *ctx, uint8_t state)
Brushless 9 brk pin setting.
uint8_t brushless9_get_int_pin(brushless9_t *ctx)
Brushless 9 int_pin state.
err_t brushless9_set_duty_cycle(brushless9_t *ctx, float duty_cycle)
Brushless 9 sets PWM duty cycle.
void brushless9_cfg_setup(brushless9_cfg_t *cfg)
Brushless 9 configuration object setup function.
Brushless 9 Click configuration object.
Definition brushless9.h:133
pin_name_t fg
Definition brushless9.h:138
uint32_t dev_pwm_freq
Definition brushless9.h:144
pin_name_t dir
Definition brushless9.h:139
pin_name_t int_pin
Definition brushless9.h:141
pin_name_t pwm
Definition brushless9.h:135
pin_name_t brk
Definition brushless9.h:140
Brushless 9 Click driver selector.
Definition brushless9.h:111
digital_out_t brk
Definition brushless9.h:114
uint32_t pwm_freq
Definition brushless9.h:124
digital_in_t int_pin
Definition brushless9.h:118
digital_in_t fg
Definition brushless9.h:117
pwm_t pwm
Definition brushless9.h:121
digital_out_t dir
Definition brushless9.h:113