buck19  2.1.0.0
buck19.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 BUCK19_H
29 #define BUCK19_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 BUCK19_REG_VOUT 0x00
70 #define BUCK19_REG_ILIMIT 0x01
71 #define BUCK19_REG_INT_STATUS 0x02
72 #define BUCK19_REG_INT_LATCH 0x03
73 #define BUCK19_REG_INT_MASK 0x04
74 #define BUCK19_REG_CONFIG_0 0x05
75 #define BUCK19_REG_CONFIG_1 0x06
76  // buck19_reg
78 
93 #define BUCK19_VOUT_MIN 3.0f
94 #define BUCK19_VOUT_MAX 20.0f
95 #define BUCK19_VOUT_DEFAULT 5.0f
96 #define BUCK19_VOUT_11V 11.0f
97 #define BUCK19_VOUT_11V_STEP 0.2f
98 #define BUCK19_VOUT_5p9V 5.9f
99 #define BUCK19_VOUT_5p9V_STEP 0.1f
100 #define BUCK19_VOUT_STEP 0.02f
101 #define BUCK19_FLOAT_COMPARE_TOLERANCE 0.0001f
102 
107 #define BUCK19_ILIMIT_MIN 100
108 #define BUCK19_ILIMIT_MAX 3000
109 #define BUCK19_ILIMIT_STEP 100
110 #define BUCK19_ILIMIT_DEFAULT 500
111 
116 #define BUCK19_INT_INDUCTOR_PCP 0x80
117 #define BUCK19_INT_OT_WARNING 0x40
118 #define BUCK19_INT_OT_PROTECT 0x20
119 #define BUCK19_INT_WATCHDOG 0x10
120 #define BUCK19_INT_POWER_ON 0x08
121 #define BUCK19_INT_SHORT_PROTECT 0x04
122 #define BUCK19_INT_CC_FUNCTION 0x02
123 #define BUCK19_INT_OV_PROTECT 0x01
124 #define BUCK19_INT_DISABLE_ALL 0x00
125 
130 #define BUCK19_CONFIG_0_WATCHDOG_100MS 0x00
131 #define BUCK19_CONFIG_0_WATCHDOG_500MS 0x40
132 #define BUCK19_CONFIG_0_WATCHDOG_1S 0x80
133 #define BUCK19_CONFIG_0_WATCHDOG_5S 0xC0
134 #define BUCK19_CONFIG_0_CDC_OFF 0x00
135 #define BUCK19_CONFIG_0_CDC_FULL 0x10
136 #define BUCK19_CONFIG_0_SW_FREQ_500KHZ 0x00
137 #define BUCK19_CONFIG_0_SW_FREQ_750KHZ 0x04
138 #define BUCK19_CONFIG_0_DITHERING_OFF 0x00
139 #define BUCK19_CONFIG_0_DITHERING_ON 0x02
140 #define BUCK19_CONFIG_0_DISCHARGE_OFF 0x00
141 #define BUCK19_CONFIG_0_DISCHARGE_ON 0x01
142 
147 #define BUCK19_CONFIG_1_WATCHDOG_EN_OFF 0x00
148 #define BUCK19_CONFIG_1_WATCHDOG_EN_ON 0x02
149 #define BUCK19_CONFIG_1_DIG_EN_OFF 0x00
150 #define BUCK19_CONFIG_1_DIG_EN_ON 0x01
151 
157 #define BUCK19_DEVICE_ADDRESS_VCC 0x04
158 #define BUCK19_DEVICE_ADDRESS_GND 0x05
159 #define BUCK19_DEVICE_ADDRESS_SDA 0x06
160 #define BUCK19_DEVICE_ADDRESS_SCL 0x07
161  // buck19_set
163 
178 #define BUCK19_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
180  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
181  cfg.pon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
182  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
183  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
184  // buck19_map // buck19
187 
192 typedef struct
193 {
194  // Output pins
195  digital_out_t en;
197  // Input pins
198  digital_in_t pon;
199  digital_in_t int_pin;
201  // Modules
202  i2c_master_t i2c;
204  // I2C slave address
205  uint8_t slave_address;
207 } buck19_t;
208 
213 typedef struct
214 {
215  pin_name_t scl;
216  pin_name_t sda;
218  pin_name_t pon;
219  pin_name_t en;
220  pin_name_t int_pin;
222  uint32_t i2c_speed;
223  uint8_t i2c_address;
225 } buck19_cfg_t;
226 
231 typedef enum
232 {
234  BUCK19_ERROR = -1
235 
237 
254 
268 err_t buck19_init ( buck19_t *ctx, buck19_cfg_t *cfg );
269 
283 
297 err_t buck19_write_register ( buck19_t *ctx, uint8_t reg, uint8_t data_in );
298 
311 err_t buck19_read_register ( buck19_t *ctx, uint8_t reg, uint8_t *data_out );
312 
322 
332 
341 uint8_t buck19_get_pon_pin ( buck19_t *ctx );
342 
351 uint8_t buck19_get_int_pin ( buck19_t *ctx );
352 
364 err_t buck19_set_vout ( buck19_t *ctx, float vout );
365 
377 err_t buck19_set_ilimit ( buck19_t *ctx, uint16_t ilimit );
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 #endif // BUCK19_H
383  // buck19
385 
386 // ------------------------------------------------------------------------ END
buck19_cfg_t::sda
pin_name_t sda
Definition: buck19.h:216
buck19_set_vout
err_t buck19_set_vout(buck19_t *ctx, float vout)
Buck 19 set vout function.
buck19_t::int_pin
digital_in_t int_pin
Definition: buck19.h:199
buck19_t::slave_address
uint8_t slave_address
Definition: buck19.h:205
buck19_cfg_t::en
pin_name_t en
Definition: buck19.h:219
buck19_t
Buck 19 Click context object.
Definition: buck19.h:193
buck19_cfg_t::int_pin
pin_name_t int_pin
Definition: buck19.h:220
buck19_get_int_pin
uint8_t buck19_get_int_pin(buck19_t *ctx)
Buck 19 get int pin function.
buck19_cfg_t
Buck 19 Click configuration object.
Definition: buck19.h:214
BUCK19_ERROR
@ BUCK19_ERROR
Definition: buck19.h:234
buck19_disable_device
void buck19_disable_device(buck19_t *ctx)
Buck 19 disable device function.
buck19_cfg_t::scl
pin_name_t scl
Definition: buck19.h:215
buck19_init
err_t buck19_init(buck19_t *ctx, buck19_cfg_t *cfg)
Buck 19 initialization function.
BUCK19_OK
@ BUCK19_OK
Definition: buck19.h:233
buck19_t::i2c
i2c_master_t i2c
Definition: buck19.h:202
buck19_set_ilimit
err_t buck19_set_ilimit(buck19_t *ctx, uint16_t ilimit)
Buck 19 set ilimit function.
buck19_enable_device
void buck19_enable_device(buck19_t *ctx)
Buck 19 enable device function.
buck19_cfg_setup
void buck19_cfg_setup(buck19_cfg_t *cfg)
Buck 19 configuration object setup function.
buck19_cfg_t::pon
pin_name_t pon
Definition: buck19.h:218
buck19_return_value_t
buck19_return_value_t
Buck 19 Click return value data.
Definition: buck19.h:232
buck19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck19.h:222
buck19_t::pon
digital_in_t pon
Definition: buck19.h:198
buck19_get_pon_pin
uint8_t buck19_get_pon_pin(buck19_t *ctx)
Buck 19 get pon pin function.
buck19_write_register
err_t buck19_write_register(buck19_t *ctx, uint8_t reg, uint8_t data_in)
Buck 19 write register function.
buck19_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck19.h:223
buck19_t::en
digital_out_t en
Definition: buck19.h:195
buck19_default_cfg
err_t buck19_default_cfg(buck19_t *ctx)
Buck 19 default configuration function.
buck19_read_register
err_t buck19_read_register(buck19_t *ctx, uint8_t reg, uint8_t *data_out)
Buck 19 read register function.