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
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#include "drv_i2c_master.h"
52#include "drv_pwm.h"
53
79#define HBRIDGE6_REG_IN_PORT 0x00
80#define HBRIDGE6_REG_OUT_PORT 0x01
81#define HBRIDGE6_REG_POL_INV 0x02
82#define HBRIDGE6_REG_CONFIG 0x03
83
88#define HBRIDGE6_PIN_STATE_LOW 0x00
89#define HBRIDGE6_PIN_STATE_HIGH 0x01
90
91#define HBRIDGE6_IN_PORT_MULTI_SENSE_LOW 0xFB
92#define HBRIDGE6_IN_PORT_MULTI_SENSE_HIGH 0x04
93
94#define HBRIDGE6_IN_PORT_IN_LOW 0xFE
95#define HBRIDGE6_IN_PORT_IN_HIGH 0x01
96
97#define HBRIDGE6_MS_EN_LOW 0xFD
98#define HBRIDGE6_MS_EN_HIGH 0x02
99
100#define HBRIDGE6_DIAGNOSTIC_DISABLE 0x00
101#define HBRIDGE6_DIAGNOSTIC_ENABLE 0x01
102
103#define HBRIDGE6_DEFAULT_CFG 0xE0
104
105#define HBRIDGE6_IN_PORT_SEL_BIT_MASK 0x01
106#define HBRIDGE6_IN_PORT_SEL_0 0x00
107#define HBRIDGE6_IN_PORT_SEL_1 0x01
108
109#define HBRIDGE6_NUMBER_OF_PORTS 0x07
110
115#define HBRIDGE6_DIRECTION_BRAKE 0x00
116#define HBRIDGE6_DIRECTION_CLOCKWISE 0x01
117#define HBRIDGE6_DIRECTION_COUNTERCLOCKWISE 0x02
118
124#define HBRIDGE6_I2C_SLAVE_ADR_0 0x70
125#define HBRIDGE6_I2C_SLAVE_ADR_1 0x71
126#define HBRIDGE6_I2C_SLAVE_ADR_2 0x72
127#define HBRIDGE6_I2C_SLAVE_ADR_3 0x73
128
133#define HBRIDGE6_DEF_FREQ 5000
134
135 // hbridge6_set
136
151#define HBRIDGE6_MAP_MIKROBUS( cfg, mikrobus ) \
152 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
154 cfg.ms = MIKROBUS( mikrobus, MIKROBUS_AN ); \
155 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
156 cfg.pwm = MIKROBUS( mikrobus, MIKROBUS_PWM )
157
158 // hbridge6_map
159 // hbridge6
160
165typedef struct
166{
167 // Output pins
168 digital_out_t rst;
170 // Input pins
171 digital_in_t ms;
173 // Modules
174 i2c_master_t i2c;
175 pwm_t pwm;
177 // I2C slave address
180 uint32_t pwm_freq;
182} hbridge6_t;
183
188typedef struct
189{
190 pin_name_t scl;
191 pin_name_t sda;
193 pin_name_t ms;
194 pin_name_t rst;
195 pin_name_t pwm;
197 uint32_t i2c_speed;
198 uint8_t i2c_address;
200 uint32_t dev_pwm_freq;
202 uint8_t in_out;
203 uint8_t invert;
204 uint8_t out_val;
205
207
212typedef enum
213{
215 HBRIDGE6_ERROR = -1
216
218
236
251
263void hbridge6_generic_write ( hbridge6_t *ctx, uint8_t reg, uint8_t tx_buf );
264
274uint8_t hbridge6_generic_read ( hbridge6_t *ctx, uint8_t reg );
275
290
302err_t hbridge6_set_duty_cycle ( hbridge6_t *ctx, float duty_cycle );
303
315
327
338
350void hbridge6_set_output ( hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t cfg_data );
351
363void hbridge6_get_output ( hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t *cfg_data );
364
375
386void hbridge6_set_input_port_a ( hbridge6_t *ctx, uint8_t pin_state );
387
398void hbridge6_set_input_port_b ( hbridge6_t *ctx, uint8_t pin_state );
399
410void hbridge6_enable_diagnostic ( hbridge6_t *ctx, uint8_t en_state );
411
423void hbridge6_set_multi_sense ( hbridge6_t *ctx, uint8_t sel_num, uint8_t pin_state );
424
434void hbridge6_set_direction ( hbridge6_t *ctx, uint8_t direction );
435
445
446#ifdef __cplusplus
447}
448#endif
449#endif // HBRIDGE6_H
450
451 // hbridge6
452
453// ------------------------------------------------------------------------ END
void hbridge6_get_output(hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t *cfg_data)
Get output function.
void hbridge6_set_input_port_b(hbridge6_t *ctx, uint8_t pin_state)
Set input port B function.
err_t hbridge6_set_duty_cycle(hbridge6_t *ctx, float duty_cycle)
H-Bridge 6 sets PWM duty cycle.
void hbridge6_set_output(hbridge6_t *ctx, uint8_t n_out_port, hbridge6_cfg_t cfg_data)
Set output function.
uint8_t hbridge6_get_an_diagnostic(hbridge6_t *ctx)
Get diagnostic function.
void hbridge6_generic_write(hbridge6_t *ctx, uint8_t reg, uint8_t tx_buf)
H-Bridge 6 I2C writing function.
void hbridge6_reset(hbridge6_t *ctx)
HW reset function.
void hbridge6_set_multi_sense(hbridge6_t *ctx, uint8_t sel_num, uint8_t pin_state)
Set multi sense function.
err_t hbridge6_default_cfg(hbridge6_t *ctx)
H-Bridge 6 default configuration function.
void hbridge6_set_input_port_a(hbridge6_t *ctx, uint8_t pin_state)
Set input port A function.
err_t hbridge6_pwm_start(hbridge6_t *ctx)
H-Bridge 6 start PWM module.
void hbridge6_default_config(hbridge6_t *ctx)
Default config function.
err_t hbridge6_init(hbridge6_t *ctx, hbridge6_cfg_t *cfg)
H-Bridge 6 initialization function.
void hbridge6_set_direction(hbridge6_t *ctx, uint8_t direction)
Adjust the direction function.
err_t hbridge6_pwm_stop(hbridge6_t *ctx)
H-Bridge 6 stop PWM module.
void hbridge6_cfg_setup(hbridge6_cfg_t *cfg)
H-Bridge 6 configuration object setup function.
void hbridge6_enable_diagnostic(hbridge6_t *ctx, uint8_t en_state)
Enable the diagnostic function.
uint8_t hbridge6_generic_read(hbridge6_t *ctx, uint8_t reg)
H-Bridge 6 I2C reading function.
hbridge6_return_value_t
H-Bridge 6 Click return value data.
Definition hbridge6.h:213
@ HBRIDGE6_ERROR
Definition hbridge6.h:215
@ HBRIDGE6_OK
Definition hbridge6.h:214
H-Bridge 6 Click configuration object.
Definition hbridge6.h:189
uint8_t out_val
Definition hbridge6.h:204
uint32_t i2c_speed
Definition hbridge6.h:197
uint8_t in_out
Definition hbridge6.h:202
uint32_t dev_pwm_freq
Definition hbridge6.h:200
pin_name_t scl
Definition hbridge6.h:190
pin_name_t pwm
Definition hbridge6.h:195
pin_name_t sda
Definition hbridge6.h:191
pin_name_t ms
Definition hbridge6.h:193
pin_name_t rst
Definition hbridge6.h:194
uint8_t invert
Definition hbridge6.h:203
uint8_t i2c_address
Definition hbridge6.h:198
H-Bridge 6 Click context object.
Definition hbridge6.h:166
digital_in_t ms
Definition hbridge6.h:171
uint32_t pwm_freq
Definition hbridge6.h:180
i2c_master_t i2c
Definition hbridge6.h:174
digital_out_t rst
Definition hbridge6.h:168
uint8_t slave_address
Definition hbridge6.h:178
pwm_t pwm
Definition hbridge6.h:175