multisteppertb67s102 2.0.0.0
multisteppertb67s102.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 MULTISTEPPERTB67S102_H
29#define MULTISTEPPERTB67S102_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 MULTISTEPPERTB67S102_REG_INPUT 0x00
74#define MULTISTEPPERTB67S102_REG_OUTPUT 0x01
75#define MULTISTEPPERTB67S102_REG_POLARITY 0x02
76#define MULTISTEPPERTB67S102_REG_CONFIG 0x03
77
78 // multisteppertb67s102_reg
79
94#define MULTISTEPPERTB67S102_DMODE1_PIN 0x02
95#define MULTISTEPPERTB67S102_DMODE2_PIN 0x04
96#define MULTISTEPPERTB67S102_MO_PIN 0x40
97
102#define MULTISTEPPERTB67S102_DEFAULT_CONFIG 0xF9
103
108#define MULTISTEPPERTB67S102_DIR_CW 0
109#define MULTISTEPPERTB67S102_DIR_CCW 1
110
115#define MULTISTEPPERTB67S102_PIN_LOW_LEVEL 0
116#define MULTISTEPPERTB67S102_PIN_HIGH_LEVEL 1
117
122#define MULTISTEPPERTB67S102_MODE_STANDBY 0x00
123#define MULTISTEPPERTB67S102_MODE_HALF_STEP_TYPE_A 0x02
124#define MULTISTEPPERTB67S102_MODE_FULL_STEP 0x04
125#define MULTISTEPPERTB67S102_MODE_QUARTER_STEP 0x06
126#define MULTISTEPPERTB67S102_MODE_BITS_MASK 0x06
127
132#define MULTISTEPPERTB67S102_SPEED_VERY_SLOW 0
133#define MULTISTEPPERTB67S102_SPEED_SLOW 1
134#define MULTISTEPPERTB67S102_SPEED_MEDIUM 2
135#define MULTISTEPPERTB67S102_SPEED_FAST 3
136#define MULTISTEPPERTB67S102_SPEED_VERY_FAST 4
137
143#define MULTISTEPPERTB67S102_DEVICE_ADDRESS_A1A0_00 0x70
144#define MULTISTEPPERTB67S102_DEVICE_ADDRESS_A1A0_01 0x71
145#define MULTISTEPPERTB67S102_DEVICE_ADDRESS_A1A0_10 0x72
146#define MULTISTEPPERTB67S102_DEVICE_ADDRESS_A1A0_11 0x73
147
148 // multisteppertb67s102_set
149
164#define MULTISTEPPERTB67S102_MAP_MIKROBUS( cfg, mikrobus ) \
165 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
166 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
167 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
168 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
169 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
170 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
171 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
172
173 // multisteppertb67s102_map
174 // multisteppertb67s102
175
180typedef struct
181{
182 // Output pins
183 digital_out_t en;
184 digital_out_t an;
185 digital_out_t rst;
186 digital_out_t clk;
188 // Input pins
189 digital_in_t int_pin;
191 // Modules
192 i2c_master_t i2c;
194 // I2C slave address
198
203typedef struct
204{
205 pin_name_t scl;
206 pin_name_t sda;
208 pin_name_t en;
209 pin_name_t an;
210 pin_name_t rst;
211 pin_name_t clk;
212 pin_name_t int_pin;
214 uint32_t i2c_speed;
215 uint8_t i2c_address;
218
229
246
261
276
290err_t multisteppertb67s102_write_register ( multisteppertb67s102_t *ctx, uint8_t reg, uint8_t data_in );
291
304err_t multisteppertb67s102_read_register ( multisteppertb67s102_t *ctx, uint8_t reg, uint8_t *data_out );
305
318
331
347void multisteppertb67s102_drive_motor ( multisteppertb67s102_t *ctx, uint32_t steps, uint8_t speed );
348
358
368
380
390
400
410
422
423#ifdef __cplusplus
424}
425#endif
426#endif // MULTISTEPPERTB67S102_H
427
428 // multisteppertb67s102
429
430// ------------------------------------------------------------------------ END
void multisteppertb67s102_cfg_setup(multisteppertb67s102_cfg_t *cfg)
Multi Stepper TB67S102 configuration object setup function.
uint8_t multisteppertb67s102_get_int_pin(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 get int pin function.
void multisteppertb67s102_switch_direction(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 switch direction function.
void multisteppertb67s102_reset_device(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 reset device function.
void multisteppertb67s102_set_clk_pin(multisteppertb67s102_t *ctx, uint8_t state)
Multi Stepper TB67S102 set clk pin function.
void multisteppertb67s102_drive_motor(multisteppertb67s102_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB67S102 driver motor function.
void multisteppertb67s102_enable_device(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 enable device function.
void multisteppertb67s102_disable_device(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 disable device function.
err_t multisteppertb67s102_set_step_mode(multisteppertb67s102_t *ctx, uint8_t mode)
Multi Stepper TB67S102 set step mode function.
err_t multisteppertb67s102_default_cfg(multisteppertb67s102_t *ctx)
Multi Stepper TB67S102 default configuration function.
err_t multisteppertb67s102_get_step_mode(multisteppertb67s102_t *ctx, uint8_t *mode)
Multi Stepper TB67S102 get step mode function.
err_t multisteppertb67s102_write_register(multisteppertb67s102_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB67S102 write register function.
void multisteppertb67s102_set_direction(multisteppertb67s102_t *ctx, uint8_t dir)
Multi Stepper TB67S102 set direction function.
err_t multisteppertb67s102_init(multisteppertb67s102_t *ctx, multisteppertb67s102_cfg_t *cfg)
Multi Stepper TB67S102 initialization function.
err_t multisteppertb67s102_read_register(multisteppertb67s102_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB67S102 read register function.
multisteppertb67s102_return_value_t
Multi Stepper TB67S102 Click return value data.
Definition multisteppertb67s102.h:224
@ MULTISTEPPERTB67S102_ERROR
Definition multisteppertb67s102.h:226
@ MULTISTEPPERTB67S102_OK
Definition multisteppertb67s102.h:225
Multi Stepper TB67S102 Click configuration object.
Definition multisteppertb67s102.h:204
pin_name_t clk
Definition multisteppertb67s102.h:211
uint32_t i2c_speed
Definition multisteppertb67s102.h:214
pin_name_t scl
Definition multisteppertb67s102.h:205
pin_name_t en
Definition multisteppertb67s102.h:208
pin_name_t int_pin
Definition multisteppertb67s102.h:212
pin_name_t sda
Definition multisteppertb67s102.h:206
pin_name_t rst
Definition multisteppertb67s102.h:210
pin_name_t an
Definition multisteppertb67s102.h:209
uint8_t i2c_address
Definition multisteppertb67s102.h:215
Multi Stepper TB67S102 Click context object.
Definition multisteppertb67s102.h:181
digital_in_t int_pin
Definition multisteppertb67s102.h:189
i2c_master_t i2c
Definition multisteppertb67s102.h:192
digital_out_t clk
Definition multisteppertb67s102.h:186
digital_out_t en
Definition multisteppertb67s102.h:183
digital_out_t rst
Definition multisteppertb67s102.h:185
uint8_t slave_address
Definition multisteppertb67s102.h:195
digital_out_t an
Definition multisteppertb67s102.h:184