brushless13 2.1.0.0
brushless13.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 BRUSHLESS13_H
29#define BRUSHLESS13_H
30
31#ifdef __cplusplus
32extern "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 BRUSHLESS13_REG_INPUT_PORT 0x00
74#define BRUSHLESS13_REG_OUTPUT_PORT 0x01
75#define BRUSHLESS13_REG_POLARITY_INV 0x02
76#define BRUSHLESS13_REG_CONFIG 0x03
77
78 // brushless13_reg
79
94#define BRUSHLESS13_TR_COM_STATE_COAST 0x00
95#define BRUSHLESS13_TR_COM_STATE_1 0x01
96#define BRUSHLESS13_TR_COM_STATE_2 0x02
97#define BRUSHLESS13_TR_COM_STATE_3 0x03
98#define BRUSHLESS13_TR_COM_STATE_4 0x04
99#define BRUSHLESS13_TR_COM_STATE_5 0x05
100#define BRUSHLESS13_TR_COM_STATE_6 0x06
101#define BRUSHLESS13_TR_COM_STATE_BRAKE 0x07
102
107#define BRUSHLESS13_NONE_PIN 0x00
108#define BRUSHLESS13_ENW_PIN 0x01
109#define BRUSHLESS13_INW_PIN 0x02
110#define BRUSHLESS13_ENV_PIN 0x04
111#define BRUSHLESS13_INV_PIN 0x08
112#define BRUSHLESS13_ENU_PIN 0x10
113#define BRUSHLESS13_INU_PIN 0x20
114#define BRUSHLESS13_FLT_PIN 0x40
115#define BRUSHLESS13_ALL_OUTPUT_PIN 0x3F
116#define BRUSHLESS13_ALL_PIN 0x7F
117
122#define BRUSHLESS13_MODE_ENX_INX 0x01
123#define BRUSHLESS13_MODE_INXL_INXH 0x00
124
129#define BRUSHLESS13_DIR_CW 0x01
130#define BRUSHLESS13_DIR_CCW 0x00
131
136#define BRUSHLESS13_PIN_STATE_LOW 0x00
137#define BRUSHLESS13_PIN_STATE_HIGH 0x01
138
143#define BRUSHLESS13_FLT_PIN_INACTIVE 0x01
144#define BRUSHLESS13_FLT_PIN_ACTIVE 0x00
145
150#define BRUSHLESS13_SPEED_MIN 0
151#define BRUSHLESS13_SPEED_MAX 100
152#define BRUSHLESS13_NUM_PIN_TOGGLE 8
153#define BRUSHLESS13_ROUND_TO_NEAREAST_INT 0.5
154
164#define BRUSHLESS13_COM_SEQ_DURATION_FOR_SPEED_MAX 20.293
165#define BRUSHLESS13_COM_SEQ_DURATION_SPEED_STEP ( 20.351 - BRUSHLESS13_COM_SEQ_DURATION_FOR_SPEED_MAX )
166
172#define BRUSHLESS13_DEVICE_ADDRESS_A1A0_00 0x70
173#define BRUSHLESS13_DEVICE_ADDRESS_A1A0_01 0x71
174#define BRUSHLESS13_DEVICE_ADDRESS_A1A0_10 0x72
175#define BRUSHLESS13_DEVICE_ADDRESS_A1A0_11 0x73
176
177 // brushless13_set
178
193#define BRUSHLESS13_MAP_MIKROBUS( cfg, mikrobus ) \
194 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
195 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
196 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
197 cfg.mod = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
198 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
199
200 // brushless13_map
201 // brushless13
202
207typedef struct
208{
209 // Output pins
210 digital_out_t rst;
211 digital_out_t mod;
213 // Input pins
214 digital_in_t flt;
216 // Modules
217 i2c_master_t i2c;
219 // I2C slave address
222 uint8_t mode;
225
230typedef struct
231{
232 pin_name_t scl;
233 pin_name_t sda;
235 pin_name_t rst;
236 pin_name_t mod;
237 pin_name_t flt;
239 uint32_t i2c_speed;
240 uint8_t i2c_address;
243
254
271
286
300
315err_t brushless13_generic_write ( brushless13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
316
331err_t brushless13_generic_read ( brushless13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
332
342void brushless13_set_rst_pin ( brushless13_t *ctx, uint8_t pin_state );
343
355
365void brushless13_set_mode ( brushless13_t *ctx, uint8_t mode_sel );
366
376
386
400err_t brushless13_write_reg ( brushless13_t *ctx, uint8_t reg, uint8_t data_in );
401
414err_t brushless13_read_reg ( brushless13_t *ctx, uint8_t reg, uint8_t *data_out );
415
428err_t brushless13_set_pins ( brushless13_t *ctx, uint8_t set_mask, uint8_t clr_mask );
429
441err_t brushless13_set_trap_com_state ( brushless13_t *ctx, uint8_t state );
442
456err_t brushless13_toggle_pin ( brushless13_t *ctx, uint8_t pin_mask, uint8_t speed );
457
471err_t brushless13_perform_com_seq ( brushless13_t *ctx, uint8_t dir, uint8_t speed );
472
487err_t brushless13_drive_motor ( brushless13_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms );
488
489#ifdef __cplusplus
490}
491#endif
492#endif // BRUSHLESS13_H
493
494 // brushless13
495
496// ------------------------------------------------------------------------ END
brushless13_return_value_t
Brushless 13 Click return value data.
Definition brushless13.h:249
@ BRUSHLESS13_OK
Definition brushless13.h:250
@ BRUSHLESS13_ERROR
Definition brushless13.h:251
err_t brushless13_read_reg(brushless13_t *ctx, uint8_t reg, uint8_t *data_out)
Brushless 13 read register function.
err_t brushless13_init(brushless13_t *ctx, brushless13_cfg_t *cfg)
Brushless 13 initialization function.
err_t brushless13_toggle_pin(brushless13_t *ctx, uint8_t pin_mask, uint8_t speed)
Brushless 13 toggle pin function.
void brushless13_reset_port_exp(brushless13_t *ctx)
Brushless 13 reset port expander function.
void brushless13_set_mode(brushless13_t *ctx, uint8_t mode_sel)
Brushless 13 set mode pin function.
err_t brushless13_generic_read(brushless13_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Brushless 13 I2C reading function.
void brushless13_set_rst_pin(brushless13_t *ctx, uint8_t pin_state)
Brushless 13 set rst pin function.
uint8_t brushless13_get_flt_state(brushless13_t *ctx)
Brushless 13 get flt pin function.
err_t brushless13_default_cfg(brushless13_t *ctx)
Brushless 13 default configuration function.
err_t brushless13_generic_write(brushless13_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Brushless 13 I2C writing function.
err_t brushless13_set_pins(brushless13_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Brushless 13 set pins function.
err_t brushless13_perform_com_seq(brushless13_t *ctx, uint8_t dir, uint8_t speed)
Brushless 13 perform com sequence function.
err_t brushless13_write_reg(brushless13_t *ctx, uint8_t reg, uint8_t data_in)
Brushless 13 write register function.
err_t brushless13_drive_motor(brushless13_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms)
Brushless 13 drive motor function.
void brushless13_cfg_setup(brushless13_cfg_t *cfg)
Brushless 13 configuration object setup function.
err_t brushless13_set_trap_com_state(brushless13_t *ctx, uint8_t state)
Brushless 13 set trapezoidal com state function.
uint8_t brushless13_get_flt_pin(brushless13_t *ctx)
Brushless 13 get fault pin function.
Brushless 13 Click configuration object.
Definition brushless13.h:231
uint32_t i2c_speed
Definition brushless13.h:239
pin_name_t mod
Definition brushless13.h:236
pin_name_t flt
Definition brushless13.h:237
pin_name_t scl
Definition brushless13.h:232
pin_name_t sda
Definition brushless13.h:233
pin_name_t rst
Definition brushless13.h:235
uint8_t i2c_address
Definition brushless13.h:240
Brushless 13 Click context object.
Definition brushless13.h:208
digital_out_t mod
Definition brushless13.h:211
uint8_t mode
Definition brushless13.h:222
digital_in_t flt
Definition brushless13.h:214
i2c_master_t i2c
Definition brushless13.h:217
digital_out_t rst
Definition brushless13.h:210
uint8_t slave_address
Definition brushless13.h:220