hbridge  2.1.0.0
hbridge.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 HBRIDGE_H
29 #define HBRIDGE_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 HBRIDGE_DIR_CW 0
69 #define HBRIDGE_DIR_CCW 1
70 
75 #define HBRIDGE_PIN_LOW_LEVEL 0
76 #define HBRIDGE_PIN_HIGH_LEVEL 1
77 
82 #define HBRIDGE_MODE_FULL_STEP 0
83 #define HBRIDGE_MODE_HALF_STEP 1
84 
89 #define HBRIDGE_SPEED_VERY_SLOW 0
90 #define HBRIDGE_SPEED_SLOW 1
91 #define HBRIDGE_SPEED_MEDIUM 2
92 #define HBRIDGE_SPEED_FAST 3
93 #define HBRIDGE_SPEED_VERY_FAST 4
94  // hbridge_set
96 
111 #define HBRIDGE_MAP_MIKROBUS( cfg, mikrobus ) \
112  cfg.in2a = MIKROBUS( mikrobus, MIKROBUS_AN ); \
113  cfg.in2b = MIKROBUS( mikrobus, MIKROBUS_RST ); \
114  cfg.in1b = MIKROBUS( mikrobus, MIKROBUS_CS ); \
115  cfg.in1a = MIKROBUS( mikrobus, MIKROBUS_PWM );
116  // hbridge_map // hbridge
119 
124 typedef struct
125 {
126  digital_out_t in2a;
127  digital_out_t in2b;
128  digital_out_t in1b;
129  digital_out_t in1a;
131  uint8_t step_mode;
132  uint8_t direction;
134 } hbridge_t;
135 
140 typedef struct
141 {
142  pin_name_t in2a;
143  pin_name_t in2b;
144  pin_name_t in1b;
145  pin_name_t in1a;
147 } hbridge_cfg_t;
148 
153 typedef enum
154 {
156  HBRIDGE_ERROR = -1
157 
159 
176 
190 err_t hbridge_init ( hbridge_t *ctx, hbridge_cfg_t *cfg );
191 
202 void hbridge_set_in1a_pin ( hbridge_t *ctx, uint8_t state );
203 
214 void hbridge_set_in2a_pin ( hbridge_t *ctx, uint8_t state );
215 
226 void hbridge_set_in1b_pin ( hbridge_t *ctx, uint8_t state );
227 
238 void hbridge_set_in2b_pin ( hbridge_t *ctx, uint8_t state );
239 
251 void hbridge_set_step_mode ( hbridge_t *ctx, uint8_t mode );
252 
263 void hbridge_set_direction ( hbridge_t *ctx, uint8_t dir );
264 
274 
284 
294 
310 void hbridge_drive_motor ( hbridge_t *ctx, uint32_t steps, uint8_t speed );
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // HBRIDGE_H
316  // hbridge
318 
319 // ------------------------------------------------------------------------ END
hbridge_t::direction
uint8_t direction
Definition: hbridge.h:132
hbridge_return_value_t
hbridge_return_value_t
H-Bridge Click return value data.
Definition: hbridge.h:154
hbridge_cfg_t::in2b
pin_name_t in2b
Definition: hbridge.h:143
HBRIDGE_OK
@ HBRIDGE_OK
Definition: hbridge.h:155
hbridge_cfg_t::in1b
pin_name_t in1b
Definition: hbridge.h:144
hbridge_t::in1a
digital_out_t in1a
Definition: hbridge.h:129
hbridge_cfg_t
H-Bridge Click configuration object.
Definition: hbridge.h:141
hbridge_disable_device
void hbridge_disable_device(hbridge_t *ctx)
H-Bridge disable device function.
hbridge_t::in2b
digital_out_t in2b
Definition: hbridge.h:127
hbridge_t::in2a
digital_out_t in2a
Definition: hbridge.h:126
hbridge_cfg_t::in1a
pin_name_t in1a
Definition: hbridge.h:145
hbridge_set_in2b_pin
void hbridge_set_in2b_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in2b pin function.
HBRIDGE_ERROR
@ HBRIDGE_ERROR
Definition: hbridge.h:156
hbridge_cfg_t::in2a
pin_name_t in2a
Definition: hbridge.h:142
hbridge_drive_motor
void hbridge_drive_motor(hbridge_t *ctx, uint32_t steps, uint8_t speed)
H-Bridge driver motor function.
hbridge_t
H-Bridge Click context object.
Definition: hbridge.h:125
hbridge_switch_direction
void hbridge_switch_direction(hbridge_t *ctx)
H-Bridge switch direction function.
hbridge_init
err_t hbridge_init(hbridge_t *ctx, hbridge_cfg_t *cfg)
H-Bridge initialization function.
hbridge_set_in1b_pin
void hbridge_set_in1b_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in1b pin function.
hbridge_set_step_mode
void hbridge_set_step_mode(hbridge_t *ctx, uint8_t mode)
H-Bridge set step mode function.
hbridge_t::in1b
digital_out_t in1b
Definition: hbridge.h:128
hbridge_set_direction
void hbridge_set_direction(hbridge_t *ctx, uint8_t dir)
H-Bridge set direction function.
hbridge_enable_device
void hbridge_enable_device(hbridge_t *ctx)
H-Bridge enable device function.
hbridge_t::step_mode
uint8_t step_mode
Definition: hbridge.h:131
hbridge_set_in2a_pin
void hbridge_set_in2a_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in2a pin function.
hbridge_cfg_setup
void hbridge_cfg_setup(hbridge_cfg_t *cfg)
H-Bridge configuration object setup function.
hbridge_set_in1a_pin
void hbridge_set_in1a_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in1a pin function.