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 )
78#define HBRIDGE5_RETVAL uint8_t
79
80#define HBRIDGE5_OK 0x00
81#define HBRIDGE5_INIT_ERROR 0xFF
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
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
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
120#define HBRIDGE5_ENABLE_ALL_OUTPUT_PORT 0xE0
121#define HBRIDGE5_DISABLE_ALL_OUTPUT_PORT 0xFF
124 // End group macro
125// --------------------------------------------------------------- PUBLIC TYPES
134typedef 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
152
153} hbridge5_t;
154
158typedef 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
178 // End types group
179// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
180
186#ifdef __cplusplus
187extern "C"{
188#endif
189
199
209
218
229void hbridge5_generic_write ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230
241void hbridge5_generic_read ( hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242
251void hbridge5_rst_state ( hbridge5_t *ctx, uint8_t state );
252
261
272uint8_t hbridge5_read_byte ( hbridge5_t *ctx, uint8_t cmd );
273
283void hbridge5_write_byte ( hbridge5_t *ctx, uint8_t cmd, uint8_t data_in );
284
294void hbridge5_set_port ( hbridge5_t *ctx, uint8_t port, uint8_t value );
295
305
314
323
332
341
350
359void hbridge5_sleep( hbridge5_t *ctx, uint8_t state );
360
369void hbridge5_configuration ( hbridge5_t *ctx, uint8_t cfg_data );
370
379
380#ifdef __cplusplus
381}
382#endif
383#endif // _HBRIDGE5_H_
384
385 // End public_function group
387
388// ------------------------------------------------------------------------- END
#define HBRIDGE5_RETVAL
Definition hbridge5.h:78
void hbridge5_cfg_setup(hbridge5_cfg_t *cfg)
Config Object Initialization function.
HBRIDGE5_RETVAL hbridge5_init(hbridge5_t *ctx, hbridge5_cfg_t *cfg)
Initialization function.
void hbridge5_generic_write(hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void hbridge5_forward(hbridge5_t *ctx)
Puts motor into forward motion.
void hbridge5_sync_decay_rev(hbridge5_t *ctx)
Synchronization fast decay reverse function.
void hbridge5_write_byte(hbridge5_t *ctx, uint8_t cmd, uint8_t data_in)
Function writes one byte in register.
void hbridge5_set_port(hbridge5_t *ctx, uint8_t port, uint8_t value)
Function sets port.
void hbridge5_reverse(hbridge5_t *ctx)
Puts motor into reverse motion.
void hbridge5_configuration(hbridge5_t *ctx, uint8_t cfg_data)
Configuration function.
uint8_t hbridge5_get_interrupt_state(hbridge5_t *ctx)
Reads interrupt pin state.
void hbridge5_default_cfg(hbridge5_t *ctx)
Click Default Configuration function.
void hbridge5_sleep(hbridge5_t *ctx, uint8_t state)
Sleep function.
void hbridge5_brake_high(hbridge5_t *ctx)
Puts motor to a halt.
void hbridge5_rst_state(hbridge5_t *ctx, uint8_t state)
Resets pin state.
uint8_t hbridge5_n_fault_check(hbridge5_t *ctx)
N fault check function.
void hbridge5_generic_read(hbridge5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t hbridge5_read_byte(hbridge5_t *ctx, uint8_t cmd)
Function reads byte from register.
void hbridge5_sync_decay_fwd(hbridge5_t *ctx)
Synchronization fast decay foreward function.
void hbridge5_brake_low(hbridge5_t *ctx)
Puts motor to a halt.
Click configuration structure definition.
Definition hbridge5.h:159
uint32_t i2c_speed
Definition hbridge5.h:173
pin_name_t scl
Definition hbridge5.h:162
pin_name_t int_pin
Definition hbridge5.h:169
pin_name_t sda
Definition hbridge5.h:163
pin_name_t rst
Definition hbridge5.h:168
pin_name_t an
Definition hbridge5.h:167
uint8_t i2c_address
Definition hbridge5.h:174
Click ctx object definition.
Definition hbridge5.h:135
digital_in_t int_pin
Definition hbridge5.h:143
i2c_master_t i2c
Definition hbridge5.h:147
digital_in_t an
Definition hbridge5.h:142
digital_out_t rst
Definition hbridge5.h:138
uint8_t slave_address
Definition hbridge5.h:151