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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 
68 #define STEPPER2_PIN_STATE_LOW 0
69 #define STEPPER2_PIN_STATE_HIGH 1
70 
75 #define STEPPER2_DIR_CCW 0
76 #define STEPPER2_DIR_CW 1
77 
82 #define STEPPER2_MODE_FULL_STEP 0
83 #define STEPPER2_MODE_HALF_STEP 1
84 #define STEPPER2_MODE_QUARTER_STEP 2
85 #define STEPPER2_MODE_1_OVER_8_STEP 3
86 
91 #define STEPPER2_MICROSTEP_NUM_PER_STEP 32
92 
97 #define STEPPER2_SPEED_VERY_SLOW 0
98 #define STEPPER2_SPEED_SLOW 1
99 #define STEPPER2_SPEED_MEDIUM 2
100 #define STEPPER2_SPEED_FAST 3
101 #define STEPPER2_SPEED_VERY_FAST 4
102  // stepper2_set
104 
119 #define STEPPER2_MAP_MIKROBUS( cfg, mikrobus ) \
120  cfg.en = MIKROBUS( mikrobus, MIKROBUS_AN ); \
121  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
122  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
123  cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
124  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_INT )
125  // stepper2_map // stepper2
128 
133 typedef struct
134 {
135  digital_out_t en;
136  digital_out_t rst;
137  digital_out_t slp;
138  digital_out_t step;
139  digital_out_t dir;
141 } stepper2_t;
142 
147 typedef struct
148 {
149  pin_name_t en;
150  pin_name_t rst;
151  pin_name_t slp;
152  pin_name_t step;
153  pin_name_t dir;
156 
161 typedef enum
162 {
164  STEPPER2_ERROR = -1
165 
167 
184 
199 
211 
227 void stepper2_drive_motor ( stepper2_t *ctx, uint32_t steps, uint8_t speed );
228 
238 
248 
258 
268 
278 
288 
299 void stepper2_set_direction ( stepper2_t *ctx, uint8_t dir );
300 
310 
321 void stepper2_set_step_pin ( stepper2_t *ctx, uint8_t state );
322 
323 #ifdef __cplusplus
324 }
325 #endif
326 #endif // STEPPER2_H
327  // stepper2
329 
330 // ------------------------------------------------------------------------ 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:151
stepper2_cfg_t::step
pin_name_t step
Definition: stepper2.h:152
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:148
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:136
stepper2_cfg_t::en
pin_name_t en
Definition: stepper2.h:149
stepper2_t::dir
digital_out_t dir
Definition: stepper2.h:139
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:137
stepper2_t
Stepper 2 Click context object.
Definition: stepper2.h:134
stepper2_return_value_t
stepper2_return_value_t
Stepper 2 Click return value data.
Definition: stepper2.h:162
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:164
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:150
stepper2_t::en
digital_out_t en
Definition: stepper2.h:135
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:138
STEPPER2_OK
@ STEPPER2_OK
Definition: stepper2.h:163
stepper2_cfg_t::dir
pin_name_t dir
Definition: stepper2.h:153