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 "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 STEPPER12_REG_INPUT_0 0x00
70 #define STEPPER12_REG_INPUT_1 0x01
71 #define STEPPER12_REG_OUTPUT_0 0x02
72 #define STEPPER12_REG_OUTPUT_1 0x03
73 #define STEPPER12_REG_POLARITY_0 0x04
74 #define STEPPER12_REG_POLARITY_1 0x05
75 #define STEPPER12_REG_CONFIG_0 0x06
76 #define STEPPER12_REG_CONFIG_1 0x07
77  // stepper12_reg
79 
94 #define STEPPER12_P0_DMODE0_PIN 0x01
95 #define STEPPER12_P0_DMODE1_PIN 0x02
96 #define STEPPER12_P0_DMODE2_PIN 0x04
97 #define STEPPER12_P0_DECAY_PIN 0x08
98 #define STEPPER12_P0_TRQ0_PIN 0x20
99 #define STEPPER12_P0_TRQ1_PIN 0x40
100 #define STEPPER12_P0_SLEEP_X_PIN 0x80
101 #define STEPPER12_P1_LO_PIN 0x01
102 #define STEPPER12_P1_MO_PIN 0x04
103 
108 #define STEPPER12_P0_DEFAULT_CONFIG 0x10
109 #define STEPPER12_P1_DEFAULT_CONFIG 0xFF
110 
115 #define STEPPER12_DIR_CW 1
116 #define STEPPER12_DIR_CCW 0
117 
122 #define STEPPER12_PIN_LOW_LEVEL 0
123 #define STEPPER12_PIN_HIGH_LEVEL 1
124 
129 #define STEPPER12_MODE_FULL_STEP 0x00
130 #define STEPPER12_MODE_1_OVER_8 0x01
131 #define STEPPER12_MODE_HALF_STEP_TYPE_B 0x02
132 #define STEPPER12_MODE_1_OVER_32 0x03
133 #define STEPPER12_MODE_HALF_STEP_TYPE_A 0x04
134 #define STEPPER12_MODE_1_OVER_16 0x05
135 #define STEPPER12_MODE_QUARTER_STEP 0x06
136 #define STEPPER12_MODE_MASK 0x07
137 
142 #define STEPPER12_TORQUE_100_PCT 0x00
143 #define STEPPER12_TORQUE_75_PCT 0x01
144 #define STEPPER12_TORQUE_50_PCT 0x02
145 #define STEPPER12_TORQUE_25_PCT 0x03
146 #define STEPPER12_TORQUE_MASK 0x03
147 
152 #define STEPPER12_SPEED_VERY_SLOW 0
153 #define STEPPER12_SPEED_SLOW 1
154 #define STEPPER12_SPEED_MEDIUM 2
155 #define STEPPER12_SPEED_FAST 3
156 #define STEPPER12_SPEED_VERY_FAST 4
157 
163 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_000 0x20
164 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_001 0x21
165 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_010 0x22
166 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_011 0x23
167 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_100 0x24
168 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_101 0x25
169 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_110 0x26
170 #define STEPPER12_DEVICE_ADDRESS_A2A1A0_111 0x27
171  // stepper12_set
173 
188 #define STEPPER12_MAP_MIKROBUS( cfg, mikrobus ) \
189  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
190  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
191  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
192  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
193  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
194  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
195  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
196  // stepper12_map // stepper12
199 
204 typedef struct
205 {
206  // Output pins
207  digital_out_t en;
208  digital_out_t dir;
209  digital_out_t rst;
210  digital_out_t clk;
212  // Input pins
213  digital_in_t int_pin;
215  // Modules
216  i2c_master_t i2c;
218  // I2C slave address
219  uint8_t slave_address;
221 } stepper12_t;
222 
227 typedef struct
228 {
229  pin_name_t scl;
230  pin_name_t sda;
232  pin_name_t en;
233  pin_name_t dir;
234  pin_name_t rst;
235  pin_name_t clk;
236  pin_name_t int_pin;
238  uint32_t i2c_speed;
239  uint8_t i2c_address;
242 
247 typedef enum
248 {
250  STEPPER12_ERROR = -1
251 
253 
270 
285 
299 
313 err_t stepper12_write_register ( stepper12_t *ctx, uint8_t reg, uint8_t data_in );
314 
327 err_t stepper12_read_register ( stepper12_t *ctx, uint8_t reg, uint8_t *data_out );
328 
340 err_t stepper12_get_step_mode ( stepper12_t *ctx, uint8_t *mode );
341 
353 err_t stepper12_set_step_mode ( stepper12_t *ctx, uint8_t mode );
354 
366 err_t stepper12_get_torque ( stepper12_t *ctx, uint8_t *torque );
367 
379 err_t stepper12_set_torque ( stepper12_t *ctx, uint8_t torque );
380 
393 err_t stepper12_get_decay_pin ( stepper12_t *ctx, uint8_t *state );
394 
407 err_t stepper12_set_decay_pin ( stepper12_t *ctx, uint8_t state );
408 
421 err_t stepper12_get_sleep_x_pin ( stepper12_t *ctx, uint8_t *state );
422 
435 err_t stepper12_set_sleep_x_pin ( stepper12_t *ctx, uint8_t state );
436 
449 err_t stepper12_get_lo_pin ( stepper12_t *ctx, uint8_t *state );
450 
463 err_t stepper12_get_mo_pin ( stepper12_t *ctx, uint8_t *state );
464 
480 void stepper12_drive_motor ( stepper12_t *ctx, uint32_t steps, uint8_t speed );
481 
491 
501 
512 void stepper12_set_direction ( stepper12_t *ctx, uint8_t dir );
513 
523 
533 
543 
554 void stepper12_set_clk_pin ( stepper12_t *ctx, uint8_t state );
555 
556 #ifdef __cplusplus
557 }
558 #endif
559 #endif // STEPPER12_H
560  // stepper12
562 
563 // ------------------------------------------------------------------------ END
STEPPER12_OK
@ STEPPER12_OK
Definition: stepper12.h:249
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:209
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:213
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:233
stepper12_cfg_t::clk
pin_name_t clk
Definition: stepper12.h:235
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:229
STEPPER12_ERROR
@ STEPPER12_ERROR
Definition: stepper12.h:250
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:205
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:207
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:234
stepper12_t::clk
digital_out_t clk
Definition: stepper12.h:210
stepper12_t::i2c
i2c_master_t i2c
Definition: stepper12.h:216
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:208
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:239
stepper12_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper12.h:236
stepper12_cfg_t::sda
pin_name_t sda
Definition: stepper12.h:230
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:228
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:238
stepper12_cfg_t::en
pin_name_t en
Definition: stepper12.h:232
stepper12_return_value_t
stepper12_return_value_t
Stepper 12 Click return value data.
Definition: stepper12.h:248
stepper12_t::slave_address
uint8_t slave_address
Definition: stepper12.h:219
stepper12_set_torque
err_t stepper12_set_torque(stepper12_t *ctx, uint8_t torque)
Stepper 12 set torque function.