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
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 BUCK23_REG_ID 0x00
60 #define BUCK23_REG_VIDMAX 0x02
61 #define BUCK23_REG_STATUS 0x04
62 #define BUCK23_REG_CONFIG 0x05
63 #define BUCK23_REG_SLEW 0x06
64 #define BUCK23_REG_VID 0x07
65  // buck23_reg
67 
82 #define BUCK23_DEVICE_ID 0x03
83 
88 #define BUCK23_VIDMAX_UNCAPPED 0x4E
89 
94 #define BUCK23_CONFIG_VSTEP_10 0x00
95 #define BUCK23_CONFIG_VSTEP_12_5 0x80
96 #define BUCK23_CONFIG_VSTEP_MASK 0x80
97 #define BUCK23_CONFIG_MODE_SYNC 0x00
98 #define BUCK23_CONFIG_MODE_FPWM 0x08
99 #define BUCK23_CONFIG_MODE_MASK 0x08
100 #define BUCK23_CONFIG_SS_DIS 0x00
101 #define BUCK23_CONFIG_SS_3_PCT_SPREAD 0x04
102 #define BUCK23_CONFIG_SS_MASK 0x04
103 #define BUCK23_CONFIG_SYNC_IO_IN_RISE 0x00
104 #define BUCK23_CONFIG_SYNC_IO_IN_FALL 0x01
105 #define BUCK23_CONFIG_SYNC_IO_OUT_FALL 0x02
106 #define BUCK23_CONFIG_SYNC_IO_MASK 0x03
107 
112 #define BUCK23_STATUS_INTERR 0x80
113 #define BUCK23_STATUS_VRHOT 0x20
114 #define BUCK23_STATUS_UV 0x10
115 #define BUCK23_STATUS_OV 0x08
116 #define BUCK23_STATUS_OC 0x04
117 #define BUCK23_STATUS_VMERR 0x02
118 
123 #define BUCK23_SLEW_SS_22_DVS_22 0x00
124 #define BUCK23_SLEW_SS_11_DVS_22 0x01
125 #define BUCK23_SLEW_SS_5_5_DVS_22 0x02
126 #define BUCK23_SLEW_SS_11_DVS_11 0x03
127 #define BUCK23_SLEW_SS_5_5_DVS_11 0x04
128 #define BUCK23_SLEW_SS_44_DVS_44 0x05
129 #define BUCK23_SLEW_SS_22_DVS_44 0x06
130 #define BUCK23_SLEW_SS_11_DVS_44 0x07
131 #define BUCK23_SLEW_SS_5_5_DVS_44 0x08
132 #define BUCK23_SLEW_SS_5_5_DVS_5_5 0x09
133 #define BUCK23_SLEW_MASK 0x0F
134 
139 #define BUCK23_VSTEP_10 0
140 #define BUCK23_VSTEP_12_5 1
141 
146 #define BUCK23_VID_MIN 0x01
147 #define BUCK23_VID_MAX 0x4E
148 #define BUCK23_VOUT_MIN_VSTEP_10 500u
149 #define BUCK23_VOUT_MAX_VSTEP_10 1270u
150 #define BUCK23_VOUT_MIN_VSTEP_12_5 625u
151 #define BUCK23_VOUT_MAX_VSTEP_12_5 1587u
152 #define BUCK23_VOUT_RES_VSTEP_10 10.0f
153 #define BUCK23_VOUT_RES_VSTEP_12_5 12.5f
154 
160 #define BUCK23_DEVICE_ADDRESS_0 0x38
161 #define BUCK23_DEVICE_ADDRESS_1 0x39
162  // buck23_set
164 
179 #define BUCK23_MAP_MIKROBUS( cfg, mikrobus ) \
180  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
181  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
182  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
183  cfg.sync = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
184  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
185  // buck23_map // buck23
188 
193 typedef struct
194 {
195  // Output pins
196  digital_out_t en;
197  digital_out_t sync;
199  // Input pins
200  digital_in_t pg;
202  // Modules
203  i2c_master_t i2c;
205  // I2C slave address
206  uint8_t slave_address;
208  uint8_t vstep;
210 } buck23_t;
211 
216 typedef struct
217 {
218  pin_name_t scl;
219  pin_name_t sda;
221  pin_name_t en;
222  pin_name_t sync;
223  pin_name_t pg;
225  uint32_t i2c_speed;
226  uint8_t i2c_address;
228 } buck23_cfg_t;
229 
234 typedef enum
235 {
237  BUCK23_ERROR = -1
238 
240 
257 
271 err_t buck23_init ( buck23_t *ctx, buck23_cfg_t *cfg );
272 
286 
299 err_t buck23_write_register ( buck23_t *ctx, uint8_t reg, uint8_t data_in );
300 
313 err_t buck23_read_register ( buck23_t *ctx, uint8_t reg, uint8_t *data_out );
314 
324 
334 
344 
354 void buck23_set_sync_pin ( buck23_t *ctx, uint8_t state );
355 
364 uint8_t buck23_get_pg_pin ( buck23_t *ctx );
365 
378 
391 err_t buck23_set_vstep ( buck23_t *ctx, uint8_t vstep );
392 
405 err_t buck23_set_vout ( buck23_t *ctx, uint16_t vout_mv );
406 
407 #ifdef __cplusplus
408 }
409 #endif
410 #endif // BUCK23_H
411  // buck23
413 
414 // ------------------------------------------------------------------------ END
buck23_t::i2c
i2c_master_t i2c
Definition: buck23.h:203
buck23_write_register
err_t buck23_write_register(buck23_t *ctx, uint8_t reg, uint8_t data_in)
Buck 23 write register function.
buck23_cfg_t
Buck 23 Click configuration object.
Definition: buck23.h:217
buck23_t::vstep
uint8_t vstep
Definition: buck23.h:208
buck23_t::sync
digital_out_t sync
Definition: buck23.h:197
buck23_disable_device
void buck23_disable_device(buck23_t *ctx)
Buck 23 disable device function.
buck23_enable_device
void buck23_enable_device(buck23_t *ctx)
Buck 23 enable device function.
buck23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck23.h:225
buck23_t::slave_address
uint8_t slave_address
Definition: buck23.h:206
buck23_restart_device
void buck23_restart_device(buck23_t *ctx)
Buck 23 restart device function.
buck23_set_vstep
err_t buck23_set_vstep(buck23_t *ctx, uint8_t vstep)
Buck 23 set vstep function.
buck23_cfg_t::sda
pin_name_t sda
Definition: buck23.h:219
buck23_default_cfg
err_t buck23_default_cfg(buck23_t *ctx)
Buck 23 default configuration function.
buck23_init
err_t buck23_init(buck23_t *ctx, buck23_cfg_t *cfg)
Buck 23 initialization function.
buck23_return_value_t
buck23_return_value_t
Buck 23 Click return value data.
Definition: buck23.h:235
buck23_t::en
digital_out_t en
Definition: buck23.h:196
buck23_cfg_t::pg
pin_name_t pg
Definition: buck23.h:223
buck23_t
Buck 23 Click context object.
Definition: buck23.h:194
BUCK23_ERROR
@ BUCK23_ERROR
Definition: buck23.h:237
buck23_set_vout
err_t buck23_set_vout(buck23_t *ctx, uint16_t vout_mv)
Buck 23 set vout function.
buck23_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck23.h:226
buck23_set_sync_pin
void buck23_set_sync_pin(buck23_t *ctx, uint8_t state)
Buck 23 set sync pin function.
buck23_check_communication
err_t buck23_check_communication(buck23_t *ctx)
Buck 23 check communication function.
buck23_cfg_t::en
pin_name_t en
Definition: buck23.h:221
BUCK23_OK
@ BUCK23_OK
Definition: buck23.h:236
buck23_cfg_t::sync
pin_name_t sync
Definition: buck23.h:222
buck23_t::pg
digital_in_t pg
Definition: buck23.h:200
buck23_cfg_t::scl
pin_name_t scl
Definition: buck23.h:218
buck23_cfg_setup
void buck23_cfg_setup(buck23_cfg_t *cfg)
Buck 23 configuration object setup function.
buck23_read_register
err_t buck23_read_register(buck23_t *ctx, uint8_t reg, uint8_t *data_out)
Buck 23 read register function.
buck23_get_pg_pin
uint8_t buck23_get_pg_pin(buck23_t *ctx)
Buck 23 get pg pin function.