stepper6 2.1.0.0
stepper6.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 STEPPER6_H
29#define STEPPER6_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 STEPPER6_PCA9538A_REG_INPUT 0x00
76#define STEPPER6_PCA9538A_REG_OUTPUT 0x01
77#define STEPPER6_PCA9538A_REG_POLARITY 0x02
78#define STEPPER6_PCA9538A_REG_CONFIG 0x03
79
80 // stepper6_reg
81
96#define STEPPER6_PIN_TRQ 0x01
97#define STEPPER6_PIN_M1 0x02
98#define STEPPER6_PIN_M0 0x04
99#define STEPPER6_PIN_SLEEP 0x08
100#define STEPPER6_PIN_FAULT 0x10
101
106#define STEPPER6_PCA9538A_DEFAULT_CONFIG 0xF0
107
112#define STEPPER6_DIR_CW 0
113#define STEPPER6_DIR_CCW 1
114
119#define STEPPER6_PIN_STATE_LOW 0
120#define STEPPER6_PIN_STATE_HIGH 1
121#define STEPPER6_PIN_STATE_OPEN 2
122
127#define STEPPER6_SPEED_VERY_SLOW 0
128#define STEPPER6_SPEED_SLOW 1
129#define STEPPER6_SPEED_MEDIUM 2
130#define STEPPER6_SPEED_FAST 3
131#define STEPPER6_SPEED_VERY_FAST 4
132
137#define STEPPER6_MODE_FULL_STEP 0
138#define STEPPER6_MODE_1_OVER_16 1
139#define STEPPER6_MODE_HALF_STEP 2
140#define STEPPER6_MODE_QUARTER_STEP 3
141#define STEPPER6_MODE_1_OVER_8 4
142#define STEPPER6_MODE_HALF_NON_CIRC_STEP 5
143
148#define STEPPER6_DAC_DEFAULT_CONFIG 0x7FFFu
149
155#define STEPPER6_DEVICE_ADDRESS_A1A0_00 0x70
156#define STEPPER6_DEVICE_ADDRESS_A1A0_01 0x71
157#define STEPPER6_DEVICE_ADDRESS_A1A0_10 0x72
158#define STEPPER6_DEVICE_ADDRESS_A1A0_11 0x73
159
168#define STEPPER6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
169#define STEPPER6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
170
171 // stepper6_set
172
187#define STEPPER6_MAP_MIKROBUS( cfg, mikrobus ) \
188 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
189 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
190 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
191 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
192 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
193 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
194 cfg.step = MIKROBUS( mikrobus, MIKROBUS_AN ); \
195 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
196 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
197 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_INT )
198
199 // stepper6_map
200 // stepper6
201
206typedef struct stepper6_s
207{
208 digital_out_t step;
209 digital_out_t en;
210 digital_out_t dir;
211 digital_out_t rst;
213 i2c_master_t i2c;
214 spi_master_t spi;
217 pin_name_t chip_select;
220
225typedef struct
226{
227 pin_name_t scl;
228 pin_name_t sda;
229 pin_name_t miso;
230 pin_name_t mosi;
231 pin_name_t sck;
232 pin_name_t cs;
233 pin_name_t step;
234 pin_name_t en;
235 pin_name_t dir;
236 pin_name_t rst;
238 uint32_t i2c_speed;
239 uint8_t i2c_address;
241 uint32_t spi_speed;
242 spi_master_mode_t spi_mode;
243 spi_master_chip_select_polarity_t cs_polarity;
246
251typedef enum
252{
254 STEPPER6_ERROR = -1
255
257
274
289
303
316err_t stepper6_set_dac ( stepper6_t *ctx, uint16_t dac_cmd );
317
331err_t stepper6_pca_write_reg ( stepper6_t *ctx, uint8_t reg, uint8_t data_in );
332
345err_t stepper6_pca_read_reg ( stepper6_t *ctx, uint8_t reg, uint8_t *data_out );
346
360err_t stepper6_get_trq_pin ( stepper6_t *ctx, uint8_t *state );
361
375err_t stepper6_set_trq_pin ( stepper6_t *ctx, uint8_t state );
376
389err_t stepper6_get_m1_pin ( stepper6_t *ctx, uint8_t *state );
390
403err_t stepper6_set_m1_pin ( stepper6_t *ctx, uint8_t state );
404
418err_t stepper6_get_m0_pin ( stepper6_t *ctx, uint8_t *state );
419
433err_t stepper6_set_m0_pin ( stepper6_t *ctx, uint8_t state );
434
447err_t stepper6_get_sleep_pin ( stepper6_t *ctx, uint8_t *state );
448
461err_t stepper6_set_sleep_pin ( stepper6_t *ctx, uint8_t state );
462
475err_t stepper6_get_fault_pin ( stepper6_t *ctx, uint8_t *state );
476
486
496
507void stepper6_set_direction ( stepper6_t *ctx, uint8_t dir );
508
518
528
539void stepper6_set_rst_pin ( stepper6_t *ctx, uint8_t state );
540
551void stepper6_set_step_pin ( stepper6_t *ctx, uint8_t state );
552
570err_t stepper6_get_step_mode ( stepper6_t *ctx, uint8_t *mode );
571
589err_t stepper6_set_step_mode ( stepper6_t *ctx, uint8_t mode );
590
606void stepper6_drive_motor ( stepper6_t *ctx, uint32_t steps, uint8_t speed );
607
608#ifdef __cplusplus
609}
610#endif
611#endif // STEPPER6_H
612
613 // stepper6
614
615// ------------------------------------------------------------------------ END
void stepper6_reset_pca(stepper6_t *ctx)
Stepper 6 reset device function.
err_t stepper6_set_step_mode(stepper6_t *ctx, uint8_t mode)
Stepper 6 set step mode function.
err_t stepper6_set_sleep_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set sleep pin function.
err_t stepper6_get_trq_pin(stepper6_t *ctx, uint8_t *state)
Stepper 6 get trq pin function.
err_t stepper6_set_trq_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set trq pin function.
err_t stepper6_get_m0_pin(stepper6_t *ctx, uint8_t *state)
Stepper 6 get M0 pin function.
err_t stepper6_set_dac(stepper6_t *ctx, uint16_t dac_cmd)
Stepper 6 set dac function.
err_t stepper6_set_m1_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set M1 pin function.
err_t stepper6_get_fault_pin(stepper6_t *ctx, uint8_t *state)
Stepper 6 get fault pin function.
err_t stepper6_pca_write_reg(stepper6_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 6 pca write reg function.
err_t stepper6_get_sleep_pin(stepper6_t *ctx, uint8_t *state)
Stepper 6 get sleep pin function.
err_t stepper6_init(stepper6_t *ctx, stepper6_cfg_t *cfg)
Stepper 6 initialization function.
void stepper6_cfg_setup(stepper6_cfg_t *cfg)
Stepper 6 configuration object setup function.
void stepper6_switch_direction(stepper6_t *ctx)
Stepper 6 switch direction function.
void stepper6_set_step_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set step pin function.
err_t stepper6_get_m1_pin(stepper6_t *ctx, uint8_t *state)
Stepper 6 get M1 pin function.
err_t stepper6_default_cfg(stepper6_t *ctx)
Stepper 6 default configuration function.
void stepper6_enable_device(stepper6_t *ctx)
Stepper 6 enable device function.
err_t stepper6_set_m0_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set M0 pin function.
void stepper6_disable_device(stepper6_t *ctx)
Stepper 6 disable device function.
void stepper6_set_direction(stepper6_t *ctx, uint8_t dir)
Stepper 6 set direction function.
err_t stepper6_pca_read_reg(stepper6_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 6 pca read reg function.
err_t stepper6_get_step_mode(stepper6_t *ctx, uint8_t *mode)
Stepper 6 get step mode function.
void stepper6_drive_motor(stepper6_t *ctx, uint32_t steps, uint8_t speed)
Stepper 6 driver motor function.
void stepper6_set_rst_pin(stepper6_t *ctx, uint8_t state)
Stepper 6 set rst pin function.
This file contains SPI specific macros, functions, etc.
struct stepper6_s stepper6_t
Stepper 6 Click context object.
stepper6_return_value_t
Stepper 6 Click return value data.
Definition stepper6.h:252
@ STEPPER6_ERROR
Definition stepper6.h:254
@ STEPPER6_OK
Definition stepper6.h:253
Stepper 6 Click configuration object.
Definition stepper6.h:226
pin_name_t step
Definition stepper6.h:233
uint32_t i2c_speed
Definition stepper6.h:238
spi_master_chip_select_polarity_t cs_polarity
Definition stepper6.h:243
pin_name_t sck
Definition stepper6.h:231
spi_master_mode_t spi_mode
Definition stepper6.h:242
pin_name_t mosi
Definition stepper6.h:230
uint32_t spi_speed
Definition stepper6.h:241
pin_name_t dir
Definition stepper6.h:235
pin_name_t scl
Definition stepper6.h:227
pin_name_t en
Definition stepper6.h:234
pin_name_t miso
Definition stepper6.h:229
pin_name_t sda
Definition stepper6.h:228
pin_name_t rst
Definition stepper6.h:236
pin_name_t cs
Definition stepper6.h:232
uint8_t i2c_address
Definition stepper6.h:239
Stepper 6 Click context object.
Definition stepper6.h:207
spi_master_t spi
Definition stepper6.h:214
digital_out_t step
Definition stepper6.h:208
i2c_master_t i2c
Definition stepper6.h:213
digital_out_t en
Definition stepper6.h:209
digital_out_t rst
Definition stepper6.h:211
uint8_t slave_address
Definition stepper6.h:216
pin_name_t chip_select
Definition stepper6.h:217
digital_out_t dir
Definition stepper6.h:210