buck23 2.1.0.0
buck23.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 BUCK23_H
29#define BUCK23_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 BUCK23_REG_ID 0x00
74#define BUCK23_REG_VIDMAX 0x02
75#define BUCK23_REG_STATUS 0x04
76#define BUCK23_REG_CONFIG 0x05
77#define BUCK23_REG_SLEW 0x06
78#define BUCK23_REG_VID 0x07
79
80 // buck23_reg
81
96#define BUCK23_DEVICE_ID 0x03
97
102#define BUCK23_VIDMAX_UNCAPPED 0x4E
103
108#define BUCK23_CONFIG_VSTEP_10 0x00
109#define BUCK23_CONFIG_VSTEP_12_5 0x80
110#define BUCK23_CONFIG_VSTEP_MASK 0x80
111#define BUCK23_CONFIG_MODE_SYNC 0x00
112#define BUCK23_CONFIG_MODE_FPWM 0x08
113#define BUCK23_CONFIG_MODE_MASK 0x08
114#define BUCK23_CONFIG_SS_DIS 0x00
115#define BUCK23_CONFIG_SS_3_PCT_SPREAD 0x04
116#define BUCK23_CONFIG_SS_MASK 0x04
117#define BUCK23_CONFIG_SYNC_IO_IN_RISE 0x00
118#define BUCK23_CONFIG_SYNC_IO_IN_FALL 0x01
119#define BUCK23_CONFIG_SYNC_IO_OUT_FALL 0x02
120#define BUCK23_CONFIG_SYNC_IO_MASK 0x03
121
126#define BUCK23_STATUS_INTERR 0x80
127#define BUCK23_STATUS_VRHOT 0x20
128#define BUCK23_STATUS_UV 0x10
129#define BUCK23_STATUS_OV 0x08
130#define BUCK23_STATUS_OC 0x04
131#define BUCK23_STATUS_VMERR 0x02
132
137#define BUCK23_SLEW_SS_22_DVS_22 0x00
138#define BUCK23_SLEW_SS_11_DVS_22 0x01
139#define BUCK23_SLEW_SS_5_5_DVS_22 0x02
140#define BUCK23_SLEW_SS_11_DVS_11 0x03
141#define BUCK23_SLEW_SS_5_5_DVS_11 0x04
142#define BUCK23_SLEW_SS_44_DVS_44 0x05
143#define BUCK23_SLEW_SS_22_DVS_44 0x06
144#define BUCK23_SLEW_SS_11_DVS_44 0x07
145#define BUCK23_SLEW_SS_5_5_DVS_44 0x08
146#define BUCK23_SLEW_SS_5_5_DVS_5_5 0x09
147#define BUCK23_SLEW_MASK 0x0F
148
153#define BUCK23_VSTEP_10 0
154#define BUCK23_VSTEP_12_5 1
155
160#define BUCK23_VID_MIN 0x01
161#define BUCK23_VID_MAX 0x4E
162#define BUCK23_VOUT_MIN_VSTEP_10 500u
163#define BUCK23_VOUT_MAX_VSTEP_10 1270u
164#define BUCK23_VOUT_MIN_VSTEP_12_5 625u
165#define BUCK23_VOUT_MAX_VSTEP_12_5 1587u
166#define BUCK23_VOUT_RES_VSTEP_10 10.0f
167#define BUCK23_VOUT_RES_VSTEP_12_5 12.5f
168
174#define BUCK23_DEVICE_ADDRESS_0 0x38
175#define BUCK23_DEVICE_ADDRESS_1 0x39
176
177 // buck23_set
178
193#define BUCK23_MAP_MIKROBUS( cfg, mikrobus ) \
194 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
195 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
196 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
197 cfg.sync = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
198 cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
199
200 // buck23_map
201 // buck23
202
207typedef struct
208{
209 // Output pins
210 digital_out_t en;
211 digital_out_t sync;
213 // Input pins
214 digital_in_t pg;
216 // Modules
217 i2c_master_t i2c;
219 // I2C slave address
222 uint8_t vstep;
224} buck23_t;
225
230typedef struct
231{
232 pin_name_t scl;
233 pin_name_t sda;
235 pin_name_t en;
236 pin_name_t sync;
237 pin_name_t pg;
239 uint32_t i2c_speed;
240 uint8_t i2c_address;
243
248typedef enum
249{
251 BUCK23_ERROR = -1
252
254
271
285err_t buck23_init ( buck23_t *ctx, buck23_cfg_t *cfg );
286
300
313err_t buck23_write_register ( buck23_t *ctx, uint8_t reg, uint8_t data_in );
314
327err_t buck23_read_register ( buck23_t *ctx, uint8_t reg, uint8_t *data_out );
328
338
348
358
368void buck23_set_sync_pin ( buck23_t *ctx, uint8_t state );
369
379
392
405err_t buck23_set_vstep ( buck23_t *ctx, uint8_t vstep );
406
419err_t buck23_set_vout ( buck23_t *ctx, uint16_t vout_mv );
420
421#ifdef __cplusplus
422}
423#endif
424#endif // BUCK23_H
425
426 // buck23
427
428// ------------------------------------------------------------------------ END
buck23_return_value_t
Buck 23 Click return value data.
Definition buck23.h:249
@ BUCK23_OK
Definition buck23.h:250
@ BUCK23_ERROR
Definition buck23.h:251
err_t buck23_default_cfg(buck23_t *ctx)
Buck 23 default configuration function.
err_t buck23_write_register(buck23_t *ctx, uint8_t reg, uint8_t data_in)
Buck 23 write register function.
void buck23_restart_device(buck23_t *ctx)
Buck 23 restart device function.
void buck23_set_sync_pin(buck23_t *ctx, uint8_t state)
Buck 23 set sync pin function.
err_t buck23_init(buck23_t *ctx, buck23_cfg_t *cfg)
Buck 23 initialization function.
void buck23_enable_device(buck23_t *ctx)
Buck 23 enable device function.
uint8_t buck23_get_pg_pin(buck23_t *ctx)
Buck 23 get pg pin function.
void buck23_cfg_setup(buck23_cfg_t *cfg)
Buck 23 configuration object setup function.
err_t buck23_set_vout(buck23_t *ctx, uint16_t vout_mv)
Buck 23 set vout function.
void buck23_disable_device(buck23_t *ctx)
Buck 23 disable device function.
err_t buck23_check_communication(buck23_t *ctx)
Buck 23 check communication function.
err_t buck23_set_vstep(buck23_t *ctx, uint8_t vstep)
Buck 23 set vstep function.
err_t buck23_read_register(buck23_t *ctx, uint8_t reg, uint8_t *data_out)
Buck 23 read register function.
Buck 23 Click configuration object.
Definition buck23.h:231
pin_name_t sync
Definition buck23.h:236
uint32_t i2c_speed
Definition buck23.h:239
pin_name_t scl
Definition buck23.h:232
pin_name_t en
Definition buck23.h:235
pin_name_t sda
Definition buck23.h:233
pin_name_t pg
Definition buck23.h:237
uint8_t i2c_address
Definition buck23.h:240
Buck 23 Click context object.
Definition buck23.h:208
digital_out_t sync
Definition buck23.h:211
uint8_t vstep
Definition buck23.h:222
i2c_master_t i2c
Definition buck23.h:217
digital_out_t en
Definition buck23.h:210
uint8_t slave_address
Definition buck23.h:220
digital_in_t pg
Definition buck23.h:214