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
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 BUCK22_REG_VOUT 0x01
60 #define BUCK22_REG_CONTROL 0x03
61 #define BUCK22_REG_STATUS 0x05
62  // buck22_reg
64 
79 #define BUCK22_VOUT_MIN 800
80 #define BUCK22_VOUT_MAX 3350
81 #define BUCK22_VOLTAGE_FACTOR 2
82 #define BUCK22_VOUT_RESOLUTION ( 5 * BUCK22_VOLTAGE_FACTOR )
83 
88 #define BUCK22_CONTROL_RESET 0x80
89 #define BUCK22_CONTROL_FPWM_VOUT_CHANGE 0x40
90 #define BUCK22_CONTROL_SOFT_EN 0x20
91 #define BUCK22_CONTROL_FPWM_EN 0x10
92 #define BUCK22_CONTROL_DISCHARGE_EN 0x08
93 #define BUCK22_CONTROL_HICCUP_EN 0x04
94 #define BUCK22_CONTROL_VRAMP_SPEED_20 0x00
95 #define BUCK22_CONTROL_VRAMP_SPEED_10 0x01
96 #define BUCK22_CONTROL_VRAMP_SPEED_5 0x02
97 #define BUCK22_CONTROL_VRAMP_SPEED_1 0x03
98 #define BUCK22_CONTROL_VRAMP_SPEED_MASK 0x03
99 #define BUCK22_CONTROL_DEFAULT_SETTING ( BUCK22_CONTROL_FPWM_VOUT_CHANGE | \
100  BUCK22_CONTROL_SOFT_EN | \
101  BUCK22_CONTROL_DISCHARGE_EN | \
102  BUCK22_CONTROL_HICCUP_EN | \
103  BUCK22_CONTROL_VRAMP_SPEED_1 )
104 
109 #define BUCK22_STATUS_THERMAL_WARNING 0x10
110 #define BUCK22_STATUS_HICCUP 0x08
111 #define BUCK22_STATUS_UVLO 0x01
112 
118 #define BUCK22_DEVICE_ADDRESS 0x42
119  // buck22_set
121 
136 #define BUCK22_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
138  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
139  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
140  // buck22_map // buck22
143 
148 typedef struct
149 {
150  // Input pins
151  digital_in_t pg;
153  // Modules
154  i2c_master_t i2c;
156  // I2C slave address
157  uint8_t slave_address;
159 } buck22_t;
160 
165 typedef struct
166 {
167  pin_name_t scl;
168  pin_name_t sda;
170  pin_name_t pg;
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
175 } buck22_cfg_t;
176 
181 typedef enum
182 {
184  BUCK22_ERROR = -1
185 
187 
204 
218 err_t buck22_init ( buck22_t *ctx, buck22_cfg_t *cfg );
219 
231 err_t buck22_set_vout ( buck22_t *ctx, uint16_t vout_mv );
232 
244 err_t buck22_read_vout ( buck22_t *ctx, uint16_t *vout_mv );
245 
257 err_t buck22_set_control ( buck22_t *ctx, uint8_t control );
258 
270 err_t buck22_read_status ( buck22_t *ctx, uint8_t *status );
271 
280 uint8_t buck22_get_pg_pin ( buck22_t *ctx );
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // BUCK22_H
286  // buck22
288 
289 // ------------------------------------------------------------------------ END
buck22_t::i2c
i2c_master_t i2c
Definition: buck22.h:154
buck22_get_pg_pin
uint8_t buck22_get_pg_pin(buck22_t *ctx)
Buck 22 get pg pin function.
buck22_set_vout
err_t buck22_set_vout(buck22_t *ctx, uint16_t vout_mv)
Buck 22 set vout function.
buck22_cfg_t
Buck 22 Click configuration object.
Definition: buck22.h:166
buck22_init
err_t buck22_init(buck22_t *ctx, buck22_cfg_t *cfg)
Buck 22 initialization function.
buck22_cfg_t::pg
pin_name_t pg
Definition: buck22.h:170
buck22_set_control
err_t buck22_set_control(buck22_t *ctx, uint8_t control)
Buck 22 set control function.
buck22_t::slave_address
uint8_t slave_address
Definition: buck22.h:157
buck22_cfg_setup
void buck22_cfg_setup(buck22_cfg_t *cfg)
Buck 22 configuration object setup function.
buck22_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck22.h:173
buck22_cfg_t::scl
pin_name_t scl
Definition: buck22.h:167
buck22_cfg_t::sda
pin_name_t sda
Definition: buck22.h:168
buck22_read_status
err_t buck22_read_status(buck22_t *ctx, uint8_t *status)
Buck 22 read status function.
BUCK22_OK
@ BUCK22_OK
Definition: buck22.h:183
buck22_return_value_t
buck22_return_value_t
Buck 22 Click return value data.
Definition: buck22.h:182
buck22_read_vout
err_t buck22_read_vout(buck22_t *ctx, uint16_t *vout_mv)
Buck 22 read vout function.
buck22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck22.h:172
buck22_t::pg
digital_in_t pg
Definition: buck22.h:151
BUCK22_ERROR
@ BUCK22_ERROR
Definition: buck22.h:184
buck22_t
Buck 22 Click context object.
Definition: buck22.h:149