smartbuck2  2.1.0.0
smartbuck2.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 SMARTBUCK2_H
29 #define SMARTBUCK2_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 SMARTBUCK2_REG_SET0 0x00
70 #define SMARTBUCK2_REG_SET1 0x01
71 #define SMARTBUCK2_REG_SET2 0x02
72 #define SMARTBUCK2_REG_SET3 0x03
73 #define SMARTBUCK2_REG_CTRL 0x04
74 #define SMARTBUCK2_REG_TEMP 0x05
75 #define SMARTBUCK2_REG_RMPCTRL 0x06
76 #define SMARTBUCK2_REG_CHIP_ID_0 0x08
77 #define SMARTBUCK2_REG_CHIP_ID_1 0x09
78  // smartbuck2_reg
80 
95 #define SMARTBUCK2_OP_MOD_BIT_MASK 0x80
96 #define SMARTBUCK2_OP_MODE_FORCED_PWM 0x80
97 #define SMARTBUCK2_OP_MODE_PFM 0x00
98 
103 #define SMARTBUCK2_CTRL_BIT_MASK 0xE0
104 #define SMARTBUCK2_CTRL_PD_EN 0x80
105 #define SMARTBUCK2_CTRL_PD_DIS 0x00
106 #define SMARTBUCK2_CTRL_PD_VSEL0_EN 0x40
107 #define SMARTBUCK2_CTRL_PD_VSEL0_DIS 0x00
108 #define SMARTBUCK2_CTRL_PD_VSEL1_EN 0x20
109 #define SMARTBUCK2_CTRL_PD_VSEL1_DIS 0x00
110 #define SMARTBUCK2_CTRL_PD_VSEL 0x40
111 
116 #define SMARTBUCK2_TEMP_DIS_BIT_MASK 0xFB
117 #define SMARTBUCK2_TEMP_TS_ENABLE 0x00
118 #define SMARTBUCK2_TEMP_TS_DISABLE 0x04
119 #define SMARTBUCK2_TEMP_TJEW 0x02
120 #define SMARTBUCK2_TEMP_TJEW_BIT_MASK 0xFD
121 #define SMARTBUCK2_TEMP_LT_120_C 0x00
122 #define SMARTBUCK2_TEMP_GT_120_C 0x01
123 #define SMARTBUCK2_TEMP_ERROR 0x02
124 #define SMARTBUCK2_TEMP_TJTS 0x01
125 
130 #define SMARTBUCK2_RMP_VTG_T_BIT_MASK 0xE0
131 #define SMARTBUCK2_RMP_SET 0xE0
132 #define SMARTBUCK2_RMP_EN_DISC 0x04
133 #define SMARTBUCK2_RMP_PFM 0x02
134 #define SMARTBUCK2_RMP_VTG_T_32MVNS 0x00
135 #define SMARTBUCK2_RMP_VTG_T_16MVNS 0x01
136 #define SMARTBUCK2_RMP_VTG_T_8MVNS 0x02
137 #define SMARTBUCK2_RMP_VTG_T_4MVNS 0x03
138 #define SMARTBUCK2_RMP_VTG_T_2MVNS 0x04
139 #define SMARTBUCK2_RMP_VTG_T_1MVNS 0x05
140 #define SMARTBUCK2_RMP_VTG_T_0_5MVNS 0x06
141 #define SMARTBUCK2_RMP_VTG_T_0_25MVNS 0x07
142 
147 #define SMARTBUCK2_VENDOR_ID_BIT_MASK 0xF0
148 #define SMARTBUCK2_ID_VENDOR 0x80
149 #define SMARTBUCK2_PART_NUM_ID_BIT_MASK 0x0C
150 #define SMARTBUCK2_ID_PART_NUM 0x03
151 #define SMARTBUCK2_CHIP_REV_ID_BIT_MASK 0x03
152 
157 #define SMARTBUCK2_VOUT_MIN 500u
158 #define SMARTBUCK2_VOUT_MAX 1770u
159 #define SMARTBUCK2_VOUT_STEP_10MV 10u
160 #define SMARTBUCK2_VOUT_START_500MV 500u
161 
167 #define SMARTBUCK2_DEVICE_ADDRESS 0x60
168  // smartbuck2_set
170 
185 #define SMARTBUCK2_MAP_MIKROBUS( cfg, mikrobus ) \
186  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
187  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
188  // smartbuck2_map // smartbuck2
191 
196 typedef struct
197 {
198  // Modules
199  i2c_master_t i2c;
201  // I2C slave address
202  uint8_t slave_address;
204 } smartbuck2_t;
205 
210 typedef struct
211 {
212  pin_name_t scl;
213  pin_name_t sda;
215  uint32_t i2c_speed;
216  uint8_t i2c_address;
219 
224 typedef enum
225 {
227  SMARTBUCK2_ERROR = -1
228 
230 
247 
262 
276 
291 err_t smartbuck2_generic_write ( smartbuck2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
292 
307 err_t smartbuck2_generic_read ( smartbuck2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
308 
322 err_t smartbuck2_set_voltage ( smartbuck2_t *ctx, uint16_t vout_mv );
323 
337 err_t smartbuck2_get_voltage ( smartbuck2_t *ctx, uint16_t *vout_mv );
338 
354 err_t smartbuck2_set_op_mode ( smartbuck2_t *ctx, uint8_t op_mode );
355 
369 err_t smartbuck2_get_op_mode ( smartbuck2_t *ctx, uint8_t *op_mode );
370 
384 err_t smartbuck2_set_ctrl ( smartbuck2_t *ctx, uint8_t ctrl );
385 
401 err_t smartbuck2_set_temp_shd ( smartbuck2_t *ctx, uint8_t temp_enable );
402 
415 
437 err_t smartbuck2_set_vtg_ramp_timing ( smartbuck2_t *ctx, uint8_t slope );
438 
454 err_t smartbuck2_get_device_id ( smartbuck2_t *ctx, uint8_t *ven_id, uint8_t *part_num_id, uint8_t *chip_id );
455 
456 #ifdef __cplusplus
457 }
458 #endif
459 #endif // SMARTBUCK2_H
460  // smartbuck2
462 
463 // ------------------------------------------------------------------------ END
SMARTBUCK2_ERROR
@ SMARTBUCK2_ERROR
Definition: smartbuck2.h:227
smartbuck2_set_ctrl
err_t smartbuck2_set_ctrl(smartbuck2_t *ctx, uint8_t ctrl)
Smart Buck 2 set control function.
smartbuck2_cfg_t::scl
pin_name_t scl
Definition: smartbuck2.h:212
smartbuck2_cfg_t
Smart Buck 2 Click configuration object.
Definition: smartbuck2.h:211
smartbuck2_return_value_t
smartbuck2_return_value_t
Smart Buck 2 Click return value data.
Definition: smartbuck2.h:225
smartbuck2_check_temp_warning
uint8_t smartbuck2_check_temp_warning(smartbuck2_t *ctx)
Smart Buck 2 check temperature warning function.
smartbuck2_t::slave_address
uint8_t slave_address
Definition: smartbuck2.h:202
smartbuck2_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartbuck2.h:216
smartbuck2_get_voltage
err_t smartbuck2_get_voltage(smartbuck2_t *ctx, uint16_t *vout_mv)
Smart Buck 2 get voltage function.
smartbuck2_get_op_mode
err_t smartbuck2_get_op_mode(smartbuck2_t *ctx, uint8_t *op_mode)
Smart Buck 2 get operation mode function.
smartbuck2_set_op_mode
err_t smartbuck2_set_op_mode(smartbuck2_t *ctx, uint8_t op_mode)
Smart Buck 2 set operation mode function.
smartbuck2_set_voltage
err_t smartbuck2_set_voltage(smartbuck2_t *ctx, uint16_t vout_mv)
Smart Buck 2 set voltage function.
smartbuck2_t
Smart Buck 2 Click context object.
Definition: smartbuck2.h:197
smartbuck2_cfg_t::sda
pin_name_t sda
Definition: smartbuck2.h:213
smartbuck2_t::i2c
i2c_master_t i2c
Definition: smartbuck2.h:199
smartbuck2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartbuck2.h:215
SMARTBUCK2_OK
@ SMARTBUCK2_OK
Definition: smartbuck2.h:226
smartbuck2_set_temp_shd
err_t smartbuck2_set_temp_shd(smartbuck2_t *ctx, uint8_t temp_enable)
Smart Buck 2 set temperature shutdown function.
smartbuck2_cfg_setup
void smartbuck2_cfg_setup(smartbuck2_cfg_t *cfg)
Smart Buck 2 configuration object setup function.
smartbuck2_generic_write
err_t smartbuck2_generic_write(smartbuck2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart Buck 2 I2C writing function.
smartbuck2_set_vtg_ramp_timing
err_t smartbuck2_set_vtg_ramp_timing(smartbuck2_t *ctx, uint8_t slope)
Smart Buck 2 set voltage ramp timing function.
smartbuck2_init
err_t smartbuck2_init(smartbuck2_t *ctx, smartbuck2_cfg_t *cfg)
Smart Buck 2 initialization function.
smartbuck2_generic_read
err_t smartbuck2_generic_read(smartbuck2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart Buck 2 I2C reading function.
smartbuck2_default_cfg
err_t smartbuck2_default_cfg(smartbuck2_t *ctx)
Smart Buck 2 default configuration function.
smartbuck2_get_device_id
err_t smartbuck2_get_device_id(smartbuck2_t *ctx, uint8_t *ven_id, uint8_t *part_num_id, uint8_t *chip_id)
Smart Buck 2 get device ID function.