stepper4  2.1.0.0
stepper4.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 STEPPER4_H
29 #define STEPPER4_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 STEPPER4_DIR_CW 0
73 #define STEPPER4_DIR_CCW 1
74 
79 #define STEPPER4_PIN_LOW_LEVEL 0
80 #define STEPPER4_PIN_HIGH_LEVEL 1
81 
86 #define STEPPER4_SPEED_VERY_SLOW 0
87 #define STEPPER4_SPEED_SLOW 1
88 #define STEPPER4_SPEED_MEDIUM 2
89 #define STEPPER4_SPEED_FAST 3
90 #define STEPPER4_SPEED_VERY_FAST 4
91  // stepper4_set
93 
108 #define STEPPER4_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
111  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
112  cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
113  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
114  // stepper4_map // stepper4
117 
122 typedef struct
123 {
124  digital_out_t dir;
125  digital_out_t rst;
126  digital_out_t en;
127  digital_out_t step;
129  digital_in_t int_pin;
131 } stepper4_t;
132 
137 typedef struct
138 {
139  pin_name_t dir;
140  pin_name_t rst;
141  pin_name_t en;
142  pin_name_t step;
143  pin_name_t int_pin;
146 
151 typedef enum
152 {
154  STEPPER4_ERROR = -1
155 
157 
174 
189 
201 
217 void stepper4_drive_motor ( stepper4_t *ctx, uint32_t steps, uint8_t speed );
218 
228 
238 
249 void stepper4_set_direction ( stepper4_t *ctx, uint8_t dir );
250 
260 
270 
280 
291 void stepper4_set_step_pin ( stepper4_t *ctx, uint8_t state );
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 #endif // STEPPER4_H
297  // stepper4
299 
300 // ------------------------------------------------------------------------ END
stepper4_cfg_t::rst
pin_name_t rst
Definition: stepper4.h:140
stepper4_enable_device
void stepper4_enable_device(stepper4_t *ctx)
Stepper 4 enable device function.
stepper4_cfg_t
Stepper 4 Click configuration object.
Definition: stepper4.h:138
stepper4_get_int_pin
uint8_t stepper4_get_int_pin(stepper4_t *ctx)
Stepper 4 get int pin function.
stepper4_t::en
digital_out_t en
Definition: stepper4.h:126
stepper4_default_cfg
void stepper4_default_cfg(stepper4_t *ctx)
Stepper 4 default configuration function.
stepper4_t
Stepper 4 Click context object.
Definition: stepper4.h:123
stepper4_return_value_t
stepper4_return_value_t
Stepper 4 Click return value data.
Definition: stepper4.h:152
stepper4_init
err_t stepper4_init(stepper4_t *ctx, stepper4_cfg_t *cfg)
Stepper 4 initialization function.
stepper4_drive_motor
void stepper4_drive_motor(stepper4_t *ctx, uint32_t steps, uint8_t speed)
Stepper 4 drive motor function.
stepper4_t::step
digital_out_t step
Definition: stepper4.h:127
stepper4_cfg_t::dir
pin_name_t dir
Definition: stepper4.h:139
stepper4_cfg_setup
void stepper4_cfg_setup(stepper4_cfg_t *cfg)
Stepper 4 configuration object setup function.
stepper4_cfg_t::int_pin
pin_name_t int_pin
Definition: stepper4.h:143
stepper4_set_direction
void stepper4_set_direction(stepper4_t *ctx, uint8_t dir)
Stepper 4 set direction function.
stepper4_disable_device
void stepper4_disable_device(stepper4_t *ctx)
Stepper 4 disable device function.
STEPPER4_OK
@ STEPPER4_OK
Definition: stepper4.h:153
stepper4_cfg_t::step
pin_name_t step
Definition: stepper4.h:142
stepper4_t::rst
digital_out_t rst
Definition: stepper4.h:125
stepper4_switch_direction
void stepper4_switch_direction(stepper4_t *ctx)
Stepper 4 switch direction function.
stepper4_set_step_pin
void stepper4_set_step_pin(stepper4_t *ctx, uint8_t state)
Stepper 4 set step pin function.
STEPPER4_ERROR
@ STEPPER4_ERROR
Definition: stepper4.h:154
stepper4_reset_device
void stepper4_reset_device(stepper4_t *ctx)
Stepper 4 reset device function.
stepper4_t::dir
digital_out_t dir
Definition: stepper4.h:124
stepper4_t::int_pin
digital_in_t int_pin
Definition: stepper4.h:129
stepper4_cfg_t::en
pin_name_t en
Definition: stepper4.h:141