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
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_i2c_master.h"
52
73#define BUCK19_REG_VOUT 0x00
74#define BUCK19_REG_ILIMIT 0x01
75#define BUCK19_REG_INT_STATUS 0x02
76#define BUCK19_REG_INT_LATCH 0x03
77#define BUCK19_REG_INT_MASK 0x04
78#define BUCK19_REG_CONFIG_0 0x05
79#define BUCK19_REG_CONFIG_1 0x06
80
81 // buck19_reg
82
97#define BUCK19_VOUT_MIN 3.0f
98#define BUCK19_VOUT_MAX 20.0f
99#define BUCK19_VOUT_DEFAULT 5.0f
100#define BUCK19_VOUT_11V 11.0f
101#define BUCK19_VOUT_11V_STEP 0.2f
102#define BUCK19_VOUT_5p9V 5.9f
103#define BUCK19_VOUT_5p9V_STEP 0.1f
104#define BUCK19_VOUT_STEP 0.02f
105#define BUCK19_FLOAT_COMPARE_TOLERANCE 0.0001f
106
111#define BUCK19_ILIMIT_MIN 100
112#define BUCK19_ILIMIT_MAX 3000
113#define BUCK19_ILIMIT_STEP 100
114#define BUCK19_ILIMIT_DEFAULT 500
115
120#define BUCK19_INT_INDUCTOR_PCP 0x80
121#define BUCK19_INT_OT_WARNING 0x40
122#define BUCK19_INT_OT_PROTECT 0x20
123#define BUCK19_INT_WATCHDOG 0x10
124#define BUCK19_INT_POWER_ON 0x08
125#define BUCK19_INT_SHORT_PROTECT 0x04
126#define BUCK19_INT_CC_FUNCTION 0x02
127#define BUCK19_INT_OV_PROTECT 0x01
128#define BUCK19_INT_DISABLE_ALL 0x00
129
134#define BUCK19_CONFIG_0_WATCHDOG_100MS 0x00
135#define BUCK19_CONFIG_0_WATCHDOG_500MS 0x40
136#define BUCK19_CONFIG_0_WATCHDOG_1S 0x80
137#define BUCK19_CONFIG_0_WATCHDOG_5S 0xC0
138#define BUCK19_CONFIG_0_CDC_OFF 0x00
139#define BUCK19_CONFIG_0_CDC_FULL 0x10
140#define BUCK19_CONFIG_0_SW_FREQ_500KHZ 0x00
141#define BUCK19_CONFIG_0_SW_FREQ_750KHZ 0x04
142#define BUCK19_CONFIG_0_DITHERING_OFF 0x00
143#define BUCK19_CONFIG_0_DITHERING_ON 0x02
144#define BUCK19_CONFIG_0_DISCHARGE_OFF 0x00
145#define BUCK19_CONFIG_0_DISCHARGE_ON 0x01
146
151#define BUCK19_CONFIG_1_WATCHDOG_EN_OFF 0x00
152#define BUCK19_CONFIG_1_WATCHDOG_EN_ON 0x02
153#define BUCK19_CONFIG_1_DIG_EN_OFF 0x00
154#define BUCK19_CONFIG_1_DIG_EN_ON 0x01
155
161#define BUCK19_DEVICE_ADDRESS_VCC 0x04
162#define BUCK19_DEVICE_ADDRESS_GND 0x05
163#define BUCK19_DEVICE_ADDRESS_SDA 0x06
164#define BUCK19_DEVICE_ADDRESS_SCL 0x07
165
166 // buck19_set
167
182#define BUCK19_MAP_MIKROBUS( cfg, mikrobus ) \
183 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
185 cfg.pon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
186 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
187 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
188
189 // buck19_map
190 // buck19
191
196typedef struct
197{
198 // Output pins
199 digital_out_t en;
201 // Input pins
202 digital_in_t pon;
203 digital_in_t int_pin;
205 // Modules
206 i2c_master_t i2c;
208 // I2C slave address
211} buck19_t;
212
217typedef struct
218{
219 pin_name_t scl;
220 pin_name_t sda;
222 pin_name_t pon;
223 pin_name_t en;
224 pin_name_t int_pin;
226 uint32_t i2c_speed;
227 uint8_t i2c_address;
230
235typedef enum
236{
238 BUCK19_ERROR = -1
239
241
258
272err_t buck19_init ( buck19_t *ctx, buck19_cfg_t *cfg );
273
287
301err_t buck19_write_register ( buck19_t *ctx, uint8_t reg, uint8_t data_in );
302
315err_t buck19_read_register ( buck19_t *ctx, uint8_t reg, uint8_t *data_out );
316
326
336
346
356
368err_t buck19_set_vout ( buck19_t *ctx, float vout );
369
381err_t buck19_set_ilimit ( buck19_t *ctx, uint16_t ilimit );
382
383#ifdef __cplusplus
384}
385#endif
386#endif // BUCK19_H
387
388 // buck19
389
390// ------------------------------------------------------------------------ END
buck19_return_value_t
Buck 19 Click return value data.
Definition buck19.h:236
@ BUCK19_ERROR
Definition buck19.h:238
@ BUCK19_OK
Definition buck19.h:237
void buck19_cfg_setup(buck19_cfg_t *cfg)
Buck 19 configuration object setup function.
uint8_t buck19_get_pon_pin(buck19_t *ctx)
Buck 19 get pon pin function.
err_t buck19_default_cfg(buck19_t *ctx)
Buck 19 default configuration function.
err_t buck19_write_register(buck19_t *ctx, uint8_t reg, uint8_t data_in)
Buck 19 write register function.
void buck19_enable_device(buck19_t *ctx)
Buck 19 enable device function.
err_t buck19_read_register(buck19_t *ctx, uint8_t reg, uint8_t *data_out)
Buck 19 read register function.
err_t buck19_set_vout(buck19_t *ctx, float vout)
Buck 19 set vout function.
err_t buck19_set_ilimit(buck19_t *ctx, uint16_t ilimit)
Buck 19 set ilimit function.
void buck19_disable_device(buck19_t *ctx)
Buck 19 disable device function.
err_t buck19_init(buck19_t *ctx, buck19_cfg_t *cfg)
Buck 19 initialization function.
uint8_t buck19_get_int_pin(buck19_t *ctx)
Buck 19 get int pin function.
Buck 19 Click configuration object.
Definition buck19.h:218
uint32_t i2c_speed
Definition buck19.h:226
pin_name_t pon
Definition buck19.h:222
pin_name_t scl
Definition buck19.h:219
pin_name_t en
Definition buck19.h:223
pin_name_t int_pin
Definition buck19.h:224
pin_name_t sda
Definition buck19.h:220
uint8_t i2c_address
Definition buck19.h:227
Buck 19 Click context object.
Definition buck19.h:197
digital_in_t int_pin
Definition buck19.h:203
i2c_master_t i2c
Definition buck19.h:206
digital_out_t en
Definition buck19.h:199
digital_in_t pon
Definition buck19.h:202
uint8_t slave_address
Definition buck19.h:209