stepper14  2.1.0.0
stepper14.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 STEPPER14_H
29 #define STEPPER14_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 STEPPER14_PCA9538A_REG_INPUT 0x00
70 #define STEPPER14_PCA9538A_REG_OUTPUT 0x01
71 #define STEPPER14_PCA9538A_REG_POLARITY 0x02
72 #define STEPPER14_PCA9538A_REG_CONFIG 0x03
73  // stepper14_reg
75 
90 #define STEPPER14_PIN_IN1 0x01
91 #define STEPPER14_PIN_IN2 0x02
92 #define STEPPER14_PIN_MODE 0x04
93 #define STEPPER14_PIN_IN3 0x08
94 #define STEPPER14_PIN_IN4 0x10
95 #define STEPPER14_PIN_TRQ 0x20
96 
101 #define STEPPER14_PCA9538A_DEFAULT_CONFIG 0xC0
102 
107 #define STEPPER14_DIR_CW 0
108 #define STEPPER14_DIR_CCW 1
109 
114 #define STEPPER14_PIN_STATE_LOW 0
115 #define STEPPER14_PIN_STATE_HIGH 1
116 
121 #define STEPPER14_INTERFACE_4_PIN 0
122 #define STEPPER14_INTERFACE_2_PIN 1
123 
128 #define STEPPER14_SPEED_VERY_SLOW 0
129 #define STEPPER14_SPEED_SLOW 1
130 #define STEPPER14_SPEED_MEDIUM 2
131 #define STEPPER14_SPEED_FAST 3
132 #define STEPPER14_SPEED_VERY_FAST 4
133 
138 #define STEPPER14_MODE_FULL_STEP 0
139 #define STEPPER14_MODE_HALF_STEP 1
140 
146 #define STEPPER14_DEVICE_ADDRESS_A1A0_00 0x70
147 #define STEPPER14_DEVICE_ADDRESS_A1A0_01 0x71
148 #define STEPPER14_DEVICE_ADDRESS_A1A0_10 0x72
149 #define STEPPER14_DEVICE_ADDRESS_A1A0_11 0x73
150  // stepper14_set
152 
167 #define STEPPER14_MAP_MIKROBUS( cfg, mikrobus ) \
168  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
169  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
170  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
171  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
172  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
173  // stepper14_map // stepper14
176 
181 typedef struct
182 {
183  // Output pins
184  digital_out_t en;
185  digital_out_t rst;
187  // Input pins
188  digital_in_t flt;
190  // Modules
191  i2c_master_t i2c;
193  // I2C slave address
194  uint8_t slave_address;
196  uint8_t pin_mode;
197  uint8_t step_mode;
198  uint8_t direction;
200 } stepper14_t;
201 
206 typedef struct
207 {
208  pin_name_t scl;
209  pin_name_t sda;
211  pin_name_t en;
212  pin_name_t rst;
213  pin_name_t flt;
215  uint32_t i2c_speed;
216  uint8_t i2c_address;
219 
224 typedef enum
225 {
227  STEPPER14_ERROR = -1
228 
230 
247 
262 
276 
290 err_t stepper14_pca_write_reg ( stepper14_t *ctx, uint8_t reg, uint8_t data_in );
291 
304 err_t stepper14_pca_read_reg ( stepper14_t *ctx, uint8_t reg, uint8_t *data_out );
305 
316 void stepper14_set_rst_pin ( stepper14_t *ctx, uint8_t state );
317 
327 
337 
347 
357 
370 err_t stepper14_set_in1_pin ( stepper14_t *ctx, uint8_t state );
371 
384 err_t stepper14_set_in2_pin ( stepper14_t *ctx, uint8_t state );
385 
398 err_t stepper14_set_in3_pin ( stepper14_t *ctx, uint8_t state );
399 
412 err_t stepper14_set_in4_pin ( stepper14_t *ctx, uint8_t state );
413 
426 err_t stepper14_set_mode_pin ( stepper14_t *ctx, uint8_t state );
427 
440 err_t stepper14_set_trq_pin ( stepper14_t *ctx, uint8_t state );
441 
455 err_t stepper14_set_interface_mode ( stepper14_t *ctx, uint8_t mode );
456 
468 void stepper14_set_step_mode ( stepper14_t *ctx, uint8_t mode );
469 
480 void stepper14_set_direction ( stepper14_t *ctx, uint8_t dir );
481 
491 
509 err_t stepper14_drive_motor ( stepper14_t *ctx, uint32_t steps, uint8_t speed );
510 
511 #ifdef __cplusplus
512 }
513 #endif
514 #endif // STEPPER14_H
515  // stepper14
517 
518 // ------------------------------------------------------------------------ END
stepper14_get_fault_pin
uint8_t stepper14_get_fault_pin(stepper14_t *ctx)
Stepper 14 get FAULT pin function.
stepper14_switch_direction
void stepper14_switch_direction(stepper14_t *ctx)
Stepper 14 switch direction function.
STEPPER14_OK
@ STEPPER14_OK
Definition: stepper14.h:226
stepper14_t::direction
uint8_t direction
Definition: stepper14.h:198
stepper14_cfg_t::sda
pin_name_t sda
Definition: stepper14.h:209
stepper14_set_in3_pin
err_t stepper14_set_in3_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN3 pin function.
stepper14_t::slave_address
uint8_t slave_address
Definition: stepper14.h:194
stepper14_cfg_t::en
pin_name_t en
Definition: stepper14.h:211
stepper14_cfg_t::rst
pin_name_t rst
Definition: stepper14.h:212
stepper14_set_rst_pin
void stepper14_set_rst_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set rst pin function.
stepper14_t::en
digital_out_t en
Definition: stepper14.h:184
stepper14_set_in2_pin
err_t stepper14_set_in2_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN2 pin function.
stepper14_t
Stepper 14 Click context object.
Definition: stepper14.h:182
stepper14_t::flt
digital_in_t flt
Definition: stepper14.h:188
stepper14_disable_device
void stepper14_disable_device(stepper14_t *ctx)
Stepper 14 disable device function.
stepper14_reset_pca
void stepper14_reset_pca(stepper14_t *ctx)
Stepper 14 reset device function.
stepper14_return_value_t
stepper14_return_value_t
Stepper 14 Click return value data.
Definition: stepper14.h:225
stepper14_enable_device
void stepper14_enable_device(stepper14_t *ctx)
Stepper 14 enable device function.
stepper14_set_mode_pin
err_t stepper14_set_mode_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set MODE pin function.
stepper14_t::step_mode
uint8_t step_mode
Definition: stepper14.h:197
stepper14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper14.h:215
stepper14_t::pin_mode
uint8_t pin_mode
Definition: stepper14.h:196
stepper14_t::i2c
i2c_master_t i2c
Definition: stepper14.h:191
stepper14_set_in4_pin
err_t stepper14_set_in4_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN4 pin function.
stepper14_set_direction
void stepper14_set_direction(stepper14_t *ctx, uint8_t dir)
Stepper 14 set direction function.
stepper14_cfg_t::scl
pin_name_t scl
Definition: stepper14.h:208
STEPPER14_ERROR
@ STEPPER14_ERROR
Definition: stepper14.h:227
stepper14_set_trq_pin
err_t stepper14_set_trq_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set TRQ pin function.
stepper14_default_cfg
err_t stepper14_default_cfg(stepper14_t *ctx)
Stepper 14 default configuration function.
stepper14_pca_write_reg
err_t stepper14_pca_write_reg(stepper14_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 14 pca write reg function.
stepper14_drive_motor
err_t stepper14_drive_motor(stepper14_t *ctx, uint32_t steps, uint8_t speed)
Stepper 14 driver motor function.
stepper14_init
err_t stepper14_init(stepper14_t *ctx, stepper14_cfg_t *cfg)
Stepper 14 initialization function.
stepper14_cfg_t
Stepper 14 Click configuration object.
Definition: stepper14.h:207
stepper14_set_step_mode
void stepper14_set_step_mode(stepper14_t *ctx, uint8_t mode)
Stepper 14 set step mode function.
stepper14_cfg_setup
void stepper14_cfg_setup(stepper14_cfg_t *cfg)
Stepper 14 configuration object setup function.
stepper14_pca_read_reg
err_t stepper14_pca_read_reg(stepper14_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 14 pca read reg function.
stepper14_cfg_t::flt
pin_name_t flt
Definition: stepper14.h:213
stepper14_set_in1_pin
err_t stepper14_set_in1_pin(stepper14_t *ctx, uint8_t state)
Stepper 14 set IN1 pin function.
stepper14_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper14.h:216
stepper14_t::rst
digital_out_t rst
Definition: stepper14.h:185
stepper14_set_interface_mode
err_t stepper14_set_interface_mode(stepper14_t *ctx, uint8_t mode)
Stepper 14 set interface mode function.