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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define HBRIDGE5_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
72 
78 #define HBRIDGE5_RETVAL uint8_t
79 
80 #define HBRIDGE5_OK 0x00
81 #define HBRIDGE5_INIT_ERROR 0xFF
82 
88 #define HBRIDGE5_DEVICE_SLAVE_ADDR_0_0 0x70
89 #define HBRIDGE5_DEVICE_SLAVE_ADDR_0_1 0x71
90 #define HBRIDGE5_DEVICE_SLAVE_ADDR_1_0 0x72
91 #define HBRIDGE5_DEVICE_SLAVE_ADDR_1_1 0x73
92 
98 #define HBRIDGE5_CMD_INPUT_PORT 0x00
99 #define HBRIDGE5_CMD_OUTPUT_PORT 0x01
100 #define HBRIDGE5_CMD_POLARITY_INVERSION 0x02
101 #define HBRIDGE5_CMD_CONFIGURATION 0x03
102 
108 #define HBRIDGE5_PORT_PHASE 0x01
109 #define HBRIDGE5_PORT_ENABLE 0x02
110 #define HBRIDGE5_PORT_BRAKE 0x04
111 #define HBRIDGE5_PORT_B_MODE 0x08
112 #define HBRIDGE5_PORT_N_SLEEP 0x10
113 #define HBRIDGE5_PORT_N_FAULT 0x20
114 
120 #define HBRIDGE5_ENABLE_ALL_OUTPUT_PORT 0xE0
121 #define HBRIDGE5_DISABLE_ALL_OUTPUT_PORT 0xFF
122  // End group macro
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136  // Output pins
137 
138  digital_out_t rst;
139 
140  // Input pins
141 
142  digital_in_t an;
143  digital_in_t int_pin;
144 
145  // Modules
146 
147  i2c_master_t i2c;
148 
149  // ctx variable
150 
151  uint8_t slave_address;
152 
153 } hbridge5_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // Additional gpio pins
166 
167  pin_name_t an;
168  pin_name_t rst;
169  pin_name_t int_pin;
170 
171  // static variable
172 
173  uint32_t i2c_speed;
174  uint8_t i2c_address;
175 
177  // End types group
179 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
180 
186 #ifdef __cplusplus
187 extern "C"{
188 #endif
189 
199 
209 
218 
229 void hbridge5_generic_write ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230 
241 void hbridge5_generic_read ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242 
251 void hbridge5_rst_state ( hbridge5_t *ctx, uint8_t state );
252 
261 
272 uint8_t hbridge5_read_byte ( hbridge5_t *ctx, uint8_t cmd );
273 
283 void hbridge5_write_byte ( hbridge5_t *ctx, uint8_t cmd, uint8_t data_in );
284 
294 void hbridge5_set_port ( hbridge5_t *ctx, uint8_t port, uint8_t value );
295 
305 
314 
323 
332 
341 
350 
359 void hbridge5_sleep( hbridge5_t *ctx, uint8_t state );
360 
369 void hbridge5_configuration ( hbridge5_t *ctx, uint8_t cfg_data );
370 
379 
380 #ifdef __cplusplus
381 }
382 #endif
383 #endif // _HBRIDGE5_H_
384  // End public_function group
387 
388 // ------------------------------------------------------------------------- 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:174
hbridge5_cfg_t::an
pin_name_t an
Definition: hbridge5.h:167
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:147
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:162
hbridge5_cfg_t::int_pin
pin_name_t int_pin
Definition: hbridge5.h:169
hbridge5_cfg_t::rst
pin_name_t rst
Definition: hbridge5.h:168
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:163
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:151
hbridge5_t
Click ctx object definition.
Definition: hbridge5.h:135
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:143
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:159
hbridge5_t::an
digital_in_t an
Definition: hbridge5.h:142
hbridge5_brake_low
void hbridge5_brake_low(hbridge5_t *ctx)
Puts motor to a halt.
HBRIDGE5_RETVAL
#define HBRIDGE5_RETVAL
Definition: hbridge5.h:78
hbridge5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: hbridge5.h:173
hbridge5_t::rst
digital_out_t rst
Definition: hbridge5.h:138