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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_pwm.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define BRUSHLESS2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.cfg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
69  cfg.fr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.fgs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define BRUSHLESS2_RETVAL uint8_t
79 
80 #define BRUSHLESS2_OK 0x00
81 #define BRUSHLESS2_INIT_ERROR 0xFF
82 
88 #define BRUSHLESS2_DEF_FREQ 5000
89  // End group macro
92 // --------------------------------------------------------------- PUBLIC TYPES
101 typedef struct
102 {
103 
104  // Output pins
105 
106  digital_out_t fr;
107  digital_out_t fgs;
108 
109  // Input pins
110 
111  digital_in_t cfg;
112  digital_in_t int_pin;
113 
114  // Modules
115 
116  pwm_t pwm;
117 
118  // ctx variable
119 
120  uint32_t pwm_freq;
121 
122 } brushless2_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t pwm;
132 
133  // Additional gpio pins
134 
135  pin_name_t cfg;
136  pin_name_t fr;
137  pin_name_t fgs;
138  pin_name_t int_pin;
139 
140  // static variable
141 
142  uint32_t dev_pwm_freq;
143 
145  // End types group
147 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
148 
154 #ifdef __cplusplus
155 extern "C"{
156 #endif
157 
167 
176 
186 void brushless2_set_duty_cycle ( brushless2_t *ctx, float duty_cycle );
187 
196 
205 
215 
225 
235 
248 
249 #ifdef __cplusplus
250 }
251 #endif
252 #endif // _BRUSHLESS2_H_
253  // End public_function group
256 
257 // ------------------------------------------------------------------------- END
brushless2_cfg_t::fgs
pin_name_t fgs
Definition: brushless2.h:137
brushless2_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless2.h:138
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:107
brushless2_t::pwm
pwm_t pwm
Definition: brushless2.h:116
brushless2_t
Click ctx object definition.
Definition: brushless2.h:102
brushless2_t::fr
digital_out_t fr
Definition: brushless2.h:106
brushless2_cfg_t::pwm
pin_name_t pwm
Definition: brushless2.h:131
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:112
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:135
brushless2_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: brushless2.h:142
brushless2_t::cfg
digital_in_t cfg
Definition: brushless2.h:111
BRUSHLESS2_RETVAL
#define BRUSHLESS2_RETVAL
Definition: brushless2.h:78
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:136
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:120
brushless2_cfg_t
Click configuration structure definition.
Definition: brushless2.h:128
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.