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 "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 BUCK22_REG_VOUT 0x01
70 #define BUCK22_REG_CONTROL 0x03
71 #define BUCK22_REG_STATUS 0x05
72  // buck22_reg
74 
89 #define BUCK22_VOUT_MIN 800
90 #define BUCK22_VOUT_MAX 3350
91 #define BUCK22_VOLTAGE_FACTOR 2
92 #define BUCK22_VOUT_RESOLUTION ( 5 * BUCK22_VOLTAGE_FACTOR )
93 
98 #define BUCK22_CONTROL_RESET 0x80
99 #define BUCK22_CONTROL_FPWM_VOUT_CHANGE 0x40
100 #define BUCK22_CONTROL_SOFT_EN 0x20
101 #define BUCK22_CONTROL_FPWM_EN 0x10
102 #define BUCK22_CONTROL_DISCHARGE_EN 0x08
103 #define BUCK22_CONTROL_HICCUP_EN 0x04
104 #define BUCK22_CONTROL_VRAMP_SPEED_20 0x00
105 #define BUCK22_CONTROL_VRAMP_SPEED_10 0x01
106 #define BUCK22_CONTROL_VRAMP_SPEED_5 0x02
107 #define BUCK22_CONTROL_VRAMP_SPEED_1 0x03
108 #define BUCK22_CONTROL_VRAMP_SPEED_MASK 0x03
109 #define BUCK22_CONTROL_DEFAULT_SETTING ( BUCK22_CONTROL_FPWM_VOUT_CHANGE | \
110  BUCK22_CONTROL_SOFT_EN | \
111  BUCK22_CONTROL_DISCHARGE_EN | \
112  BUCK22_CONTROL_HICCUP_EN | \
113  BUCK22_CONTROL_VRAMP_SPEED_1 )
114 
119 #define BUCK22_STATUS_THERMAL_WARNING 0x10
120 #define BUCK22_STATUS_HICCUP 0x08
121 #define BUCK22_STATUS_UVLO 0x01
122 
128 #define BUCK22_DEVICE_ADDRESS 0x42
129  // buck22_set
131 
146 #define BUCK22_MAP_MIKROBUS( cfg, mikrobus ) \
147  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
148  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
149  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
150  // buck22_map // buck22
153 
158 typedef struct
159 {
160  // Input pins
161  digital_in_t pg;
163  // Modules
164  i2c_master_t i2c;
166  // I2C slave address
167  uint8_t slave_address;
169 } buck22_t;
170 
175 typedef struct
176 {
177  pin_name_t scl;
178  pin_name_t sda;
180  pin_name_t pg;
182  uint32_t i2c_speed;
183  uint8_t i2c_address;
185 } buck22_cfg_t;
186 
191 typedef enum
192 {
194  BUCK22_ERROR = -1
195 
197 
214 
228 err_t buck22_init ( buck22_t *ctx, buck22_cfg_t *cfg );
229 
241 err_t buck22_set_vout ( buck22_t *ctx, uint16_t vout_mv );
242 
254 err_t buck22_read_vout ( buck22_t *ctx, uint16_t *vout_mv );
255 
267 err_t buck22_set_control ( buck22_t *ctx, uint8_t control );
268 
280 err_t buck22_read_status ( buck22_t *ctx, uint8_t *status );
281 
290 uint8_t buck22_get_pg_pin ( buck22_t *ctx );
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 #endif // BUCK22_H
296  // buck22
298 
299 // ------------------------------------------------------------------------ END
buck22_t::i2c
i2c_master_t i2c
Definition: buck22.h:164
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:176
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:180
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:167
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:183
buck22_cfg_t::scl
pin_name_t scl
Definition: buck22.h:177
buck22_cfg_t::sda
pin_name_t sda
Definition: buck22.h:178
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:193
buck22_return_value_t
buck22_return_value_t
Buck 22 Click return value data.
Definition: buck22.h:192
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:182
buck22_t::pg
digital_in_t pg
Definition: buck22.h:161
BUCK22_ERROR
@ BUCK22_ERROR
Definition: buck22.h:194
buck22_t
Buck 22 Click context object.
Definition: buck22.h:159