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
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define STEPPER13_PCA9538A_REG_INPUT 0x00
74#define STEPPER13_PCA9538A_REG_OUTPUT 0x01
75#define STEPPER13_PCA9538A_REG_POLARITY 0x02
76#define STEPPER13_PCA9538A_REG_CONFIG 0x03
77
78 // stepper13_reg
79
95#define STEPPER13_PIN_MS1 0x01
96#define STEPPER13_PIN_MS2 0x02
97#define STEPPER13_PIN_MS_MASK 0x03
98#define STEPPER13_PIN_FAULT 0x04
99#define STEPPER13_PIN_DIR 0x08
100#define STEPPER13_PIN_SLEEP 0x10
101#define STEPPER13_PIN_ENABLE 0x20
102
107#define STEPPER13_PCA9538A_DEFAULT_CONFIG 0xC4
108
113#define STEPPER13_DIR_CW 0
114#define STEPPER13_DIR_CCW 1
115
120#define STEPPER13_PIN_STATE_LOW 0
121#define STEPPER13_PIN_STATE_HIGH 1
122
127#define STEPPER13_SPEED_VERY_SLOW 0
128#define STEPPER13_SPEED_SLOW 1
129#define STEPPER13_SPEED_MEDIUM 2
130#define STEPPER13_SPEED_FAST 3
131#define STEPPER13_SPEED_VERY_FAST 4
132
137#define STEPPER13_MODE_FULL_STEP 0
138#define STEPPER13_MODE_HALF_STEP 1
139#define STEPPER13_MODE_QUARTER_STEP 2
140#define STEPPER13_MODE_1_OVER_8 3
141
147#define STEPPER13_DEVICE_ADDRESS_A1A0_00 0x70
148#define STEPPER13_DEVICE_ADDRESS_A1A0_01 0x71
149#define STEPPER13_DEVICE_ADDRESS_A1A0_10 0x72
150#define STEPPER13_DEVICE_ADDRESS_A1A0_11 0x73
151
152 // stepper13_set
153
168#define STEPPER13_MAP_MIKROBUS( cfg, mikrobus ) \
169 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
170 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
171 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
172 cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
173 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
174
175 // stepper13_map
176 // stepper13
177
182typedef struct
183{
184 // Output pins
185 digital_out_t rst;
186 digital_out_t step;
188 // Input pins
189 digital_in_t int_pin;
191 // Modules
192 i2c_master_t i2c;
194 // I2C slave address
198
203typedef struct
204{
205 pin_name_t scl;
206 pin_name_t sda;
208 pin_name_t rst;
209 pin_name_t step;
210 pin_name_t int_pin;
212 uint32_t i2c_speed;
213 uint8_t i2c_address;
216
227
244
259
273
287err_t stepper13_pca_write_reg ( stepper13_t *ctx, uint8_t reg, uint8_t data_in );
288
301err_t stepper13_pca_read_reg ( stepper13_t *ctx, uint8_t reg, uint8_t *data_out );
302
315err_t stepper13_get_fault_pin ( stepper13_t *ctx, uint8_t *state );
316
328
340
352
364
377err_t stepper13_set_direction ( stepper13_t *ctx, uint8_t dir );
378
390
401void stepper13_set_rst_pin ( stepper13_t *ctx, uint8_t state );
402
412
422
433void stepper13_set_step_pin ( stepper13_t *ctx, uint8_t state );
434
450err_t stepper13_get_step_mode ( stepper13_t *ctx, uint8_t *mode );
451
467err_t stepper13_set_step_mode ( stepper13_t *ctx, uint8_t mode );
468
486err_t stepper13_drive_motor ( stepper13_t *ctx, uint32_t steps, uint8_t speed );
487
488#ifdef __cplusplus
489}
490#endif
491#endif // STEPPER13_H
492
493 // stepper13
494
495// ------------------------------------------------------------------------ END
err_t stepper13_disable_device(stepper13_t *ctx)
Stepper 13 disable device function.
err_t stepper13_pca_read_reg(stepper13_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 13 pca read reg function.
err_t stepper13_disable_sleep(stepper13_t *ctx)
Stepper 13 disable sleep function.
err_t stepper13_switch_direction(stepper13_t *ctx)
Stepper 13 switch direction function.
uint8_t stepper13_get_int_pin(stepper13_t *ctx)
Stepper 13 get INT pin function.
err_t stepper13_set_step_mode(stepper13_t *ctx, uint8_t mode)
Stepper 13 set step mode function.
err_t stepper13_get_fault_pin(stepper13_t *ctx, uint8_t *state)
Stepper 13 get fault pin function.
void stepper13_set_rst_pin(stepper13_t *ctx, uint8_t state)
Stepper 13 set rst pin function.
err_t stepper13_drive_motor(stepper13_t *ctx, uint32_t steps, uint8_t speed)
Stepper 13 driver motor function.
err_t stepper13_get_step_mode(stepper13_t *ctx, uint8_t *mode)
Stepper 13 get step mode function.
void stepper13_cfg_setup(stepper13_cfg_t *cfg)
Stepper 13 configuration object setup function.
err_t stepper13_pca_write_reg(stepper13_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 13 pca write reg function.
err_t stepper13_enable_sleep(stepper13_t *ctx)
Stepper 13 enable sleep function.
err_t stepper13_enable_device(stepper13_t *ctx)
Stepper 13 enable device function.
err_t stepper13_default_cfg(stepper13_t *ctx)
Stepper 13 default configuration function.
err_t stepper13_set_direction(stepper13_t *ctx, uint8_t dir)
Stepper 13 set direction function.
err_t stepper13_init(stepper13_t *ctx, stepper13_cfg_t *cfg)
Stepper 13 initialization function.
void stepper13_set_step_pin(stepper13_t *ctx, uint8_t state)
Stepper 13 set step pin function.
void stepper13_reset_pca(stepper13_t *ctx)
Stepper 13 reset device function.
stepper13_return_value_t
Stepper 13 Click return value data.
Definition stepper13.h:222
@ STEPPER13_OK
Definition stepper13.h:223
@ STEPPER13_ERROR
Definition stepper13.h:224
Stepper 13 Click configuration object.
Definition stepper13.h:204
pin_name_t step
Definition stepper13.h:209
uint32_t i2c_speed
Definition stepper13.h:212
pin_name_t scl
Definition stepper13.h:205
pin_name_t int_pin
Definition stepper13.h:210
pin_name_t sda
Definition stepper13.h:206
pin_name_t rst
Definition stepper13.h:208
uint8_t i2c_address
Definition stepper13.h:213
Stepper 13 Click context object.
Definition stepper13.h:183
digital_in_t int_pin
Definition stepper13.h:189
digital_out_t step
Definition stepper13.h:186
i2c_master_t i2c
Definition stepper13.h:192
digital_out_t rst
Definition stepper13.h:185
uint8_t slave_address
Definition stepper13.h:195