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
32extern "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 BRUSHLESS26_REG_INPUT_PORT 0x00
60#define BRUSHLESS26_REG_OUTPUT_PORT 0x01
61#define BRUSHLESS26_REG_POLARITY_INV 0x02
62#define BRUSHLESS26_REG_CONFIG 0x03
63 // brushless26_reg
65
80#define BRUSHLESS26_TR_COM_STATE_COAST 0x00
81#define BRUSHLESS26_TR_COM_STATE_1 0x01
82#define BRUSHLESS26_TR_COM_STATE_2 0x02
83#define BRUSHLESS26_TR_COM_STATE_3 0x03
84#define BRUSHLESS26_TR_COM_STATE_4 0x04
85#define BRUSHLESS26_TR_COM_STATE_5 0x05
86#define BRUSHLESS26_TR_COM_STATE_6 0x06
87#define BRUSHLESS26_TR_COM_STATE_BRAKE 0x07
88
93#define BRUSHLESS26_NONE_PIN 0x00
94#define BRUSHLESS26_INLC_PIN 0x01
95#define BRUSHLESS26_INHC_PIN 0x02
96#define BRUSHLESS26_INLB_PIN 0x04
97#define BRUSHLESS26_INHB_PIN 0x08
98#define BRUSHLESS26_INLA_PIN 0x10
99#define BRUSHLESS26_INHA_PIN 0x20
100#define BRUSHLESS26_SLP_PIN 0x40
101#define BRUSHLESS26_ALL_OUTPUT_PIN 0x3F
102#define BRUSHLESS26_ALL_PIN 0x7F
103
108#define BRUSHLESS26_MODE_6X_PWM 0x01
109#define BRUSHLESS26_MODE_3X_PWM 0x00
110
115#define BRUSHLESS26_DIR_CW 0x01
116#define BRUSHLESS26_DIR_CCW 0x00
117
122#define BRUSHLESS26_PIN_STATE_LOW 0x00
123#define BRUSHLESS26_PIN_STATE_HIGH 0x01
124
129#define BRUSHLESS26_SPEED_MIN 0
130#define BRUSHLESS26_SPEED_MAX 100
131#define BRUSHLESS26_NUM_PIN_TOGGLE 8
132#define BRUSHLESS26_ROUND_TO_NEAREAST_INT 0.5
133
143#define BRUSHLESS26_COM_SEQ_DURATION_FOR_SPEED_MAX 20.293
144#define BRUSHLESS26_COM_SEQ_DURATION_SPEED_STEP ( 20.351 - BRUSHLESS26_COM_SEQ_DURATION_FOR_SPEED_MAX )
145
151#define BRUSHLESS26_DEVICE_ADDRESS_A1A0_00 0x70
152#define BRUSHLESS26_DEVICE_ADDRESS_A1A0_01 0x71
153#define BRUSHLESS26_DEVICE_ADDRESS_A1A0_10 0x72
154#define BRUSHLESS26_DEVICE_ADDRESS_A1A0_11 0x73
155 // brushless26_set
157
172#define BRUSHLESS26_MAP_MIKROBUS( cfg, mikrobus ) \
173 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
174 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
175 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
176 cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
177 // brushless26_map // brushless26
180
185typedef struct
186{
187 // Output pins
188 digital_out_t rst;
190 // Input pins
191 digital_in_t flt;
193 // Modules
194 i2c_master_t i2c;
196 // I2C slave address
199 uint8_t mode;
202
207typedef struct
208{
209 pin_name_t scl;
210 pin_name_t sda;
212 pin_name_t rst;
213 pin_name_t flt;
215 uint32_t i2c_speed;
216 uint8_t i2c_address;
219
224typedef enum
225{
228
230
247
262
276
291err_t brushless26_generic_write ( brushless26_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
292
307err_t brushless26_generic_read ( brushless26_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
308
318void brushless26_set_rst_pin ( brushless26_t *ctx, uint8_t pin_state );
319
329
339
353err_t brushless26_write_reg ( brushless26_t *ctx, uint8_t reg, uint8_t data_in );
354
367err_t brushless26_read_reg ( brushless26_t *ctx, uint8_t reg, uint8_t *data_out );
368
381err_t brushless26_set_pins ( brushless26_t *ctx, uint8_t set_mask, uint8_t clr_mask );
382
394err_t brushless26_set_trap_com_state ( brushless26_t *ctx, uint8_t state );
395
409err_t brushless26_toggle_pin ( brushless26_t *ctx, uint8_t pin_mask, uint8_t speed );
410
424err_t brushless26_perform_com_seq ( brushless26_t *ctx, uint8_t dir, uint8_t speed );
425
439err_t brushless26_drive_motor ( brushless26_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms );
440
441#ifdef __cplusplus
442}
443#endif
444#endif // BRUSHLESS26_H
445 // brushless26
447
448// ------------------------------------------------------------------------ END
brushless26_return_value_t
Brushless 26 Click return value data.
Definition: brushless26.h:225
@ BRUSHLESS26_OK
Definition: brushless26.h:226
@ BRUSHLESS26_ERROR
Definition: brushless26.h:227
err_t brushless26_perform_com_seq(brushless26_t *ctx, uint8_t dir, uint8_t speed)
Brushless 26 perform com sequence function.
err_t brushless26_drive_motor(brushless26_t *ctx, uint8_t dir, uint8_t speed, uint32_t time_ms)
Brushless 26 drive motor function.
void brushless26_cfg_setup(brushless26_cfg_t *cfg)
Brushless 26 configuration object setup function.
err_t brushless26_generic_write(brushless26_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Brushless 26 I2C writing function.
err_t brushless26_set_pins(brushless26_t *ctx, uint8_t set_mask, uint8_t clr_mask)
Brushless 26 set pins function.
err_t brushless26_toggle_pin(brushless26_t *ctx, uint8_t pin_mask, uint8_t speed)
Brushless 26 toggle pin function.
err_t brushless26_default_cfg(brushless26_t *ctx)
Brushless 26 default configuration function.
void brushless26_set_rst_pin(brushless26_t *ctx, uint8_t pin_state)
Brushless 26 set rst pin function.
uint8_t brushless26_get_flt_pin(brushless26_t *ctx)
Brushless 26 get fault pin function.
err_t brushless26_read_reg(brushless26_t *ctx, uint8_t reg, uint8_t *data_out)
Brushless 26 read register function.
err_t brushless26_set_trap_com_state(brushless26_t *ctx, uint8_t state)
Brushless 26 set trapezoidal com state function.
err_t brushless26_generic_read(brushless26_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Brushless 26 I2C reading function.
void brushless26_reset_port_exp(brushless26_t *ctx)
Brushless 26 reset port expander function.
err_t brushless26_init(brushless26_t *ctx, brushless26_cfg_t *cfg)
Brushless 26 initialization function.
err_t brushless26_write_reg(brushless26_t *ctx, uint8_t reg, uint8_t data_in)
Brushless 26 write register function.
Brushless 26 Click configuration object.
Definition: brushless26.h:208
uint32_t i2c_speed
Definition: brushless26.h:215
pin_name_t flt
Definition: brushless26.h:213
pin_name_t scl
Definition: brushless26.h:209
pin_name_t sda
Definition: brushless26.h:210
pin_name_t rst
Definition: brushless26.h:212
uint8_t i2c_address
Definition: brushless26.h:216
Brushless 26 Click context object.
Definition: brushless26.h:186
uint8_t mode
Definition: brushless26.h:199
digital_in_t flt
Definition: brushless26.h:191
i2c_master_t i2c
Definition: brushless26.h:194
digital_out_t rst
Definition: brushless26.h:188
uint8_t slave_address
Definition: brushless26.h:197