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 
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 #include "drv_pwm.h"
48 
65 #define HBRIDGE8_MODE_REVERSE 0
66 #define HBRIDGE8_MODE_FORWARD 1
67  // mode
69 
84 #define HBRIDGE8_DEF_FREQ 225000
85  // hbridge8_cfg
87 
102 #define HBRIDGE8_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
104  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
105  cfg.mod = MIKROBUS( mikrobus, MIKROBUS_CS ); \
106  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
107  // hbridge8_map // hbridge8
110 
120 typedef struct
121 {
122  // Output pins
123  digital_out_t en;
124  digital_out_t mod;
126  // Input pins
127  digital_in_t flt;
129  // Modules
130  pwm_t pwm;
132  // ctx variable
133  uint32_t pwm_freq;
135 } hbridge8_t;
136 
141 typedef struct
142 {
143  // Communication gpio pins
144  pin_name_t pwm;
146  // Additional gpio pins
147  pin_name_t en;
148  pin_name_t mod;
149  pin_name_t flt;
151  // Static variable
152  uint32_t dev_pwm_freq;
155 
160 typedef enum
161 {
163  HBRIDGE8_ERROR = -1
164 
166 
183 
199 
214 
227 err_t hbridge8_set_duty_cycle ( hbridge8_t *ctx, float duty_cycle );
228 
241 
254 
270 err_t hbridge8_set_mode ( hbridge8_t *ctx, uint8_t mode );
271 
285 
299 
313 
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif // HBRIDGE8_H
318  // hbridge8
320 
321 // ------------------------------------------------------------------------ END
hbridge8_cfg_t::flt
pin_name_t flt
Definition: hbridge8.h:149
hbridge8_t::en
digital_out_t en
Definition: hbridge8.h:123
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:130
hbridge8_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hbridge8.h:152
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:144
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:121
HBRIDGE8_OK
@ HBRIDGE8_OK
Definition: hbridge8.h:162
hbridge8_t::mod
digital_out_t mod
Definition: hbridge8.h:124
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:133
HBRIDGE8_ERROR
@ HBRIDGE8_ERROR
Definition: hbridge8.h:163
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:148
hbridge8_cfg_t
H-Bridge 8 Click configuration object.
Definition: hbridge8.h:142
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:147
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:127
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:161
hbridge8_pwm_start
err_t hbridge8_pwm_start(hbridge8_t *ctx)
H-Bridge 8 start PWM module.