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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_pwm.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define BRUSHLESS2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
64  cfg.cfg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
65  cfg.fr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.fgs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define BRUSHLESS2_RETVAL uint8_t
75 
76 #define BRUSHLESS2_OK 0x00
77 #define BRUSHLESS2_INIT_ERROR 0xFF
78 
84 #define BRUSHLESS2_DEF_FREQ 5000
85  // End group macro
88 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99 
100  // Output pins
101 
102  digital_out_t fr;
103  digital_out_t fgs;
104 
105  // Input pins
106 
107  digital_in_t cfg;
108  digital_in_t int_pin;
109 
110  // Modules
111 
112  pwm_t pwm;
113 
114  // ctx variable
115 
116  uint32_t pwm_freq;
117 
118 } brushless2_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t pwm;
128 
129  // Additional gpio pins
130 
131  pin_name_t cfg;
132  pin_name_t fr;
133  pin_name_t fgs;
134  pin_name_t int_pin;
135 
136  // static variable
137 
138  uint32_t dev_pwm_freq;
139 
141  // End types group
143 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
144 
150 #ifdef __cplusplus
151 extern "C"{
152 #endif
153 
163 
172 
182 void brushless2_set_duty_cycle ( brushless2_t *ctx, float duty_cycle );
183 
192 
201 
211 
221 
231 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 #endif // _BRUSHLESS2_H_
249  // End public_function group
252 
253 // ------------------------------------------------------------------------- END
brushless2_cfg_t::fgs
pin_name_t fgs
Definition: brushless2.h:133
brushless2_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless2.h:134
brushless2_get_interrupt_status
uint8_t brushless2_get_interrupt_status(brushless2_t *ctx)
Get Interrupt pin state function.
brushless2_t::fgs
digital_out_t fgs
Definition: brushless2.h:103
brushless2_t::pwm
pwm_t pwm
Definition: brushless2.h:112
brushless2_t
Click ctx object definition.
Definition: brushless2.h:98
brushless2_t::fr
digital_out_t fr
Definition: brushless2.h:102
brushless2_cfg_t::pwm
pin_name_t pwm
Definition: brushless2.h:127
brushless2_clockwise
void brushless2_clockwise(brushless2_t *ctx)
Set the direction of rotation in the clockwise direction function.
brushless2_pwm_stop
void brushless2_pwm_stop(brushless2_t *ctx)
Stop PWM module.
brushless2_t::int_pin
digital_in_t int_pin
Definition: brushless2.h:108
brushless2_pwm_start
void brushless2_pwm_start(brushless2_t *ctx)
Start PWM module.
brushless2_set_duty_cycle
void brushless2_set_duty_cycle(brushless2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
brushless2_cfg_t::cfg
pin_name_t cfg
Definition: brushless2.h:131
brushless2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless2.h:138
brushless2_t::cfg
digital_in_t cfg
Definition: brushless2.h:107
BRUSHLESS2_RETVAL
#define BRUSHLESS2_RETVAL
Definition: brushless2.h:74
brushless2_cfg_setup
void brushless2_cfg_setup(brushless2_cfg_t *cfg)
Config Object Initialization function.
brushless2_cfg_t::fr
pin_name_t fr
Definition: brushless2.h:132
brushless2_init
BRUSHLESS2_RETVAL brushless2_init(brushless2_t *ctx, brushless2_cfg_t *cfg)
Initialization function.
brushless2_t::pwm_freq
uint32_t pwm_freq
Definition: brushless2.h:116
brushless2_cfg_t
Click configuration structure definition.
Definition: brushless2.h:124
brushless2_counter_clockwise
void brushless2_counter_clockwise(brushless2_t *ctx)
Set the direction of rotation in the counterclockwise direction function.
brushless2_invert_direction
void brushless2_invert_direction(brushless2_t *ctx)
Invert the direction of rotation.