buck19  2.1.0.0
buck19.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 BUCK19_H
29 #define BUCK19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define BUCK19_REG_VOUT 0x00
60 #define BUCK19_REG_ILIMIT 0x01
61 #define BUCK19_REG_INT_STATUS 0x02
62 #define BUCK19_REG_INT_LATCH 0x03
63 #define BUCK19_REG_INT_MASK 0x04
64 #define BUCK19_REG_CONFIG_0 0x05
65 #define BUCK19_REG_CONFIG_1 0x06
66  // buck19_reg
68 
83 #define BUCK19_VOUT_MIN 3.0f
84 #define BUCK19_VOUT_MAX 20.0f
85 #define BUCK19_VOUT_DEFAULT 5.0f
86 #define BUCK19_VOUT_11V 11.0f
87 #define BUCK19_VOUT_11V_STEP 0.2f
88 #define BUCK19_VOUT_5p9V 5.9f
89 #define BUCK19_VOUT_5p9V_STEP 0.1f
90 #define BUCK19_VOUT_STEP 0.02f
91 #define BUCK19_FLOAT_COMPARE_TOLERANCE 0.0001f
92 
97 #define BUCK19_ILIMIT_MIN 100
98 #define BUCK19_ILIMIT_MAX 3000
99 #define BUCK19_ILIMIT_STEP 100
100 #define BUCK19_ILIMIT_DEFAULT 500
101 
106 #define BUCK19_INT_INDUCTOR_PCP 0x80
107 #define BUCK19_INT_OT_WARNING 0x40
108 #define BUCK19_INT_OT_PROTECT 0x20
109 #define BUCK19_INT_WATCHDOG 0x10
110 #define BUCK19_INT_POWER_ON 0x08
111 #define BUCK19_INT_SHORT_PROTECT 0x04
112 #define BUCK19_INT_CC_FUNCTION 0x02
113 #define BUCK19_INT_OV_PROTECT 0x01
114 #define BUCK19_INT_DISABLE_ALL 0x00
115 
120 #define BUCK19_CONFIG_0_WATCHDOG_100MS 0x00
121 #define BUCK19_CONFIG_0_WATCHDOG_500MS 0x40
122 #define BUCK19_CONFIG_0_WATCHDOG_1S 0x80
123 #define BUCK19_CONFIG_0_WATCHDOG_5S 0xC0
124 #define BUCK19_CONFIG_0_CDC_OFF 0x00
125 #define BUCK19_CONFIG_0_CDC_FULL 0x10
126 #define BUCK19_CONFIG_0_SW_FREQ_500KHZ 0x00
127 #define BUCK19_CONFIG_0_SW_FREQ_750KHZ 0x04
128 #define BUCK19_CONFIG_0_DITHERING_OFF 0x00
129 #define BUCK19_CONFIG_0_DITHERING_ON 0x02
130 #define BUCK19_CONFIG_0_DISCHARGE_OFF 0x00
131 #define BUCK19_CONFIG_0_DISCHARGE_ON 0x01
132 
137 #define BUCK19_CONFIG_1_WATCHDOG_EN_OFF 0x00
138 #define BUCK19_CONFIG_1_WATCHDOG_EN_ON 0x02
139 #define BUCK19_CONFIG_1_DIG_EN_OFF 0x00
140 #define BUCK19_CONFIG_1_DIG_EN_ON 0x01
141 
147 #define BUCK19_DEVICE_ADDRESS_VCC 0x04
148 #define BUCK19_DEVICE_ADDRESS_GND 0x05
149 #define BUCK19_DEVICE_ADDRESS_SDA 0x06
150 #define BUCK19_DEVICE_ADDRESS_SCL 0x07
151  // buck19_set
153 
168 #define BUCK19_MAP_MIKROBUS( cfg, mikrobus ) \
169  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
170  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
171  cfg.pon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
172  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
173  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
174  // buck19_map // buck19
177 
182 typedef struct
183 {
184  // Output pins
185  digital_out_t en;
187  // Input pins
188  digital_in_t pon;
189  digital_in_t int_pin;
191  // Modules
192  i2c_master_t i2c;
194  // I2C slave address
195  uint8_t slave_address;
197 } buck19_t;
198 
203 typedef struct
204 {
205  pin_name_t scl;
206  pin_name_t sda;
208  pin_name_t pon;
209  pin_name_t en;
210  pin_name_t int_pin;
212  uint32_t i2c_speed;
213  uint8_t i2c_address;
215 } buck19_cfg_t;
216 
221 typedef enum
222 {
224  BUCK19_ERROR = -1
225 
227 
244 
258 err_t buck19_init ( buck19_t *ctx, buck19_cfg_t *cfg );
259 
273 
287 err_t buck19_write_register ( buck19_t *ctx, uint8_t reg, uint8_t data_in );
288 
301 err_t buck19_read_register ( buck19_t *ctx, uint8_t reg, uint8_t *data_out );
302 
312 
322 
331 uint8_t buck19_get_pon_pin ( buck19_t *ctx );
332 
341 uint8_t buck19_get_int_pin ( buck19_t *ctx );
342 
354 err_t buck19_set_vout ( buck19_t *ctx, float vout );
355 
367 err_t buck19_set_ilimit ( buck19_t *ctx, uint16_t ilimit );
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // BUCK19_H
373  // buck19
375 
376 // ------------------------------------------------------------------------ END
buck19_cfg_t::sda
pin_name_t sda
Definition: buck19.h:206
buck19_set_vout
err_t buck19_set_vout(buck19_t *ctx, float vout)
Buck 19 set vout function.
buck19_t::int_pin
digital_in_t int_pin
Definition: buck19.h:189
buck19_t::slave_address
uint8_t slave_address
Definition: buck19.h:195
buck19_cfg_t::en
pin_name_t en
Definition: buck19.h:209
buck19_t
Buck 19 Click context object.
Definition: buck19.h:183
buck19_cfg_t::int_pin
pin_name_t int_pin
Definition: buck19.h:210
buck19_get_int_pin
uint8_t buck19_get_int_pin(buck19_t *ctx)
Buck 19 get int pin function.
buck19_cfg_t
Buck 19 Click configuration object.
Definition: buck19.h:204
BUCK19_ERROR
@ BUCK19_ERROR
Definition: buck19.h:224
buck19_disable_device
void buck19_disable_device(buck19_t *ctx)
Buck 19 disable device function.
buck19_cfg_t::scl
pin_name_t scl
Definition: buck19.h:205
buck19_init
err_t buck19_init(buck19_t *ctx, buck19_cfg_t *cfg)
Buck 19 initialization function.
BUCK19_OK
@ BUCK19_OK
Definition: buck19.h:223
buck19_t::i2c
i2c_master_t i2c
Definition: buck19.h:192
buck19_set_ilimit
err_t buck19_set_ilimit(buck19_t *ctx, uint16_t ilimit)
Buck 19 set ilimit function.
buck19_enable_device
void buck19_enable_device(buck19_t *ctx)
Buck 19 enable device function.
buck19_cfg_setup
void buck19_cfg_setup(buck19_cfg_t *cfg)
Buck 19 configuration object setup function.
buck19_cfg_t::pon
pin_name_t pon
Definition: buck19.h:208
buck19_return_value_t
buck19_return_value_t
Buck 19 Click return value data.
Definition: buck19.h:222
buck19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck19.h:212
buck19_t::pon
digital_in_t pon
Definition: buck19.h:188
buck19_get_pon_pin
uint8_t buck19_get_pon_pin(buck19_t *ctx)
Buck 19 get pon pin function.
buck19_write_register
err_t buck19_write_register(buck19_t *ctx, uint8_t reg, uint8_t data_in)
Buck 19 write register function.
buck19_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck19.h:213
buck19_t::en
digital_out_t en
Definition: buck19.h:185
buck19_default_cfg
err_t buck19_default_cfg(buck19_t *ctx)
Buck 19 default configuration function.
buck19_read_register
err_t buck19_read_register(buck19_t *ctx, uint8_t reg, uint8_t *data_out)
Buck 19 read register function.