hbridge14  2.1.0.0
hbridge14.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 HBRIDGE14_H
29 #define HBRIDGE14_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_spi_master.h"
49 #include "spi_specifics.h"
50 
71 #define HBRIDGE14_REG_FAULT_STATUS 0x00
72 #define HBRIDGE14_REG_DIAG_STATUS 0x02
73 #define HBRIDGE14_REG_IC1_CTRL 0x04
74 #define HBRIDGE14_REG_IC2_CTRL 0x06
75 #define HBRIDGE14_REG_IC3_CTRL 0x08
76 #define HBRIDGE14_REG_IC4_CTRL 0x0A
77 #define HBRIDGE14_REG_INPUT_PORT 0x00
78 #define HBRIDGE14_REG_OUTPUT_PORT 0x01
79 #define HBRIDGE14_REG_POLARITY_INV 0x02
80 #define HBRIDGE14_REG_CONFIG 0x03
81  // hbridge14_reg
83 
99 #define HBRIDGE14_DIS_ON 0x01
100 #define HBRIDGE14_DIS_OFF 0x00
101 
107 #define HBRIDGE14_SLEEP_ON 0x01
108 #define HBRIDGE14_SLEEP_OFF 0x00
109 
115 #define HBRIDGE14_PIN_STATE_HIGH 0x01
116 #define HBRIDGE14_PIN_STATE_LOW 0x00
117 
123 #define HBRIDGE14_DRIVE_MOTOR_CW 0x00
124 #define HBRIDGE14_DRIVE_MOTOR_CCW 0x01
125 #define HBRIDGE14_DRIVE_MOTOR_BRAKE 0x02
126 #define HBRIDGE14_DRIVE_MOTOR_COASTING 0x03
127 
133 #define HBRIDGE14_NONE_PIN 0x00
134 #define HBRIDGE14_SLP_PIN 0x01
135 #define HBRIDGE14_FLT_PIN 0x02
136 #define HBRIDGE14_DIS_PIN 0x04
137 #define HBRIDGE14_ALL_PIN 0x07
138 
144 #define HBRIDGE14_TOF_80_US 0xC0
145 #define HBRIDGE14_TOF_60_US 0x80
146 #define HBRIDGE14_TOF_40_US 0x40
147 #define HBRIDGE14_TOF_20_US 0x00
148 #define HBRIDGE14_SPI_IN_EN 0x20
149 #define HBRIDGE14_SPI_IN_DIS 0x00
150 #define HBRIDGE14_S_SR_2_6V_US 0x1C
151 #define HBRIDGE14_S_SR_5_3V_US 0x18
152 #define HBRIDGE14_S_SR_7_9V_US 0x14
153 #define HBRIDGE14_S_SR_10_8V_US 0x10
154 #define HBRIDGE14_S_SR_13_V_US 0x0C
155 #define HBRIDGE14_S_SR_18_3V_US 0x08
156 #define HBRIDGE14_S_SR_34_V_US 0x04
157 #define HBRIDGE14_S_SR_53_2V_US 0x00
158 #define HBRIDGE14_MODE_DISABLED 0x03
159 #define HBRIDGE14_MODE_INDEPENDENT 0x02
160 #define HBRIDGE14_MODE_PWM 0x01
161 #define HBRIDGE14_MODE_PH_EN 0x00
162 
168 #define HBRIDGE14_ITRIP_REP 0x80
169 #define HBRIDGE14_TSD_MODE_AUTO 0x40
170 #define HBRIDGE14_OTW_REP 0x20
171 #define HBRIDGE14_DIS_CPUV 0x10
172 #define HBRIDGE14_OCP_TRETRY_4_MS 0x0C
173 #define HBRIDGE14_OCP_TRETRY_2_MS 0x08
174 #define HBRIDGE14_OCP_TRETRY_1_MS 0x04
175 #define HBRIDGE14_OCP_TRETRY_500_NS 0x00
176 #define HBRIDGE14_OCP_MODE_NOT_REPORT 0x03
177 #define HBRIDGE14_OCP_MODE_REPORT 0x02
178 #define HBRIDGE14_OCP_MODE_RETRING 0x01
179 #define HBRIDGE14_OCP_MODE_LATCHED 0x00
180 
186 #define HBRIDGE14_CLR_FLT 0x80
187 #define HBRIDGE14_LOCK_REG 0x30
188 #define HBRIDGE14_UNLOCK_REG 0x40
189 #define HBRIDGE14_OUT1_DIS 0x08
190 #define HBRIDGE14_OUT2_DIS 0x04
191 #define HBRIDGE14_EN_IN1 0x02
192 #define HBRIDGE14_PH_IN2 0x01
193 
199 #define HBRIDGE14_EN_OLP 0x40
200 #define HBRIDGE14_OLP_DLY_300_US 0x00
201 #define HBRIDGE14_OLP_DLY_1_2_MS 0x20
202 #define HBRIDGE14_EN_OLA 0x10
203 #define HBRIDGE14_ITRIP_LVL_7_A 0x0C
204 #define HBRIDGE14_ITRIP_LVL_6_5_A 0x08
205 #define HBRIDGE14_ITRIP_LVL_5_4_A 0x04
206 #define HBRIDGE14_ITRIP_LVL_4_A 0x00
207 #define HBRIDGE14_DIS_ITRIP_OUT1_OUT2 0x03
208 #define HBRIDGE14_DIS_ITRIP_OUT2 0x02
209 #define HBRIDGE14_DIS_ITRIP_OUT1 0x01
210 #define HBRIDGE14_DIS_ITRIP 0x00
211 
217 #define HBRIDGE14_DEVICE_ADDRESS_A1A0_00 0x70
218 #define HBRIDGE14_DEVICE_ADDRESS_A1A0_01 0x71
219 #define HBRIDGE14_DEVICE_ADDRESS_A1A0_10 0x72
220 #define HBRIDGE14_DEVICE_ADDRESS_A1A0_11 0x73
221 
230 #define HBRIDGE14_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
231 #define HBRIDGE14_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
232  // hbridge14_set
234 
249 #define HBRIDGE14_MAP_MIKROBUS( cfg, mikrobus ) \
250  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
251  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
252  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
253  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
254  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
255  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
256  cfg.in2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
257  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
258  cfg.in1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
259  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
260  // hbridge14_map // hbridge14
263 
268 typedef struct hbridge14_s
269 {
270  digital_out_t in2;
271  digital_out_t rst;
272  digital_out_t in1;
274  digital_in_t int_pin;
276  i2c_master_t i2c;
277  spi_master_t spi;
279  uint8_t slave_address;
280  pin_name_t chip_select;
283 
288 typedef struct
289 {
290  pin_name_t scl;
291  pin_name_t sda;
292  pin_name_t miso;
293  pin_name_t mosi;
294  pin_name_t sck;
295  pin_name_t cs;
296  pin_name_t in2;
297  pin_name_t rst;
298  pin_name_t in1;
299  pin_name_t int_pin;
301  uint32_t i2c_speed;
302  uint8_t i2c_address;
304  uint32_t spi_speed;
305  spi_master_mode_t spi_mode;
306  spi_master_chip_select_polarity_t cs_polarity;
309 
314 typedef enum
315 {
317  HBRIDGE14_ERROR = -1
318 
320 
337 
352 
366 
381 err_t hbridge14_generic_write ( hbridge14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
382 
397 err_t hbridge14_generic_read ( hbridge14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
398 
408 void hbridge14_set_in1_pin ( hbridge14_t *ctx, uint8_t pin_state );
409 
419 void hbridge14_set_rst_pin ( hbridge14_t *ctx, uint8_t pin_state );
420 
430 
440 
455 err_t hbridge14_register_write ( hbridge14_t *ctx, uint8_t reg, uint8_t data_in );
456 
470 err_t hbridge14_register_read ( hbridge14_t *ctx, uint8_t reg, uint8_t *data_out );
471 
486 err_t hbridge14_port_expander_write ( hbridge14_t *ctx, uint8_t reg, uint8_t data_in );
487 
501 err_t hbridge14_port_expander_read ( hbridge14_t *ctx, uint8_t reg, uint8_t *data_out );
502 
515 err_t hbridge14_set_pins ( hbridge14_t *ctx, uint8_t set_mask, uint8_t clr_mask );
516 
528 err_t hbridge14_disable_state ( hbridge14_t *ctx, uint8_t dis_state );
529 
541 err_t hbridge14_sleep_state ( hbridge14_t *ctx, uint8_t sleep_state );
542 
554 err_t hbridge14_drive_motor ( hbridge14_t *ctx, uint8_t state );
555 
556 #ifdef __cplusplus
557 }
558 #endif
559 #endif // HBRIDGE14_H
560  // hbridge14
562 
563 // ------------------------------------------------------------------------ END
hbridge14_s
H-Bridge 14 Click context object.
Definition: hbridge14.h:269
hbridge14_drive_motor
err_t hbridge14_drive_motor(hbridge14_t *ctx, uint8_t state)
H-Bridge 14 drive motor function.
hbridge14_get_ip_pin
uint8_t hbridge14_get_ip_pin(hbridge14_t *ctx)
H-Bridge 14 get IP pin function.
hbridge14_cfg_t::cs
pin_name_t cs
Definition: hbridge14.h:295
hbridge14_sleep_state
err_t hbridge14_sleep_state(hbridge14_t *ctx, uint8_t sleep_state)
H-Bridge 14 control sleep function.
hbridge14_cfg_t::int_pin
pin_name_t int_pin
Definition: hbridge14.h:299
hbridge14_cfg_t::mosi
pin_name_t mosi
Definition: hbridge14.h:293
hbridge14_s::i2c
i2c_master_t i2c
Definition: hbridge14.h:276
hbridge14_cfg_t::scl
pin_name_t scl
Definition: hbridge14.h:290
HBRIDGE14_OK
@ HBRIDGE14_OK
Definition: hbridge14.h:316
hbridge14_cfg_setup
void hbridge14_cfg_setup(hbridge14_cfg_t *cfg)
H-Bridge 14 configuration object setup function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hbridge14_s::int_pin
digital_in_t int_pin
Definition: hbridge14.h:274
hbridge14_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hbridge14.h:305
hbridge14_cfg_t::i2c_address
uint8_t i2c_address
Definition: hbridge14.h:302
HBRIDGE14_ERROR
@ HBRIDGE14_ERROR
Definition: hbridge14.h:317
hbridge14_cfg_t::sck
pin_name_t sck
Definition: hbridge14.h:294
hbridge14_s::slave_address
uint8_t slave_address
Definition: hbridge14.h:279
hbridge14_cfg_t
H-Bridge 14 Click configuration object.
Definition: hbridge14.h:289
hbridge14_cfg_t::in1
pin_name_t in1
Definition: hbridge14.h:298
hbridge14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hbridge14.h:301
hbridge14_cfg_t::miso
pin_name_t miso
Definition: hbridge14.h:292
hbridge14_cfg_t::sda
pin_name_t sda
Definition: hbridge14.h:291
hbridge14_cfg_t::in2
pin_name_t in2
Definition: hbridge14.h:296
hbridge14_s::in1
digital_out_t in1
Definition: hbridge14.h:272
hbridge14_set_rst_pin
void hbridge14_set_rst_pin(hbridge14_t *ctx, uint8_t pin_state)
H-Bridge 14 set RST pin function.
hbridge14_generic_read
err_t hbridge14_generic_read(hbridge14_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
H-Bridge 14 data reading function.
hbridge14_cfg_t::rst
pin_name_t rst
Definition: hbridge14.h:297
hbridge14_disable_state
err_t hbridge14_disable_state(hbridge14_t *ctx, uint8_t dis_state)
H-Bridge 14 control disable function.
hbridge14_set_pins
err_t hbridge14_set_pins(hbridge14_t *ctx, uint8_t set_mask, uint8_t clr_mask)
H-Bridge 14 set pins function.
hbridge14_return_value_t
hbridge14_return_value_t
H-Bridge 14 Click return value data.
Definition: hbridge14.h:315
hbridge14_get_int_pin
uint8_t hbridge14_get_int_pin(hbridge14_t *ctx)
H-Bridge 14 get INT pin function.
hbridge14_init
err_t hbridge14_init(hbridge14_t *ctx, hbridge14_cfg_t *cfg)
H-Bridge 14 initialization function.
hbridge14_s::chip_select
pin_name_t chip_select
Definition: hbridge14.h:280
hbridge14_set_in1_pin
void hbridge14_set_in1_pin(hbridge14_t *ctx, uint8_t pin_state)
H-Bridge 14 set IN1 pin function.
hbridge14_t
struct hbridge14_s hbridge14_t
H-Bridge 14 Click context object.
hbridge14_s::spi
spi_master_t spi
Definition: hbridge14.h:277
hbridge14_s::in2
digital_out_t in2
Definition: hbridge14.h:270
hbridge14_cfg_t::spi_speed
uint32_t spi_speed
Definition: hbridge14.h:304
hbridge14_register_write
err_t hbridge14_register_write(hbridge14_t *ctx, uint8_t reg, uint8_t data_in)
H-Bridge 14 data register writing function.
hbridge14_generic_write
err_t hbridge14_generic_write(hbridge14_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
H-Bridge 14 data writing function.
hbridge14_s::rst
digital_out_t rst
Definition: hbridge14.h:271
hbridge14_register_read
err_t hbridge14_register_read(hbridge14_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 14 data register reading function.
hbridge14_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hbridge14.h:306
hbridge14_default_cfg
err_t hbridge14_default_cfg(hbridge14_t *ctx)
H-Bridge 14 default configuration function.
hbridge14_port_expander_read
err_t hbridge14_port_expander_read(hbridge14_t *ctx, uint8_t reg, uint8_t *data_out)
H-Bridge 14 port ecpander read register function.
hbridge14_port_expander_write
err_t hbridge14_port_expander_write(hbridge14_t *ctx, uint8_t reg, uint8_t data_in)
H-Bridge 14 port ecpander write register function.