hbridge15 2.1.0.0
hbridge15.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 HBRIDGE15_H
29#define HBRIDGE15_H
30
31#ifdef __cplusplus
32extern "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
69#define HBRIDGE15_REG_INPUT_PORT 0x00
70#define HBRIDGE15_REG_OUTPUT_PORT 0x01
71#define HBRIDGE15_REG_POLARITY_INVERSION 0x02
72#define HBRIDGE15_REG_CONFIGURATION 0x03
73 // hbridge15_reg
75
90#define HBRIDGE15_PIN_MASK_NONE 0x00
91#define HBRIDGE15_PIN_MASK_SLP 0x01
92#define HBRIDGE15_PIN_MASK_FLT 0x02
93#define HBRIDGE15_PIN_MASK_CONFIG 0x04
94#define HBRIDGE15_PIN_MASK_M1 0x08
95#define HBRIDGE15_PIN_MASK_M0 0x10
96#define HBRIDGE15_PIN_MASK_DIR 0x20
97#define HBRIDGE15_PIN_MASK_EN_B 0x40
98#define HBRIDGE15_PIN_MASK_EN_A 0x80
99#define HBRIDGE15_PIN_MASK_ALL 0xFF
100
105#define HBRIDGE15_PIN_STATE_HIGH 0x01
106#define HBRIDGE15_PIN_STATE_LOW 0x00
107
112#define HBRIDGE15_SLEEP_STATE_ON 0x01
113#define HBRIDGE15_SLEEP_STATE_OFF 0x00
114
119#define HBRIDGE15_DRIVE_MOTOR_REVERSE 0x00
120#define HBRIDGE15_DRIVE_MOTOR_FORWARD 0x01
121#define HBRIDGE15_DRIVE_MOTOR_FREEWHEEL 0x02
122#define HBRIDGE15_DRIVE_MOTOR_BRAKE 0x03
123
129#define HBRIDGE15_DEVICE_ADDRESS_00 0x70
130#define HBRIDGE15_DEVICE_ADDRESS_01 0x71
131#define HBRIDGE15_DEVICE_ADDRESS_10 0x72
132#define HBRIDGE15_DEVICE_ADDRESS_11 0x73
133 // hbridge15_set
135
150#define HBRIDGE15_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
152 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
153 cfg.ena = MIKROBUS( mikrobus, MIKROBUS_CS ); \
154 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
155 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156 // hbridge15_map // hbridge15
159
164typedef struct
165{
166 // Output pins
167 digital_out_t ena;
168 digital_out_t rst;
170 // Input pins
171 digital_in_t int_pin;
173 // Modules
174 i2c_master_t i2c;
176 // I2C slave address
180
185typedef struct
186{
187 pin_name_t scl;
188 pin_name_t sda;
190 pin_name_t ena;
191 pin_name_t rst;
192 pin_name_t int_pin;
194 uint32_t i2c_speed;
195 uint8_t i2c_address;
198
203typedef enum
204{
206 HBRIDGE15_ERROR = -1
207
209
226
241
255
270err_t hbridge15_generic_write ( hbridge15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
271
286err_t hbridge15_generic_read ( hbridge15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
287
297void hbridge15_set_rst_pin ( hbridge15_t *ctx, uint8_t pin_state );
298
308void hbridge15_set_ena_pin ( hbridge15_t *ctx, uint8_t pin_state );
309
319
329
343err_t hbridge15_write_reg ( hbridge15_t *ctx, uint8_t reg, uint8_t data_in );
344
357err_t hbridge15_read_reg ( hbridge15_t *ctx, uint8_t reg, uint8_t *data_out );
358
371err_t hbridge15_set_pins ( hbridge15_t *ctx, uint8_t set_mask, uint8_t clr_mask );
372
385err_t hbridge15_set_sleep ( hbridge15_t *ctx, uint8_t sleep_state );
386
399err_t hbridge15_set_out_state ( hbridge15_t *ctx, uint8_t out_state );
400
401#ifdef __cplusplus
402}
403#endif
404#endif // HBRIDGE15_H
405 // hbridge15
407
408// ------------------------------------------------------------------------ END
void hbridge15_cfg_setup(hbridge15_cfg_t *cfg)
H-Bridge 15 configuration object setup function.
err_t hbridge15_set_sleep(hbridge15_t *ctx, uint8_t sleep_state)
H-Bridge 15 set sleep function.
void hbridge15_reset_port_exp(hbridge15_t *ctx)
H-Bridge 15 reset port expander function.
err_t hbridge15_generic_write(hbridge15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
H-Bridge 15 I2C writing function.
err_t hbridge15_init(hbridge15_t *ctx, hbridge15_cfg_t *cfg)
H-Bridge 15 initialization function.
err_t hbridge15_generic_read(hbridge15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
H-Bridge 15 I2C reading function.
err_t hbridge15_write_reg(hbridge15_t *ctx, uint8_t reg, uint8_t data_in)
H-Bridge 15 write register function.
err_t hbridge15_read_reg(hbridge15_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 15 read register function.
uint8_t hbridge15_get_int_state(hbridge15_t *ctx)
H-Bridge 15 get INT pin state function.
void hbridge15_set_rst_pin(hbridge15_t *ctx, uint8_t pin_state)
H-Bridge 15 set RST pin function.
void hbridge15_set_ena_pin(hbridge15_t *ctx, uint8_t pin_state)
H-Bridge 15 set ENA pin function.
err_t hbridge15_default_cfg(hbridge15_t *ctx)
H-Bridge 15 default configuration function.
err_t hbridge15_set_pins(hbridge15_t *ctx, uint8_t set_mask, uint8_t clr_mask)
H-Bridge 15 set pins function.
err_t hbridge15_set_out_state(hbridge15_t *ctx, uint8_t out_state)
H-Bridge 15 set output function.
hbridge15_return_value_t
H-Bridge 15 Click return value data.
Definition: hbridge15.h:204
@ HBRIDGE15_ERROR
Definition: hbridge15.h:206
@ HBRIDGE15_OK
Definition: hbridge15.h:205
H-Bridge 15 Click configuration object.
Definition: hbridge15.h:186
uint32_t i2c_speed
Definition: hbridge15.h:194
pin_name_t ena
Definition: hbridge15.h:190
pin_name_t scl
Definition: hbridge15.h:187
pin_name_t int_pin
Definition: hbridge15.h:192
pin_name_t sda
Definition: hbridge15.h:188
pin_name_t rst
Definition: hbridge15.h:191
uint8_t i2c_address
Definition: hbridge15.h:195
H-Bridge 15 Click context object.
Definition: hbridge15.h:165
digital_out_t ena
Definition: hbridge15.h:167
digital_in_t int_pin
Definition: hbridge15.h:171
i2c_master_t i2c
Definition: hbridge15.h:174
digital_out_t rst
Definition: hbridge15.h:168
uint8_t slave_address
Definition: hbridge15.h:177