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 "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_pwm.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define BRUSHLESS2_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
54 cfg.cfg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
55 cfg.fr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56 cfg.fgs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define BRUSHLESS2_RETVAL uint8_t
65
66#define BRUSHLESS2_OK 0x00
67#define BRUSHLESS2_INIT_ERROR 0xFF
74#define BRUSHLESS2_DEF_FREQ 5000 // End group macro
78// --------------------------------------------------------------- PUBLIC TYPES
87typedef struct
88{
89
90 // Output pins
91
92 digital_out_t fr;
93 digital_out_t fgs;
94
95 // Input pins
96
97 digital_in_t cfg;
98 digital_in_t int_pin;
99
100 // Modules
101
102 pwm_t pwm;
103
104 // ctx variable
105
106 uint32_t pwm_freq;
107
109
113typedef struct
114{
115 // Communication gpio pins
116
117 pin_name_t pwm;
118
119 // Additional gpio pins
120
121 pin_name_t cfg;
122 pin_name_t fr;
123 pin_name_t fgs;
124 pin_name_t int_pin;
125
126 // static variable
127
128 uint32_t dev_pwm_freq;
129
131 // End types group
133// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134
140#ifdef __cplusplus
141extern "C"{
142#endif
143
153
162
172void brushless2_set_duty_cycle ( brushless2_t *ctx, float duty_cycle );
173
182
191
201
211
221
234
235#ifdef __cplusplus
236}
237#endif
238#endif // _BRUSHLESS2_H_
239 // End public_function group
242
243// ------------------------------------------------------------------------- END
#define BRUSHLESS2_RETVAL
Definition: brushless2.h:64
void brushless2_invert_direction(brushless2_t *ctx)
Invert the direction of rotation.
void brushless2_pwm_start(brushless2_t *ctx)
Start PWM module.
void brushless2_cfg_setup(brushless2_cfg_t *cfg)
Config Object Initialization function.
void brushless2_set_duty_cycle(brushless2_t *ctx, float duty_cycle)
Generic sets PWM duty cycle.
uint8_t brushless2_get_interrupt_status(brushless2_t *ctx)
Get Interrupt pin state function.
void brushless2_pwm_stop(brushless2_t *ctx)
Stop PWM module.
void brushless2_clockwise(brushless2_t *ctx)
Set the direction of rotation in the clockwise direction function.
void brushless2_counter_clockwise(brushless2_t *ctx)
Set the direction of rotation in the counterclockwise direction function.
BRUSHLESS2_RETVAL brushless2_init(brushless2_t *ctx, brushless2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition: brushless2.h:114
pin_name_t fgs
Definition: brushless2.h:123
pin_name_t cfg
Definition: brushless2.h:121
uint32_t dev_pwm_freq
Definition: brushless2.h:128
pin_name_t int_pin
Definition: brushless2.h:124
pin_name_t pwm
Definition: brushless2.h:117
pin_name_t fr
Definition: brushless2.h:122
Click ctx object definition.
Definition: brushless2.h:88
digital_out_t fgs
Definition: brushless2.h:93
digital_in_t cfg
Definition: brushless2.h:97
uint32_t pwm_freq
Definition: brushless2.h:106
digital_in_t int_pin
Definition: brushless2.h:98
pwm_t pwm
Definition: brushless2.h:102
digital_out_t fr
Definition: brushless2.h:92