buck22 2.1.0.0
buck22.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 BUCK22_H
29#define BUCK22_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 BUCK22_REG_VOUT 0x01
74#define BUCK22_REG_CONTROL 0x03
75#define BUCK22_REG_STATUS 0x05
76
77 // buck22_reg
78
93#define BUCK22_VOUT_MIN 800
94#define BUCK22_VOUT_MAX 3350
95#define BUCK22_VOLTAGE_FACTOR 2
96#define BUCK22_VOUT_RESOLUTION ( 5 * BUCK22_VOLTAGE_FACTOR )
97
102#define BUCK22_CONTROL_RESET 0x80
103#define BUCK22_CONTROL_FPWM_VOUT_CHANGE 0x40
104#define BUCK22_CONTROL_SOFT_EN 0x20
105#define BUCK22_CONTROL_FPWM_EN 0x10
106#define BUCK22_CONTROL_DISCHARGE_EN 0x08
107#define BUCK22_CONTROL_HICCUP_EN 0x04
108#define BUCK22_CONTROL_VRAMP_SPEED_20 0x00
109#define BUCK22_CONTROL_VRAMP_SPEED_10 0x01
110#define BUCK22_CONTROL_VRAMP_SPEED_5 0x02
111#define BUCK22_CONTROL_VRAMP_SPEED_1 0x03
112#define BUCK22_CONTROL_VRAMP_SPEED_MASK 0x03
113#define BUCK22_CONTROL_DEFAULT_SETTING ( BUCK22_CONTROL_FPWM_VOUT_CHANGE | \
114 BUCK22_CONTROL_SOFT_EN | \
115 BUCK22_CONTROL_DISCHARGE_EN | \
116 BUCK22_CONTROL_HICCUP_EN | \
117 BUCK22_CONTROL_VRAMP_SPEED_1 )
118
123#define BUCK22_STATUS_THERMAL_WARNING 0x10
124#define BUCK22_STATUS_HICCUP 0x08
125#define BUCK22_STATUS_UVLO 0x01
126
132#define BUCK22_DEVICE_ADDRESS 0x42
133
134 // buck22_set
135
150#define BUCK22_MAP_MIKROBUS( cfg, mikrobus ) \
151 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
152 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
153 cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
154
155 // buck22_map
156 // buck22
157
162typedef struct
163{
164 // Input pins
165 digital_in_t pg;
167 // Modules
168 i2c_master_t i2c;
170 // I2C slave address
173} buck22_t;
174
179typedef struct
180{
181 pin_name_t scl;
182 pin_name_t sda;
184 pin_name_t pg;
186 uint32_t i2c_speed;
187 uint8_t i2c_address;
190
195typedef enum
196{
198 BUCK22_ERROR = -1
199
201
218
232err_t buck22_init ( buck22_t *ctx, buck22_cfg_t *cfg );
233
245err_t buck22_set_vout ( buck22_t *ctx, uint16_t vout_mv );
246
258err_t buck22_read_vout ( buck22_t *ctx, uint16_t *vout_mv );
259
271err_t buck22_set_control ( buck22_t *ctx, uint8_t control );
272
284err_t buck22_read_status ( buck22_t *ctx, uint8_t *status );
285
295
296#ifdef __cplusplus
297}
298#endif
299#endif // BUCK22_H
300
301 // buck22
302
303// ------------------------------------------------------------------------ END
buck22_return_value_t
Buck 22 Click return value data.
Definition buck22.h:196
@ BUCK22_OK
Definition buck22.h:197
@ BUCK22_ERROR
Definition buck22.h:198
err_t buck22_set_control(buck22_t *ctx, uint8_t control)
Buck 22 set control function.
void buck22_cfg_setup(buck22_cfg_t *cfg)
Buck 22 configuration object setup function.
uint8_t buck22_get_pg_pin(buck22_t *ctx)
Buck 22 get pg pin function.
err_t buck22_read_status(buck22_t *ctx, uint8_t *status)
Buck 22 read status function.
err_t buck22_init(buck22_t *ctx, buck22_cfg_t *cfg)
Buck 22 initialization function.
err_t buck22_read_vout(buck22_t *ctx, uint16_t *vout_mv)
Buck 22 read vout function.
err_t buck22_set_vout(buck22_t *ctx, uint16_t vout_mv)
Buck 22 set vout function.
Buck 22 Click configuration object.
Definition buck22.h:180
uint32_t i2c_speed
Definition buck22.h:186
pin_name_t scl
Definition buck22.h:181
pin_name_t sda
Definition buck22.h:182
pin_name_t pg
Definition buck22.h:184
uint8_t i2c_address
Definition buck22.h:187
Buck 22 Click context object.
Definition buck22.h:163
i2c_master_t i2c
Definition buck22.h:168
uint8_t slave_address
Definition buck22.h:171
digital_in_t pg
Definition buck22.h:165