smartbuck3  2.1.0.0
smartbuck3.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 SMARTBUCK3_H
29 #define SMARTBUCK3_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 SMARTBUCK3_REG_SET0 0x00
70 #define SMARTBUCK3_REG_SET1 0x01
71 #define SMARTBUCK3_REG_CTRL 0x04
72 #define SMARTBUCK3_REG_TEMP 0x05
73 #define SMARTBUCK3_REG_RMPCTRL 0x06
74 #define SMARTBUCK3_REG_CHIP_ID_0 0x08
75 #define SMARTBUCK3_REG_CHIP_ID_1 0x09
76  // smartbuck3_reg
78 
93 #define SMARTBUCK3_MOD_BIT_MASK 0x80
94 #define SMARTBUCK3_OP_MODE_FORCED_PWM 0x80
95 #define SMARTBUCK3_OP_MODE_PFM 0x00
96 #define SMARTBUCK3_OV_BIT_MASK 0x7F
97 #define SMARTBUCK3_CTRL_PD_EN 0x80
98 #define SMARTBUCK3_CTRL_PD_VSEL 0x40
99 #define SMARTBUCK3_TEMP_DIS_BIT_MASK 0xFB
100 #define SMARTBUCK3_TEMP_TS_ENABLE 0x00
101 #define SMARTBUCK3_TEMP_TS_DISABLE 0x04
102 #define SMARTBUCK3_TEMP_TJEW 0x02
103 #define SMARTBUCK3_TEMP_TJEW_BIT_MASK 0xFD
104 #define SMARTBUCK3_TEMP_LT_120_C 0x00
105 #define SMARTBUCK3_TEMP_GT_120_C 0x01
106 #define SMARTBUCK3_TEMP_ERROR 0x02
107 #define SMARTBUCK3_TEMP_TJTS 0x01
108 #define SMARTBUCK3_RMP_SET 0xE0
109 #define SMARTBUCK3_RMP_EN_DISC 0x04
110 #define SMARTBUCK3_RMP_PFM 0x02
111 #define SMARTBUCK3_ID_VENDOR 0xF0
112 #define SMARTBUCK3_ID_PART 0x0C
113 #define SMARTBUCK3_ID_REV 0x03
114 #define SMARTBUCK3_VTG_RAMP_T_32mVns 0x00
115 #define SMARTBUCK3_VTG_RAMP_T_16mVns 0x01
116 #define SMARTBUCK3_VTG_RAMP_T_8mVns 0x02
117 #define SMARTBUCK3_VTG_RAMP_T_4mVns 0x03
118 #define SMARTBUCK3_VTG_RAMP_T_2mVns 0x04
119 #define SMARTBUCK3_VTG_RAMP_T_1mVns 0x05
120 #define SMARTBUCK3_VTG_RAMP_T_0_5mVns 0x06
121 #define SMARTBUCK3_VTG_RAMP_T_0_25mVns 0x07
122 #define SMARTBUCK3_VTG_RAMP_T_BIT_MASK 0xE0
123 #define SMARTBUCK3_VOUT_MAX 1770
124 #define SMARTBUCK3_VOUT_MIN 500
125 #define SMARTBUCK3_DEVICE_ID 0x91
126 
132 #define SMARTBUCK3_DEVICE_ADDRESS 0x60
133  // smartbuck3_set
135 
150 #define SMARTBUCK3_MAP_MIKROBUS( cfg, mikrobus ) \
151  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
152  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
153  // smartbuck3_map // smartbuck3
156 
161 typedef struct
162 {
163  // Modules
164  i2c_master_t i2c;
166  // I2C slave address
167  uint8_t slave_address;
169 } smartbuck3_t;
170 
175 typedef struct
176 {
177  pin_name_t scl;
178  pin_name_t sda;
180  uint32_t i2c_speed;
181  uint8_t i2c_address;
184 
189 typedef enum
190 {
192  SMARTBUCK3_ERROR = -1
193 
195 
212 
227 
241 
256 err_t smartbuck3_generic_write ( smartbuck3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
257 
272 err_t smartbuck3_generic_read ( smartbuck3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
273 
287 err_t smartbuck3_set_voltage ( smartbuck3_t *ctx, uint16_t vout_mv );
288 
302 err_t smartbuck3_get_voltage ( smartbuck3_t *ctx, uint16_t *vout_mv );
303 
319 err_t smartbuck3_set_operation_mode ( smartbuck3_t *ctx, uint8_t op_mode );
320 
336 err_t smartbuck3_get_operation_mode ( smartbuck3_t *ctx, uint8_t *op_mode );
337 
353 err_t smartbuck3_set_temperature_shutdown ( smartbuck3_t *ctx, uint8_t temp_enable );
354 
367 
389 err_t smartbuck3_set_voltage_ramp_timing ( smartbuck3_t *ctx, uint8_t slope );
390 
406 err_t smartbuck3_get_device_id ( smartbuck3_t *ctx, uint8_t *device_id );
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 #endif // SMARTBUCK3_H
412  // smartbuck3
414 
415 // ------------------------------------------------------------------------ END
smartbuck3_cfg_t::sda
pin_name_t sda
Definition: smartbuck3.h:178
smartbuck3_cfg_t
Smart Buck 3 Click configuration object.
Definition: smartbuck3.h:176
smartbuck3_init
err_t smartbuck3_init(smartbuck3_t *ctx, smartbuck3_cfg_t *cfg)
Smart Buck 3 initialization function.
smartbuck3_generic_write
err_t smartbuck3_generic_write(smartbuck3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Smart Buck 3 I2C writing function.
smartbuck3_cfg_t::i2c_address
uint8_t i2c_address
Definition: smartbuck3.h:181
smartbuck3_return_value_t
smartbuck3_return_value_t
Smart Buck 3 Click return value data.
Definition: smartbuck3.h:190
smartbuck3_set_operation_mode
err_t smartbuck3_set_operation_mode(smartbuck3_t *ctx, uint8_t op_mode)
Smart Buck 3 set operation mode function.
smartbuck3_get_operation_mode
err_t smartbuck3_get_operation_mode(smartbuck3_t *ctx, uint8_t *op_mode)
Smart Buck 3 get operation mode function.
smartbuck3_t::slave_address
uint8_t slave_address
Definition: smartbuck3.h:167
smartbuck3_t
Smart Buck 3 Click context object.
Definition: smartbuck3.h:162
smartbuck3_get_voltage
err_t smartbuck3_get_voltage(smartbuck3_t *ctx, uint16_t *vout_mv)
Smart Buck 3 get voltage function.
smartbuck3_cfg_setup
void smartbuck3_cfg_setup(smartbuck3_cfg_t *cfg)
Smart Buck 3 configuration object setup function.
smartbuck3_get_device_id
err_t smartbuck3_get_device_id(smartbuck3_t *ctx, uint8_t *device_id)
Smart Buck 3 get device ID function.
smartbuck3_t::i2c
i2c_master_t i2c
Definition: smartbuck3.h:164
smartbuck3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: smartbuck3.h:180
smartbuck3_set_temperature_shutdown
err_t smartbuck3_set_temperature_shutdown(smartbuck3_t *ctx, uint8_t temp_enable)
Smart Buck 3 set temperature shutdown function.
smartbuck3_default_cfg
err_t smartbuck3_default_cfg(smartbuck3_t *ctx)
Smart Buck 3 default configuration function.
smartbuck3_check_temperature_warning
uint8_t smartbuck3_check_temperature_warning(smartbuck3_t *ctx)
Smart Buck 3 check temperature warning function.
smartbuck3_cfg_t::scl
pin_name_t scl
Definition: smartbuck3.h:177
SMARTBUCK3_ERROR
@ SMARTBUCK3_ERROR
Definition: smartbuck3.h:192
smartbuck3_set_voltage
err_t smartbuck3_set_voltage(smartbuck3_t *ctx, uint16_t vout_mv)
Smart Buck 3 set voltage function.
smartbuck3_generic_read
err_t smartbuck3_generic_read(smartbuck3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Smart Buck 3 I2C reading function.
SMARTBUCK3_OK
@ SMARTBUCK3_OK
Definition: smartbuck3.h:191
smartbuck3_set_voltage_ramp_timing
err_t smartbuck3_set_voltage_ramp_timing(smartbuck3_t *ctx, uint8_t slope)
Smart Buck 3 set voltage ramp timing function.