stepper12  2.1.0.0
stepper12.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 STEPPER12_H
29 #define STEPPER12_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define STEPPER12_REG_INPUT_0 0x00
60 #define STEPPER12_REG_INPUT_1 0x01
61 #define STEPPER12_REG_OUTPUT_0 0x02
62 #define STEPPER12_REG_OUTPUT_1 0x03
63 #define STEPPER12_REG_POLARITY_0 0x04
64 #define STEPPER12_REG_POLARITY_1 0x05
65 #define STEPPER12_REG_CONFIG_0 0x06
66 #define STEPPER12_REG_CONFIG_1 0x07
67  // stepper12_reg
69 
84 #define STEPPER12_P0_DMODE0_PIN 0x01
85 #define STEPPER12_P0_DMODE1_PIN 0x02
86 #define STEPPER12_P0_DMODE2_PIN 0x04
87 #define STEPPER12_P0_DECAY_PIN 0x08
88 #define STEPPER12_P0_TRQ0_PIN 0x20
89 #define STEPPER12_P0_TRQ1_PIN 0x40
90 #define STEPPER12_P0_SLEEP_X_PIN 0x80
91 #define STEPPER12_P1_LO_PIN 0x01
92 #define STEPPER12_P1_MO_PIN 0x04
93 
98 #define STEPPER12_P0_DEFAULT_CONFIG 0x10
99 #define STEPPER12_P1_DEFAULT_CONFIG 0xFF
100 
105 #define STEPPER12_DIR_CW 1
106 #define STEPPER12_DIR_CCW 0
107 
112 #define STEPPER12_PIN_LOW_LEVEL 0
113 #define STEPPER12_PIN_HIGH_LEVEL 1
114 
119 #define STEPPER12_MODE_FULL_STEP 0x00
120 #define STEPPER12_MODE_1_OVER_8 0x01
121 #define STEPPER12_MODE_HALF_STEP_TYPE_B 0x02
122 #define STEPPER12_MODE_1_OVER_32 0x03
123 #define STEPPER12_MODE_HALF_STEP_TYPE_A 0x04
124 #define STEPPER12_MODE_1_OVER_16 0x05
125 #define STEPPER12_MODE_QUARTER_STEP 0x06
126 #define STEPPER12_MODE_MASK 0x07
127 
132 #define STEPPER12_TORQUE_100_PCT 0x00
133 #define STEPPER12_TORQUE_75_PCT 0x01
134 #define STEPPER12_TORQUE_50_PCT 0x02
135 #define STEPPER12_TORQUE_25_PCT 0x03
136 #define STEPPER12_TORQUE_MASK 0x03
137 
142 #define STEPPER12_SPEED_VERY_SLOW 0
143 #define STEPPER12_SPEED_SLOW 1
144 #define STEPPER12_SPEED_MEDIUM 2
145 #define STEPPER12_SPEED_FAST 3
146 #define STEPPER12_SPEED_VERY_FAST 4
147 
153 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_000 0x20
154 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_001 0x21
155 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_010 0x22
156 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_011 0x23
157 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_100 0x24
158 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_101 0x25
159 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_110 0x26
160 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_111 0x27
161  // stepper12_set
163 
178 #define STEPPER12_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.dir = 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  // stepper12_map // stepper12
189 
194 typedef struct
195 {
196  // Output pins
197  digital_out_t en;
198  digital_out_t dir;
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;
211 } stepper12_t;
212 
217 typedef struct
218 {
219  pin_name_t scl;
220  pin_name_t sda;
222  pin_name_t en;
223  pin_name_t dir;
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 {
240  STEPPER12_ERROR = -1
241 
243 
260 
275 
289 
303 err_t stepper12_write_register ( stepper12_t *ctx, uint8_t reg, uint8_t data_in );
304 
317 err_t stepper12_read_register ( stepper12_t *ctx, uint8_t reg, uint8_t *data_out );
318 
330 err_t stepper12_get_step_mode ( stepper12_t *ctx, uint8_t *mode );
331 
343 err_t stepper12_set_step_mode ( stepper12_t *ctx, uint8_t mode );
344 
356 err_t stepper12_get_torque ( stepper12_t *ctx, uint8_t *torque );
357 
369 err_t stepper12_set_torque ( stepper12_t *ctx, uint8_t torque );
370 
383 err_t stepper12_get_decay_pin ( stepper12_t *ctx, uint8_t *state );
384 
397 err_t stepper12_set_decay_pin ( stepper12_t *ctx, uint8_t state );
398 
411 err_t stepper12_get_sleep_x_pin ( stepper12_t *ctx, uint8_t *state );
412 
425 err_t stepper12_set_sleep_x_pin ( stepper12_t *ctx, uint8_t state );
426 
439 err_t stepper12_get_lo_pin ( stepper12_t *ctx, uint8_t *state );
440 
453 err_t stepper12_get_mo_pin ( stepper12_t *ctx, uint8_t *state );
454 
470 void stepper12_drive_motor ( stepper12_t *ctx, uint32_t steps, uint8_t speed );
471 
481 
491 
502 void stepper12_set_direction ( stepper12_t *ctx, uint8_t dir );
503 
513 
523 
533 
544 void stepper12_set_clk_pin ( stepper12_t *ctx, uint8_t state );
545 
546 #ifdef __cplusplus
547 }
548 #endif
549 #endif // STEPPER12_H
550  // stepper12
552 
553 // ------------------------------------------------------------------------ END
STEPPER12_OK
@ STEPPER12_OK
Definition: stepper12.h:239
stepper12_get_torque
err_t stepper12_get_torque(stepper12_t *ctx, uint8_t *torque)
Stepper 12 get torque function.
stepper12_set_sleep_x_pin
err_t stepper12_set_sleep_x_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set sleep x pin function.
stepper12_drive_motor
void stepper12_drive_motor(stepper12_t *ctx, uint32_t steps, uint8_t speed)
Stepper 12 driver motor function.
stepper12_t::rst
digital_out_t rst
Definition: stepper12.h:199
stepper12_set_direction
void stepper12_set_direction(stepper12_t *ctx, uint8_t dir)
Stepper 12 set direction function.
stepper12_t::int_pin
digital_in_t int_pin
Definition: stepper12.h:203
stepper12_disable_device
void stepper12_disable_device(stepper12_t *ctx)
Stepper 12 disable device function.
stepper12_reset_device
void stepper12_reset_device(stepper12_t *ctx)
Stepper 12 reset device function.
stepper12_cfg_t::dir
pin_name_t dir
Definition: stepper12.h:223
stepper12_cfg_t::clk
pin_name_t clk
Definition: stepper12.h:225
stepper12_set_decay_pin
err_t stepper12_set_decay_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set decay pin function.
stepper12_cfg_t::scl
pin_name_t scl
Definition: stepper12.h:219
STEPPER12_ERROR
@ STEPPER12_ERROR
Definition: stepper12.h:240
stepper12_switch_direction
void stepper12_switch_direction(stepper12_t *ctx)
Stepper 12 switch direction function.
stepper12_init
err_t stepper12_init(stepper12_t *ctx, stepper12_cfg_t *cfg)
Stepper 12 initialization function.
stepper12_t
Stepper 12 Click context object.
Definition: stepper12.h:195
stepper12_cfg_setup
void stepper12_cfg_setup(stepper12_cfg_t *cfg)
Stepper 12 configuration object setup function.
stepper12_t::en
digital_out_t en
Definition: stepper12.h:197
stepper12_set_step_mode
err_t stepper12_set_step_mode(stepper12_t *ctx, uint8_t mode)
Stepper 12 set step mode function.
stepper12_cfg_t::rst
pin_name_t rst
Definition: stepper12.h:224
stepper12_t::clk
digital_out_t clk
Definition: stepper12.h:200
stepper12_t::i2c
i2c_master_t i2c
Definition: stepper12.h:206
stepper12_write_register
err_t stepper12_write_register(stepper12_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 12 write register function.
stepper12_default_cfg
err_t stepper12_default_cfg(stepper12_t *ctx)
Stepper 12 default configuration function.
stepper12_read_register
err_t stepper12_read_register(stepper12_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 12 read register function.
stepper12_t::dir
digital_out_t dir
Definition: stepper12.h:198
stepper12_get_mo_pin
err_t stepper12_get_mo_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get mo pin function.
stepper12_get_step_mode
err_t stepper12_get_step_mode(stepper12_t *ctx, uint8_t *mode)
Stepper 12 get step mode function.
stepper12_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper12.h:229
stepper12_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper12.h:226
stepper12_cfg_t::sda
pin_name_t sda
Definition: stepper12.h:220
stepper12_enable_device
void stepper12_enable_device(stepper12_t *ctx)
Stepper 12 enable device function.
stepper12_get_decay_pin
err_t stepper12_get_decay_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get decay pin function.
stepper12_get_lo_pin
err_t stepper12_get_lo_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get lo pin function.
stepper12_get_int_pin
uint8_t stepper12_get_int_pin(stepper12_t *ctx)
Stepper 12 get int pin function.
stepper12_set_clk_pin
void stepper12_set_clk_pin(stepper12_t *ctx, uint8_t state)
Stepper 12 set clk pin function.
stepper12_cfg_t
Stepper 12 Click configuration object.
Definition: stepper12.h:218
stepper12_get_sleep_x_pin
err_t stepper12_get_sleep_x_pin(stepper12_t *ctx, uint8_t *state)
Stepper 12 get sleep x pin function.
stepper12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper12.h:228
stepper12_cfg_t::en
pin_name_t en
Definition: stepper12.h:222
stepper12_return_value_t
stepper12_return_value_t
Stepper 12 Click return value data.
Definition: stepper12.h:238
stepper12_t::slave_address
uint8_t slave_address
Definition: stepper12.h:209
stepper12_set_torque
err_t stepper12_set_torque(stepper12_t *ctx, uint8_t torque)
Stepper 12 set torque function.