stepper17  2.1.0.0
stepper17.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 STEPPER17_H
29 #define STEPPER17_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 STEPPER17_REG_INPUT_0 0x00
70 #define STEPPER17_REG_INPUT_1 0x01
71 #define STEPPER17_REG_OUTPUT_0 0x02
72 #define STEPPER17_REG_OUTPUT_1 0x03
73 #define STEPPER17_REG_POLARITY_0 0x04
74 #define STEPPER17_REG_POLARITY_1 0x05
75 #define STEPPER17_REG_CONFIG_0 0x06
76 #define STEPPER17_REG_CONFIG_1 0x07
77  // stepper17_reg
79 
94 #define STEPPER17_P0_DMODE0_PIN 0x01
95 #define STEPPER17_P0_DMODE1_PIN 0x02
96 #define STEPPER17_P0_DMODE2_PIN 0x04
97 #define STEPPER17_P0_DECAY1_PIN 0x08
98 #define STEPPER17_P0_DECAY2_PIN 0x10
99 #define STEPPER17_P0_TRQ0_PIN 0x20
100 #define STEPPER17_P0_TRQ1_PIN 0x40
101 #define STEPPER17_P0_SLEEP_X_PIN 0x80
102 #define STEPPER17_P1_LO1_PIN 0x01
103 #define STEPPER17_P1_LO2_PIN 0x02
104 #define STEPPER17_P1_MO_PIN 0x04
105 
110 #define STEPPER17_P0_DEFAULT_CONFIG 0x00
111 #define STEPPER17_P1_DEFAULT_CONFIG 0xFF
112 
117 #define STEPPER17_DIR_CW 1
118 #define STEPPER17_DIR_CCW 0
119 
124 #define STEPPER17_PIN_LOW_LEVEL 0
125 #define STEPPER17_PIN_HIGH_LEVEL 1
126 
131 #define STEPPER17_MODE_FULL_STEP 0x00
132 #define STEPPER17_MODE_1_OVER_8 0x01
133 #define STEPPER17_MODE_HALF_STEP_TYPE_B 0x02
134 #define STEPPER17_MODE_1_OVER_32 0x03
135 #define STEPPER17_MODE_HALF_STEP_TYPE_A 0x04
136 #define STEPPER17_MODE_1_OVER_16 0x05
137 #define STEPPER17_MODE_QUARTER_STEP 0x06
138 #define STEPPER17_MODE_MASK 0x07
139 
144 #define STEPPER17_TORQUE_100_PCT 0x00
145 #define STEPPER17_TORQUE_75_PCT 0x01
146 #define STEPPER17_TORQUE_50_PCT 0x02
147 #define STEPPER17_TORQUE_25_PCT 0x03
148 #define STEPPER17_TORQUE_MASK 0x03
149 
154 #define STEPPER17_DECAY_MIXED 0x00
155 #define STEPPER17_DECAY_SLOW 0x01
156 #define STEPPER17_DECAY_FAST 0x02
157 #define STEPPER17_DECAY_ADMD 0x03
158 #define STEPPER17_DECAY_MASK 0x03
159 
164 #define STEPPER17_SPEED_VERY_SLOW 0
165 #define STEPPER17_SPEED_SLOW 1
166 #define STEPPER17_SPEED_MEDIUM 2
167 #define STEPPER17_SPEED_FAST 3
168 #define STEPPER17_SPEED_VERY_FAST 4
169 
175 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_000 0x20
176 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_001 0x21
177 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_010 0x22
178 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_011 0x23
179 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_100 0x24
180 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_101 0x25
181 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_110 0x26
182 #define STEPPER17_DEVICE_ADDRESS_A2A1A0_111 0x27
183  // stepper17_set
185 
200 #define STEPPER17_MAP_MIKROBUS( cfg, mikrobus ) \
201  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
202  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
203  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
204  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
205  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
206  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
207  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
208  // stepper17_map // stepper17
211 
216 typedef struct
217 {
218  // Output pins
219  digital_out_t en;
220  digital_out_t dir;
221  digital_out_t rst;
222  digital_out_t clk;
224  // Input pins
225  digital_in_t int_pin;
227  // Modules
228  i2c_master_t i2c;
230  // I2C slave address
231  uint8_t slave_address;
233 } stepper17_t;
234 
239 typedef struct
240 {
241  pin_name_t scl;
242  pin_name_t sda;
244  pin_name_t en;
245  pin_name_t dir;
246  pin_name_t rst;
247  pin_name_t clk;
248  pin_name_t int_pin;
250  uint32_t i2c_speed;
251  uint8_t i2c_address;
254 
259 typedef enum
260 {
262  STEPPER17_ERROR = -1
263 
265 
282 
297 
311 
325 err_t stepper17_write_register ( stepper17_t *ctx, uint8_t reg, uint8_t data_in );
326 
339 err_t stepper17_read_register ( stepper17_t *ctx, uint8_t reg, uint8_t *data_out );
340 
352 err_t stepper17_get_step_mode ( stepper17_t *ctx, uint8_t *mode );
353 
365 err_t stepper17_set_step_mode ( stepper17_t *ctx, uint8_t mode );
366 
378 err_t stepper17_get_torque ( stepper17_t *ctx, uint8_t *torque );
379 
391 err_t stepper17_set_torque ( stepper17_t *ctx, uint8_t torque );
392 
404 err_t stepper17_get_decay ( stepper17_t *ctx, uint8_t *decay );
405 
417 err_t stepper17_set_decay ( stepper17_t *ctx, uint8_t decay );
418 
431 err_t stepper17_get_sleep_x_pin ( stepper17_t *ctx, uint8_t *state );
432 
445 err_t stepper17_set_sleep_x_pin ( stepper17_t *ctx, uint8_t state );
446 
459 err_t stepper17_get_lo1_pin ( stepper17_t *ctx, uint8_t *state );
460 
473 err_t stepper17_get_lo2_pin ( stepper17_t *ctx, uint8_t *state );
474 
487 err_t stepper17_get_mo_pin ( stepper17_t *ctx, uint8_t *state );
488 
504 void stepper17_drive_motor ( stepper17_t *ctx, uint32_t steps, uint8_t speed );
505 
515 
525 
536 void stepper17_set_direction ( stepper17_t *ctx, uint8_t dir );
537 
547 
557 
567 
578 void stepper17_set_clk_pin ( stepper17_t *ctx, uint8_t state );
579 
580 #ifdef __cplusplus
581 }
582 #endif
583 #endif // STEPPER17_H
584  // stepper17
586 
587 // ------------------------------------------------------------------------ END
stepper17_get_decay
err_t stepper17_get_decay(stepper17_t *ctx, uint8_t *decay)
Stepper 17 get decay function.
STEPPER17_OK
@ STEPPER17_OK
Definition: stepper17.h:261
stepper17_read_register
err_t stepper17_read_register(stepper17_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 17 read register function.
stepper17_cfg_t::dir
pin_name_t dir
Definition: stepper17.h:245
stepper17_cfg_t::en
pin_name_t en
Definition: stepper17.h:244
stepper17_return_value_t
stepper17_return_value_t
Stepper 17 Click return value data.
Definition: stepper17.h:260
stepper17_get_torque
err_t stepper17_get_torque(stepper17_t *ctx, uint8_t *torque)
Stepper 17 get torque function.
stepper17_t::int_pin
digital_in_t int_pin
Definition: stepper17.h:225
stepper17_get_mo_pin
err_t stepper17_get_mo_pin(stepper17_t *ctx, uint8_t *state)
Stepper 17 get mo pin function.
stepper17_write_register
err_t stepper17_write_register(stepper17_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 17 write register function.
stepper17_set_decay
err_t stepper17_set_decay(stepper17_t *ctx, uint8_t decay)
Stepper 17 set decay function.
stepper17_t
Stepper 17 Click context object.
Definition: stepper17.h:217
stepper17_get_int_pin
uint8_t stepper17_get_int_pin(stepper17_t *ctx)
Stepper 17 get int pin function.
stepper17_get_lo1_pin
err_t stepper17_get_lo1_pin(stepper17_t *ctx, uint8_t *state)
Stepper 17 get lo1 pin function.
stepper17_set_direction
void stepper17_set_direction(stepper17_t *ctx, uint8_t dir)
Stepper 17 set direction function.
stepper17_get_lo2_pin
err_t stepper17_get_lo2_pin(stepper17_t *ctx, uint8_t *state)
Stepper 17 get lo2 pin function.
stepper17_get_step_mode
err_t stepper17_get_step_mode(stepper17_t *ctx, uint8_t *mode)
Stepper 17 get step mode function.
stepper17_t::en
digital_out_t en
Definition: stepper17.h:219
stepper17_get_sleep_x_pin
err_t stepper17_get_sleep_x_pin(stepper17_t *ctx, uint8_t *state)
Stepper 17 get sleep x pin function.
stepper17_t::clk
digital_out_t clk
Definition: stepper17.h:222
stepper17_init
err_t stepper17_init(stepper17_t *ctx, stepper17_cfg_t *cfg)
Stepper 17 initialization function.
stepper17_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper17.h:248
stepper17_cfg_t::clk
pin_name_t clk
Definition: stepper17.h:247
stepper17_set_sleep_x_pin
err_t stepper17_set_sleep_x_pin(stepper17_t *ctx, uint8_t state)
Stepper 17 set sleep x pin function.
stepper17_cfg_t::scl
pin_name_t scl
Definition: stepper17.h:241
stepper17_cfg_t::sda
pin_name_t sda
Definition: stepper17.h:242
stepper17_set_torque
err_t stepper17_set_torque(stepper17_t *ctx, uint8_t torque)
Stepper 17 set torque function.
stepper17_drive_motor
void stepper17_drive_motor(stepper17_t *ctx, uint32_t steps, uint8_t speed)
Stepper 17 driver motor function.
stepper17_t::dir
digital_out_t dir
Definition: stepper17.h:220
stepper17_enable_device
void stepper17_enable_device(stepper17_t *ctx)
Stepper 17 enable device function.
stepper17_switch_direction
void stepper17_switch_direction(stepper17_t *ctx)
Stepper 17 switch direction function.
STEPPER17_ERROR
@ STEPPER17_ERROR
Definition: stepper17.h:262
stepper17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper17.h:250
stepper17_t::i2c
i2c_master_t i2c
Definition: stepper17.h:228
stepper17_default_cfg
err_t stepper17_default_cfg(stepper17_t *ctx)
Stepper 17 default configuration function.
stepper17_reset_device
void stepper17_reset_device(stepper17_t *ctx)
Stepper 17 reset device function.
stepper17_cfg_t::rst
pin_name_t rst
Definition: stepper17.h:246
stepper17_set_clk_pin
void stepper17_set_clk_pin(stepper17_t *ctx, uint8_t state)
Stepper 17 set clk pin function.
stepper17_cfg_t
Stepper 17 Click configuration object.
Definition: stepper17.h:240
stepper17_t::slave_address
uint8_t slave_address
Definition: stepper17.h:231
stepper17_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper17.h:251
stepper17_t::rst
digital_out_t rst
Definition: stepper17.h:221
stepper17_set_step_mode
err_t stepper17_set_step_mode(stepper17_t *ctx, uint8_t mode)
Stepper 17 set step mode function.
stepper17_cfg_setup
void stepper17_cfg_setup(stepper17_cfg_t *cfg)
Stepper 17 configuration object setup function.
stepper17_disable_device
void stepper17_disable_device(stepper17_t *ctx)
Stepper 17 disable device function.