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 "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 BUCK23_REG_ID 0x00
70 #define BUCK23_REG_VIDMAX 0x02
71 #define BUCK23_REG_STATUS 0x04
72 #define BUCK23_REG_CONFIG 0x05
73 #define BUCK23_REG_SLEW 0x06
74 #define BUCK23_REG_VID 0x07
75  // buck23_reg
77 
92 #define BUCK23_DEVICE_ID 0x03
93 
98 #define BUCK23_VIDMAX_UNCAPPED 0x4E
99 
104 #define BUCK23_CONFIG_VSTEP_10 0x00
105 #define BUCK23_CONFIG_VSTEP_12_5 0x80
106 #define BUCK23_CONFIG_VSTEP_MASK 0x80
107 #define BUCK23_CONFIG_MODE_SYNC 0x00
108 #define BUCK23_CONFIG_MODE_FPWM 0x08
109 #define BUCK23_CONFIG_MODE_MASK 0x08
110 #define BUCK23_CONFIG_SS_DIS 0x00
111 #define BUCK23_CONFIG_SS_3_PCT_SPREAD 0x04
112 #define BUCK23_CONFIG_SS_MASK 0x04
113 #define BUCK23_CONFIG_SYNC_IO_IN_RISE 0x00
114 #define BUCK23_CONFIG_SYNC_IO_IN_FALL 0x01
115 #define BUCK23_CONFIG_SYNC_IO_OUT_FALL 0x02
116 #define BUCK23_CONFIG_SYNC_IO_MASK 0x03
117 
122 #define BUCK23_STATUS_INTERR 0x80
123 #define BUCK23_STATUS_VRHOT 0x20
124 #define BUCK23_STATUS_UV 0x10
125 #define BUCK23_STATUS_OV 0x08
126 #define BUCK23_STATUS_OC 0x04
127 #define BUCK23_STATUS_VMERR 0x02
128 
133 #define BUCK23_SLEW_SS_22_DVS_22 0x00
134 #define BUCK23_SLEW_SS_11_DVS_22 0x01
135 #define BUCK23_SLEW_SS_5_5_DVS_22 0x02
136 #define BUCK23_SLEW_SS_11_DVS_11 0x03
137 #define BUCK23_SLEW_SS_5_5_DVS_11 0x04
138 #define BUCK23_SLEW_SS_44_DVS_44 0x05
139 #define BUCK23_SLEW_SS_22_DVS_44 0x06
140 #define BUCK23_SLEW_SS_11_DVS_44 0x07
141 #define BUCK23_SLEW_SS_5_5_DVS_44 0x08
142 #define BUCK23_SLEW_SS_5_5_DVS_5_5 0x09
143 #define BUCK23_SLEW_MASK 0x0F
144 
149 #define BUCK23_VSTEP_10 0
150 #define BUCK23_VSTEP_12_5 1
151 
156 #define BUCK23_VID_MIN 0x01
157 #define BUCK23_VID_MAX 0x4E
158 #define BUCK23_VOUT_MIN_VSTEP_10 500u
159 #define BUCK23_VOUT_MAX_VSTEP_10 1270u
160 #define BUCK23_VOUT_MIN_VSTEP_12_5 625u
161 #define BUCK23_VOUT_MAX_VSTEP_12_5 1587u
162 #define BUCK23_VOUT_RES_VSTEP_10 10.0f
163 #define BUCK23_VOUT_RES_VSTEP_12_5 12.5f
164 
170 #define BUCK23_DEVICE_ADDRESS_0 0x38
171 #define BUCK23_DEVICE_ADDRESS_1 0x39
172  // buck23_set
174 
189 #define BUCK23_MAP_MIKROBUS( cfg, mikrobus ) \
190  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
191  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
192  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
193  cfg.sync = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
194  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
195  // buck23_map // buck23
198 
203 typedef struct
204 {
205  // Output pins
206  digital_out_t en;
207  digital_out_t sync;
209  // Input pins
210  digital_in_t pg;
212  // Modules
213  i2c_master_t i2c;
215  // I2C slave address
216  uint8_t slave_address;
218  uint8_t vstep;
220 } buck23_t;
221 
226 typedef struct
227 {
228  pin_name_t scl;
229  pin_name_t sda;
231  pin_name_t en;
232  pin_name_t sync;
233  pin_name_t pg;
235  uint32_t i2c_speed;
236  uint8_t i2c_address;
238 } buck23_cfg_t;
239 
244 typedef enum
245 {
247  BUCK23_ERROR = -1
248 
250 
267 
281 err_t buck23_init ( buck23_t *ctx, buck23_cfg_t *cfg );
282 
296 
309 err_t buck23_write_register ( buck23_t *ctx, uint8_t reg, uint8_t data_in );
310 
323 err_t buck23_read_register ( buck23_t *ctx, uint8_t reg, uint8_t *data_out );
324 
334 
344 
354 
364 void buck23_set_sync_pin ( buck23_t *ctx, uint8_t state );
365 
374 uint8_t buck23_get_pg_pin ( buck23_t *ctx );
375 
388 
401 err_t buck23_set_vstep ( buck23_t *ctx, uint8_t vstep );
402 
415 err_t buck23_set_vout ( buck23_t *ctx, uint16_t vout_mv );
416 
417 #ifdef __cplusplus
418 }
419 #endif
420 #endif // BUCK23_H
421  // buck23
423 
424 // ------------------------------------------------------------------------ END
buck23_t::i2c
i2c_master_t i2c
Definition: buck23.h:213
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:227
buck23_t::vstep
uint8_t vstep
Definition: buck23.h:218
buck23_t::sync
digital_out_t sync
Definition: buck23.h:207
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:235
buck23_t::slave_address
uint8_t slave_address
Definition: buck23.h:216
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:229
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:245
buck23_t::en
digital_out_t en
Definition: buck23.h:206
buck23_cfg_t::pg
pin_name_t pg
Definition: buck23.h:233
buck23_t
Buck 23 Click context object.
Definition: buck23.h:204
BUCK23_ERROR
@ BUCK23_ERROR
Definition: buck23.h:247
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:236
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:231
BUCK23_OK
@ BUCK23_OK
Definition: buck23.h:246
buck23_cfg_t::sync
pin_name_t sync
Definition: buck23.h:232
buck23_t::pg
digital_in_t pg
Definition: buck23.h:210
buck23_cfg_t::scl
pin_name_t scl
Definition: buck23.h:228
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.