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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define STEPPER9_REG_INPUT 0x00
60 #define STEPPER9_REG_OUTPUT 0x01
61 #define STEPPER9_REG_POLARITY 0x02
62 #define STEPPER9_REG_CONFIG 0x03
63  // stepper9_reg
65 
80 #define STEPPER9_DMODE0_PIN 0x01
81 #define STEPPER9_DMODE1_PIN 0x02
82 #define STEPPER9_DMODE2_PIN 0x04
83 #define STEPPER9_SLEEP_X_PIN 0x08
84 #define STEPPER9_LO_PIN 0x10
85 #define STEPPER9_MO_PIN 0x20
86 
91 #define STEPPER9_DEFAULT_CONFIG 0xF0
92 
97 #define STEPPER9_DIR_CCW 0
98 #define STEPPER9_DIR_CW 1
99 
104 #define STEPPER9_PIN_LOW_LEVEL 0
105 #define STEPPER9_PIN_HIGH_LEVEL 1
106 
111 #define STEPPER9_MODE_FULL_STEP 0x00
112 #define STEPPER9_MODE_HALF_STEP 0x01
113 #define STEPPER9_MODE_QUARTER_STEP 0x02
114 #define STEPPER9_MODE_1_OVER_8 0x03
115 #define STEPPER9_MODE_1_OVER_16 0x04
116 #define STEPPER9_MODE_1_OVER_32 0x05
117 #define STEPPER9_MODE_MASK 0x07
118 
123 #define STEPPER9_SPEED_VERY_SLOW 0
124 #define STEPPER9_SPEED_SLOW 1
125 #define STEPPER9_SPEED_MEDIUM 2
126 #define STEPPER9_SPEED_FAST 3
127 #define STEPPER9_SPEED_VERY_FAST 4
128 
134 #define STEPPER9_DEVICE_ADDRESS_A1A0_00 0x70
135 #define STEPPER9_DEVICE_ADDRESS_A1A0_01 0x71
136 #define STEPPER9_DEVICE_ADDRESS_A1A0_10 0x72
137 #define STEPPER9_DEVICE_ADDRESS_A1A0_11 0x73
138  // stepper9_set
140 
155 #define STEPPER9_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
158  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
159  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
160  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
161  cfg.clk = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
162  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
163  // stepper9_map // stepper9
166 
171 typedef struct
172 {
173  // Output pins
174  digital_out_t en;
175  digital_out_t dir;
176  digital_out_t rst;
177  digital_out_t clk;
179  // Input pins
180  digital_in_t int_pin;
182  // Modules
183  i2c_master_t i2c;
185  // I2C slave address
186  uint8_t slave_address;
188 } stepper9_t;
189 
194 typedef struct
195 {
196  pin_name_t scl;
197  pin_name_t sda;
199  pin_name_t en;
200  pin_name_t dir;
201  pin_name_t rst;
202  pin_name_t clk;
203  pin_name_t int_pin;
205  uint32_t i2c_speed;
206  uint8_t i2c_address;
209 
214 typedef enum
215 {
217  STEPPER9_ERROR = -1
218 
220 
237 
252 
266 
280 err_t stepper9_write_register ( stepper9_t *ctx, uint8_t reg, uint8_t data_in );
281 
294 err_t stepper9_read_register ( stepper9_t *ctx, uint8_t reg, uint8_t *data_out );
295 
307 err_t stepper9_get_step_mode ( stepper9_t *ctx, uint8_t *mode );
308 
320 err_t stepper9_set_step_mode ( stepper9_t *ctx, uint8_t mode );
321 
334 err_t stepper9_get_sleep_x_pin ( stepper9_t *ctx, uint8_t *state );
335 
348 err_t stepper9_set_sleep_x_pin ( stepper9_t *ctx, uint8_t state );
349 
362 err_t stepper9_get_lo_pin ( stepper9_t *ctx, uint8_t *state );
363 
376 err_t stepper9_get_mo_pin ( stepper9_t *ctx, uint8_t *state );
377 
393 void stepper9_drive_motor ( stepper9_t *ctx, uint32_t steps, uint8_t speed );
394 
404 
414 
425 void stepper9_set_direction ( stepper9_t *ctx, uint8_t dir );
426 
436 
446 
456 
467 void stepper9_set_clk_pin ( stepper9_t *ctx, uint8_t state );
468 
469 #ifdef __cplusplus
470 }
471 #endif
472 #endif // STEPPER9_H
473  // stepper9
475 
476 // ------------------------------------------------------------------------ END
stepper9_cfg_t::dir
pin_name_t dir
Definition: stepper9.h:200
stepper9_t
Stepper 9 Click context object.
Definition: stepper9.h:172
stepper9_get_step_mode
err_t stepper9_get_step_mode(stepper9_t *ctx, uint8_t *mode)
Stepper 9 get step mode function.
stepper9_cfg_t::scl
pin_name_t scl
Definition: stepper9.h:196
stepper9_reset_device
void stepper9_reset_device(stepper9_t *ctx)
Stepper 9 reset device function.
stepper9_return_value_t
stepper9_return_value_t
Stepper 9 Click return value data.
Definition: stepper9.h:215
stepper9_cfg_t
Stepper 9 Click configuration object.
Definition: stepper9.h:195
stepper9_t::i2c
i2c_master_t i2c
Definition: stepper9.h:183
STEPPER9_OK
@ STEPPER9_OK
Definition: stepper9.h:216
stepper9_get_mo_pin
err_t stepper9_get_mo_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get mo pin function.
stepper9_read_register
err_t stepper9_read_register(stepper9_t *ctx, uint8_t reg, uint8_t *data_out)
Stepper 9 read register function.
stepper9_get_lo_pin
err_t stepper9_get_lo_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get lo pin function.
stepper9_set_step_mode
err_t stepper9_set_step_mode(stepper9_t *ctx, uint8_t mode)
Stepper 9 set step mode function.
stepper9_get_int_pin
uint8_t stepper9_get_int_pin(stepper9_t *ctx)
Stepper 9 get int pin function.
stepper9_write_register
err_t stepper9_write_register(stepper9_t *ctx, uint8_t reg, uint8_t data_in)
Stepper 9 write register function.
stepper9_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper9.h:203
stepper9_t::clk
digital_out_t clk
Definition: stepper9.h:177
stepper9_enable_device
void stepper9_enable_device(stepper9_t *ctx)
Stepper 9 enable device function.
stepper9_disable_device
void stepper9_disable_device(stepper9_t *ctx)
Stepper 9 disable device function.
stepper9_cfg_t::sda
pin_name_t sda
Definition: stepper9.h:197
stepper9_cfg_t::rst
pin_name_t rst
Definition: stepper9.h:201
stepper9_get_sleep_x_pin
err_t stepper9_get_sleep_x_pin(stepper9_t *ctx, uint8_t *state)
Stepper 9 get sleep x pin function.
stepper9_t::int_pin
digital_in_t int_pin
Definition: stepper9.h:180
stepper9_init
err_t stepper9_init(stepper9_t *ctx, stepper9_cfg_t *cfg)
Stepper 9 initialization function.
stepper9_cfg_setup
void stepper9_cfg_setup(stepper9_cfg_t *cfg)
Stepper 9 configuration object setup function.
stepper9_t::rst
digital_out_t rst
Definition: stepper9.h:176
stepper9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: stepper9.h:205
stepper9_default_cfg
err_t stepper9_default_cfg(stepper9_t *ctx)
Stepper 9 default configuration function.
stepper9_switch_direction
void stepper9_switch_direction(stepper9_t *ctx)
Stepper 9 switch direction function.
stepper9_set_direction
void stepper9_set_direction(stepper9_t *ctx, uint8_t dir)
Stepper 9 set direction function.
stepper9_set_sleep_x_pin
err_t stepper9_set_sleep_x_pin(stepper9_t *ctx, uint8_t state)
Stepper 9 set sleep x pin function.
stepper9_t::slave_address
uint8_t slave_address
Definition: stepper9.h:186
stepper9_t::dir
digital_out_t dir
Definition: stepper9.h:175
STEPPER9_ERROR
@ STEPPER9_ERROR
Definition: stepper9.h:217
stepper9_set_clk_pin
void stepper9_set_clk_pin(stepper9_t *ctx, uint8_t state)
Stepper 9 set clk pin function.
stepper9_cfg_t::clk
pin_name_t clk
Definition: stepper9.h:202
stepper9_drive_motor
void stepper9_drive_motor(stepper9_t *ctx, uint32_t steps, uint8_t speed)
Stepper 9 driver motor function.
stepper9_cfg_t::en
pin_name_t en
Definition: stepper9.h:199
stepper9_cfg_t::i2c_address
uint8_t i2c_address
Definition: stepper9.h:206
stepper9_t::en
digital_out_t en
Definition: stepper9.h:174