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 
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 HBRIDGE_DIR_CW 0
73 #define HBRIDGE_DIR_CCW 1
74 
79 #define HBRIDGE_PIN_LOW_LEVEL 0
80 #define HBRIDGE_PIN_HIGH_LEVEL 1
81 
86 #define HBRIDGE_MODE_FULL_STEP 0
87 #define HBRIDGE_MODE_HALF_STEP 1
88 
93 #define HBRIDGE_SPEED_VERY_SLOW 0
94 #define HBRIDGE_SPEED_SLOW 1
95 #define HBRIDGE_SPEED_MEDIUM 2
96 #define HBRIDGE_SPEED_FAST 3
97 #define HBRIDGE_SPEED_VERY_FAST 4
98  // hbridge_set
100 
115 #define HBRIDGE_MAP_MIKROBUS( cfg, mikrobus ) \
116  cfg.in2a = MIKROBUS( mikrobus, MIKROBUS_AN ); \
117  cfg.in2b = MIKROBUS( mikrobus, MIKROBUS_RST ); \
118  cfg.in1b = MIKROBUS( mikrobus, MIKROBUS_CS ); \
119  cfg.in1a = MIKROBUS( mikrobus, MIKROBUS_PWM );
120  // hbridge_map // hbridge
123 
128 typedef struct
129 {
130  digital_out_t in2a;
131  digital_out_t in2b;
132  digital_out_t in1b;
133  digital_out_t in1a;
135  uint8_t step_mode;
136  uint8_t direction;
138 } hbridge_t;
139 
144 typedef struct
145 {
146  pin_name_t in2a;
147  pin_name_t in2b;
148  pin_name_t in1b;
149  pin_name_t in1a;
151 } hbridge_cfg_t;
152 
157 typedef enum
158 {
160  HBRIDGE_ERROR = -1
161 
163 
180 
194 err_t hbridge_init ( hbridge_t *ctx, hbridge_cfg_t *cfg );
195 
206 void hbridge_set_in1a_pin ( hbridge_t *ctx, uint8_t state );
207 
218 void hbridge_set_in2a_pin ( hbridge_t *ctx, uint8_t state );
219 
230 void hbridge_set_in1b_pin ( hbridge_t *ctx, uint8_t state );
231 
242 void hbridge_set_in2b_pin ( hbridge_t *ctx, uint8_t state );
243 
255 void hbridge_set_step_mode ( hbridge_t *ctx, uint8_t mode );
256 
267 void hbridge_set_direction ( hbridge_t *ctx, uint8_t dir );
268 
278 
288 
298 
314 void hbridge_drive_motor ( hbridge_t *ctx, uint32_t steps, uint8_t speed );
315 
316 #ifdef __cplusplus
317 }
318 #endif
319 #endif // HBRIDGE_H
320  // hbridge
322 
323 // ------------------------------------------------------------------------ END
hbridge_t::direction
uint8_t direction
Definition: hbridge.h:136
hbridge_return_value_t
hbridge_return_value_t
H-Bridge Click return value data.
Definition: hbridge.h:158
hbridge_cfg_t::in2b
pin_name_t in2b
Definition: hbridge.h:147
HBRIDGE_OK
@ HBRIDGE_OK
Definition: hbridge.h:159
hbridge_cfg_t::in1b
pin_name_t in1b
Definition: hbridge.h:148
hbridge_t::in1a
digital_out_t in1a
Definition: hbridge.h:133
hbridge_cfg_t
H-Bridge Click configuration object.
Definition: hbridge.h:145
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:131
hbridge_t::in2a
digital_out_t in2a
Definition: hbridge.h:130
hbridge_cfg_t::in1a
pin_name_t in1a
Definition: hbridge.h:149
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:160
hbridge_cfg_t::in2a
pin_name_t in2a
Definition: hbridge.h:146
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:129
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:132
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:135
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.