multisteppertb67s209  2.0.0.0
multisteppertb67s209.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 MULTISTEPPERTB67S209_H
29 #define MULTISTEPPERTB67S209_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 MULTISTEPPERTB67S209_REG_INPUT 0x00
70 #define MULTISTEPPERTB67S209_REG_OUTPUT 0x01
71 #define MULTISTEPPERTB67S209_REG_POLARITY 0x02
72 #define MULTISTEPPERTB67S209_REG_CONFIG 0x03
73  // multisteppertb67s209_reg
75 
90 #define MULTISTEPPERTB67S209_DMODE0_PIN 0x01
91 #define MULTISTEPPERTB67S209_DMODE1_PIN 0x02
92 #define MULTISTEPPERTB67S209_DMODE2_PIN 0x04
93 #define MULTISTEPPERTB67S209_SMD1_PIN 0x10
94 #define MULTISTEPPERTB67S209_SMD0_PIN 0x20
95 #define MULTISTEPPERTB67S209_MO_PIN 0x40
96 #define MULTISTEPPERTB67S209_LO_PIN 0x80
97 
102 #define MULTISTEPPERTB67S209_DEFAULT_CONFIG 0xC8
103 
108 #define MULTISTEPPERTB67S209_DIR_CW 0
109 #define MULTISTEPPERTB67S209_DIR_CCW 1
110 
115 #define MULTISTEPPERTB67S209_PIN_LOW_LEVEL 0
116 #define MULTISTEPPERTB67S209_PIN_HIGH_LEVEL 1
117 
122 #define MULTISTEPPERTB67S209_MODE_STANDBY 0x00
123 #define MULTISTEPPERTB67S209_MODE_HALF_STEP_TYPE_B 0x01
124 #define MULTISTEPPERTB67S209_MODE_HALF_STEP_TYPE_A 0x02
125 #define MULTISTEPPERTB67S209_MODE_1_OVER_16 0x03
126 #define MULTISTEPPERTB67S209_MODE_FULL_STEP 0x04
127 #define MULTISTEPPERTB67S209_MODE_1_OVER_8 0x05
128 #define MULTISTEPPERTB67S209_MODE_QUARTER_STEP 0x06
129 #define MULTISTEPPERTB67S209_MODE_1_OVER_32 0x07
130 #define MULTISTEPPERTB67S209_MODE_BITS_MASK 0x07
131 
136 #define MULTISTEPPERTB67S209_SMD_MODE_FD_12p5_PERCENT 0x00
137 #define MULTISTEPPERTB67S209_SMD_MODE_FD_37p5_PERCENT 0x01
138 #define MULTISTEPPERTB67S209_SMD_MODE_FD_50_PERCENT 0x02
139 #define MULTISTEPPERTB67S209_SMD_MODE_FD_ONLY 0x03
140 #define MULTISTEPPERTB67S209_SMD_MODE_BITS_MASK 0x30
141 
146 #define MULTISTEPPERTB67S209_SPEED_VERY_SLOW 0
147 #define MULTISTEPPERTB67S209_SPEED_SLOW 1
148 #define MULTISTEPPERTB67S209_SPEED_MEDIUM 2
149 #define MULTISTEPPERTB67S209_SPEED_FAST 3
150 #define MULTISTEPPERTB67S209_SPEED_VERY_FAST 4
151 
157 #define MULTISTEPPERTB67S209_DEVICE_ADDRESS_A1A0_00 0x70
158 #define MULTISTEPPERTB67S209_DEVICE_ADDRESS_A1A0_01 0x71
159 #define MULTISTEPPERTB67S209_DEVICE_ADDRESS_A1A0_10 0x72
160 #define MULTISTEPPERTB67S209_DEVICE_ADDRESS_A1A0_11 0x73
161  // multisteppertb67s209_set
163 
178 #define MULTISTEPPERTB67S209_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
180  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
181  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
182  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
183  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
184  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
185  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
186  // multisteppertb67s209_map // multisteppertb67s209
189 
194 typedef struct
195 {
196  // Output pins
197  digital_out_t en;
198  digital_out_t an;
199  digital_out_t rst;
200  digital_out_t clk;
202  // Input pins
203  digital_in_t int_pin;
205  // Modules
206  i2c_master_t i2c;
208  // I2C slave address
209  uint8_t slave_address;
212 
217 typedef struct
218 {
219  pin_name_t scl;
220  pin_name_t sda;
222  pin_name_t en;
223  pin_name_t an;
224  pin_name_t rst;
225  pin_name_t clk;
226  pin_name_t int_pin;
228  uint32_t i2c_speed;
229  uint8_t i2c_address;
232 
237 typedef enum
238 {
241 
243 
260 
275 
290 
304 err_t multisteppertb67s209_write_register ( multisteppertb67s209_t *ctx, uint8_t reg, uint8_t data_in );
305 
318 err_t multisteppertb67s209_read_register ( multisteppertb67s209_t *ctx, uint8_t reg, uint8_t *data_out );
319 
332 
345 
358 
371 
387 void multisteppertb67s209_drive_motor ( multisteppertb67s209_t *ctx, uint32_t steps, uint8_t speed );
388 
398 
408 
420 
430 
440 
450 
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 #endif // MULTISTEPPERTB67S209_H
467  // multisteppertb67s209
469 
470 // ------------------------------------------------------------------------ END
multisteppertb67s209_return_value_t
multisteppertb67s209_return_value_t
Multi Stepper TB67S209 Click return value data.
Definition: multisteppertb67s209.h:238
MULTISTEPPERTB67S209_OK
@ MULTISTEPPERTB67S209_OK
Definition: multisteppertb67s209.h:239
multisteppertb67s209_drive_motor
void multisteppertb67s209_drive_motor(multisteppertb67s209_t *ctx, uint32_t steps, uint8_t speed)
Multi Stepper TB67S209 driver motor function.
multisteppertb67s209_set_direction
void multisteppertb67s209_set_direction(multisteppertb67s209_t *ctx, uint8_t dir)
Multi Stepper TB67S209 set direction function.
multisteppertb67s209_enable_device
void multisteppertb67s209_enable_device(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 enable device function.
multisteppertb67s209_cfg_t::int_pin
pin_name_t int_pin
Definition: multisteppertb67s209.h:226
multisteppertb67s209_cfg_t::i2c_address
uint8_t i2c_address
Definition: multisteppertb67s209.h:229
multisteppertb67s209_set_smd_mode
err_t multisteppertb67s209_set_smd_mode(multisteppertb67s209_t *ctx, uint8_t mode)
Multi Stepper TB67S209 set smd mode function.
multisteppertb67s209_cfg_t::an
pin_name_t an
Definition: multisteppertb67s209.h:223
multisteppertb67s209_t::clk
digital_out_t clk
Definition: multisteppertb67s209.h:200
multisteppertb67s209_disable_device
void multisteppertb67s209_disable_device(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 disable device function.
multisteppertb67s209_cfg_setup
void multisteppertb67s209_cfg_setup(multisteppertb67s209_cfg_t *cfg)
Multi Stepper TB67S209 configuration object setup function.
multisteppertb67s209_cfg_t::sda
pin_name_t sda
Definition: multisteppertb67s209.h:220
multisteppertb67s209_default_cfg
err_t multisteppertb67s209_default_cfg(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 default configuration function.
multisteppertb67s209_cfg_t::clk
pin_name_t clk
Definition: multisteppertb67s209.h:225
multisteppertb67s209_t::slave_address
uint8_t slave_address
Definition: multisteppertb67s209.h:209
multisteppertb67s209_t
Multi Stepper TB67S209 Click context object.
Definition: multisteppertb67s209.h:195
multisteppertb67s209_t::en
digital_out_t en
Definition: multisteppertb67s209.h:197
multisteppertb67s209_t::rst
digital_out_t rst
Definition: multisteppertb67s209.h:199
multisteppertb67s209_cfg_t::scl
pin_name_t scl
Definition: multisteppertb67s209.h:219
multisteppertb67s209_reset_device
void multisteppertb67s209_reset_device(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 reset device function.
multisteppertb67s209_set_step_mode
err_t multisteppertb67s209_set_step_mode(multisteppertb67s209_t *ctx, uint8_t mode)
Multi Stepper TB67S209 set step mode function.
multisteppertb67s209_get_int_pin
uint8_t multisteppertb67s209_get_int_pin(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 get int pin function.
multisteppertb67s209_write_register
err_t multisteppertb67s209_write_register(multisteppertb67s209_t *ctx, uint8_t reg, uint8_t data_in)
Multi Stepper TB67S209 write register function.
multisteppertb67s209_get_step_mode
err_t multisteppertb67s209_get_step_mode(multisteppertb67s209_t *ctx, uint8_t *mode)
Multi Stepper TB67S209 get step mode function.
multisteppertb67s209_get_smd_mode
err_t multisteppertb67s209_get_smd_mode(multisteppertb67s209_t *ctx, uint8_t *mode)
Multi Stepper TB67S209 get smd mode function.
multisteppertb67s209_cfg_t
Multi Stepper TB67S209 Click configuration object.
Definition: multisteppertb67s209.h:218
MULTISTEPPERTB67S209_ERROR
@ MULTISTEPPERTB67S209_ERROR
Definition: multisteppertb67s209.h:240
multisteppertb67s209_set_clk_pin
void multisteppertb67s209_set_clk_pin(multisteppertb67s209_t *ctx, uint8_t state)
Multi Stepper TB67S209 set clk pin function.
multisteppertb67s209_t::an
digital_out_t an
Definition: multisteppertb67s209.h:198
multisteppertb67s209_switch_direction
void multisteppertb67s209_switch_direction(multisteppertb67s209_t *ctx)
Multi Stepper TB67S209 switch direction function.
multisteppertb67s209_read_register
err_t multisteppertb67s209_read_register(multisteppertb67s209_t *ctx, uint8_t reg, uint8_t *data_out)
Multi Stepper TB67S209 read register function.
multisteppertb67s209_cfg_t::en
pin_name_t en
Definition: multisteppertb67s209.h:222
multisteppertb67s209_t::int_pin
digital_in_t int_pin
Definition: multisteppertb67s209.h:203
multisteppertb67s209_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: multisteppertb67s209.h:228
multisteppertb67s209_cfg_t::rst
pin_name_t rst
Definition: multisteppertb67s209.h:224
multisteppertb67s209_t::i2c
i2c_master_t i2c
Definition: multisteppertb67s209.h:206
multisteppertb67s209_init
err_t multisteppertb67s209_init(multisteppertb67s209_t *ctx, multisteppertb67s209_cfg_t *cfg)
Multi Stepper TB67S209 initialization function.