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 
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_analog_in.h"
48 #include "drv_i2c_master.h"
49 
70 #define BUCK18_CMD_RDAC 0x00
71 #define BUCK18_CMD_RDAC_OTP 0x80
72  // buck18_reg
74 
89 #define BUCK18_OTP_VALID_PRG_RDY 0x00
90 #define BUCK18_OTP_VALID_TEST 0x40
91 #define BUCK18_OTP_VALID_ERROR 0x80
92 #define BUCK18_OTP_VALID_PRG_OK 0xC0
93 
98 #define BUCK18_WIPER_POS_MAX 0x3F
99 #define BUCK18_RES_5_KOHM 5.0f
100 #define BUCK18_RES_50_KOHM 50.0f
101 #define BUCK18_RES_55_KOHM 55.0f
102 #define BUCK18_RDAC_WIPER_POSITION 6, 9, 19, 26, 34, 39, 55, 48, 52, 54, 57, 59, 60, 62, 63
103 
108 #define BUCK18_ADC_RESOLUTION 0x0FFF
109 #define BUCK18_VREF_3V3 3.3
110 #define BUCK18_VREF_5V 5.0
111 
117 #define BUCK18_SET_DEV_ADDR_0 0x2C
118 #define BUCK18_SET_DEV_ADDR_1 0x2D
119  // buck18_set
121 
136 #define BUCK18_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
138  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
139  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
140  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
141  // buck18_map // buck18
144 
149 typedef struct
150 {
151  digital_out_t rst;
153  analog_in_t adc;
154  i2c_master_t i2c;
156  uint8_t slave_address;
157  float vref;
159 } buck18_t;
160 
165 typedef struct
166 {
167  pin_name_t an;
168  pin_name_t scl;
169  pin_name_t sda;
170  pin_name_t rst;
172  analog_in_resolution_t resolution;
173  float vref;
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
178 } buck18_cfg_t;
179 
184 typedef enum
185 {
201 
203 
208 typedef enum
209 {
211  BUCK18_ERROR = -1
212 
214 
231 
245 err_t buck18_init ( buck18_t *ctx, buck18_cfg_t *cfg );
246 
260 
272 err_t buck18_read_raw_adc ( buck18_t *ctx, uint16_t *raw_adc );
273 
285 err_t buck18_read_voltage ( buck18_t *ctx, float *voltage );
286 
298 err_t buck18_set_vref ( buck18_t *ctx, float vref );
299 
310 void buck18_enable ( buck18_t *ctx );
311 
322 void buck18_disable ( buck18_t *ctx );
323 
338 err_t buck18_write_data ( buck18_t *ctx, uint8_t cmd, uint8_t data_in );
339 
353 err_t buck18_read_data ( buck18_t *ctx, uint8_t *data_out );
354 
368 err_t buck18_write_rdac ( buck18_t *ctx, uint8_t wiper_pos );
369 
383 err_t buck18_set_resistance ( buck18_t *ctx, float res_kohm );
384 
400 
401 #ifdef __cplusplus
402 }
403 #endif
404 #endif // BUCK18_H
405  // buck18
407 
408 // ------------------------------------------------------------------------ END
BUCK18_VOUT_2V75
@ BUCK18_VOUT_2V75
Definition: buck18.h:189
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:151
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:170
BUCK18_VOUT_1V25
@ BUCK18_VOUT_1V25
Definition: buck18.h:194
buck18_cfg_t
Buck 18 Click configuration object.
Definition: buck18.h:166
BUCK18_VOUT_2V0
@ BUCK18_VOUT_2V0
Definition: buck18.h:191
buck18_cfg_t::i2c_address
uint8_t i2c_address
Definition: buck18.h:176
buck18_disable
void buck18_disable(buck18_t *ctx)
Buck 18 disable the device function.
BUCK18_VOUT_2V5
@ BUCK18_VOUT_2V5
Definition: buck18.h:190
buck18_enable
void buck18_enable(buck18_t *ctx)
Buck 18 enable the device function.
BUCK18_VOUT_1V
@ BUCK18_VOUT_1V
Definition: buck18.h:198
buck18_cfg_setup
void buck18_cfg_setup(buck18_cfg_t *cfg)
Buck 18 configuration object setup function.
BUCK18_ERROR
@ BUCK18_ERROR
Definition: buck18.h:211
buck18_t::slave_address
uint8_t slave_address
Definition: buck18.h:156
buck18_cfg_t::an
pin_name_t an
Definition: buck18.h:167
BUCK18_VOUT_1V5
@ BUCK18_VOUT_1V5
Definition: buck18.h:193
BUCK18_VOUT_1V8
@ BUCK18_VOUT_1V8
Definition: buck18.h:192
buck18_vout_t
buck18_vout_t
Buck 18 Click output voltage selection.
Definition: buck18.h:185
BUCK18_VOUT_0V95
@ BUCK18_VOUT_0V95
Definition: buck18.h:199
BUCK18_VOUT_1V1
@ BUCK18_VOUT_1V1
Definition: buck18.h:197
buck18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: buck18.h:175
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:196
buck18_t::adc
analog_in_t adc
Definition: buck18.h:153
buck18_cfg_t::scl
pin_name_t scl
Definition: buck18.h:168
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:209
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:157
BUCK18_VOUT_0V9
@ BUCK18_VOUT_0V9
Definition: buck18.h:200
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:172
buck18_cfg_t::vref
float vref
Definition: buck18.h:173
buck18_cfg_t::sda
pin_name_t sda
Definition: buck18.h:169
BUCK18_VOUT_3V3
@ BUCK18_VOUT_3V3
Definition: buck18.h:186
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:154
buck18_t
Buck 18 Click context object.
Definition: buck18.h:150
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:187
BUCK18_OK
@ BUCK18_OK
Definition: buck18.h:210
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:195
BUCK18_VOUT_2V8
@ BUCK18_VOUT_2V8
Definition: buck18.h:188