multisteppertb67s269  2.0.0.0
multisteppertb67s269.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 MULTISTEPPERTB67S269_H
29 #define MULTISTEPPERTB67S269_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 MULTISTEPPERTB67S269_REG_INPUT 0x00
74 #define MULTISTEPPERTB67S269_REG_OUTPUT 0x01
75 #define MULTISTEPPERTB67S269_REG_POLARITY 0x02
76 #define MULTISTEPPERTB67S269_REG_CONFIG 0x03
77  // multisteppertb67s269_reg
79 
94 #define MULTISTEPPERTB67S269_DMODE0_PIN 0x01
95 #define MULTISTEPPERTB67S269_DMODE1_PIN 0x02
96 #define MULTISTEPPERTB67S269_DMODE2_PIN 0x04
97 #define MULTISTEPPERTB67S269_MO_PIN 0x40
98 #define MULTISTEPPERTB67S269_LO_PIN 0x80
99 
104 #define MULTISTEPPERTB67S269_DEFAULT_CONFIG 0xF8
105 
110 #define MULTISTEPPERTB67S269_DIR_CW 0
111 #define MULTISTEPPERTB67S269_DIR_CCW 1
112 
117 #define MULTISTEPPERTB67S269_PIN_LOW_LEVEL 0
118 #define MULTISTEPPERTB67S269_PIN_HIGH_LEVEL 1
119 
124 #define MULTISTEPPERTB67S269_MODE_STANDBY 0x00
125 #define MULTISTEPPERTB67S269_MODE_HALF_STEP_TYPE_B 0x01
126 #define MULTISTEPPERTB67S269_MODE_HALF_STEP_TYPE_A 0x02
127 #define MULTISTEPPERTB67S269_MODE_1_OVER_16 0x03
128 #define MULTISTEPPERTB67S269_MODE_FULL_STEP 0x04
129 #define MULTISTEPPERTB67S269_MODE_1_OVER_8 0x05
130 #define MULTISTEPPERTB67S269_MODE_QUARTER_STEP 0x06
131 #define MULTISTEPPERTB67S269_MODE_1_OVER_32 0x07
132 #define MULTISTEPPERTB67S269_MODE_BITS_MASK 0x07
133 
138 #define MULTISTEPPERTB67S269_SPEED_VERY_SLOW 0
139 #define MULTISTEPPERTB67S269_SPEED_SLOW 1
140 #define MULTISTEPPERTB67S269_SPEED_MEDIUM 2
141 #define MULTISTEPPERTB67S269_SPEED_FAST 3
142 #define MULTISTEPPERTB67S269_SPEED_VERY_FAST 4
143 
149 #define MULTISTEPPERTB67S269_DEVICE_ADDRESS_A1A0_00 0x70
150 #define MULTISTEPPERTB67S269_DEVICE_ADDRESS_A1A0_01 0x71
151 #define MULTISTEPPERTB67S269_DEVICE_ADDRESS_A1A0_10 0x72
152 #define MULTISTEPPERTB67S269_DEVICE_ADDRESS_A1A0_11 0x73
153  // multisteppertb67s269_set
155 
170 #define MULTISTEPPERTB67S269_MAP_MIKROBUS( cfg, mikrobus ) \
171  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
172  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
173  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
174  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
175  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
176  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
177  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
178  // multisteppertb67s269_map // multisteppertb67s269
181 
186 typedef struct
187 {
188  // Output pins
189  digital_out_t en;
190  digital_out_t an;
191  digital_out_t rst;
192  digital_out_t clk;
194  // Input pins
195  digital_in_t int_pin;
197  // Modules
198  i2c_master_t i2c;
200  // I2C slave address
201  uint8_t slave_address;
204 
209 typedef struct
210 {
211  pin_name_t scl;
212  pin_name_t sda;
214  pin_name_t en;
215  pin_name_t an;
216  pin_name_t rst;
217  pin_name_t clk;
218  pin_name_t int_pin;
220  uint32_t i2c_speed;
221  uint8_t i2c_address;
224 
229 typedef enum
230 {
233 
235 
252 
267 
282 
296 err_t multisteppertb67s269_write_register ( multisteppertb67s269_t *ctx, uint8_t reg, uint8_t data_in );
297 
310 err_t multisteppertb67s269_read_register ( multisteppertb67s269_t *ctx, uint8_t reg, uint8_t *data_out );
311 
324 
337 
353 void multisteppertb67s269_drive_motor ( multisteppertb67s269_t *ctx, uint32_t steps, uint8_t speed );
354 
364 
374 
386 
396 
406 
416 
428 
429 #ifdef __cplusplus
430 }
431 #endif
432 #endif // MULTISTEPPERTB67S269_H
433  // multisteppertb67s269
435 
436 // ------------------------------------------------------------------------ END
multisteppertb67s269_set_clk_pin
void multisteppertb67s269_set_clk_pin(multisteppertb67s269_t *ctx, uint8_t state)
Multi Stepper TB67S269 set clk pin function.
MULTISTEPPERTB67S269_OK
@ MULTISTEPPERTB67S269_OK
Definition: multisteppertb67s269.h:231
multisteppertb67s269_switch_direction
void multisteppertb67s269_switch_direction(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 switch direction function.
multisteppertb67s269_t::clk
digital_out_t clk
Definition: multisteppertb67s269.h:192
multisteppertb67s269_read_register
err_t multisteppertb67s269_read_register(multisteppertb67s269_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB67S269 read register function.
multisteppertb67s269_enable_device
void multisteppertb67s269_enable_device(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 enable device function.
multisteppertb67s269_cfg_t::int_pin
pin_name_t int_pin
Definition: multisteppertb67s269.h:218
multisteppertb67s269_default_cfg
err_t multisteppertb67s269_default_cfg(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 default configuration function.
multisteppertb67s269_cfg_t::en
pin_name_t en
Definition: multisteppertb67s269.h:214
multisteppertb67s269_t::slave_address
uint8_t slave_address
Definition: multisteppertb67s269.h:201
multisteppertb67s269_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: multisteppertb67s269.h:220
multisteppertb67s269_get_step_mode
err_t multisteppertb67s269_get_step_mode(multisteppertb67s269_t *ctx, uint8_t *mode)
Multi Stepper TB67S269 get step mode function.
multisteppertb67s269_cfg_t::scl
pin_name_t scl
Definition: multisteppertb67s269.h:211
multisteppertb67s269_t::en
digital_out_t en
Definition: multisteppertb67s269.h:189
multisteppertb67s269_cfg_t::rst
pin_name_t rst
Definition: multisteppertb67s269.h:216
multisteppertb67s269_write_register
err_t multisteppertb67s269_write_register(multisteppertb67s269_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB67S269 write register function.
multisteppertb67s269_cfg_t::an
pin_name_t an
Definition: multisteppertb67s269.h:215
multisteppertb67s269_t::rst
digital_out_t rst
Definition: multisteppertb67s269.h:191
multisteppertb67s269_cfg_t
Multi Stepper TB67S269 Click configuration object.
Definition: multisteppertb67s269.h:210
multisteppertb67s269_set_step_mode
err_t multisteppertb67s269_set_step_mode(multisteppertb67s269_t *ctx, uint8_t mode)
Multi Stepper TB67S269 set step mode function.
multisteppertb67s269_get_int_pin
uint8_t multisteppertb67s269_get_int_pin(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 get int pin function.
multisteppertb67s269_t::an
digital_out_t an
Definition: multisteppertb67s269.h:190
multisteppertb67s269_disable_device
void multisteppertb67s269_disable_device(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 disable device function.
multisteppertb67s269_cfg_t::clk
pin_name_t clk
Definition: multisteppertb67s269.h:217
multisteppertb67s269_t
Multi Stepper TB67S269 Click context object.
Definition: multisteppertb67s269.h:187
multisteppertb67s269_t::int_pin
digital_in_t int_pin
Definition: multisteppertb67s269.h:195
multisteppertb67s269_cfg_t::i2c_address
uint8_t i2c_address
Definition: multisteppertb67s269.h:221
multisteppertb67s269_set_direction
void multisteppertb67s269_set_direction(multisteppertb67s269_t *ctx, uint8_t dir)
Multi Stepper TB67S269 set direction function.
multisteppertb67s269_reset_device
void multisteppertb67s269_reset_device(multisteppertb67s269_t *ctx)
Multi Stepper TB67S269 reset device function.
MULTISTEPPERTB67S269_ERROR
@ MULTISTEPPERTB67S269_ERROR
Definition: multisteppertb67s269.h:232
multisteppertb67s269_t::i2c
i2c_master_t i2c
Definition: multisteppertb67s269.h:198
multisteppertb67s269_init
err_t multisteppertb67s269_init(multisteppertb67s269_t *ctx, multisteppertb67s269_cfg_t *cfg)
Multi Stepper TB67S269 initialization function.
multisteppertb67s269_drive_motor
void multisteppertb67s269_drive_motor(multisteppertb67s269_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB67S269 driver motor function.
multisteppertb67s269_cfg_setup
void multisteppertb67s269_cfg_setup(multisteppertb67s269_cfg_t *cfg)
Multi Stepper TB67S269 configuration object setup function.
multisteppertb67s269_cfg_t::sda
pin_name_t sda
Definition: multisteppertb67s269.h:212
multisteppertb67s269_return_value_t
multisteppertb67s269_return_value_t
Multi Stepper TB67S269 Click return value data.
Definition: multisteppertb67s269.h:230