hbridge16  2.1.0.0
hbridge16.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 HBRIDGE16_H
29 #define HBRIDGE16_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 
69 #define HBRIDGE16_REG_INPUT_PORT 0x00
70 #define HBRIDGE16_REG_OUTPUT_PORT 0x01
71 #define HBRIDGE16_REG_POLARITY_INV 0x02
72 #define HBRIDGE16_REG_CONFIG 0x03
73  // hbridge16_reg
75 
90 #define HBRIDGE16_NONE_PIN 0x00
91 #define HBRIDGE16_IN1_PIN 0x01
92 #define HBRIDGE16_IN2_PIN 0x02
93 #define HBRIDGE16_IN3_PIN 0x04
94 #define HBRIDGE16_IN4_PIN 0x08
95 #define HBRIDGE16_DECAY_PIN 0x10
96 #define HBRIDGE16_MD_PIN 0x20
97 #define HBRIDGE16_OCPM_PIN 0x40
98 #define HBRIDGE16_FLT_PIN 0x80
99 #define HBRIDGE16_ALL_OUTPUT_PIN 0x7F
100 #define HBRIDGE16_ALL_PIN 0xFF
101 
106 #define HBRIDGE16_DRIVE_MOTOR_REVERSE 0x00
107 #define HBRIDGE16_DRIVE_MOTOR_FORWARD 0x01
108 #define HBRIDGE16_DRIVE_MOTOR_FREEWHEEL 0x02
109 #define HBRIDGE16_DRIVE_MOTOR_BRAKE 0x03
110 
115 #define HBRIDGE16_PWM_MODE 0x01
116 #define HBRIDGE16_PH_EN_MODE 0x00
117 
122 #define HBRIDGE16_SLEEP_MODE_OFF 0x01
123 #define HBRIDGE16_SLEEP_MODE_ON 0x00
124 
130 #define HBRIDGE16_DEVICE_ADDRESS_A1A0_00 0x70
131 #define HBRIDGE16_DEVICE_ADDRESS_A1A0_01 0x71
132 #define HBRIDGE16_DEVICE_ADDRESS_A1A0_10 0x72
133 #define HBRIDGE16_DEVICE_ADDRESS_A1A0_11 0x73
134  // hbridge16_set
136 
151 #define HBRIDGE16_MAP_MIKROBUS( cfg, mikrobus ) \
152  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
153  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
154  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
155  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
156  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
157  // hbridge16_map // hbridge16
160 
165 typedef struct
166 {
167  // Output pins
168  digital_out_t rst;
169  digital_out_t slp;
171  // Input pins
172  digital_in_t int_pin;
174  // Modules
175  i2c_master_t i2c;
177  // I2C slave address
178  uint8_t slave_address;
180 } hbridge16_t;
181 
186 typedef struct
187 {
188  pin_name_t scl;
189  pin_name_t sda;
191  pin_name_t rst;
192  pin_name_t slp;
193  pin_name_t int_pin;
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
199 
204 typedef enum
205 {
207  HBRIDGE16_ERROR = -1
208 
210 
227 
242 
256 
271 err_t hbridge16_generic_write ( hbridge16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
272 
287 err_t hbridge16_generic_read ( hbridge16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
288 
289 
299 
310 
320 void hbridge16_set_slp_pin ( hbridge16_t *ctx, uint8_t pin_state );
321 
335 err_t hbridge16_write_reg ( hbridge16_t *ctx, uint8_t reg, uint8_t data_in );
336 
349 err_t hbridge16_read_reg ( hbridge16_t *ctx, uint8_t reg, uint8_t *data_out );
350 
363 err_t hbridge16_set_pins ( hbridge16_t *ctx, uint8_t set_mask, uint8_t clr_mask );
364 
376 err_t hbridge16_set_mode ( hbridge16_t *ctx, uint8_t mode_sel );
377 
390 err_t hbridge16_set_out_state ( hbridge16_t *ctx, uint8_t out_state );
391 
392 #ifdef __cplusplus
393 }
394 #endif
395 #endif // HBRIDGE16_H
396  // hbridge16
398 
399 // ------------------------------------------------------------------------ END
hbridge16_t::int_pin
digital_in_t int_pin
Definition: hbridge16.h:172
hbridge16_cfg_t::slp
pin_name_t slp
Definition: hbridge16.h:192
hbridge16_cfg_t::rst
pin_name_t rst
Definition: hbridge16.h:191
hbridge16_read_reg
err_t hbridge16_read_reg(hbridge16_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 16 read register function.
hbridge16_t::rst
digital_out_t rst
Definition: hbridge16.h:168
hbridge16_t
H-Bridge 16 Click context object.
Definition: hbridge16.h:166
hbridge16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hbridge16.h:195
hbridge16_t::slave_address
uint8_t slave_address
Definition: hbridge16.h:178
hbridge16_cfg_t::i2c_address
uint8_t i2c_address
Definition: hbridge16.h:196
hbridge16_write_reg
err_t hbridge16_write_reg(hbridge16_t *ctx, uint8_t reg, uint8_t data_in)
H-Bridge 16 write register function.
hbridge16_t::i2c
i2c_master_t i2c
Definition: hbridge16.h:175
HBRIDGE16_OK
@ HBRIDGE16_OK
Definition: hbridge16.h:206
hbridge16_init
err_t hbridge16_init(hbridge16_t *ctx, hbridge16_cfg_t *cfg)
H-Bridge 16 initialization function.
hbridge16_reset_port_exp
void hbridge16_reset_port_exp(hbridge16_t *ctx)
H-Bridge 16 reset port expander function.
hbridge16_cfg_setup
void hbridge16_cfg_setup(hbridge16_cfg_t *cfg)
H-Bridge 16 configuration object setup function.
hbridge16_cfg_t::scl
pin_name_t scl
Definition: hbridge16.h:188
hbridge16_cfg_t
H-Bridge 16 Click configuration object.
Definition: hbridge16.h:187
hbridge16_return_value_t
hbridge16_return_value_t
H-Bridge 16 Click return value data.
Definition: hbridge16.h:205
hbridge16_cfg_t::int_pin
pin_name_t int_pin
Definition: hbridge16.h:193
hbridge16_generic_write
err_t hbridge16_generic_write(hbridge16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
H-Bridge 16 I2C writing function.
hbridge16_set_slp_pin
void hbridge16_set_slp_pin(hbridge16_t *ctx, uint8_t pin_state)
H-Bridge 15 set Sleep pin function.
hbridge16_default_cfg
err_t hbridge16_default_cfg(hbridge16_t *ctx)
H-Bridge 16 default configuration function.
hbridge16_get_int_pin
uint8_t hbridge16_get_int_pin(hbridge16_t *ctx)
H-Bridge 16 get Interrupt pin function.
hbridge16_t::slp
digital_out_t slp
Definition: hbridge16.h:169
HBRIDGE16_ERROR
@ HBRIDGE16_ERROR
Definition: hbridge16.h:207
hbridge16_set_mode
err_t hbridge16_set_mode(hbridge16_t *ctx, uint8_t mode_sel)
H-Bridge 16 set mode function.
hbridge16_cfg_t::sda
pin_name_t sda
Definition: hbridge16.h:189
hbridge16_generic_read
err_t hbridge16_generic_read(hbridge16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
H-Bridge 16 I2C reading function.
hbridge16_set_out_state
err_t hbridge16_set_out_state(hbridge16_t *ctx, uint8_t out_state)
H-Bridge 16 set output function.
hbridge16_set_pins
err_t hbridge16_set_pins(hbridge16_t *ctx, uint8_t set_mask, uint8_t clr_mask)
H-Bridge 16 set pins function.