hbridge8  2.0.0.0
hbridge8.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 HBRIDGE8_H
29 #define HBRIDGE8_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 #include "drv_pwm.h"
52 
69 #define HBRIDGE8_MODE_REVERSE 0
70 #define HBRIDGE8_MODE_FORWARD 1
71  // mode
73 
88 #define HBRIDGE8_DEF_FREQ 225000
89  // hbridge8_cfg
91 
106 #define HBRIDGE8_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
108  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_CS ); \
110  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
111  // hbridge8_map // hbridge8
114 
124 typedef struct
125 {
126  // Output pins
127  digital_out_t en;
128  digital_out_t mod;
130  // Input pins
131  digital_in_t flt;
133  // Modules
134  pwm_t pwm;
136  // ctx variable
137  uint32_t pwm_freq;
139 } hbridge8_t;
140 
145 typedef struct
146 {
147  // Communication gpio pins
148  pin_name_t pwm;
150  // Additional gpio pins
151  pin_name_t en;
152  pin_name_t mod;
153  pin_name_t flt;
155  // Static variable
156  uint32_t dev_pwm_freq;
159 
164 typedef enum
165 {
167  HBRIDGE8_ERROR = -1
168 
170 
187 
203 
218 
231 err_t hbridge8_set_duty_cycle ( hbridge8_t *ctx, float duty_cycle );
232 
245 
258 
274 err_t hbridge8_set_mode ( hbridge8_t *ctx, uint8_t mode );
275 
289 
303 
317 
318 #ifdef __cplusplus
319 }
320 #endif
321 #endif // HBRIDGE8_H
322  // hbridge8
324 
325 // ------------------------------------------------------------------------ END
hbridge8_cfg_t::flt
pin_name_t flt
Definition: hbridge8.h:153
hbridge8_t::en
digital_out_t en
Definition: hbridge8.h:127
hbridge8_set_mode
err_t hbridge8_set_mode(hbridge8_t *ctx, uint8_t mode)
H-Bridge 8 set operating mode function.
hbridge8_t::pwm
pwm_t pwm
Definition: hbridge8.h:134
hbridge8_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hbridge8.h:156
hbridge8_pwm_stop
err_t hbridge8_pwm_stop(hbridge8_t *ctx)
H-Bridge 8 stop PWM module.
mode
uint8_t mode
Definition: main.c:32
hbridge8_cfg_t::pwm
pin_name_t pwm
Definition: hbridge8.h:148
hbridge8_disable
err_t hbridge8_disable(hbridge8_t *ctx)
H-Bridge 8 set IC disable function.
hbridge8_t
H-Bridge 8 Click driver selector.
Definition: hbridge8.h:125
HBRIDGE8_OK
@ HBRIDGE8_OK
Definition: hbridge8.h:166
hbridge8_t::mod
digital_out_t mod
Definition: hbridge8.h:128
hbridge8_default_cfg
err_t hbridge8_default_cfg(hbridge8_t *ctx)
H-Bridge 8 default configuration function.
hbridge8_t::pwm_freq
uint32_t pwm_freq
Definition: hbridge8.h:137
HBRIDGE8_ERROR
@ HBRIDGE8_ERROR
Definition: hbridge8.h:167
hbridge8_set_duty_cycle
err_t hbridge8_set_duty_cycle(hbridge8_t *ctx, float duty_cycle)
H-Bridge 8 sets PWM duty cycle.
hbridge8_cfg_t::mod
pin_name_t mod
Definition: hbridge8.h:152
hbridge8_cfg_t
H-Bridge 8 Click configuration object.
Definition: hbridge8.h:146
hbridge8_cfg_setup
void hbridge8_cfg_setup(hbridge8_cfg_t *cfg)
H-Bridge 8 configuration object setup function.
hbridge8_cfg_t::en
pin_name_t en
Definition: hbridge8.h:151
hbridge8_get_fault_indication
uint8_t hbridge8_get_fault_indication(hbridge8_t *ctx)
H-Bridge 8 get fault indication function.
hbridge8_t::flt
digital_in_t flt
Definition: hbridge8.h:131
hbridge8_enable
err_t hbridge8_enable(hbridge8_t *ctx)
H-Bridge 8 set IC enable function.
hbridge8_init
err_t hbridge8_init(hbridge8_t *ctx, hbridge8_cfg_t *cfg)
H-Bridge 8 initialization function.
hbridge8_return_value_t
hbridge8_return_value_t
H-Bridge 8 Click return value data.
Definition: hbridge8.h:165
hbridge8_pwm_start
err_t hbridge8_pwm_start(hbridge8_t *ctx)
H-Bridge 8 start PWM module.