brushless26  2.1.0.0
brushless26.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 BRUSHLESS26_H
29 #define BRUSHLESS26_H
30 
31 #ifdef __cplusplus
32 extern "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_i2c_master.h"
52 
73 #define BRUSHLESS26_REG_INPUT_PORT 0x00
74 #define BRUSHLESS26_REG_OUTPUT_PORT 0x01
75 #define BRUSHLESS26_REG_POLARITY_INV 0x02
76 #define BRUSHLESS26_REG_CONFIG 0x03
77  // brushless26_reg
79 
94 #define BRUSHLESS26_TR_COM_STATE_COAST 0x00
95 #define BRUSHLESS26_TR_COM_STATE_1 0x01
96 #define BRUSHLESS26_TR_COM_STATE_2 0x02
97 #define BRUSHLESS26_TR_COM_STATE_3 0x03
98 #define BRUSHLESS26_TR_COM_STATE_4 0x04
99 #define BRUSHLESS26_TR_COM_STATE_5 0x05
100 #define BRUSHLESS26_TR_COM_STATE_6 0x06
101 #define BRUSHLESS26_TR_COM_STATE_BRAKE 0x07
102 
107 #define BRUSHLESS26_NONE_PIN 0x00
108 #define BRUSHLESS26_INLC_PIN 0x01
109 #define BRUSHLESS26_INHC_PIN 0x02
110 #define BRUSHLESS26_INLB_PIN 0x04
111 #define BRUSHLESS26_INHB_PIN 0x08
112 #define BRUSHLESS26_INLA_PIN 0x10
113 #define BRUSHLESS26_INHA_PIN 0x20
114 #define BRUSHLESS26_SLP_PIN 0x40
115 #define BRUSHLESS26_ALL_OUTPUT_PIN 0x3F
116 #define BRUSHLESS26_ALL_PIN 0x7F
117 
122 #define BRUSHLESS26_MODE_6X_PWM 0x01
123 #define BRUSHLESS26_MODE_3X_PWM 0x00
124 
129 #define BRUSHLESS26_DIR_CW 0x01
130 #define BRUSHLESS26_DIR_CCW 0x00
131 
136 #define BRUSHLESS26_PIN_STATE_LOW 0x00
137 #define BRUSHLESS26_PIN_STATE_HIGH 0x01
138 
143 #define BRUSHLESS26_SPEED_MIN 0
144 #define BRUSHLESS26_SPEED_MAX 100
145 #define BRUSHLESS26_NUM_PIN_TOGGLE 8
146 #define BRUSHLESS26_ROUND_TO_NEAREAST_INT 0.5
147 
157 #define BRUSHLESS26_COM_SEQ_DURATION_FOR_SPEED_MAX 20.293
158 #define BRUSHLESS26_COM_SEQ_DURATION_SPEED_STEP ( 20.351 - BRUSHLESS26_COM_SEQ_DURATION_FOR_SPEED_MAX )
159 
165 #define BRUSHLESS26_DEVICE_ADDRESS_A1A0_00 0x70
166 #define BRUSHLESS26_DEVICE_ADDRESS_A1A0_01 0x71
167 #define BRUSHLESS26_DEVICE_ADDRESS_A1A0_10 0x72
168 #define BRUSHLESS26_DEVICE_ADDRESS_A1A0_11 0x73
169  // brushless26_set
171 
186 #define BRUSHLESS26_MAP_MIKROBUS( cfg, mikrobus ) \
187  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
188  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
189  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
190  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
191  // brushless26_map // brushless26
194 
199 typedef struct
200 {
201  // Output pins
202  digital_out_t rst;
204  // Input pins
205  digital_in_t flt;
207  // Modules
208  i2c_master_t i2c;
210  // I2C slave address
211  uint8_t slave_address;
213  uint8_t mode;
215 } brushless26_t;
216 
221 typedef struct
222 {
223  pin_name_t scl;
224  pin_name_t sda;
226  pin_name_t rst;
227  pin_name_t flt;
229  uint32_t i2c_speed;
230  uint8_t i2c_address;
233 
238 typedef enum
239 {
241  BRUSHLESS26_ERROR = -1
242 
244 
261 
276 
290 
305 err_t brushless26_generic_write ( brushless26_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
306 
321 err_t brushless26_generic_read ( brushless26_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
322 
332 void brushless26_set_rst_pin ( brushless26_t *ctx, uint8_t pin_state );
333 
343 
353 
367 err_t brushless26_write_reg ( brushless26_t *ctx, uint8_t reg, uint8_t data_in );
368 
381 err_t brushless26_read_reg ( brushless26_t *ctx, uint8_t reg, uint8_t *data_out );
382 
395 err_t brushless26_set_pins ( brushless26_t *ctx, uint8_t set_mask, uint8_t clr_mask );
396 
408 err_t brushless26_set_trap_com_state ( brushless26_t *ctx, uint8_t state );
409 
423 err_t brushless26_toggle_pin ( brushless26_t *ctx, uint8_t pin_mask, uint8_t speed );
424 
438 err_t brushless26_perform_com_seq ( brushless26_t *ctx, uint8_t dir, uint8_t speed );
439 
453 err_t brushless26_drive_motor ( brushless26_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms );
454 
455 #ifdef __cplusplus
456 }
457 #endif
458 #endif // BRUSHLESS26_H
459  // brushless26
461 
462 // ------------------------------------------------------------------------ END
BRUSHLESS26_OK
@ BRUSHLESS26_OK
Definition: brushless26.h:240
brushless26_t::slave_address
uint8_t slave_address
Definition: brushless26.h:211
brushless26_drive_motor
err_t brushless26_drive_motor(brushless26_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms)
Brushless 26 drive motor function.
brushless26_read_reg
err_t brushless26_read_reg(brushless26_t *ctx, uint8_t reg, uint8_t *data_out)
Brushless 26 read register function.
brushless26_get_flt_pin
uint8_t brushless26_get_flt_pin(brushless26_t *ctx)
Brushless 26 get fault pin function.
brushless26_set_rst_pin
void brushless26_set_rst_pin(brushless26_t *ctx, uint8_t pin_state)
Brushless 26 set rst pin function.
brushless26_cfg_t::rst
pin_name_t rst
Definition: brushless26.h:226
brushless26_cfg_t::flt
pin_name_t flt
Definition: brushless26.h:227
brushless26_cfg_t
Brushless 26 Click configuration object.
Definition: brushless26.h:222
brushless26_t
Brushless 26 Click context object.
Definition: brushless26.h:200
brushless26_t::flt
digital_in_t flt
Definition: brushless26.h:205
brushless26_t::mode
uint8_t mode
Definition: brushless26.h:213
brushless26_set_pins
err_t brushless26_set_pins(brushless26_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Brushless 26 set pins function.
brushless26_t::i2c
i2c_master_t i2c
Definition: brushless26.h:208
brushless26_cfg_t::sda
pin_name_t sda
Definition: brushless26.h:224
brushless26_cfg_t::scl
pin_name_t scl
Definition: brushless26.h:223
brushless26_generic_write
err_t brushless26_generic_write(brushless26_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Brushless 26 I2C writing function.
brushless26_write_reg
err_t brushless26_write_reg(brushless26_t *ctx, uint8_t reg, uint8_t data_in)
Brushless 26 write register function.
brushless26_default_cfg
err_t brushless26_default_cfg(brushless26_t *ctx)
Brushless 26 default configuration function.
brushless26_generic_read
err_t brushless26_generic_read(brushless26_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Brushless 26 I2C reading function.
brushless26_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: brushless26.h:229
brushless26_init
err_t brushless26_init(brushless26_t *ctx, brushless26_cfg_t *cfg)
Brushless 26 initialization function.
brushless26_reset_port_exp
void brushless26_reset_port_exp(brushless26_t *ctx)
Brushless 26 reset port expander function.
brushless26_set_trap_com_state
err_t brushless26_set_trap_com_state(brushless26_t *ctx, uint8_t state)
Brushless 26 set trapezoidal com state function.
brushless26_perform_com_seq
err_t brushless26_perform_com_seq(brushless26_t *ctx, uint8_t dir, uint8_t speed)
Brushless 26 perform com sequence function.
brushless26_t::rst
digital_out_t rst
Definition: brushless26.h:202
brushless26_return_value_t
brushless26_return_value_t
Brushless 26 Click return value data.
Definition: brushless26.h:239
brushless26_cfg_setup
void brushless26_cfg_setup(brushless26_cfg_t *cfg)
Brushless 26 configuration object setup function.
BRUSHLESS26_ERROR
@ BRUSHLESS26_ERROR
Definition: brushless26.h:241
brushless26_cfg_t::i2c_address
uint8_t i2c_address
Definition: brushless26.h:230
brushless26_toggle_pin
err_t brushless26_toggle_pin(brushless26_t *ctx, uint8_t pin_mask, uint8_t speed)
Brushless 26 toggle pin function.