hbridge10  2.0.0.0
hbridge10.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 HBRIDGE10_H
29 #define HBRIDGE10_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_spi_master.h"
48 #include "spi_specifics.h"
49 #include "drv_analog_in.h"
50 
71 #define HBRIDGE10_IN_STATUS_RESET 0x8000
72 #define HBRIDGE10_IN_OUT_LS1_ON 0x1000
73 #define HBRIDGE10_IN_OUT_HS1_ON 0x0800
74 #define HBRIDGE10_IN_OUT_LS2_ON 0x0100
75 #define HBRIDGE10_IN_OUT_HS2_ON 0x0080
76 #define HBRIDGE10_IN_OUT_LS3_ON 0x0010
77 #define HBRIDGE10_IN_OUT_HS3_ON 0x0008
78 #define HBRIDGE10_IN_OPEN_LOAD_OFF 0x0004
79 #define HBRIDGE10_IN_SHORT_SD_DELAY_12MS 0x0002
80 #define HBRIDGE10_IN_SHORT_SD_DELAY_1p5MS 0x0000
81 #define HBRIDGE10_IN_SOFT_ENABLE 0x0001
82 
87 #define HBRIDGE10_OUT_OVER_TEMP_SD 0xFFFF
88 #define HBRIDGE10_OUT_OVER_TEMP_WARNING 0x8000
89 #define HBRIDGE10_OUT_STATUS_LS1_ON 0x1000
90 #define HBRIDGE10_OUT_STATUS_HS1_ON 0x0800
91 #define HBRIDGE10_OUT_STATUS_LS2_ON 0x0100
92 #define HBRIDGE10_OUT_STATUS_HS2_ON 0x0080
93 #define HBRIDGE10_OUT_STATUS_LS3_ON 0x0010
94 #define HBRIDGE10_OUT_STATUS_HS3_ON 0x0008
95 #define HBRIDGE10_OUT_SHORT_CIRCUIT_DETECTED 0x0004
96 #define HBRIDGE10_OUT_NORMAL_OPERATION 0x0002
97 #define HBRIDGE10_OUT_VS_UNDER_VOLTAGE 0x0001
98 
103 #define HBRIDGE10_CHANNEL_OUT1 1
104 #define HBRIDGE10_CHANNEL_OUT2 2
105 #define HBRIDGE10_CHANNEL_OUT3 3
106 #define HBRIDGE10_OUT_OFF 0
107 #define HBRIDGE10_OUT_HIGH 1
108 #define HBRIDGE10_OUT_LOW 2
109 #define HBRIDGE10_OUT_MASK 3u
110 
115 #define HBRIDGE10_ADC_VREF 3.3
116 
125 #define HBRIDGE10_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
126 #define HBRIDGE10_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
127  // hbridge10_set
129 
144 #define HBRIDGE10_MAP_MIKROBUS( cfg, mikrobus ) \
145  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
146  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
147  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
148  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
149  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
150  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
151  cfg.flt = MIKROBUS( mikrobus, MIKROBUS_INT )
152  // hbridge10_map // hbridge10
155 
160 typedef struct
161 {
162  // Output pins
163  digital_out_t en;
165  // Input pins
166  digital_in_t flt;
168  // Modules
169  analog_in_t adc;
170  spi_master_t spi;
172  pin_name_t chip_select;
174  uint16_t input_data;
176 } hbridge10_t;
177 
182 typedef struct
183 {
184  // Communication gpio pins
185  pin_name_t miso;
186  pin_name_t mosi;
187  pin_name_t sck;
188  pin_name_t cs;
190  // Additional gpio pins
191  pin_name_t an;
192  pin_name_t en;
193  pin_name_t flt;
195  // static variable
196  uint32_t spi_speed;
197  spi_master_mode_t spi_mode;
198  spi_master_chip_select_polarity_t cs_polarity;
200  analog_in_resolution_t resolution;
201  float vref;
204 
209 typedef enum
210 {
212  HBRIDGE10_ERROR = -1
213 
215 
232 
247 
261 
275 err_t hbridge10_transfer_data ( hbridge10_t *ctx, uint16_t data_in, uint16_t *data_out );
276 
291 err_t hbridge10_set_output_state ( hbridge10_t *ctx, uint8_t channel, uint8_t state );
292 
304 err_t hbridge10_get_status ( hbridge10_t *ctx, uint16_t *status );
305 
317 err_t hbridge10_read_an_pin_value ( hbridge10_t *ctx, uint16_t *data_out );
318 
332 err_t hbridge10_read_an_pin_voltage ( hbridge10_t *ctx, float *data_out );
333 
343 
353 
363 
364 #ifdef __cplusplus
365 }
366 #endif
367 #endif // HBRIDGE10_H
368  // hbridge10
370 
371 // ------------------------------------------------------------------------ END
hbridge10_cfg_t::flt
pin_name_t flt
Definition: hbridge10.h:193
hbridge10_cfg_setup
void hbridge10_cfg_setup(hbridge10_cfg_t *cfg)
H-Bridge 10 configuration object setup function.
hbridge10_disable_device
void hbridge10_disable_device(hbridge10_t *ctx)
H-Bridge 10 disable device function.
hbridge10_t::en
digital_out_t en
Definition: hbridge10.h:163
hbridge10_get_fault_pin
uint8_t hbridge10_get_fault_pin(hbridge10_t *ctx)
H-Bridge 10 get fault function.
hbridge10_cfg_t::cs
pin_name_t cs
Definition: hbridge10.h:188
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hbridge10_t::input_data
uint16_t input_data
Definition: hbridge10.h:174
hbridge10_cfg_t::miso
pin_name_t miso
Definition: hbridge10.h:185
hbridge10_cfg_t
H-Bridge 10 Click configuration object.
Definition: hbridge10.h:183
hbridge10_cfg_t::an
pin_name_t an
Definition: hbridge10.h:191
hbridge10_read_an_pin_voltage
err_t hbridge10_read_an_pin_voltage(hbridge10_t *ctx, float *data_out)
H-Bridge 10 read AN pin voltage level function.
hbridge10_cfg_t::spi_speed
uint32_t spi_speed
Definition: hbridge10.h:196
hbridge10_cfg_t::sck
pin_name_t sck
Definition: hbridge10.h:187
hbridge10_t::spi
spi_master_t spi
Definition: hbridge10.h:170
HBRIDGE10_OK
@ HBRIDGE10_OK
Definition: hbridge10.h:211
hbridge10_t::chip_select
pin_name_t chip_select
Definition: hbridge10.h:172
hbridge10_t
H-Bridge 10 Click context object.
Definition: hbridge10.h:161
hbridge10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hbridge10.h:198
hbridge10_set_output_state
err_t hbridge10_set_output_state(hbridge10_t *ctx, uint8_t channel, uint8_t state)
H-Bridge 10 set output state function.
hbridge10_return_value_t
hbridge10_return_value_t
H-Bridge 10 Click return value data.
Definition: hbridge10.h:210
hbridge10_read_an_pin_value
err_t hbridge10_read_an_pin_value(hbridge10_t *ctx, uint16_t *data_out)
H-Bridge 10 read AN pin value function.
hbridge10_cfg_t::en
pin_name_t en
Definition: hbridge10.h:192
hbridge10_t::adc
analog_in_t adc
Definition: hbridge10.h:169
hbridge10_t::flt
digital_in_t flt
Definition: hbridge10.h:166
hbridge10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hbridge10.h:197
hbridge10_cfg_t::mosi
pin_name_t mosi
Definition: hbridge10.h:186
hbridge10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: hbridge10.h:200
HBRIDGE10_ERROR
@ HBRIDGE10_ERROR
Definition: hbridge10.h:212
hbridge10_get_status
err_t hbridge10_get_status(hbridge10_t *ctx, uint16_t *status)
H-Bridge 10 get status function.
hbridge10_default_cfg
err_t hbridge10_default_cfg(hbridge10_t *ctx)
H-Bridge 10 default configuration function.
hbridge10_cfg_t::vref
float vref
Definition: hbridge10.h:201
hbridge10_init
err_t hbridge10_init(hbridge10_t *ctx, hbridge10_cfg_t *cfg)
H-Bridge 10 initialization function.
hbridge10_enable_device
void hbridge10_enable_device(hbridge10_t *ctx)
H-Bridge 10 enable device function.
hbridge10_transfer_data
err_t hbridge10_transfer_data(hbridge10_t *ctx, uint16_t data_in, uint16_t *data_out)
H-Bridge 10 transfer data function.