stspin220  2.1.0.0
stspin220.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 STSPIN220_H
29 #define STSPIN220_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 STSPIN220_DIR_CW 0
69 #define STSPIN220_DIR_CCW 1
70 
75 #define STSPIN220_PIN_LOW_LEVEL 0
76 #define STSPIN220_PIN_HIGH_LEVEL 1
77 
82 #define STSPIN220_SPEED_VERY_SLOW 0
83 #define STSPIN220_SPEED_SLOW 1
84 #define STSPIN220_SPEED_MEDIUM 2
85 #define STSPIN220_SPEED_FAST 3
86 #define STSPIN220_SPEED_VERY_FAST 4
87  // stspin220_set
89 
104 #define STSPIN220_MAP_MIKROBUS( cfg, mikrobus ) \
105  cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
106  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
107  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
108  cfg.step = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
109  cfg.fault = MIKROBUS( mikrobus, MIKROBUS_INT )
110  // stspin220_map // stspin220
113 
118 typedef struct
119 {
120  digital_out_t dir;
121  digital_out_t rst;
122  digital_out_t en;
123  digital_out_t step;
125  digital_in_t fault;
127 } stspin220_t;
128 
133 typedef struct
134 {
135  pin_name_t dir;
136  pin_name_t rst;
137  pin_name_t en;
138  pin_name_t step;
139  pin_name_t fault;
142 
147 typedef enum
148 {
150  STSPIN220_ERROR = -1
151 
153 
170 
185 
197 
213 void stspin220_drive_motor ( stspin220_t *ctx, uint32_t steps, uint8_t speed );
214 
224 
234 
245 void stspin220_set_direction ( stspin220_t *ctx, uint8_t dir );
246 
256 
266 
277 void stspin220_set_rst_pin ( stspin220_t *ctx, uint8_t state );
278 
288 
299 void stspin220_set_step_pin ( stspin220_t *ctx, uint8_t state );
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 #endif // STSPIN220_H
305  // stspin220
307 
308 // ------------------------------------------------------------------------ END
stspin220_cfg_t::rst
pin_name_t rst
Definition: stspin220.h:136
STSPIN220_ERROR
@ STSPIN220_ERROR
Definition: stspin220.h:150
stspin220_cfg_setup
void stspin220_cfg_setup(stspin220_cfg_t *cfg)
STSPIN220 configuration object setup function.
stspin220_enable_device
void stspin220_enable_device(stspin220_t *ctx)
STSPIN220 enable device function.
stspin220_get_fault_pin
uint8_t stspin220_get_fault_pin(stspin220_t *ctx)
STSPIN220 get fault pin function.
stspin220_switch_direction
void stspin220_switch_direction(stspin220_t *ctx)
STSPIN220 switch direction function.
stspin220_t::dir
digital_out_t dir
Definition: stspin220.h:120
stspin220_cfg_t::en
pin_name_t en
Definition: stspin220.h:137
stspin220_set_step_pin
void stspin220_set_step_pin(stspin220_t *ctx, uint8_t state)
STSPIN220 set step pin function.
stspin220_disable_device
void stspin220_disable_device(stspin220_t *ctx)
STSPIN220 disable device function.
stspin220_t::fault
digital_in_t fault
Definition: stspin220.h:125
stspin220_default_cfg
void stspin220_default_cfg(stspin220_t *ctx)
STSPIN220 default configuration function.
stspin220_cfg_t::step
pin_name_t step
Definition: stspin220.h:138
stspin220_t::step
digital_out_t step
Definition: stspin220.h:123
stspin220_cfg_t::dir
pin_name_t dir
Definition: stspin220.h:135
stspin220_cfg_t::fault
pin_name_t fault
Definition: stspin220.h:139
stspin220_cfg_t
STSPIN220 Click configuration object.
Definition: stspin220.h:134
stspin220_t::en
digital_out_t en
Definition: stspin220.h:122
stspin220_reset_device
void stspin220_reset_device(stspin220_t *ctx)
STSPIN220 reset device function.
stspin220_init
err_t stspin220_init(stspin220_t *ctx, stspin220_cfg_t *cfg)
STSPIN220 initialization function.
stspin220_set_direction
void stspin220_set_direction(stspin220_t *ctx, uint8_t dir)
STSPIN220 set direction function.
stspin220_t::rst
digital_out_t rst
Definition: stspin220.h:121
stspin220_set_rst_pin
void stspin220_set_rst_pin(stspin220_t *ctx, uint8_t state)
STSPIN220 set rst pin function.
stspin220_drive_motor
void stspin220_drive_motor(stspin220_t *ctx, uint32_t steps, uint8_t speed)
STSPIN220 drive motor function.
STSPIN220_OK
@ STSPIN220_OK
Definition: stspin220.h:149
stspin220_t
STSPIN220 Click context object.
Definition: stspin220.h:119
stspin220_return_value_t
stspin220_return_value_t
STSPIN220 Click return value data.
Definition: stspin220.h:148