stepper13  2.1.0.0
stepper13.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 STEPPER13_H
29 #define STEPPER13_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 STEPPER13_PCA9538A_REG_INPUT 0x00
70 #define STEPPER13_PCA9538A_REG_OUTPUT 0x01
71 #define STEPPER13_PCA9538A_REG_POLARITY 0x02
72 #define STEPPER13_PCA9538A_REG_CONFIG 0x03
73  // stepper13_reg
75 
91 #define STEPPER13_PIN_MS1 0x01
92 #define STEPPER13_PIN_MS2 0x02
93 #define STEPPER13_PIN_MS_MASK 0x03
94 #define STEPPER13_PIN_FAULT 0x04
95 #define STEPPER13_PIN_DIR 0x08
96 #define STEPPER13_PIN_SLEEP 0x10
97 #define STEPPER13_PIN_ENABLE 0x20
98 
103 #define STEPPER13_PCA9538A_DEFAULT_CONFIG 0xC4
104 
109 #define STEPPER13_DIR_CW 0
110 #define STEPPER13_DIR_CCW 1
111 
116 #define STEPPER13_PIN_STATE_LOW 0
117 #define STEPPER13_PIN_STATE_HIGH 1
118 
123 #define STEPPER13_SPEED_VERY_SLOW 0
124 #define STEPPER13_SPEED_SLOW 1
125 #define STEPPER13_SPEED_MEDIUM 2
126 #define STEPPER13_SPEED_FAST 3
127 #define STEPPER13_SPEED_VERY_FAST 4
128 
133 #define STEPPER13_MODE_FULL_STEP 0
134 #define STEPPER13_MODE_HALF_STEP 1
135 #define STEPPER13_MODE_QUARTER_STEP 2
136 #define STEPPER13_MODE_1_OVER_8 3
137 
143 #define STEPPER13_DEVICE_ADDRESS_A1A0_00 0x70
144 #define STEPPER13_DEVICE_ADDRESS_A1A0_01 0x71
145 #define STEPPER13_DEVICE_ADDRESS_A1A0_10 0x72
146 #define STEPPER13_DEVICE_ADDRESS_A1A0_11 0x73
147  // stepper13_set
149 
164 #define STEPPER13_MAP_MIKROBUS( cfg, mikrobus ) \
165  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
166  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
167  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
168  cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
169  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
170  // stepper13_map // stepper13
173 
178 typedef struct
179 {
180  // Output pins
181  digital_out_t rst;
182  digital_out_t step;
184  // Input pins
185  digital_in_t int_pin;
187  // Modules
188  i2c_master_t i2c;
190  // I2C slave address
191  uint8_t slave_address;
193 } stepper13_t;
194 
199 typedef struct
200 {
201  pin_name_t scl;
202  pin_name_t sda;
204  pin_name_t rst;
205  pin_name_t step;
206  pin_name_t int_pin;
208  uint32_t i2c_speed;
209  uint8_t i2c_address;
212 
217 typedef enum
218 {
220  STEPPER13_ERROR = -1
221 
223 
240 
255 
269 
283 err_t stepper13_pca_write_reg ( stepper13_t *ctx, uint8_t reg, uint8_t data_in );
284 
297 err_t stepper13_pca_read_reg ( stepper13_t *ctx, uint8_t reg, uint8_t *data_out );
298 
311 err_t stepper13_get_fault_pin ( stepper13_t *ctx, uint8_t *state );
312 
324 
336 
348 
360 
373 err_t stepper13_set_direction ( stepper13_t *ctx, uint8_t dir );
374 
386 
397 void stepper13_set_rst_pin ( stepper13_t *ctx, uint8_t state );
398 
408 
418 
429 void stepper13_set_step_pin ( stepper13_t *ctx, uint8_t state );
430 
446 err_t stepper13_get_step_mode ( stepper13_t *ctx, uint8_t *mode );
447 
463 err_t stepper13_set_step_mode ( stepper13_t *ctx, uint8_t mode );
464 
482 err_t stepper13_drive_motor ( stepper13_t *ctx, uint32_t steps, uint8_t speed );
483 
484 #ifdef __cplusplus
485 }
486 #endif
487 #endif // STEPPER13_H
488  // stepper13
490 
491 // ------------------------------------------------------------------------ END
stepper13_t::rst
digital_out_t rst
Definition: stepper13.h:181
stepper13_set_step_pin
void stepper13_set_step_pin(stepper13_t *ctx, uint8_t state)
Stepper 13 set step pin function.
stepper13_cfg_t::step
pin_name_t step
Definition: stepper13.h:205
stepper13_pca_read_reg
err_t stepper13_pca_read_reg(stepper13_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 13 pca read reg function.
stepper13_disable_sleep
err_t stepper13_disable_sleep(stepper13_t *ctx)
Stepper 13 disable sleep function.
stepper13_t
Stepper 13 Click context object.
Definition: stepper13.h:179
stepper13_t::int_pin
digital_in_t int_pin
Definition: stepper13.h:185
stepper13_init
err_t stepper13_init(stepper13_t *ctx, stepper13_cfg_t *cfg)
Stepper 13 initialization function.
stepper13_get_step_mode
err_t stepper13_get_step_mode(stepper13_t *ctx, uint8_t *mode)
Stepper 13 get step mode function.
stepper13_cfg_t::scl
pin_name_t scl
Definition: stepper13.h:201
stepper13_cfg_t::sda
pin_name_t sda
Definition: stepper13.h:202
stepper13_pca_write_reg
err_t stepper13_pca_write_reg(stepper13_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 13 pca write reg function.
stepper13_set_step_mode
err_t stepper13_set_step_mode(stepper13_t *ctx, uint8_t mode)
Stepper 13 set step mode function.
stepper13_reset_pca
void stepper13_reset_pca(stepper13_t *ctx)
Stepper 13 reset device function.
stepper13_set_rst_pin
void stepper13_set_rst_pin(stepper13_t *ctx, uint8_t state)
Stepper 13 set rst pin function.
stepper13_switch_direction
err_t stepper13_switch_direction(stepper13_t *ctx)
Stepper 13 switch direction function.
stepper13_get_int_pin
uint8_t stepper13_get_int_pin(stepper13_t *ctx)
Stepper 13 get INT pin function.
stepper13_enable_device
err_t stepper13_enable_device(stepper13_t *ctx)
Stepper 13 enable device function.
stepper13_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper13.h:206
STEPPER13_OK
@ STEPPER13_OK
Definition: stepper13.h:219
stepper13_enable_sleep
err_t stepper13_enable_sleep(stepper13_t *ctx)
Stepper 13 enable sleep function.
stepper13_t::slave_address
uint8_t slave_address
Definition: stepper13.h:191
stepper13_t::step
digital_out_t step
Definition: stepper13.h:182
stepper13_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper13.h:209
stepper13_set_direction
err_t stepper13_set_direction(stepper13_t *ctx, uint8_t dir)
Stepper 13 set direction function.
stepper13_disable_device
err_t stepper13_disable_device(stepper13_t *ctx)
Stepper 13 disable device function.
stepper13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper13.h:208
STEPPER13_ERROR
@ STEPPER13_ERROR
Definition: stepper13.h:220
stepper13_cfg_t
Stepper 13 Click configuration object.
Definition: stepper13.h:200
stepper13_cfg_setup
void stepper13_cfg_setup(stepper13_cfg_t *cfg)
Stepper 13 configuration object setup function.
stepper13_default_cfg
err_t stepper13_default_cfg(stepper13_t *ctx)
Stepper 13 default configuration function.
stepper13_cfg_t::rst
pin_name_t rst
Definition: stepper13.h:204
stepper13_drive_motor
err_t stepper13_drive_motor(stepper13_t *ctx, uint32_t steps, uint8_t speed)
Stepper 13 driver motor function.
stepper13_t::i2c
i2c_master_t i2c
Definition: stepper13.h:188
stepper13_return_value_t
stepper13_return_value_t
Stepper 13 Click return value data.
Definition: stepper13.h:218
stepper13_get_fault_pin
err_t stepper13_get_fault_pin(stepper13_t *ctx, uint8_t *state)
Stepper 13 get fault pin function.