hbridge5  2.0.0.0
hbridge5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef HBRIDGE5_H
36 #define HBRIDGE5_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define HBRIDGE5_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
58 
64 #define HBRIDGE5_RETVAL uint8_t
65 
66 #define HBRIDGE5_OK 0x00
67 #define HBRIDGE5_INIT_ERROR 0xFF
68 
74 #define HBRIDGE5_DEVICE_SLAVE_ADDR_0_0 0x70
75 #define HBRIDGE5_DEVICE_SLAVE_ADDR_0_1 0x71
76 #define HBRIDGE5_DEVICE_SLAVE_ADDR_1_0 0x72
77 #define HBRIDGE5_DEVICE_SLAVE_ADDR_1_1 0x73
78 
84 #define HBRIDGE5_CMD_INPUT_PORT 0x00
85 #define HBRIDGE5_CMD_OUTPUT_PORT 0x01
86 #define HBRIDGE5_CMD_POLARITY_INVERSION 0x02
87 #define HBRIDGE5_CMD_CONFIGURATION 0x03
88 
94 #define HBRIDGE5_PORT_PHASE 0x01
95 #define HBRIDGE5_PORT_ENABLE 0x02
96 #define HBRIDGE5_PORT_BRAKE 0x04
97 #define HBRIDGE5_PORT_B_MODE 0x08
98 #define HBRIDGE5_PORT_N_SLEEP 0x10
99 #define HBRIDGE5_PORT_N_FAULT 0x20
100 
106 #define HBRIDGE5_ENABLE_ALL_OUTPUT_PORT 0xE0
107 #define HBRIDGE5_DISABLE_ALL_OUTPUT_PORT 0xFF
108  // End group macro
111 // --------------------------------------------------------------- PUBLIC TYPES
120 typedef struct
121 {
122  // Output pins
123 
124  digital_out_t rst;
125 
126  // Input pins
127 
128  digital_in_t an;
129  digital_in_t int_pin;
130 
131  // Modules
132 
133  i2c_master_t i2c;
134 
135  // ctx variable
136 
137  uint8_t slave_address;
138 
139 } hbridge5_t;
140 
144 typedef struct
145 {
146  // Communication gpio pins
147 
148  pin_name_t scl;
149  pin_name_t sda;
150 
151  // Additional gpio pins
152 
153  pin_name_t an;
154  pin_name_t rst;
155  pin_name_t int_pin;
156 
157  // static variable
158 
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
161 
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
185 
195 
204 
215 void hbridge5_generic_write ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
216 
227 void hbridge5_generic_read ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
228 
237 void hbridge5_rst_state ( hbridge5_t *ctx, uint8_t state );
238 
247 
258 uint8_t hbridge5_read_byte ( hbridge5_t *ctx, uint8_t cmd );
259 
269 void hbridge5_write_byte ( hbridge5_t *ctx, uint8_t cmd, uint8_t data_in );
270 
280 void hbridge5_set_port ( hbridge5_t *ctx, uint8_t port, uint8_t value );
281 
291 
300 
309 
318 
327 
336 
345 void hbridge5_sleep( hbridge5_t *ctx, uint8_t state );
346 
355 void hbridge5_configuration ( hbridge5_t *ctx, uint8_t cfg_data );
356 
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 #endif // _HBRIDGE5_H_
370  // End public_function group
373 
374 // ------------------------------------------------------------------------- END
hbridge5_sync_decay_rev
void hbridge5_sync_decay_rev(hbridge5_t *ctx)
Synchronization fast decay reverse function.
hbridge5_brake_high
void hbridge5_brake_high(hbridge5_t *ctx)
Puts motor to a halt.
hbridge5_cfg_t::i2c_address
uint8_t i2c_address
Definition: hbridge5.h:160
hbridge5_cfg_t::an
pin_name_t an
Definition: hbridge5.h:153
hbridge5_rst_state
void hbridge5_rst_state(hbridge5_t *ctx, uint8_t state)
Resets pin state.
hbridge5_sleep
void hbridge5_sleep(hbridge5_t *ctx, uint8_t state)
Sleep function.
hbridge5_read_byte
uint8_t hbridge5_read_byte(hbridge5_t *ctx, uint8_t cmd)
Function reads byte from register.
hbridge5_get_interrupt_state
uint8_t hbridge5_get_interrupt_state(hbridge5_t *ctx)
Reads interrupt pin state.
hbridge5_cfg_setup
void hbridge5_cfg_setup(hbridge5_cfg_t *cfg)
Config Object Initialization function.
hbridge5_t::i2c
i2c_master_t i2c
Definition: hbridge5.h:133
hbridge5_sync_decay_fwd
void hbridge5_sync_decay_fwd(hbridge5_t *ctx)
Synchronization fast decay foreward function.
hbridge5_configuration
void hbridge5_configuration(hbridge5_t *ctx, uint8_t cfg_data)
Configuration function.
hbridge5_write_byte
void hbridge5_write_byte(hbridge5_t *ctx, uint8_t cmd, uint8_t data_in)
Function writes one byte in register.
hbridge5_cfg_t::scl
pin_name_t scl
Definition: hbridge5.h:148
hbridge5_cfg_t::int_pin
pin_name_t int_pin
Definition: hbridge5.h:155
hbridge5_cfg_t::rst
pin_name_t rst
Definition: hbridge5.h:154
hbridge5_default_cfg
void hbridge5_default_cfg(hbridge5_t *ctx)
Click Default Configuration function.
hbridge5_cfg_t::sda
pin_name_t sda
Definition: hbridge5.h:149
hbridge5_forward
void hbridge5_forward(hbridge5_t *ctx)
Puts motor into forward motion.
hbridge5_generic_read
void hbridge5_generic_read(hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
hbridge5_t::slave_address
uint8_t slave_address
Definition: hbridge5.h:137
hbridge5_t
Click ctx object definition.
Definition: hbridge5.h:121
hbridge5_reverse
void hbridge5_reverse(hbridge5_t *ctx)
Puts motor into reverse motion.
hbridge5_t::int_pin
digital_in_t int_pin
Definition: hbridge5.h:129
hbridge5_generic_write
void hbridge5_generic_write(hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
hbridge5_set_port
void hbridge5_set_port(hbridge5_t *ctx, uint8_t port, uint8_t value)
Function sets port.
hbridge5_n_fault_check
uint8_t hbridge5_n_fault_check(hbridge5_t *ctx)
N fault check function.
hbridge5_init
HBRIDGE5_RETVAL hbridge5_init(hbridge5_t *ctx, hbridge5_cfg_t *cfg)
Initialization function.
hbridge5_cfg_t
Click configuration structure definition.
Definition: hbridge5.h:145
hbridge5_t::an
digital_in_t an
Definition: hbridge5.h:128
hbridge5_brake_low
void hbridge5_brake_low(hbridge5_t *ctx)
Puts motor to a halt.
HBRIDGE5_RETVAL
#define HBRIDGE5_RETVAL
Definition: hbridge5.h:64
hbridge5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hbridge5.h:159
hbridge5_t::rst
digital_out_t rst
Definition: hbridge5.h:124