stepper2  2.1.0.0
stepper2.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 STEPPER2_H
29 #define STEPPER2_H
30 
31 #ifdef __cplusplus
32 extern "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 
72 #define STEPPER2_PIN_STATE_LOW 0
73 #define STEPPER2_PIN_STATE_HIGH 1
74 
79 #define STEPPER2_DIR_CCW 0
80 #define STEPPER2_DIR_CW 1
81 
86 #define STEPPER2_MODE_FULL_STEP 0
87 #define STEPPER2_MODE_HALF_STEP 1
88 #define STEPPER2_MODE_QUARTER_STEP 2
89 #define STEPPER2_MODE_1_OVER_8_STEP 3
90 
95 #define STEPPER2_MICROSTEP_NUM_PER_STEP 32
96 
101 #define STEPPER2_SPEED_VERY_SLOW 0
102 #define STEPPER2_SPEED_SLOW 1
103 #define STEPPER2_SPEED_MEDIUM 2
104 #define STEPPER2_SPEED_FAST 3
105 #define STEPPER2_SPEED_VERY_FAST 4
106  // stepper2_set
108 
123 #define STEPPER2_MAP_MIKROBUS( cfg, mikrobus ) \
124  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
125  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
127  cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
128  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_INT )
129  // stepper2_map // stepper2
132 
137 typedef struct
138 {
139  digital_out_t en;
140  digital_out_t rst;
141  digital_out_t slp;
142  digital_out_t step;
143  digital_out_t dir;
145 } stepper2_t;
146 
151 typedef struct
152 {
153  pin_name_t en;
154  pin_name_t rst;
155  pin_name_t slp;
156  pin_name_t step;
157  pin_name_t dir;
160 
165 typedef enum
166 {
168  STEPPER2_ERROR = -1
169 
171 
188 
203 
215 
231 void stepper2_drive_motor ( stepper2_t *ctx, uint32_t steps, uint8_t speed );
232 
242 
252 
262 
272 
282 
292 
303 void stepper2_set_direction ( stepper2_t *ctx, uint8_t dir );
304 
314 
325 void stepper2_set_step_pin ( stepper2_t *ctx, uint8_t state );
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 #endif // STEPPER2_H
331  // stepper2
333 
334 // ------------------------------------------------------------------------ END
stepper2_default_cfg
void stepper2_default_cfg(stepper2_t *ctx)
Stepper 2 default configuration function.
stepper2_cfg_t::slp
pin_name_t slp
Definition: stepper2.h:155
stepper2_cfg_t::step
pin_name_t step
Definition: stepper2.h:156
stepper2_set_direction
void stepper2_set_direction(stepper2_t *ctx, uint8_t dir)
Stepper 2 set direction function.
stepper2_cfg_t
Stepper 2 Click configuration object.
Definition: stepper2.h:152
stepper2_disable_reset
void stepper2_disable_reset(stepper2_t *ctx)
Stepper 2 disable reset function.
stepper2_disable_device
void stepper2_disable_device(stepper2_t *ctx)
Stepper 2 disable device function.
stepper2_set_step_pin
void stepper2_set_step_pin(stepper2_t *ctx, uint8_t state)
Stepper 2 set step pin function.
stepper2_init
err_t stepper2_init(stepper2_t *ctx, stepper2_cfg_t *cfg)
Stepper 2 initialization function.
stepper2_enable_reset
void stepper2_enable_reset(stepper2_t *ctx)
Stepper 2 enable reset function.
stepper2_t::rst
digital_out_t rst
Definition: stepper2.h:140
stepper2_cfg_t::en
pin_name_t en
Definition: stepper2.h:153
stepper2_t::dir
digital_out_t dir
Definition: stepper2.h:143
stepper2_enable_sleep
void stepper2_enable_sleep(stepper2_t *ctx)
Stepper 2 enable sleep function.
stepper2_t::slp
digital_out_t slp
Definition: stepper2.h:141
stepper2_t
Stepper 2 Click context object.
Definition: stepper2.h:138
stepper2_return_value_t
stepper2_return_value_t
Stepper 2 Click return value data.
Definition: stepper2.h:166
stepper2_cfg_setup
void stepper2_cfg_setup(stepper2_cfg_t *cfg)
Stepper 2 configuration object setup function.
stepper2_enable_device
void stepper2_enable_device(stepper2_t *ctx)
Stepper 2 enable device function.
STEPPER2_ERROR
@ STEPPER2_ERROR
Definition: stepper2.h:168
stepper2_switch_direction
void stepper2_switch_direction(stepper2_t *ctx)
Stepper 2 switch direction function.
stepper2_cfg_t::rst
pin_name_t rst
Definition: stepper2.h:154
stepper2_t::en
digital_out_t en
Definition: stepper2.h:139
stepper2_drive_motor
void stepper2_drive_motor(stepper2_t *ctx, uint32_t steps, uint8_t speed)
Stepper 2 driver motor function.
stepper2_disable_sleep
void stepper2_disable_sleep(stepper2_t *ctx)
Stepper 2 disable sleep function.
stepper2_t::step
digital_out_t step
Definition: stepper2.h:142
STEPPER2_OK
@ STEPPER2_OK
Definition: stepper2.h:167
stepper2_cfg_t::dir
pin_name_t dir
Definition: stepper2.h:157