stepper8 2.1.0.0
stepper8.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 STEPPER8_H
29#define STEPPER8_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#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define STEPPER8_PCA9538A_REG_INPUT 0x00
76#define STEPPER8_PCA9538A_REG_OUTPUT 0x01
77#define STEPPER8_PCA9538A_REG_POLARITY 0x02
78#define STEPPER8_PCA9538A_REG_CONFIG 0x03
79
80 // stepper8_reg
81
96#define STEPPER8_PIN_STBY 0x01
97#define STEPPER8_PIN_SELECT 0x02
98#define STEPPER8_PIN_EN 0x04
99
104#define STEPPER8_PCA9538A_DEFAULT_CONFIG 0xF8
105
110#define STEPPER8_DIR_CW 0
111#define STEPPER8_DIR_CCW 1
112
117#define STEPPER8_PIN_STATE_LOW 0
118#define STEPPER8_PIN_STATE_HIGH 1
119
124#define STEPPER8_SPEED_VERY_SLOW 0
125#define STEPPER8_SPEED_SLOW 1
126#define STEPPER8_SPEED_MEDIUM 2
127#define STEPPER8_SPEED_FAST 3
128#define STEPPER8_SPEED_VERY_FAST 4
129
134#define STEPPER8_MODE_FULL_STEP 0
135#define STEPPER8_MODE_HALF_STEP 1
136#define STEPPER8_MODE_QUARTER_STEP 2
137#define STEPPER8_MODE_1_OVER_8 3
138#define STEPPER8_MODE_1_OVER_16 4
139#define STEPPER8_MODE_1_OVER_32 5
140#define STEPPER8_MODE_1_OVER_64 6
141#define STEPPER8_MODE_1_OVER_128 7
142
148#define STEPPER8_DEVICE_ADDRESS_A1A0_00 0x70
149#define STEPPER8_DEVICE_ADDRESS_A1A0_01 0x71
150#define STEPPER8_DEVICE_ADDRESS_A1A0_10 0x72
151#define STEPPER8_DEVICE_ADDRESS_A1A0_11 0x73
152
161#define STEPPER8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
162#define STEPPER8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
163
164 // stepper8_set
165
180#define STEPPER8_MAP_MIKROBUS( cfg, mikrobus ) \
181 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
182 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
183 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
184 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
185 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
186 cfg.md1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
187 cfg.md3 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
188 cfg.md0 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
189 cfg.md2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
190 cfg.err = MIKROBUS( mikrobus, MIKROBUS_INT )
191
192 // stepper8_map
193 // stepper8
194
199typedef struct stepper8_s
200{
201 digital_out_t md0;
202 digital_out_t md1;
203 digital_out_t md2;
204 digital_out_t md3;
206 digital_in_t err;
208 i2c_master_t i2c;
209 spi_master_t spi;
213 uint8_t dir;
216
221typedef struct
222{
223 pin_name_t scl;
224 pin_name_t sda;
225 pin_name_t miso;
226 pin_name_t mosi;
227 pin_name_t sck;
228 pin_name_t md0;
229 pin_name_t md1;
230 pin_name_t md2;
231 pin_name_t md3;
232 pin_name_t err;
234 uint32_t i2c_speed;
235 uint8_t i2c_address;
237 uint32_t spi_speed;
238 spi_master_mode_t spi_mode;
241
246typedef enum
247{
249 STEPPER8_ERROR = -1
250
252
269
284
298
310err_t stepper8_write_spi ( stepper8_t *ctx, uint32_t data_in );
311
325err_t stepper8_pca_write_reg ( stepper8_t *ctx, uint8_t reg, uint8_t data_in );
326
339err_t stepper8_pca_read_reg ( stepper8_t *ctx, uint8_t reg, uint8_t *data_out );
340
352
364
376
388
400
412
423void stepper8_set_md0_pin ( stepper8_t *ctx, uint8_t state );
424
435void stepper8_set_md1_pin ( stepper8_t *ctx, uint8_t state );
436
447void stepper8_set_md2_pin ( stepper8_t *ctx, uint8_t state );
448
459void stepper8_set_md3_pin ( stepper8_t *ctx, uint8_t state );
460
470
481void stepper8_set_direction ( stepper8_t *ctx, uint8_t dir );
482
493void stepper8_set_rst_pin ( stepper8_t *ctx, uint8_t state );
494
505void stepper8_set_step_pin ( stepper8_t *ctx, uint8_t state );
506
526err_t stepper8_set_step_mode ( stepper8_t *ctx, uint8_t mode );
527
545err_t stepper8_drive_motor ( stepper8_t *ctx, uint32_t steps, uint8_t speed );
546
547#ifdef __cplusplus
548}
549#endif
550#endif // STEPPER8_H
551
552 // stepper8
553
554// ------------------------------------------------------------------------ END
err_t stepper8_pca_write_reg(stepper8_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 8 pca write reg function.
uint8_t stepper8_get_err_pin(stepper8_t *ctx)
Stepper 8 get ERR pin function.
err_t stepper8_select_spi(stepper8_t *ctx)
Stepper 8 select SPI function.
void stepper8_cfg_setup(stepper8_cfg_t *cfg)
Stepper 8 configuration object setup function.
void stepper8_set_md2_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set MD2 pin function.
err_t stepper8_pca_read_reg(stepper8_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 8 pca read reg function.
void stepper8_set_md0_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set MD0 pin function.
void stepper8_set_direction(stepper8_t *ctx, uint8_t dir)
Stepper 8 set direction function.
err_t stepper8_set_step_mode(stepper8_t *ctx, uint8_t mode)
Stepper 8 set step mode function.
void stepper8_set_rst_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set rst pin function.
void stepper8_set_step_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set step pin function.
err_t stepper8_enable_device(stepper8_t *ctx)
Stepper 8 enable device function.
err_t stepper8_enable_standby(stepper8_t *ctx)
Stepper 8 enable standby function.
err_t stepper8_init(stepper8_t *ctx, stepper8_cfg_t *cfg)
Stepper 8 initialization function.
err_t stepper8_disable_standby(stepper8_t *ctx)
Stepper 8 disable standby function.
void stepper8_set_md1_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set MD1 pin function.
err_t stepper8_disable_device(stepper8_t *ctx)
Stepper 8 disable device function.
void stepper8_set_md3_pin(stepper8_t *ctx, uint8_t state)
Stepper 8 set MD3 pin function.
err_t stepper8_select_gpio(stepper8_t *ctx)
Stepper 8 select GPIO function.
err_t stepper8_drive_motor(stepper8_t *ctx, uint32_t steps, uint8_t speed)
Stepper 8 driver motor function.
err_t stepper8_default_cfg(stepper8_t *ctx)
Stepper 8 default configuration function.
err_t stepper8_write_spi(stepper8_t *ctx, uint32_t data_in)
Stepper 8 write spi function.
This file contains SPI specific macros, functions, etc.
stepper8_return_value_t
Stepper 8 Click return value data.
Definition stepper8.h:247
@ STEPPER8_OK
Definition stepper8.h:248
@ STEPPER8_ERROR
Definition stepper8.h:249
struct stepper8_s stepper8_t
Stepper 8 Click context object.
Stepper 8 Click configuration object.
Definition stepper8.h:222
pin_name_t md2
Definition stepper8.h:230
uint32_t i2c_speed
Definition stepper8.h:234
pin_name_t md1
Definition stepper8.h:229
pin_name_t sck
Definition stepper8.h:227
pin_name_t err
Definition stepper8.h:232
pin_name_t md3
Definition stepper8.h:231
spi_master_mode_t spi_mode
Definition stepper8.h:238
pin_name_t md0
Definition stepper8.h:228
pin_name_t mosi
Definition stepper8.h:226
uint32_t spi_speed
Definition stepper8.h:237
pin_name_t scl
Definition stepper8.h:223
pin_name_t miso
Definition stepper8.h:225
pin_name_t sda
Definition stepper8.h:224
uint8_t i2c_address
Definition stepper8.h:235
Stepper 8 Click context object.
Definition stepper8.h:200
digital_out_t md0
Definition stepper8.h:201
spi_master_t spi
Definition stepper8.h:209
digital_out_t md3
Definition stepper8.h:204
uint8_t dir
Definition stepper8.h:213
i2c_master_t i2c
Definition stepper8.h:208
uint8_t slave_address
Definition stepper8.h:211
digital_in_t err
Definition stepper8.h:206
digital_out_t md1
Definition stepper8.h:202
digital_out_t md2
Definition stepper8.h:203