buck14  2.0.0.0
buck14.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef BUCK14_H
36 #define BUCK14_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define BUCK14_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.pg = MIKROBUS( mikrobus, MIKROBUS_AN ); \
66  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.syn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
68  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT );
69 
75 #define BUCK14_RETVAL uint8_t
76 
77 #define BUCK14_OK 0x00
78 #define BUCK14_INIT_ERROR 0xFF
79 
85 #define BUCK14_SLAVE_ADDR 0x0A
86 
92 #define BUCK14_CMD_OPERATION 0x01
93 #define BUCK14_CMD_ON_OFF_CONFIG 0x02
94 #define BUCK14_CMD_WRITE_PROTECT 0x10
95 
101 #define BUCK14_CMD_CAPABILITY 0x19
102 #define BUCK14_CMD_VOUT_MODE 0x20
103 #define BUCK14_CMD_VOUT_COMMAND 0x21
104 #define BUCK14_CMD_VOUT_TRIM 0x22
105 #define BUCK14_CMD_VOUT_CAL_OFFSET 0x23
106 #define BUCK14_CMD_VOUT_MAX 0x24
107 #define BUCK14_CMD_VOUT_MARGIN_HIGH 0x25
108 #define BUCK14_CMD_VOUT_MARGIN_LOW 0x26
109 #define BUCK14_CMD_VOUT_TRANSITION_RATE 0x27
110 #define BUCK14_CMD_VOUT_DROOP 0x28
111 #define BUCK14_CMD_FREQUENCY_SWITCH 0x33
112 #define BUCK14_CMD_VIN_ON 0x35
113 #define BUCK14_CMD_VIN_OFF 0x36
114 #define BUCK14_CMD_IOUT_CAL_GAIN 0x38
115 #define BUCK14_CMD_IOUT_CAL_OFFSET 0x39
116 
122 #define BUCK14_CMD_FAULT_POWER_GOOD_ON 0x5E
123 #define BUCK14_CMD_FAULT_POWERGOOD_OFF 0x5F
124 #define BUCK14_CMD_VOUT_OC_FAULT_LIMIT 0x40
125 #define BUCK14_CMD_VOUT_UV_FAULT_LIMIT 0x44
126 #define BUCK14_CMD_IOUT_OC_FAULT_LIMIT 0x46
127 #define BUCK14_CMD_OT_FAULT_LIMIT 0x4F
128 #define BUCK14_CMD_OT_WARN_LIMIT 0x51
129 #define BUCK14_CMD_VIN_OV_FAULT_LIMIT 0x55
130 #define BUCK14_CMD_VIN_UV_FAULT_LIMIT 0x59
131 
137 #define BUCK14_CMD_VOUT_OV_FAULT_RESPONSE 0x41
138 #define BUCK14_CMD_VOUT_UV_FAULT_RESPONSE 0x45
139 #define BUCK14_CMD_OT_FAULT_RESPONSE 0x50
140 #define BUCK14_CMD_VIN_OV_FAULT_RESPONSE 0x56
141 #define BUCK14_CMD_VIN_UV_FAULT_RESPONSE 0x5A
142 #define BUCK14_CMD_IOUT_OC_FAULT_RESPONSE 0x47
143 #define BUCK14_CMD_TON_MAX_FAULT_RESPONSE 0x63
144 
150 #define BUCK14_CMD_TON_DELAY 0x60
151 #define BUCK14_CMD_TON_RISE 0x61
152 #define BUCK14_CMD_TOFF_DELAY 0x64
153 #define BUCK14_CMD_TOFF_FALL 0x65
154 #define BUCK14_CMD_TON_MAX_FAULT_LIMIT 0x62
155 
161 #define BUCK14_CMD_CLEAR_FAULTS 0x03
162 #define BUCK14_CMD_STATUS_BYTE 0x78
163 #define BUCK14_CMD_STATUS_WORD 0x79
164 #define BUCK14_CMD_STATUS_VOUT 0x7A
165 #define BUCK14_CMD_STATUS_IOUT 0x7B
166 #define BUCK14_CMD_STATUS_INPUT 0x7C
167 #define BUCK14_CMD_STATUS_TEMPERATURE 0x7D
168 #define BUCK14_CMD_STATUS_CML 0x7E
169 #define BUCK14_CMD_STATUS_MFR_SPECIFIC 0x80
170 
176 #define BUCK14_CMD_READ_VIN 0x88
177 #define BUCK14_CMD_READ_VOUT 0x8B
178 #define BUCK14_CMD_READ_IOUT 0x8C
179 #define BUCK14_CMD_READ_TEMPERATURE_1 0x8D
180 #define BUCK14_CMD_READ_TEMPERATURE_2 0x8E
181 #define BUCK14_CMD_READ_DUTY_CYCLE 0x94
182 #define BUCK14_CMD_READ_FREQUENCY 0x95
183 
189 #define BUCK14_CMD_INTERLEAVE 0x37
190 
196 #define BUCK14_CMD_PMBUS_REVISION 0x98
197 #define BUCK14_CMD_MFR_ID 0x99
198 #define BUCK14_CMD_MFR_MODEL 0x9A
199 #define BUCK14_CMD_MFR_REVISION 0x9B
200 #define BUCK14_CMD_MFR_LOCATION 0x9C
201 #define BUCK14_CMD_MFR_DATE 0x9D
202 #define BUCK14_CMD_MFR_SERIAL 0x9E
203 #define BUCK14_CMD_IC_DEVICE_ID 0xAD
204 #define BUCK14_CMD_IC_DEVICE_REV 0xAE
205 
211 #define BUCK14_CMD_STORE_DEFAULT_ALL 0x11
212 #define BUCK14_CMD_RESTORE_DEFAUL_ALL 0x12
213 #define BUCK14_CMD_STORE_USER_ALL 0x15
214 #define BUCK14_CMD_RESTORE_USER_ALL 0x16
215 
221 #define BUCK14_CMD_ADAPTIVE_MODE 0xD0
222 #define BUCK14_CMD_FEEDBACK_EFFORT 0xD3
223 #define BUCK14_CMD_LOOP_CONFIG 0xD5
224 #define BUCK14_CMD_TEST_MODE 0xD9
225 #define BUCK14_CMD_COMP_MODEL 0xDB
226 #define BUCK14_CMD_STRAP_DISABLE 0xDC
227 #define BUCK14_CMD_MANUF_CONF 0xE0
228 #define BUCK14_CMD_MANUF_LOCK 0xE1
229 #define BUCK14_CMD_MANUF_PASSWD 0xE2
230 #define BUCK14_CMD_USER_CONF 0xE3
231 #define BUCK14_CMD_USER_LOCK 0xE4
232 #define BUCK14_CMD_USER_PASSWD 0xE5
233 #define BUCK14_CMD_SECURITY_LEVVEL 0xE6
234 #define BUCK14_CMD_DEADTIME_GCTRL 0xE7
235 #define BUCK14_CMD_ZETAP 0xE8
236 
242 #define BUCK14_CTRL_DISABLE 0x00
243 #define BUCK14_CTRL_SOFT_DISABLE 0x60
244 #define BUCK14_CTRL_ENABLE_NO_MARGIN 0x80
245 #define BUCK14_CTRL_ENABLE_LOW_MARGIN1 0x96
246 #define BUCK14_CTRL_ENABLE_LOW_MARGIN2 0x98
247 #define BUCK14_CTRL_ENABLE_HIGH_MARGIN1 0xA6
248 #define BUCK14_CTRL_ENABLE_HIGH_MARGIN2 0xA8
249 
255 #define BUCK14_VOUT_MODE_EXPONENT_12 0x14
256 #define BUCK14_VOUT_MODE_EXPONENT_13 0x13
257 #define BUCK14_VOUT_MODE_VALUE 0.000244
258 
264 #define BUCK14_PIN_STATE_HIGH 1
265 #define BUCK14_PIN_STATE_LOW 0
266 
272 #define BUCK14_SUCCESSFUL 0xAA
273 #define BUCK14_ID_ERROR 0xBB
274 #define BUCK14_CMD_ERROR 0xCC
275 #define BUCK14_ERROR 0xDD
276 
282 #define BUCK14_AMODE_CALIB_CONT_RAMP_UP 0x4B
283  // End group macro
286 // --------------------------------------------------------------- PUBLIC TYPES
295 typedef struct
296 {
297  // Output pins
298 
299  digital_out_t en;
300  digital_out_t syn;
301 
302  // Input pins
303 
304  digital_in_t pg;
305  digital_in_t alr;
306 
307  // Modules
308 
309  i2c_master_t i2c;
310 
311  // ctx variable
312 
313  uint8_t slave_address;
314 
315 } buck14_t;
316 
320 typedef struct
321 {
322  // Communication gpio pins
323 
324  pin_name_t scl;
325  pin_name_t sda;
326 
327  // Additional gpio pins
328 
329  pin_name_t pg;
330  pin_name_t en;
331  pin_name_t syn;
332  pin_name_t alr;
333 
334  // static variable
335 
336  uint32_t i2c_speed;
337  uint8_t i2c_address;
338 
339 } buck14_cfg_t;
340  // End types group
342 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
343 
349 #ifdef __cplusplus
350 extern "C"{
351 #endif
352 
362 
371 
380 
391 void buck14_generic_write ( buck14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
392 
403 void buck14_generic_read ( buck14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
404 
413 void buck14_power_ctrl ( buck14_t *ctx, uint8_t state );
414 
423 void buck14_power_sync ( buck14_t *ctx, uint8_t state );
424 
432 uint8_t buck14_power_good ( buck14_t *ctx );
433 
441 uint8_t buck14_salert ( buck14_t *ctx );
442 
450 uint8_t buck14_check_mfr_id ( buck14_t *ctx );
451 
459 void buck14_reset ( buck14_t *ctx );
460 
468 uint16_t buc14_read_vout ( buck14_t *ctx );
469 
478 uint8_t buc14_write_vout ( buck14_t *ctx, float vout );
479 
480 #ifdef __cplusplus
481 }
482 #endif
483 #endif // _BUCK14_H_
484  // End public_function group
487 
488 // ------------------------------------------------------------------------- END
buck14_t::alr
digital_in_t alr
Definition: buck14.h:305
BUCK14_RETVAL
#define BUCK14_RETVAL
Definition: buck14.h:75
buck14_cfg_setup
void buck14_cfg_setup(buck14_cfg_t *cfg)
Config Object Initialization function.
buck14_t::pg
digital_in_t pg
Definition: buck14.h:304
buck14_default_cfg
void buck14_default_cfg(buck14_t *ctx)
Click Default Configuration function.
buck14_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck14.h:336
buck14_t
Click ctx object definition.
Definition: buck14.h:296
buck14_power_good
uint8_t buck14_power_good(buck14_t *ctx)
Get power good function.
buck14_t::en
digital_out_t en
Definition: buck14.h:299
buck14_power_sync
void buck14_power_sync(buck14_t *ctx, uint8_t state)
Set power sync function.
buck14_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck14.h:337
buck14_cfg_t
Click configuration structure definition.
Definition: buck14.h:321
buck14_cfg_t::pg
pin_name_t pg
Definition: buck14.h:329
buck14_init
BUCK14_RETVAL buck14_init(buck14_t *ctx, buck14_cfg_t *cfg)
Initialization function.
buck14_generic_write
void buck14_generic_write(buck14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
buck14_cfg_t::syn
pin_name_t syn
Definition: buck14.h:331
buc14_write_vout
uint8_t buc14_write_vout(buck14_t *ctx, float vout)
Set Vout function.
buck14_generic_read
void buck14_generic_read(buck14_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
buck14_cfg_t::en
pin_name_t en
Definition: buck14.h:330
buck14_reset
void buck14_reset(buck14_t *ctx)
Reset function.
buck14_t::syn
digital_out_t syn
Definition: buck14.h:300
buck14_t::i2c
i2c_master_t i2c
Definition: buck14.h:309
buck14_t::slave_address
uint8_t slave_address
Definition: buck14.h:313
buck14_power_ctrl
void buck14_power_ctrl(buck14_t *ctx, uint8_t state)
Set power ctrl function.
buck14_cfg_t::scl
pin_name_t scl
Definition: buck14.h:324
buc14_read_vout
uint16_t buc14_read_vout(buck14_t *ctx)
Read Vout function.
buck14_salert
uint8_t buck14_salert(buck14_t *ctx)
Get alert function.
buck14_check_mfr_id
uint8_t buck14_check_mfr_id(buck14_t *ctx)
Fucntion for checking manufacturer id.
buck14_cfg_t::sda
pin_name_t sda
Definition: buck14.h:325
buck14_cfg_t::alr
pin_name_t alr
Definition: buck14.h:332