buckboost4  2.1.0.0
buckboost4.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 BUCKBOOST4_H
29 #define BUCKBOOST4_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_i2c_master.h"
48 
69 #define BUCKBOOST4_REG_REF_MSB 0x00
70 #define BUCKBOOST4_REG_REF_LSB 0x01
71 #define BUCKBOOST4_REG_IOUT_LIMIT 0x02
72 #define BUCKBOOST4_REG_VOUT_SR 0x03
73 #define BUCKBOOST4_REG_VOUT_FS 0x04
74 #define BUCKBOOST4_REG_CDC 0x05
75 #define BUCKBOOST4_REG_MODE 0x06
76 #define BUCKBOOST4_REG_STATUS 0x07
77  // buckboost4_reg
79 
94 #define BUCKBOOST4_VREF_MV_MIN 45.0f
95 #define BUCKBOOST4_VREF_MV_MAX 1200.0f
96 #define BUCKBOOST4_VREF_MV_STEP 0.5645f
97 
102 #define BUCKBOOST4_IOUT_LIMIT_CT_DIS 0x00
103 #define BUCKBOOST4_IOUT_LIMIT_CT_EN 0x01
104 #define BUCKBOOST4_IOUT_LIMIT_CLTV_MIN 0.0f
105 #define BUCKBOOST4_IOUT_LIMIT_CLTV_MAX 63.5f
106 #define BUCKBOOST4_IOUT_LIMIT_CLTV_STEP 0.5f
107 
112 #define BUCKBOOST4_VOUT_SR_OCP_DELAY_128_US 0x00
113 #define BUCKBOOST4_VOUT_SR_OCP_DELAY_3_S 0x01
114 #define BUCKBOOST4_VOUT_SR_OCP_DELAY_6_S 0x02
115 #define BUCKBOOST4_VOUT_SR_OCP_DELAY_12_S 0x03
116 #define BUCKBOOST4_VOUT_SR_OCP_DELAY_BIT_MASK 0xCF
117 
122 #define BUCKBOOST4_VOUT_SR_SR_MV_US_1_25 0x00
123 #define BUCKBOOST4_VOUT_SR_SR_MV_US_2_5 0x01
124 #define BUCKBOOST4_VOUT_SR_SR_MV_US_5 0x02
125 #define BUCKBOOST4_VOUT_SR_SR_MV_US_10 0x03
126 #define BUCKBOOST4_VOUT_SR_SR_BIT_MASK 0xFC
127 
132 #define BUCKBOOST4_VOUT_FS_FB_EXT 0x80
133 #define BUCKBOOST4_VOUT_FS_INTFB_0_2256 0x00
134 #define BUCKBOOST4_VOUT_FS_INTFB_0_1128 0x01
135 #define BUCKBOOST4_VOUT_FS_INTFB_0_0752 0x02
136 #define BUCKBOOST4_VOUT_FS_INTFB_0_0564 0x03
137 #define BUCKBOOST4_VOUT_FS_INTFB_BIT_MASK 0xFC
138 
143 #define BUCKBOOST4_MODE_OE_EN 0x80
144 #define BUCKBOOST4_MODE_FSWDBL_DIS 0x00
145 #define BUCKBOOST4_MODE_FSWDBL_EN 0x01
146 #define BUCKBOOST4_MODE_HICCUP_DIS 0x00
147 #define BUCKBOOST4_MODE_HICCUP_EN 0x01
148 #define BUCKBOOST4_MODE_DISCHG_DIS 0x00
149 #define BUCKBOOST4_MODE_DISCHG_EN 0x01
150 #define BUCKBOOST4_MODE_FPWM_DIS 0x00
151 #define BUCKBOOST4_MODE_FPWM_EN 0x01
152 #define BUCKBOOST4_MODE_BIT_MASK 0x8D
153 
158 #define BUCKBOOST4_VOUT_LIM_MIN 0.8f
159 #define BUCKBOOST4_VOUT_LIM_5_V 5.0f
160 #define BUCKBOOST4_VOUT_LIM_10_V 10.0f
161 #define BUCKBOOST4_VOUT_LIM_15_V 15.0f
162 #define BUCKBOOST4_VOUT_LIM_20_V 20.0f
163 #define BUCKBOOST4_VOUT_LIM_MAX 21.286f
164 #define BUCKBOOST4_INTFB_STEP_MAX 0.2256f
165 #define BUCKBOOST4_CONVERT_V_TO_MV 1000.0f
166 
172 #define BUCKBOOST4_DEVICE_ADDRESS_0 0x75
173 #define BUCKBOOST4_DEVICE_ADDRESS_1 0x74
174  // buckboost4_set
176 
191 #define BUCKBOOST4_MAP_MIKROBUS( cfg, mikrobus ) \
192  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
193  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
194  cfg.en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
195  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
196  // buckboost4_map // buckboost4
199 
204 typedef struct
205 {
206  // Output pins
207  digital_out_t en;
209  // Input pins
210  digital_in_t int_pin;
212  // Modules
213  i2c_master_t i2c;
215  // I2C slave address
216  uint8_t slave_address;
218 } buckboost4_t;
219 
224 typedef struct
225 {
226  pin_name_t scl;
227  pin_name_t sda;
229  pin_name_t en;
230  pin_name_t int_pin;
232  uint32_t i2c_speed;
233  uint8_t i2c_address;
236 
241 typedef enum
242 {
244  BUCKBOOST4_ERROR = -1
245 
247 
264 
279 
293 
308 err_t buckboost4_generic_write ( buckboost4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
309 
324 err_t buckboost4_generic_read ( buckboost4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
325 
336 
347 
361 err_t buckboost4_set_vref ( buckboost4_t *ctx, float vref_mv );
362 
377 err_t buckboost4_current_limit_cfg ( buckboost4_t *ctx, uint8_t cl_en, float cltv_mv );
378 
393 err_t buckboost4_set_ocp_delay ( buckboost4_t *ctx, uint8_t ocp_delay );
394 
408 err_t buckboost4_set_slew_rate ( buckboost4_t *ctx, uint8_t slew_rate );
409 
423 
437 err_t buckboost4_set_int_fb_ratio ( buckboost4_t *ctx, uint8_t int_fb_ratio );
438 
452 
466 
483 err_t buckboost4_set_mode ( buckboost4_t *ctx, uint8_t fswdbl, uint8_t hiccup,
484  uint8_t dischg, uint8_t fpwm );
485 
499 err_t buckboost4_get_status ( buckboost4_t *ctx, uint8_t *status );
500 
514 err_t buckboost4_set_vout ( buckboost4_t *ctx, float vout_v );
515 
529 
530 #ifdef __cplusplus
531 }
532 #endif
533 #endif // BUCKBOOST4_H
534  // buckboost4
536 
537 // ------------------------------------------------------------------------ END
buckboost4_output_disable
err_t buckboost4_output_disable(buckboost4_t *ctx)
Buck-Boost 4 disable output voltage function.
buckboost4_t::int_pin
digital_in_t int_pin
Definition: buckboost4.h:210
buckboost4_fault_indicator
uint8_t buckboost4_fault_indicator(buckboost4_t *ctx)
Buck-Boost 4 check fault indicator function.
buckboost4_set_slew_rate
err_t buckboost4_set_slew_rate(buckboost4_t *ctx, uint8_t slew_rate)
Buck-Boost 4 sets the slew rate for output voltage change function.
buckboost4_set_ocp_delay
err_t buckboost4_set_ocp_delay(buckboost4_t *ctx, uint8_t ocp_delay)
Buck-Boost 4 sets the output overcurrent response time function.
buckboost4_t::i2c
i2c_master_t i2c
Definition: buckboost4.h:213
buckboost4_cfg_t::i2c_address
uint8_t i2c_address
Definition: buckboost4.h:233
buckboost4_cfg_setup
void buckboost4_cfg_setup(buckboost4_cfg_t *cfg)
Buck-Boost 4 configuration object setup function.
buckboost4_t
Buck-Boost 4 Click context object.
Definition: buckboost4.h:205
buckboost4_t::slave_address
uint8_t slave_address
Definition: buckboost4.h:216
buckboost4_init
err_t buckboost4_init(buckboost4_t *ctx, buckboost4_cfg_t *cfg)
Buck-Boost 4 initialization function.
buckboost4_cfg_t::en
pin_name_t en
Definition: buckboost4.h:229
buckboost4_set_int_fb_ratio
err_t buckboost4_set_int_fb_ratio(buckboost4_t *ctx, uint8_t int_fb_ratio)
Buck-Boost 4 set the internal feedback ratio function.
buckboost4_default_cfg
err_t buckboost4_default_cfg(buckboost4_t *ctx)
Buck-Boost 4 default configuration function.
buckboost4_set_vout
err_t buckboost4_set_vout(buckboost4_t *ctx, float vout_v)
Buck-Boost 4 set the output voltage function.
buckboost4_set_vref
err_t buckboost4_set_vref(buckboost4_t *ctx, float vref_mv)
Buck-Boost 4 set internal reference voltage function.
buckboost4_enable_device
void buckboost4_enable_device(buckboost4_t *ctx)
Buck-Boost 4 enable the device function.
buckboost4_get_status
err_t buckboost4_get_status(buckboost4_t *ctx, uint8_t *status)
Buck-Boost 4 get status function.
buckboost4_en_ext_output_vtg
err_t buckboost4_en_ext_output_vtg(buckboost4_t *ctx)
Buck-Boost 4 enable external output voltage feedback function.
buckboost4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buckboost4.h:232
buckboost4_t::en
digital_out_t en
Definition: buckboost4.h:207
buckboost4_cfg_t::sda
pin_name_t sda
Definition: buckboost4.h:227
buckboost4_cfg_t::int_pin
pin_name_t int_pin
Definition: buckboost4.h:230
buckboost4_cfg_t::scl
pin_name_t scl
Definition: buckboost4.h:226
buckboost4_current_limit_cfg
err_t buckboost4_current_limit_cfg(buckboost4_t *ctx, uint8_t cl_en, float cltv_mv)
Buck-Boost 4 current limit config function.
buckboost4_generic_read
err_t buckboost4_generic_read(buckboost4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Buck-Boost 4 I2C reading function.
buckboost4_output_enable
err_t buckboost4_output_enable(buckboost4_t *ctx)
Buck-Boost 4 enable output voltage function.
buckboost4_return_value_t
buckboost4_return_value_t
Buck-Boost 4 Click return value data.
Definition: buckboost4.h:242
BUCKBOOST4_ERROR
@ BUCKBOOST4_ERROR
Definition: buckboost4.h:244
buckboost4_set_mode
err_t buckboost4_set_mode(buckboost4_t *ctx, uint8_t fswdbl, uint8_t hiccup, uint8_t dischg, uint8_t fpwm)
Buck-Boost 4 set mode function.
buckboost4_cfg_t
Buck-Boost 4 Click configuration object.
Definition: buckboost4.h:225
BUCKBOOST4_OK
@ BUCKBOOST4_OK
Definition: buckboost4.h:243
buckboost4_generic_write
err_t buckboost4_generic_write(buckboost4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Buck-Boost 4 I2C writing function.
buckboost4_disable_device
void buckboost4_disable_device(buckboost4_t *ctx)
Buck-Boost 4 disable the device function.