brushless20  2.1.0.0
brushless20.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 BRUSHLESS20_H
29 #define BRUSHLESS20_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define BRUSHLESS20_REG_INPUT 0x00
60 #define BRUSHLESS20_REG_OUTPUT 0x01
61 #define BRUSHLESS20_REG_POLARITY 0x02
62 #define BRUSHLESS20_REG_CONFIG 0x03
63  // brushless20_reg
65 
80 #define BRUSHLESS20_NONE_PIN 0x00
81 #define BRUSHLESS20_IN1_PIN 0x01
82 #define BRUSHLESS20_EN1_PIN 0x02
83 #define BRUSHLESS20_IN2_PIN 0x04
84 #define BRUSHLESS20_EN2_PIN 0x08
85 #define BRUSHLESS20_IN3_PIN 0x10
86 #define BRUSHLESS20_EN3_PIN 0x20
87 #define BRUSHLESS20_NRST_PIN 0x40
88 #define BRUSHLESS20_FLT_PIN 0x80
89 #define BRUSHLESS20_ALL_PINS 0xFF
90 
95 #define BRUSHLESS20_DEFAULT_CONFIG 0x80
96 
101 #define BRUSHLESS20_DIR_CW 0
102 #define BRUSHLESS20_DIR_CCW 1
103 
108 #define BRUSHLESS20_PIN_LOW_LEVEL 0
109 #define BRUSHLESS20_PIN_HIGH_LEVEL 1
110 
115 #define BRUSHLESS20_TR_COM_STATE_COAST 0
116 #define BRUSHLESS20_TR_COM_STATE_1 1
117 #define BRUSHLESS20_TR_COM_STATE_2 2
118 #define BRUSHLESS20_TR_COM_STATE_3 3
119 #define BRUSHLESS20_TR_COM_STATE_4 4
120 #define BRUSHLESS20_TR_COM_STATE_5 5
121 #define BRUSHLESS20_TR_COM_STATE_6 6
122 #define BRUSHLESS20_TR_COM_STATE_BRAKE 7
123 
128 #define BRUSHLESS20_SPEED_MIN 0
129 #define BRUSHLESS20_SPEED_MAX 100
130 #define BRUSHLESS20_NUM_PIN_TOGGLE 8
131 #define BRUSHLESS20_ROUND_TO_NEAREAST_INT 0.5
132 
142 #define BRUSHLESS20_COM_SEQ_DURATION_FOR_SPEED_MAX 24.729
143 #define BRUSHLESS20_COM_SEQ_DURATION_SPEED_STEP ( 29.4361 - BRUSHLESS20_COM_SEQ_DURATION_FOR_SPEED_MAX )
144 
150 #define BRUSHLESS20_DEVICE_ADDRESS_A1A0_00 0x70
151 #define BRUSHLESS20_DEVICE_ADDRESS_A1A0_01 0x71
152 #define BRUSHLESS20_DEVICE_ADDRESS_A1A0_10 0x72
153 #define BRUSHLESS20_DEVICE_ADDRESS_A1A0_11 0x73
154  // brushless20_set
156 
171 #define BRUSHLESS20_MAP_MIKROBUS( cfg, mikrobus ) \
172  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
174  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
175  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
176  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
177  // brushless20_map // brushless20
180 
185 typedef struct
186 {
187  // Output pins
188  digital_out_t slp;
189  digital_out_t rst;
191  // Input pins
192  digital_in_t int_pin;
194  // Modules
195  i2c_master_t i2c;
197  // I2C slave address
198  uint8_t slave_address;
200 } brushless20_t;
201 
206 typedef struct
207 {
208  pin_name_t scl;
209  pin_name_t sda;
211  pin_name_t slp;
212  pin_name_t rst;
213  pin_name_t int_pin;
215  uint32_t i2c_speed;
216  uint8_t i2c_address;
219 
224 typedef enum
225 {
227  BRUSHLESS20_ERROR = -1
228 
230 
247 
262 
276 
290 err_t brushless20_write_register ( brushless20_t *ctx, uint8_t reg, uint8_t data_in );
291 
304 err_t brushless20_read_register ( brushless20_t *ctx, uint8_t reg, uint8_t *data_out );
305 
318 err_t brushless20_set_pins ( brushless20_t *ctx, uint8_t set_mask, uint8_t clr_mask );
319 
332 
342 
353 void brushless20_set_rst_pin ( brushless20_t *ctx, uint8_t state );
354 
364 
374 
384 
397 
411 err_t brushless20_toggle_pin ( brushless20_t *ctx, uint8_t pin_mask, uint8_t speed );
412 
428 err_t brushless20_perform_com_sequence ( brushless20_t *ctx, uint8_t dir, uint8_t speed );
429 
450 err_t brushless20_drive_motor ( brushless20_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms );
451 
452 #ifdef __cplusplus
453 }
454 #endif
455 #endif // BRUSHLESS20_H
456  // brushless20
458 
459 // ------------------------------------------------------------------------ END
brushless20_drive_motor
err_t brushless20_drive_motor(brushless20_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms)
Brushless 20 drive motor function.
brushless20_default_cfg
err_t brushless20_default_cfg(brushless20_t *ctx)
Brushless 20 default configuration function.
brushless20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: brushless20.h:215
brushless20_get_fault_pin
err_t brushless20_get_fault_pin(brushless20_t *ctx)
Brushless 20 get fault pin function.
brushless20_return_value_t
brushless20_return_value_t
Brushless 20 Click return value data.
Definition: brushless20.h:225
brushless20_cfg_t
Brushless 20 Click configuration object.
Definition: brushless20.h:207
brushless20_perform_com_sequence
err_t brushless20_perform_com_sequence(brushless20_t *ctx, uint8_t dir, uint8_t speed)
Brushless 20 perform com sequence function.
brushless20_set_pins
err_t brushless20_set_pins(brushless20_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Brushless 20 set pins function.
brushless20_cfg_t::int_pin
pin_name_t int_pin
Definition: brushless20.h:213
brushless20_cfg_setup
void brushless20_cfg_setup(brushless20_cfg_t *cfg)
Brushless 20 configuration object setup function.
brushless20_cfg_t::i2c_address
uint8_t i2c_address
Definition: brushless20.h:216
BRUSHLESS20_OK
@ BRUSHLESS20_OK
Definition: brushless20.h:226
brushless20_toggle_pin
err_t brushless20_toggle_pin(brushless20_t *ctx, uint8_t pin_mask, uint8_t speed)
Brushless 20 toggle pin function.
brushless20_t
Brushless 20 Click context object.
Definition: brushless20.h:186
BRUSHLESS20_ERROR
@ BRUSHLESS20_ERROR
Definition: brushless20.h:227
brushless20_write_register
err_t brushless20_write_register(brushless20_t *ctx, uint8_t reg, uint8_t data_in)
Brushless 20 write register function.
brushless20_t::rst
digital_out_t rst
Definition: brushless20.h:189
brushless20_get_int_pin
uint8_t brushless20_get_int_pin(brushless20_t *ctx)
Brushless 20 get int pin function.
brushless20_exit_sleep_mode
void brushless20_exit_sleep_mode(brushless20_t *ctx)
Brushless 20 exit sleep mode function.
brushless20_t::i2c
i2c_master_t i2c
Definition: brushless20.h:195
brushless20_t::slave_address
uint8_t slave_address
Definition: brushless20.h:198
brushless20_init
err_t brushless20_init(brushless20_t *ctx, brushless20_cfg_t *cfg)
Brushless 20 initialization function.
brushless20_cfg_t::slp
pin_name_t slp
Definition: brushless20.h:211
brushless20_set_rst_pin
void brushless20_set_rst_pin(brushless20_t *ctx, uint8_t state)
Brushless 20 set rst pin function.
brushless20_cfg_t::scl
pin_name_t scl
Definition: brushless20.h:208
brushless20_cfg_t::rst
pin_name_t rst
Definition: brushless20.h:212
brushless20_t::slp
digital_out_t slp
Definition: brushless20.h:188
brushless20_read_register
err_t brushless20_read_register(brushless20_t *ctx, uint8_t reg, uint8_t *data_out)
Brushless 20 read register function.
brushless20_cfg_t::sda
pin_name_t sda
Definition: brushless20.h:209
brushless20_enter_sleep_mode
void brushless20_enter_sleep_mode(brushless20_t *ctx)
Brushless 20 enter sleep mode function.
brushless20_reset_port_expander
void brushless20_reset_port_expander(brushless20_t *ctx)
Brushless 20 reset port expander function.
brushless20_t::int_pin
digital_in_t int_pin
Definition: brushless20.h:192
brushless20_set_trapezoidal_com_state
err_t brushless20_set_trapezoidal_com_state(brushless20_t *ctx, uint8_t state)
Brushless 20 set trapezoidal com state function.