buck18  2.1.0.0
buck18.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 BUCK18_H
29 #define BUCK18_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_analog_in.h"
52 #include "drv_i2c_master.h"
53 
74 #define BUCK18_CMD_RDAC 0x00
75 #define BUCK18_CMD_RDAC_OTP 0x80
76  // buck18_reg
78 
93 #define BUCK18_OTP_VALID_PRG_RDY 0x00
94 #define BUCK18_OTP_VALID_TEST 0x40
95 #define BUCK18_OTP_VALID_ERROR 0x80
96 #define BUCK18_OTP_VALID_PRG_OK 0xC0
97 
102 #define BUCK18_WIPER_POS_MAX 0x3F
103 #define BUCK18_RES_5_KOHM 5.0f
104 #define BUCK18_RES_50_KOHM 50.0f
105 #define BUCK18_RES_55_KOHM 55.0f
106 #define BUCK18_RDAC_WIPER_POSITION 6, 9, 19, 26, 34, 39, 55, 48, 52, 54, 57, 59, 60, 62, 63
107 
112 #define BUCK18_ADC_RESOLUTION 0x0FFF
113 #define BUCK18_VREF_3V3 3.3
114 #define BUCK18_VREF_5V 5.0
115 
121 #define BUCK18_SET_DEV_ADDR_0 0x2C
122 #define BUCK18_SET_DEV_ADDR_1 0x2D
123  // buck18_set
125 
140 #define BUCK18_MAP_MIKROBUS( cfg, mikrobus ) \
141  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
142  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
143  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
144  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
145  // buck18_map // buck18
148 
153 typedef struct
154 {
155  digital_out_t rst;
157  analog_in_t adc;
158  i2c_master_t i2c;
160  uint8_t slave_address;
161  float vref;
163 } buck18_t;
164 
169 typedef struct
170 {
171  pin_name_t an;
172  pin_name_t scl;
173  pin_name_t sda;
174  pin_name_t rst;
176  analog_in_resolution_t resolution;
177  float vref;
179  uint32_t i2c_speed;
180  uint8_t i2c_address;
182 } buck18_cfg_t;
183 
188 typedef enum
189 {
205 
207 
212 typedef enum
213 {
215  BUCK18_ERROR = -1
216 
218 
235 
249 err_t buck18_init ( buck18_t *ctx, buck18_cfg_t *cfg );
250 
264 
276 err_t buck18_read_raw_adc ( buck18_t *ctx, uint16_t *raw_adc );
277 
289 err_t buck18_read_voltage ( buck18_t *ctx, float *voltage );
290 
302 err_t buck18_set_vref ( buck18_t *ctx, float vref );
303 
314 void buck18_enable ( buck18_t *ctx );
315 
326 void buck18_disable ( buck18_t *ctx );
327 
342 err_t buck18_write_data ( buck18_t *ctx, uint8_t cmd, uint8_t data_in );
343 
357 err_t buck18_read_data ( buck18_t *ctx, uint8_t *data_out );
358 
372 err_t buck18_write_rdac ( buck18_t *ctx, uint8_t wiper_pos );
373 
387 err_t buck18_set_resistance ( buck18_t *ctx, float res_kohm );
388 
404 
405 #ifdef __cplusplus
406 }
407 #endif
408 #endif // BUCK18_H
409  // buck18
411 
412 // ------------------------------------------------------------------------ END
BUCK18_VOUT_2V75
@ BUCK18_VOUT_2V75
Definition: buck18.h:193
buck18_default_cfg
err_t buck18_default_cfg(buck18_t *ctx)
Buck 18 default configuration function.
buck18_t::rst
digital_out_t rst
Definition: buck18.h:155
buck18_set_vout
err_t buck18_set_vout(buck18_t *ctx, buck18_vout_t vout)
Buck 18 sets the VOUT function.
buck18_cfg_t::rst
pin_name_t rst
Definition: buck18.h:174
BUCK18_VOUT_1V25
@ BUCK18_VOUT_1V25
Definition: buck18.h:198
buck18_cfg_t
Buck 18 Click configuration object.
Definition: buck18.h:170
BUCK18_VOUT_2V0
@ BUCK18_VOUT_2V0
Definition: buck18.h:195
buck18_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck18.h:180
buck18_disable
void buck18_disable(buck18_t *ctx)
Buck 18 disable the device function.
BUCK18_VOUT_2V5
@ BUCK18_VOUT_2V5
Definition: buck18.h:194
buck18_enable
void buck18_enable(buck18_t *ctx)
Buck 18 enable the device function.
BUCK18_VOUT_1V
@ BUCK18_VOUT_1V
Definition: buck18.h:202
buck18_cfg_setup
void buck18_cfg_setup(buck18_cfg_t *cfg)
Buck 18 configuration object setup function.
BUCK18_ERROR
@ BUCK18_ERROR
Definition: buck18.h:215
buck18_t::slave_address
uint8_t slave_address
Definition: buck18.h:160
buck18_cfg_t::an
pin_name_t an
Definition: buck18.h:171
BUCK18_VOUT_1V5
@ BUCK18_VOUT_1V5
Definition: buck18.h:197
BUCK18_VOUT_1V8
@ BUCK18_VOUT_1V8
Definition: buck18.h:196
buck18_vout_t
buck18_vout_t
Buck 18 Click output voltage selection.
Definition: buck18.h:189
BUCK18_VOUT_0V95
@ BUCK18_VOUT_0V95
Definition: buck18.h:203
BUCK18_VOUT_1V1
@ BUCK18_VOUT_1V1
Definition: buck18.h:201
buck18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck18.h:179
buck18_read_data
err_t buck18_read_data(buck18_t *ctx, uint8_t *data_out)
Buck 18 data reading function.
buck18_init
err_t buck18_init(buck18_t *ctx, buck18_cfg_t *cfg)
Buck 18 initialization function.
BUCK18_VOUT_1V15
@ BUCK18_VOUT_1V15
Definition: buck18.h:200
buck18_t::adc
analog_in_t adc
Definition: buck18.h:157
buck18_cfg_t::scl
pin_name_t scl
Definition: buck18.h:172
buck18_read_raw_adc
err_t buck18_read_raw_adc(buck18_t *ctx, uint16_t *raw_adc)
Buck 18 read raw ADC value function.
buck18_return_value_t
buck18_return_value_t
Buck 18 Click return value data.
Definition: buck18.h:213
buck18_read_voltage
err_t buck18_read_voltage(buck18_t *ctx, float *voltage)
Buck 18 read voltage level function.
buck18_t::vref
float vref
Definition: buck18.h:161
BUCK18_VOUT_0V9
@ BUCK18_VOUT_0V9
Definition: buck18.h:204
buck18_set_vref
err_t buck18_set_vref(buck18_t *ctx, float vref)
Buck 18 set vref function.
buck18_cfg_t::resolution
analog_in_resolution_t resolution
Definition: buck18.h:176
buck18_cfg_t::vref
float vref
Definition: buck18.h:177
buck18_cfg_t::sda
pin_name_t sda
Definition: buck18.h:173
BUCK18_VOUT_3V3
@ BUCK18_VOUT_3V3
Definition: buck18.h:190
buck18_write_rdac
err_t buck18_write_rdac(buck18_t *ctx, uint8_t wiper_pos)
Buck 18 data writing function.
buck18_t::i2c
i2c_master_t i2c
Definition: buck18.h:158
buck18_t
Buck 18 Click context object.
Definition: buck18.h:154
buck18_set_resistance
err_t buck18_set_resistance(buck18_t *ctx, float res_kohm)
Buck 18 sets the resistance function.
BUCK18_VOUT_3V
@ BUCK18_VOUT_3V
Definition: buck18.h:191
BUCK18_OK
@ BUCK18_OK
Definition: buck18.h:214
buck18_write_data
err_t buck18_write_data(buck18_t *ctx, uint8_t cmd, uint8_t data_in)
Buck 18 data writing function.
BUCK18_VOUT_1V2
@ BUCK18_VOUT_1V2
Definition: buck18.h:199
BUCK18_VOUT_2V8
@ BUCK18_VOUT_2V8
Definition: buck18.h:192