stepper9 2.1.0.0
stepper9.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 STEPPER9_H
29#define STEPPER9_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 STEPPER9_REG_INPUT 0x00
74#define STEPPER9_REG_OUTPUT 0x01
75#define STEPPER9_REG_POLARITY 0x02
76#define STEPPER9_REG_CONFIG 0x03
77
78 // stepper9_reg
79
94#define STEPPER9_DMODE0_PIN 0x01
95#define STEPPER9_DMODE1_PIN 0x02
96#define STEPPER9_DMODE2_PIN 0x04
97#define STEPPER9_SLEEP_X_PIN 0x08
98#define STEPPER9_LO_PIN 0x10
99#define STEPPER9_MO_PIN 0x20
100
105#define STEPPER9_DEFAULT_CONFIG 0xF0
106
111#define STEPPER9_DIR_CCW 0
112#define STEPPER9_DIR_CW 1
113
118#define STEPPER9_PIN_LOW_LEVEL 0
119#define STEPPER9_PIN_HIGH_LEVEL 1
120
125#define STEPPER9_MODE_FULL_STEP 0x00
126#define STEPPER9_MODE_HALF_STEP 0x01
127#define STEPPER9_MODE_QUARTER_STEP 0x02
128#define STEPPER9_MODE_1_OVER_8 0x03
129#define STEPPER9_MODE_1_OVER_16 0x04
130#define STEPPER9_MODE_1_OVER_32 0x05
131#define STEPPER9_MODE_MASK 0x07
132
137#define STEPPER9_SPEED_VERY_SLOW 0
138#define STEPPER9_SPEED_SLOW 1
139#define STEPPER9_SPEED_MEDIUM 2
140#define STEPPER9_SPEED_FAST 3
141#define STEPPER9_SPEED_VERY_FAST 4
142
148#define STEPPER9_DEVICE_ADDRESS_A1A0_00 0x70
149#define STEPPER9_DEVICE_ADDRESS_A1A0_01 0x71
150#define STEPPER9_DEVICE_ADDRESS_A1A0_10 0x72
151#define STEPPER9_DEVICE_ADDRESS_A1A0_11 0x73
152
153 // stepper9_set
154
169#define STEPPER9_MAP_MIKROBUS( cfg, mikrobus ) \
170 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
171 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
172 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
173 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
174 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
175 cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
176 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
177
178 // stepper9_map
179 // stepper9
180
185typedef struct
186{
187 // Output pins
188 digital_out_t en;
189 digital_out_t dir;
190 digital_out_t rst;
191 digital_out_t clk;
193 // Input pins
194 digital_in_t int_pin;
196 // Modules
197 i2c_master_t i2c;
199 // I2C slave address
202} stepper9_t;
203
208typedef struct
209{
210 pin_name_t scl;
211 pin_name_t sda;
213 pin_name_t en;
214 pin_name_t dir;
215 pin_name_t rst;
216 pin_name_t clk;
217 pin_name_t int_pin;
219 uint32_t i2c_speed;
220 uint8_t i2c_address;
223
228typedef enum
229{
231 STEPPER9_ERROR = -1
232
234
251
266
280
294err_t stepper9_write_register ( stepper9_t *ctx, uint8_t reg, uint8_t data_in );
295
308err_t stepper9_read_register ( stepper9_t *ctx, uint8_t reg, uint8_t *data_out );
309
321err_t stepper9_get_step_mode ( stepper9_t *ctx, uint8_t *mode );
322
334err_t stepper9_set_step_mode ( stepper9_t *ctx, uint8_t mode );
335
348err_t stepper9_get_sleep_x_pin ( stepper9_t *ctx, uint8_t *state );
349
362err_t stepper9_set_sleep_x_pin ( stepper9_t *ctx, uint8_t state );
363
376err_t stepper9_get_lo_pin ( stepper9_t *ctx, uint8_t *state );
377
390err_t stepper9_get_mo_pin ( stepper9_t *ctx, uint8_t *state );
391
407void stepper9_drive_motor ( stepper9_t *ctx, uint32_t steps, uint8_t speed );
408
418
428
439void stepper9_set_direction ( stepper9_t *ctx, uint8_t dir );
440
450
460
470
481void stepper9_set_clk_pin ( stepper9_t *ctx, uint8_t state );
482
483#ifdef __cplusplus
484}
485#endif
486#endif // STEPPER9_H
487
488 // stepper9
489
490// ------------------------------------------------------------------------ END
void stepper9_disable_device(stepper9_t *ctx)
Stepper 9 disable device function.
err_t stepper9_get_sleep_x_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get sleep x pin function.
err_t stepper9_write_register(stepper9_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 9 write register function.
uint8_t stepper9_get_int_pin(stepper9_t *ctx)
Stepper 9 get int pin function.
void stepper9_set_clk_pin(stepper9_t *ctx, uint8_t state)
Stepper 9 set clk pin function.
void stepper9_drive_motor(stepper9_t *ctx, uint32_t steps, uint8_t speed)
Stepper 9 driver motor function.
void stepper9_enable_device(stepper9_t *ctx)
Stepper 9 enable device function.
err_t stepper9_get_step_mode(stepper9_t *ctx, uint8_t *mode)
Stepper 9 get step mode function.
err_t stepper9_set_step_mode(stepper9_t *ctx, uint8_t mode)
Stepper 9 set step mode function.
err_t stepper9_get_lo_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get lo pin function.
void stepper9_set_direction(stepper9_t *ctx, uint8_t dir)
Stepper 9 set direction function.
err_t stepper9_read_register(stepper9_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 9 read register function.
void stepper9_switch_direction(stepper9_t *ctx)
Stepper 9 switch direction function.
err_t stepper9_get_mo_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get mo pin function.
err_t stepper9_init(stepper9_t *ctx, stepper9_cfg_t *cfg)
Stepper 9 initialization function.
void stepper9_cfg_setup(stepper9_cfg_t *cfg)
Stepper 9 configuration object setup function.
err_t stepper9_default_cfg(stepper9_t *ctx)
Stepper 9 default configuration function.
err_t stepper9_set_sleep_x_pin(stepper9_t *ctx, uint8_t state)
Stepper 9 set sleep x pin function.
void stepper9_reset_device(stepper9_t *ctx)
Stepper 9 reset device function.
stepper9_return_value_t
Stepper 9 Click return value data.
Definition stepper9.h:229
@ STEPPER9_OK
Definition stepper9.h:230
@ STEPPER9_ERROR
Definition stepper9.h:231
Stepper 9 Click configuration object.
Definition stepper9.h:209
pin_name_t clk
Definition stepper9.h:216
uint32_t i2c_speed
Definition stepper9.h:219
pin_name_t dir
Definition stepper9.h:214
pin_name_t scl
Definition stepper9.h:210
pin_name_t en
Definition stepper9.h:213
pin_name_t int_pin
Definition stepper9.h:217
pin_name_t sda
Definition stepper9.h:211
pin_name_t rst
Definition stepper9.h:215
uint8_t i2c_address
Definition stepper9.h:220
Stepper 9 Click context object.
Definition stepper9.h:186
digital_in_t int_pin
Definition stepper9.h:194
i2c_master_t i2c
Definition stepper9.h:197
digital_out_t clk
Definition stepper9.h:191
digital_out_t en
Definition stepper9.h:188
digital_out_t rst
Definition stepper9.h:190
uint8_t slave_address
Definition stepper9.h:200
digital_out_t dir
Definition stepper9.h:189