hbridge12 2.1.0.0
hbridge12.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 HBRIDGE12_H
29#define HBRIDGE12_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define HBRIDGE12_ADDR_AB 0x00
75#define HBRIDGE12_ADDR_CD 0x01
76
77 // hbridge12_reg
78
93#define HBRIDGE12_CURRENT_SCALE_20_PER 0x00
94#define HBRIDGE12_CURRENT_SCALE_38_PER 0x04
95#define HBRIDGE12_CURRENT_SCALE_56_PER 0x02
96#define HBRIDGE12_CURRENT_SCALE_71_PER 0x06
97#define HBRIDGE12_CURRENT_SCALE_83_PER 0x01
98#define HBRIDGE12_CURRENT_SCALE_92_PER 0x05
99#define HBRIDGE12_CURRENT_SCALE_98_PER 0x03
100#define HBRIDGE12_CURRENT_SCALE_100_PER 0x07
101
106#define HBRIDGE12_PHASE_OUT1_H_OUT2_L 0x01
107#define HBRIDGE12_PHASE_OUT1_L_OUT2_H 0x00
108
113#define HBRIDGE12_ENABLE_BRIDGE_OUTPUT 0x01
114#define HBRIDGE12_DISABLE_BRIDGE_OUTPUT 0x00
115
120#define HBRIDGE12_AB_BRIDGE_SEL 0x00
121#define HBRIDGE12_CD_BRIDGE_SEL 0x01
122
127#define HBRIDGE12_PIN_STATE_LOW 0x00
128#define HBRIDGE12_PIN_STATE_HIGH 0x01
129
138#define HBRIDGE12_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
139#define HBRIDGE12_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
140
141 // hbridge12_set
142
157#define HBRIDGE12_MAP_MIKROBUS( cfg, mikrobus ) \
158 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
159 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
160 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
161 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
162 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
163 cfg.slp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
164 cfg.stb = MIKROBUS( mikrobus, MIKROBUS_AN )
165
166 // hbridge12_map
167 // hbridge12
168
173typedef struct
174{
175 uint8_t addr;
176 uint8_t ch1_en;
177 uint8_t ch1_phase;
179 uint8_t ch1_decay;
180 uint8_t ch2_en;
181 uint8_t ch2_phase;
183 uint8_t ch2_decay;
186
191typedef struct
192{
193 // Output pins
194 digital_out_t rst;
195 digital_out_t slp;
196 digital_out_t stb;
198 // Configuration structures
202 // Modules
203 spi_master_t spi;
205 pin_name_t chip_select;
208
213typedef struct
214{
215 // Communication gpio pins
216 pin_name_t miso;
217 pin_name_t mosi;
218 pin_name_t sck;
219 pin_name_t cs;
221 // Additional gpio pins
222 pin_name_t rst;
223 pin_name_t slp;
224 pin_name_t stb;
226 // static variable
227 uint32_t spi_speed;
228 spi_master_mode_t spi_mode;
229 spi_master_chip_select_polarity_t cs_polarity;
232
243
260
275
289
299void hbridge12_set_rst ( hbridge12_t *ctx, uint8_t pin_state );
300
310void hbridge12_set_slp ( hbridge12_t *ctx, uint8_t pin_state );
311
321void hbridge12_set_strobe ( hbridge12_t *ctx, uint8_t pin_state );
322
332
343void hbridge12_get_settings ( hbridge12_t *ctx, uint8_t channel_sel, hbridge12_config_t *config_data );
344
356void hbridge12_set_settings ( hbridge12_t *ctx, uint8_t channel_sel, hbridge12_config_t config_data );
357
358
372
385void hbridge12_set_current_scale ( hbridge12_t *ctx, uint8_t channel_sel, uint8_t out1_curr_scale,
386 uint8_t out2_curr_scale );
387
400void hbridge12_set_decay ( hbridge12_t *ctx, uint8_t channel_sel, uint8_t out1_decay,
401 uint8_t out2_decay );
402
414err_t hbridge12_turn_clockwise ( hbridge12_t *ctx, uint8_t channel_sel );
415
427err_t hbridge12_turn_counterclockwise ( hbridge12_t *ctx, uint8_t channel_sel );
428
440err_t hbridge12_turn_brake_on ( hbridge12_t *ctx, uint8_t channel_sel );
441
453err_t hbridge12_freewheeling_on ( hbridge12_t *ctx, uint8_t channel_sel );
454
455#ifdef __cplusplus
456}
457#endif
458#endif // HBRIDGE12_H
459
460 // hbridge12
461
462// ------------------------------------------------------------------------ END
void hbridge12_set_decay(hbridge12_t *ctx, uint8_t channel_sel, uint8_t out1_decay, uint8_t out2_decay)
H-Bridge 12 set decay function.
void hbridge12_set_settings(hbridge12_t *ctx, uint8_t channel_sel, hbridge12_config_t config_data)
H-Bridge 12 set settings function.
err_t hbridge12_init(hbridge12_t *ctx, hbridge12_cfg_t *cfg)
H-Bridge 12 initialization function.
void hbridge12_cfg_setup(hbridge12_cfg_t *cfg)
H-Bridge 12 configuration object setup function.
err_t hbridge12_turn_clockwise(hbridge12_t *ctx, uint8_t channel_sel)
H-Bridge 12 turn motor clockwise function.
err_t hbridge12_turn_counterclockwise(hbridge12_t *ctx, uint8_t channel_sel)
H-Bridge 12 turn motor counterclockwise function.
err_t hbridge12_freewheeling_on(hbridge12_t *ctx, uint8_t channel_sel)
H-Bridge 12 set motor into freewheeling mode function.
err_t hbridge12_turn_brake_on(hbridge12_t *ctx, uint8_t channel_sel)
H-Bridge 12 turn motor brake on function.
void hbridge12_set_rst(hbridge12_t *ctx, uint8_t pin_state)
H-Bridge 12 set RST pin state function.
void hbridge12_set_current_scale(hbridge12_t *ctx, uint8_t channel_sel, uint8_t out1_curr_scale, uint8_t out2_curr_scale)
H-Bridge 12 set current scale function.
err_t hbridge12_write_config(hbridge12_t *ctx, hbridge12_config_t config_data)
H-Bridge 12 write settings function.
void hbridge12_set_strobe(hbridge12_t *ctx, uint8_t pin_state)
H-Bridge 12 set STB pin state function.
void hbridge12_get_settings(hbridge12_t *ctx, uint8_t channel_sel, hbridge12_config_t *config_data)
H-Bridge 12 get settings function.
void hbridge12_set_slp(hbridge12_t *ctx, uint8_t pin_state)
H-Bridge 12 set SLP pin state function.
void hbridge12_generate_strobe(hbridge12_t *ctx)
H-Bridge 12 generate strobe signal function.
err_t hbridge12_default_cfg(hbridge12_t *ctx)
H-Bridge 12 default configuration function.
hbridge12_return_value_t
H-Bridge 12 Click return value data.
Definition hbridge12.h:238
@ HBRIDGE12_OK
Definition hbridge12.h:239
@ HBRIDGE12_ERROR
Definition hbridge12.h:240
This file contains SPI specific macros, functions, etc.
H-Bridge 12 Click configuration object.
Definition hbridge12.h:214
pin_name_t slp
Definition hbridge12.h:223
spi_master_chip_select_polarity_t cs_polarity
Definition hbridge12.h:229
pin_name_t sck
Definition hbridge12.h:218
spi_master_mode_t spi_mode
Definition hbridge12.h:228
pin_name_t mosi
Definition hbridge12.h:217
uint32_t spi_speed
Definition hbridge12.h:227
pin_name_t miso
Definition hbridge12.h:216
pin_name_t rst
Definition hbridge12.h:222
pin_name_t stb
Definition hbridge12.h:224
pin_name_t cs
Definition hbridge12.h:219
H-Bridge 12 Click configuration structure.
Definition hbridge12.h:174
uint8_t ch2_decay
Definition hbridge12.h:183
uint8_t ch1_cur_scale
Definition hbridge12.h:178
uint8_t ch2_cur_scale
Definition hbridge12.h:182
uint8_t ch1_en
Definition hbridge12.h:176
uint8_t ch2_phase
Definition hbridge12.h:181
uint8_t ch2_en
Definition hbridge12.h:180
uint8_t ch1_phase
Definition hbridge12.h:177
uint8_t addr
Definition hbridge12.h:175
uint8_t ch1_decay
Definition hbridge12.h:179
H-Bridge 12 Click context object.
Definition hbridge12.h:192
spi_master_t spi
Definition hbridge12.h:203
digital_out_t slp
Definition hbridge12.h:195
digital_out_t stb
Definition hbridge12.h:196
hbridge12_config_t ab_config_data
Definition hbridge12.h:199
digital_out_t rst
Definition hbridge12.h:194
hbridge12_config_t cd_config_data
Definition hbridge12.h:200
pin_name_t chip_select
Definition hbridge12.h:205