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
32extern "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
99 // 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
121 // hbridge_map
122 // hbridge
123
128typedef 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
144typedef struct
145{
146 pin_name_t in2a;
147 pin_name_t in2b;
148 pin_name_t in1b;
149 pin_name_t in1a;
152
157typedef enum
158{
160 HBRIDGE_ERROR = -1
161
163
180
195
206void hbridge_set_in1a_pin ( hbridge_t *ctx, uint8_t state );
207
218void hbridge_set_in2a_pin ( hbridge_t *ctx, uint8_t state );
219
230void hbridge_set_in1b_pin ( hbridge_t *ctx, uint8_t state );
231
242void hbridge_set_in2b_pin ( hbridge_t *ctx, uint8_t state );
243
255void hbridge_set_step_mode ( hbridge_t *ctx, uint8_t mode );
256
267void hbridge_set_direction ( hbridge_t *ctx, uint8_t dir );
268
278
288
298
314void hbridge_drive_motor ( hbridge_t *ctx, uint32_t steps, uint8_t speed );
315
316#ifdef __cplusplus
317}
318#endif
319#endif // HBRIDGE_H
320
321 // hbridge
322
323// ------------------------------------------------------------------------ END
void hbridge_set_in2b_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in2b pin function.
void hbridge_set_step_mode(hbridge_t *ctx, uint8_t mode)
H-Bridge set step mode function.
void hbridge_set_in1b_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in1b pin function.
void hbridge_set_in1a_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in1a pin function.
void hbridge_enable_device(hbridge_t *ctx)
H-Bridge enable device function.
void hbridge_set_direction(hbridge_t *ctx, uint8_t dir)
H-Bridge set direction function.
void hbridge_drive_motor(hbridge_t *ctx, uint32_t steps, uint8_t speed)
H-Bridge driver motor function.
void hbridge_switch_direction(hbridge_t *ctx)
H-Bridge switch direction function.
err_t hbridge_init(hbridge_t *ctx, hbridge_cfg_t *cfg)
H-Bridge initialization function.
void hbridge_cfg_setup(hbridge_cfg_t *cfg)
H-Bridge configuration object setup function.
void hbridge_disable_device(hbridge_t *ctx)
H-Bridge disable device function.
void hbridge_set_in2a_pin(hbridge_t *ctx, uint8_t state)
H-Bridge set in2a pin function.
hbridge_return_value_t
H-Bridge Click return value data.
Definition hbridge.h:158
@ HBRIDGE_ERROR
Definition hbridge.h:160
@ HBRIDGE_OK
Definition hbridge.h:159
H-Bridge Click configuration object.
Definition hbridge.h:145
pin_name_t in2b
Definition hbridge.h:147
pin_name_t in2a
Definition hbridge.h:146
pin_name_t in1a
Definition hbridge.h:149
pin_name_t in1b
Definition hbridge.h:148
H-Bridge Click context object.
Definition hbridge.h:129
digital_out_t in1b
Definition hbridge.h:132
digital_out_t in2b
Definition hbridge.h:131
digital_out_t in2a
Definition hbridge.h:130
digital_out_t in1a
Definition hbridge.h:133
uint8_t step_mode
Definition hbridge.h:135
uint8_t direction
Definition hbridge.h:136