hbridge6  2.0.0.0
hbridge6.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2021 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 HBRIDGE6_H
29 #define HBRIDGE6_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_i2c_master.h"
48 #include "drv_pwm.h"
49 
75 #define HBRIDGE6_REG_IN_PORT 0x00
76 #define HBRIDGE6_REG_OUT_PORT 0x01
77 #define HBRIDGE6_REG_POL_INV 0x02
78 #define HBRIDGE6_REG_CONFIG 0x03
79 
84 #define HBRIDGE6_PIN_STATE_LOW 0x00
85 #define HBRIDGE6_PIN_STATE_HIGH 0x01
86 
87 #define HBRIDGE6_IN_PORT_MULTI_SENSE_LOW 0xFB
88 #define HBRIDGE6_IN_PORT_MULTI_SENSE_HIGH 0x04
89 
90 #define HBRIDGE6_IN_PORT_IN_LOW 0xFE
91 #define HBRIDGE6_IN_PORT_IN_HIGH 0x01
92 
93 #define HBRIDGE6_MS_EN_LOW 0xFD
94 #define HBRIDGE6_MS_EN_HIGH 0x02
95 
96 #define HBRIDGE6_DIAGNOSTIC_DISABLE 0x00
97 #define HBRIDGE6_DIAGNOSTIC_ENABLE 0x01
98 
99 #define HBRIDGE6_DEFAULT_CFG 0xE0
100 
101 #define HBRIDGE6_IN_PORT_SEL_BIT_MASK 0x01
102 #define HBRIDGE6_IN_PORT_SEL_0 0x00
103 #define HBRIDGE6_IN_PORT_SEL_1 0x01
104 
105 #define HBRIDGE6_NUMBER_OF_PORTS 0x07
106 
111 #define HBRIDGE6_DIRECTION_BRAKE 0x00
112 #define HBRIDGE6_DIRECTION_CLOCKWISE 0x01
113 #define HBRIDGE6_DIRECTION_COUNTERCLOCKWISE 0x02
114 
120 #define HBRIDGE6_I2C_SLAVE_ADR_0 0x70
121 #define HBRIDGE6_I2C_SLAVE_ADR_1 0x71
122 #define HBRIDGE6_I2C_SLAVE_ADR_2 0x72
123 #define HBRIDGE6_I2C_SLAVE_ADR_3 0x73
124 
129 #define HBRIDGE6_DEF_FREQ 5000
130  // hbridge6_set
132 
147 #define HBRIDGE6_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
150  cfg.ms = MIKROBUS( mikrobus, MIKROBUS_AN ); \
151  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152  cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
153  // hbridge6_map // hbridge6
156 
161 typedef struct
162 {
163  // Output pins
164  digital_out_t rst;
166  // Input pins
167  digital_in_t ms;
169  // Modules
170  i2c_master_t i2c;
171  pwm_t pwm;
173  // I2C slave address
174  uint8_t slave_address;
176  uint32_t pwm_freq;
178 } hbridge6_t;
179 
184 typedef struct
185 {
186  pin_name_t scl;
187  pin_name_t sda;
189  pin_name_t ms;
190  pin_name_t rst;
191  pin_name_t pwm;
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
196  uint32_t dev_pwm_freq;
198  uint8_t in_out;
199  uint8_t invert;
200  uint8_t out_val;
201 
203 
208 typedef enum
209 {
211  HBRIDGE6_ERROR = -1
212 
214 
232 
247 
259 void hbridge6_generic_write ( hbridge6_t *ctx, uint8_t reg, uint8_t tx_buf );
260 
270 uint8_t hbridge6_generic_read ( hbridge6_t *ctx, uint8_t reg );
271 
286 
298 err_t hbridge6_set_duty_cycle ( hbridge6_t *ctx, float duty_cycle );
299 
311 
323 
334 
346 void hbridge6_set_output ( hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t cfg_data );
347 
359 void hbridge6_get_output ( hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t *cfg_data );
360 
371 
382 void hbridge6_set_input_port_a ( hbridge6_t *ctx, uint8_t pin_state );
383 
394 void hbridge6_set_input_port_b ( hbridge6_t *ctx, uint8_t pin_state );
395 
406 void hbridge6_enable_diagnostic ( hbridge6_t *ctx, uint8_t en_state );
407 
419 void hbridge6_set_multi_sense ( hbridge6_t *ctx, uint8_t sel_num, uint8_t pin_state );
420 
430 void hbridge6_set_direction ( hbridge6_t *ctx, uint8_t direction );
431 
441 
442 #ifdef __cplusplus
443 }
444 #endif
445 #endif // HBRIDGE6_H
446  // hbridge6
448 
449 // ------------------------------------------------------------------------ END
hbridge6_cfg_setup
void hbridge6_cfg_setup(hbridge6_cfg_t *cfg)
H-Bridge 6 configuration object setup function.
hbridge6_generic_write
void hbridge6_generic_write(hbridge6_t *ctx, uint8_t reg, uint8_t tx_buf)
H-Bridge 6 I2C writing function.
hbridge6_cfg_t::rst
pin_name_t rst
Definition: hbridge6.h:190
hbridge6_set_duty_cycle
err_t hbridge6_set_duty_cycle(hbridge6_t *ctx, float duty_cycle)
H-Bridge 6 sets PWM duty cycle.
hbridge6_t::pwm_freq
uint32_t pwm_freq
Definition: hbridge6.h:176
hbridge6_generic_read
uint8_t hbridge6_generic_read(hbridge6_t *ctx, uint8_t reg)
H-Bridge 6 I2C reading function.
hbridge6_t::slave_address
uint8_t slave_address
Definition: hbridge6.h:174
hbridge6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hbridge6.h:193
hbridge6_reset
void hbridge6_reset(hbridge6_t *ctx)
HW reset function.
HBRIDGE6_ERROR
@ HBRIDGE6_ERROR
Definition: hbridge6.h:211
hbridge6_pwm_start
err_t hbridge6_pwm_start(hbridge6_t *ctx)
H-Bridge 6 start PWM module.
hbridge6_set_input_port_a
void hbridge6_set_input_port_a(hbridge6_t *ctx, uint8_t pin_state)
Set input port A function.
hbridge6_t::rst
digital_out_t rst
Definition: hbridge6.h:164
hbridge6_cfg_t::invert
uint8_t invert
Definition: hbridge6.h:199
hbridge6_t
H-Bridge 6 Click context object.
Definition: hbridge6.h:162
hbridge6_set_multi_sense
void hbridge6_set_multi_sense(hbridge6_t *ctx, uint8_t sel_num, uint8_t pin_state)
Set multi sense function.
hbridge6_set_output
void hbridge6_set_output(hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t cfg_data)
Set output function.
hbridge6_return_value_t
hbridge6_return_value_t
H-Bridge 6 Click return value data.
Definition: hbridge6.h:209
hbridge6_t::i2c
i2c_master_t i2c
Definition: hbridge6.h:170
hbridge6_set_input_port_b
void hbridge6_set_input_port_b(hbridge6_t *ctx, uint8_t pin_state)
Set input port B function.
hbridge6_t::ms
digital_in_t ms
Definition: hbridge6.h:167
hbridge6_get_output
void hbridge6_get_output(hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t *cfg_data)
Get output function.
hbridge6_enable_diagnostic
void hbridge6_enable_diagnostic(hbridge6_t *ctx, uint8_t en_state)
Enable the diagnostic function.
hbridge6_t::pwm
pwm_t pwm
Definition: hbridge6.h:171
hbridge6_cfg_t::pwm
pin_name_t pwm
Definition: hbridge6.h:191
hbridge6_cfg_t::dev_pwm_freq
uint32_t dev_pwm_freq
Definition: hbridge6.h:196
hbridge6_get_an_diagnostic
uint8_t hbridge6_get_an_diagnostic(hbridge6_t *ctx)
Get diagnostic function.
HBRIDGE6_OK
@ HBRIDGE6_OK
Definition: hbridge6.h:210
hbridge6_default_config
void hbridge6_default_config(hbridge6_t *ctx)
Default config function.
hbridge6_cfg_t
H-Bridge 6 Click configuration object.
Definition: hbridge6.h:185
hbridge6_default_cfg
err_t hbridge6_default_cfg(hbridge6_t *ctx)
H-Bridge 6 default configuration function.
hbridge6_cfg_t::sda
pin_name_t sda
Definition: hbridge6.h:187
hbridge6_set_direction
void hbridge6_set_direction(hbridge6_t *ctx, uint8_t direction)
Adjust the direction function.
hbridge6_cfg_t::ms
pin_name_t ms
Definition: hbridge6.h:189
hbridge6_cfg_t::i2c_address
uint8_t i2c_address
Definition: hbridge6.h:194
hbridge6_cfg_t::in_out
uint8_t in_out
Definition: hbridge6.h:198
hbridge6_cfg_t::out_val
uint8_t out_val
Definition: hbridge6.h:200
hbridge6_init
err_t hbridge6_init(hbridge6_t *ctx, hbridge6_cfg_t *cfg)
H-Bridge 6 initialization function.
hbridge6_cfg_t::scl
pin_name_t scl
Definition: hbridge6.h:186
hbridge6_pwm_stop
err_t hbridge6_pwm_stop(hbridge6_t *ctx)
H-Bridge 6 stop PWM module.