multisteppertb62269  2.0.0.0
multisteppertb62269.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 MULTISTEPPERTB62269_H
29 #define MULTISTEPPERTB62269_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define MULTISTEPPERTB62269_REG_INPUT 0x00
70 #define MULTISTEPPERTB62269_REG_OUTPUT 0x01
71 #define MULTISTEPPERTB62269_REG_POLARITY 0x02
72 #define MULTISTEPPERTB62269_REG_CONFIG 0x03
73  // multisteppertb62269_reg
75 
90 #define MULTISTEPPERTB62269_DMODE0_PIN 0x01
91 #define MULTISTEPPERTB62269_DMODE1_PIN 0x02
92 #define MULTISTEPPERTB62269_DMODE2_PIN 0x04
93 #define MULTISTEPPERTB62269_MO_PIN 0x40
94 #define MULTISTEPPERTB62269_LO_PIN 0x80
95 
100 #define MULTISTEPPERTB62269_DEFAULT_CONFIG 0xF8
101 
106 #define MULTISTEPPERTB62269_DIR_CW 0
107 #define MULTISTEPPERTB62269_DIR_CCW 1
108 
113 #define MULTISTEPPERTB62269_PIN_LOW_LEVEL 0
114 #define MULTISTEPPERTB62269_PIN_HIGH_LEVEL 1
115 
120 #define MULTISTEPPERTB62269_MODE_STANDBY 0x00
121 #define MULTISTEPPERTB62269_MODE_HALF_STEP_TYPE_B 0x01
122 #define MULTISTEPPERTB62269_MODE_HALF_STEP_TYPE_A 0x02
123 #define MULTISTEPPERTB62269_MODE_1_OVER_16 0x03
124 #define MULTISTEPPERTB62269_MODE_FULL_STEP 0x04
125 #define MULTISTEPPERTB62269_MODE_1_OVER_8 0x05
126 #define MULTISTEPPERTB62269_MODE_QUARTER_STEP 0x06
127 #define MULTISTEPPERTB62269_MODE_1_OVER_32 0x07
128 #define MULTISTEPPERTB62269_MODE_BITS_MASK 0x07
129 
134 #define MULTISTEPPERTB62269_SPEED_VERY_SLOW 0
135 #define MULTISTEPPERTB62269_SPEED_SLOW 1
136 #define MULTISTEPPERTB62269_SPEED_MEDIUM 2
137 #define MULTISTEPPERTB62269_SPEED_FAST 3
138 #define MULTISTEPPERTB62269_SPEED_VERY_FAST 4
139 
145 #define MULTISTEPPERTB62269_DEVICE_ADDRESS_A1A0_00 0x70
146 #define MULTISTEPPERTB62269_DEVICE_ADDRESS_A1A0_01 0x71
147 #define MULTISTEPPERTB62269_DEVICE_ADDRESS_A1A0_10 0x72
148 #define MULTISTEPPERTB62269_DEVICE_ADDRESS_A1A0_11 0x73
149  // multisteppertb62269_set
151 
166 #define MULTISTEPPERTB62269_MAP_MIKROBUS( cfg, mikrobus ) \
167  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
168  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
169  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
170  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
171  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
172  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
173  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
174  // multisteppertb62269_map // multisteppertb62269
177 
182 typedef struct
183 {
184  // Output pins
185  digital_out_t en;
186  digital_out_t an;
187  digital_out_t rst;
188  digital_out_t clk;
190  // Input pins
191  digital_in_t int_pin;
193  // Modules
194  i2c_master_t i2c;
196  // I2C slave address
197  uint8_t slave_address;
200 
205 typedef struct
206 {
207  pin_name_t scl;
208  pin_name_t sda;
210  pin_name_t en;
211  pin_name_t an;
212  pin_name_t rst;
213  pin_name_t clk;
214  pin_name_t int_pin;
216  uint32_t i2c_speed;
217  uint8_t i2c_address;
220 
225 typedef enum
226 {
229 
231 
248 
263 
278 
292 err_t multisteppertb62269_write_register ( multisteppertb62269_t *ctx, uint8_t reg, uint8_t data_in );
293 
306 err_t multisteppertb62269_read_register ( multisteppertb62269_t *ctx, uint8_t reg, uint8_t *data_out );
307 
320 
333 
349 void multisteppertb62269_drive_motor ( multisteppertb62269_t *ctx, uint32_t steps, uint8_t speed );
350 
360 
370 
382 
392 
402 
412 
424 
425 #ifdef __cplusplus
426 }
427 #endif
428 #endif // MULTISTEPPERTB62269_H
429  // multisteppertb62269
431 
432 // ------------------------------------------------------------------------ END
multisteppertb62269_cfg_t::scl
pin_name_t scl
Definition: multisteppertb62269.h:207
multisteppertb62269_cfg_t
Multi Stepper TB62269 Click configuration object.
Definition: multisteppertb62269.h:206
multisteppertb62269_switch_direction
void multisteppertb62269_switch_direction(multisteppertb62269_t *ctx)
Multi Stepper TB62269 switch direction function.
multisteppertb62269_default_cfg
err_t multisteppertb62269_default_cfg(multisteppertb62269_t *ctx)
Multi Stepper TB62269 default configuration function.
multisteppertb62269_cfg_t::clk
pin_name_t clk
Definition: multisteppertb62269.h:213
multisteppertb62269_set_step_mode
err_t multisteppertb62269_set_step_mode(multisteppertb62269_t *ctx, uint8_t mode)
Multi Stepper TB62269 set step mode function.
multisteppertb62269_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: multisteppertb62269.h:216
multisteppertb62269_t::int_pin
digital_in_t int_pin
Definition: multisteppertb62269.h:191
multisteppertb62269_set_direction
void multisteppertb62269_set_direction(multisteppertb62269_t *ctx, uint8_t dir)
Multi Stepper TB62269 set direction function.
multisteppertb62269_reset_device
void multisteppertb62269_reset_device(multisteppertb62269_t *ctx)
Multi Stepper TB62269 reset device function.
multisteppertb62269_return_value_t
multisteppertb62269_return_value_t
Multi Stepper TB62269 Click return value data.
Definition: multisteppertb62269.h:226
multisteppertb62269_cfg_t::sda
pin_name_t sda
Definition: multisteppertb62269.h:208
multisteppertb62269_enable_device
void multisteppertb62269_enable_device(multisteppertb62269_t *ctx)
Multi Stepper TB62269 enable device function.
multisteppertb62269_drive_motor
void multisteppertb62269_drive_motor(multisteppertb62269_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB62269 driver motor function.
MULTISTEPPERTB62269_OK
@ MULTISTEPPERTB62269_OK
Definition: multisteppertb62269.h:227
multisteppertb62269_t::i2c
i2c_master_t i2c
Definition: multisteppertb62269.h:194
multisteppertb62269_cfg_t::int_pin
pin_name_t int_pin
Definition: multisteppertb62269.h:214
multisteppertb62269_t::en
digital_out_t en
Definition: multisteppertb62269.h:185
multisteppertb62269_cfg_t::i2c_address
uint8_t i2c_address
Definition: multisteppertb62269.h:217
multisteppertb62269_get_step_mode
err_t multisteppertb62269_get_step_mode(multisteppertb62269_t *ctx, uint8_t *mode)
Multi Stepper TB62269 get step mode function.
multisteppertb62269_cfg_setup
void multisteppertb62269_cfg_setup(multisteppertb62269_cfg_t *cfg)
Multi Stepper TB62269 configuration object setup function.
multisteppertb62269_init
err_t multisteppertb62269_init(multisteppertb62269_t *ctx, multisteppertb62269_cfg_t *cfg)
Multi Stepper TB62269 initialization function.
multisteppertb62269_disable_device
void multisteppertb62269_disable_device(multisteppertb62269_t *ctx)
Multi Stepper TB62269 disable device function.
multisteppertb62269_write_register
err_t multisteppertb62269_write_register(multisteppertb62269_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB62269 write register function.
multisteppertb62269_cfg_t::rst
pin_name_t rst
Definition: multisteppertb62269.h:212
multisteppertb62269_t::an
digital_out_t an
Definition: multisteppertb62269.h:186
multisteppertb62269_set_clk_pin
void multisteppertb62269_set_clk_pin(multisteppertb62269_t *ctx, uint8_t state)
Multi Stepper TB62269 set clk pin function.
multisteppertb62269_cfg_t::en
pin_name_t en
Definition: multisteppertb62269.h:210
multisteppertb62269_t::clk
digital_out_t clk
Definition: multisteppertb62269.h:188
multisteppertb62269_get_int_pin
uint8_t multisteppertb62269_get_int_pin(multisteppertb62269_t *ctx)
Multi Stepper TB62269 get int pin function.
multisteppertb62269_read_register
err_t multisteppertb62269_read_register(multisteppertb62269_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB62269 read register function.
multisteppertb62269_t
Multi Stepper TB62269 Click context object.
Definition: multisteppertb62269.h:183
MULTISTEPPERTB62269_ERROR
@ MULTISTEPPERTB62269_ERROR
Definition: multisteppertb62269.h:228
multisteppertb62269_t::slave_address
uint8_t slave_address
Definition: multisteppertb62269.h:197
multisteppertb62269_cfg_t::an
pin_name_t an
Definition: multisteppertb62269.h:211
multisteppertb62269_t::rst
digital_out_t rst
Definition: multisteppertb62269.h:187