multisteppertb62262  2.0.0.0
multisteppertb62262.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 MULTISTEPPERTB62262_H
29 #define MULTISTEPPERTB62262_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 MULTISTEPPERTB62262_REG_INPUT 0x00
70 #define MULTISTEPPERTB62262_REG_OUTPUT 0x01
71 #define MULTISTEPPERTB62262_REG_POLARITY 0x02
72 #define MULTISTEPPERTB62262_REG_CONFIG 0x03
73  // multisteppertb62262_reg
75 
90 #define MULTISTEPPERTB62262_DMODE1_PIN 0x02
91 #define MULTISTEPPERTB62262_DMODE2_PIN 0x04
92 #define MULTISTEPPERTB62262_MO_PIN 0x40
93 
98 #define MULTISTEPPERTB62262_DEFAULT_CONFIG 0xF9
99 
104 #define MULTISTEPPERTB62262_DIR_CW 0
105 #define MULTISTEPPERTB62262_DIR_CCW 1
106 
111 #define MULTISTEPPERTB62262_PIN_LOW_LEVEL 0
112 #define MULTISTEPPERTB62262_PIN_HIGH_LEVEL 1
113 
118 #define MULTISTEPPERTB62262_MODE_STANDBY 0x00
119 #define MULTISTEPPERTB62262_MODE_HALF_STEP_TYPE_A 0x02
120 #define MULTISTEPPERTB62262_MODE_FULL_STEP 0x04
121 #define MULTISTEPPERTB62262_MODE_QUARTER_STEP 0x06
122 #define MULTISTEPPERTB62262_MODE_BITS_MASK 0x06
123 
128 #define MULTISTEPPERTB62262_SPEED_VERY_SLOW 0
129 #define MULTISTEPPERTB62262_SPEED_SLOW 1
130 #define MULTISTEPPERTB62262_SPEED_MEDIUM 2
131 #define MULTISTEPPERTB62262_SPEED_FAST 3
132 #define MULTISTEPPERTB62262_SPEED_VERY_FAST 4
133 
139 #define MULTISTEPPERTB62262_DEVICE_ADDRESS_A1A0_00 0x70
140 #define MULTISTEPPERTB62262_DEVICE_ADDRESS_A1A0_01 0x71
141 #define MULTISTEPPERTB62262_DEVICE_ADDRESS_A1A0_10 0x72
142 #define MULTISTEPPERTB62262_DEVICE_ADDRESS_A1A0_11 0x73
143  // multisteppertb62262_set
145 
160 #define MULTISTEPPERTB62262_MAP_MIKROBUS( cfg, mikrobus ) \
161  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
162  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
163  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
164  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
165  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
166  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
167  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
168  // multisteppertb62262_map // multisteppertb62262
171 
176 typedef struct
177 {
178  // Output pins
179  digital_out_t en;
180  digital_out_t an;
181  digital_out_t rst;
182  digital_out_t clk;
184  // Input pins
185  digital_in_t int_pin;
187  // Modules
188  i2c_master_t i2c;
190  // I2C slave address
191  uint8_t slave_address;
194 
199 typedef struct
200 {
201  pin_name_t scl;
202  pin_name_t sda;
204  pin_name_t en;
205  pin_name_t an;
206  pin_name_t rst;
207  pin_name_t clk;
208  pin_name_t int_pin;
210  uint32_t i2c_speed;
211  uint8_t i2c_address;
214 
219 typedef enum
220 {
223 
225 
242 
257 
272 
286 err_t multisteppertb62262_write_register ( multisteppertb62262_t *ctx, uint8_t reg, uint8_t data_in );
287 
300 err_t multisteppertb62262_read_register ( multisteppertb62262_t *ctx, uint8_t reg, uint8_t *data_out );
301 
314 
327 
343 void multisteppertb62262_drive_motor ( multisteppertb62262_t *ctx, uint32_t steps, uint8_t speed );
344 
354 
364 
376 
386 
396 
406 
418 
419 #ifdef __cplusplus
420 }
421 #endif
422 #endif // MULTISTEPPERTB62262_H
423  // multisteppertb62262
425 
426 // ------------------------------------------------------------------------ END
multisteppertb62262_t::slave_address
uint8_t slave_address
Definition: multisteppertb62262.h:191
multisteppertb62262_cfg_t
Multi Stepper TB62262 Click configuration object.
Definition: multisteppertb62262.h:200
multisteppertb62262_get_int_pin
uint8_t multisteppertb62262_get_int_pin(multisteppertb62262_t *ctx)
Multi Stepper TB62262 get int pin function.
multisteppertb62262_cfg_t::int_pin
pin_name_t int_pin
Definition: multisteppertb62262.h:208
multisteppertb62262_cfg_t::an
pin_name_t an
Definition: multisteppertb62262.h:205
multisteppertb62262_init
err_t multisteppertb62262_init(multisteppertb62262_t *ctx, multisteppertb62262_cfg_t *cfg)
Multi Stepper TB62262 initialization function.
MULTISTEPPERTB62262_OK
@ MULTISTEPPERTB62262_OK
Definition: multisteppertb62262.h:221
multisteppertb62262_t::i2c
i2c_master_t i2c
Definition: multisteppertb62262.h:188
MULTISTEPPERTB62262_ERROR
@ MULTISTEPPERTB62262_ERROR
Definition: multisteppertb62262.h:222
multisteppertb62262_default_cfg
err_t multisteppertb62262_default_cfg(multisteppertb62262_t *ctx)
Multi Stepper TB62262 default configuration function.
multisteppertb62262_cfg_t::sda
pin_name_t sda
Definition: multisteppertb62262.h:202
multisteppertb62262_cfg_t::en
pin_name_t en
Definition: multisteppertb62262.h:204
multisteppertb62262_t::en
digital_out_t en
Definition: multisteppertb62262.h:179
multisteppertb62262_cfg_t::scl
pin_name_t scl
Definition: multisteppertb62262.h:201
multisteppertb62262_return_value_t
multisteppertb62262_return_value_t
Multi Stepper TB62262 Click return value data.
Definition: multisteppertb62262.h:220
multisteppertb62262_switch_direction
void multisteppertb62262_switch_direction(multisteppertb62262_t *ctx)
Multi Stepper TB62262 switch direction function.
multisteppertb62262_read_register
err_t multisteppertb62262_read_register(multisteppertb62262_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB62262 read register function.
multisteppertb62262_write_register
err_t multisteppertb62262_write_register(multisteppertb62262_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB62262 write register function.
multisteppertb62262_set_step_mode
err_t multisteppertb62262_set_step_mode(multisteppertb62262_t *ctx, uint8_t mode)
Multi Stepper TB62262 set step mode function.
multisteppertb62262_cfg_t::i2c_address
uint8_t i2c_address
Definition: multisteppertb62262.h:211
multisteppertb62262_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: multisteppertb62262.h:210
multisteppertb62262_get_step_mode
err_t multisteppertb62262_get_step_mode(multisteppertb62262_t *ctx, uint8_t *mode)
Multi Stepper TB62262 get step mode function.
multisteppertb62262_cfg_t::rst
pin_name_t rst
Definition: multisteppertb62262.h:206
multisteppertb62262_cfg_setup
void multisteppertb62262_cfg_setup(multisteppertb62262_cfg_t *cfg)
Multi Stepper TB62262 configuration object setup function.
multisteppertb62262_t
Multi Stepper TB62262 Click context object.
Definition: multisteppertb62262.h:177
multisteppertb62262_drive_motor
void multisteppertb62262_drive_motor(multisteppertb62262_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB62262 driver motor function.
multisteppertb62262_t::rst
digital_out_t rst
Definition: multisteppertb62262.h:181
multisteppertb62262_enable_device
void multisteppertb62262_enable_device(multisteppertb62262_t *ctx)
Multi Stepper TB62262 enable device function.
multisteppertb62262_reset_device
void multisteppertb62262_reset_device(multisteppertb62262_t *ctx)
Multi Stepper TB62262 reset device function.
multisteppertb62262_set_clk_pin
void multisteppertb62262_set_clk_pin(multisteppertb62262_t *ctx, uint8_t state)
Multi Stepper TB62262 set clk pin function.
multisteppertb62262_disable_device
void multisteppertb62262_disable_device(multisteppertb62262_t *ctx)
Multi Stepper TB62262 disable device function.
multisteppertb62262_t::clk
digital_out_t clk
Definition: multisteppertb62262.h:182
multisteppertb62262_t::an
digital_out_t an
Definition: multisteppertb62262.h:180
multisteppertb62262_set_direction
void multisteppertb62262_set_direction(multisteppertb62262_t *ctx, uint8_t dir)
Multi Stepper TB62262 set direction function.
multisteppertb62262_cfg_t::clk
pin_name_t clk
Definition: multisteppertb62262.h:207
multisteppertb62262_t::int_pin
digital_in_t int_pin
Definition: multisteppertb62262.h:185