vcpmonitor6  2.1.0.0
vcpmonitor6.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 VCPMONITOR6_H
29 #define VCPMONITOR6_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_i2c_master.h"
52 
73 #define VCPMONITOR6_REG_CONFIG 0x00
74 #define VCPMONITOR6_REG_ADC_CONFIG 0x01
75 #define VCPMONITOR6_REG_VBUS 0x05
76 #define VCPMONITOR6_REG_DIETEMP 0x06
77 #define VCPMONITOR6_REG_CURRENT 0x07
78 #define VCPMONITOR6_REG_POWER 0x08
79 #define VCPMONITOR6_REG_ENERGY 0x09
80 #define VCPMONITOR6_REG_CHARGE 0x0A
81 #define VCPMONITOR6_REG_ALERT_DIAG 0x0B
82 #define VCPMONITOR6_REG_COL 0x0C
83 #define VCPMONITOR6_REG_CUL 0x0D
84 #define VCPMONITOR6_REG_BOVL 0x0E
85 #define VCPMONITOR6_REG_BUVL 0x0F
86 #define VCPMONITOR6_REG_TEMP_LIMIT 0x10
87 #define VCPMONITOR6_REG_PWR_LIMIT 0x11
88 #define VCPMONITOR6_REG_MANUFACTURER_ID 0x3E
89  // vcpmonitor6_reg
91 
106 #define VCPMONITOR6_CFG_RST 0x80
107 #define VCPMONITOR6_CFG_RSTACC 0x40
108 #define VCPMONITOR6_CFG_CONVDLY 0x01FEu
109 
114 #define VCPMONITOR6_ADC_CFG_MODE_SHD 0x00
115 #define VCPMONITOR6_ADC_CFG_MODE_TRG_BV 0x01
116 #define VCPMONITOR6_ADC_CFG_MODE_TRG_T 0x04
117 #define VCPMONITOR6_ADC_CFG_MODE_TRG_BV_T 0x05
118 #define VCPMONITOR6_ADC_CFG_MODE_TRG_T_C 0x06
119 #define VCPMONITOR6_ADC_CFG_MODE_TRG_ALL 0x07
120 #define VCPMONITOR6_ADC_CFG_MODE_SD 0x08
121 #define VCPMONITOR6_ADC_CFG_MODE_CNT_BV 0x09
122 #define VCPMONITOR6_ADC_CFG_MODE_CNT_T 0x0C
123 #define VCPMONITOR6_ADC_CFG_MODE_CNT_BV_T 0x0D
124 #define VCPMONITOR6_ADC_CFG_MODE_CNT_T_C 0x0E
125 #define VCPMONITOR6_ADC_CFG_MODE_CNT_ALL 0x0F
126 #define VCPMONITOR6_ADC_CFG_MODE_BITMASK 0x0FFFu
127 #define VCPMONITOR6_ADC_CFG_VBSTA 0x07
128 #define VCPMONITOR6_ADC_CFG_VBSTA_BITMASK 0xF007u
129 #define VCPMONITOR6_ADC_CFG_AVG 0x07
130 #define VCPMONITOR6_ADC_CFG_AVG_BITMASK 0xFFF8u
131 
136 #define VCPMONITOR6_ALR_DIAG_TRANSPARENT 0x0000u
137 #define VCPMONITOR6_ALR_DIAG_ALATCH 0x8000u
138 #define VCPMONITOR6_ALR_DIAG_CNVR_DIS 0x0000u
139 #define VCPMONITOR6_ALR_DIAG_CNVR_EN 0x4000u
140 #define VCPMONITOR6_ALR_DIAG_SLWALR_NAVG 0x0000u
141 #define VCPMONITOR6_ALR_DIAG_SLWALR_AVG 0x2000u
142 #define VCPMONITOR6_ALR_DIAG_APOL_NORMAL 0x0000u
143 #define VCPMONITOR6_ALR_DIAG_APOL_INV 0x1000u
144 #define VCPMONITOR6_ALR_DIAG_W_BITMASK 0xF000u
145 #define VCPMONITOR6_ALR_DIAG_ENERGYOF 0x0800u
146 #define VCPMONITOR6_ALR_DIAG_CHARGEOF 0x0400u
147 #define VCPMONITOR6_ALR_DIAG_MATHOF 0x0200u
148 #define VCPMONITOR6_ALR_DIAG_TMPOL 0x0080u
149 #define VCPMONITOR6_ALR_DIAG_CURRENTOL 0x0040u
150 #define VCPMONITOR6_ALR_DIAG_CURRENTUL 0x0020u
151 #define VCPMONITOR6_ALR_DIAG_BUSOL 0x0010u
152 #define VCPMONITOR6_ALR_DIAG_BUSUL 0x0008u
153 #define VCPMONITOR6_ALR_DIAG_POL 0x0004u
154 #define VCPMONITOR6_ALR_DIAG_CNVRF 0x0002u
155 #define VCPMONITOR6_ALR_DIAG_MEMSTAT 0x0001u
156 #define VCPMONITOR6_ALR_DIAG_R_BITMASK 0x0FFFu
157 
162 #define VCPMONITOR6_MANUFACTURER_ID 0x5449u
163 
168 #define VCPMONITOR6_CONV_FACT_VBUS 3.125f
169 #define VCPMONITOR6_CONV_FACT_DIETEMP 125.0f
170 #define VCPMONITOR6_CONV_FACT_CURRENT 2500.0f
171 #define VCPMONITOR6_CONV_FACT_POWER 480.0f
172 #define VCPMONITOR6_CONV_FACT_ENERGY 7.68f
173 #define VCPMONITOR6_CONV_FACT_CHARGE 150.0f
174 #define VCPMONITOR6_CALC_EN_CHRG_RES 256.0f
175 #define VCPMONITOR6_CALC_EN_CHRG 4.0f
176 #define VCPMONITOR6_UN_CONV_1K 1000.0f
177 #define VCPMONITOR6_UN_CONV_1M 1000000.0f
178 
184 #define VCPMONITOR6_DEVICE_ADDRESS_0 0x40
185 #define VCPMONITOR6_DEVICE_ADDRESS_1 0x41
186 #define VCPMONITOR6_DEVICE_ADDRESS_2 0x44
187 #define VCPMONITOR6_DEVICE_ADDRESS_3 0x45
188  // vcpmonitor6_set
190 
205 #define VCPMONITOR6_MAP_MIKROBUS( cfg, mikrobus ) \
206  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
207  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
208  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
209  // vcpmonitor6_map // vcpmonitor6
212 
217 typedef struct
218 {
219  // Input pins
220  digital_in_t alr;
222  // Modules
223  i2c_master_t i2c;
225  // I2C slave address
226  uint8_t slave_address;
228 } vcpmonitor6_t;
229 
234 typedef struct
235 {
236  pin_name_t scl;
237  pin_name_t sda;
239  pin_name_t alr;
241  uint32_t i2c_speed;
242  uint8_t i2c_address;
245 
250 typedef enum
251 {
253  VCPMONITOR6_ERROR = -1
254 
256 
273 
288 
302 
317 err_t vcpmonitor6_generic_write ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
318 
333 err_t vcpmonitor6_generic_read ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
334 
348 err_t vcpmonitor6_reg_write ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t data_in );
349 
363 err_t vcpmonitor6_reg_read ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t *data_out );
364 
377 
390 err_t vcpmonitor6_set_conv_dly ( vcpmonitor6_t *ctx, uint16_t dly_ms );
391 
405 err_t vcpmonitor6_set_op_mode ( vcpmonitor6_t *ctx, uint8_t op_mode );
406 
422 err_t vcpmonitor6_set_conv_time ( vcpmonitor6_t *ctx, uint8_t vbusct, uint8_t vsenct, uint8_t tct );
423 
436 err_t vcpmonitor6_set_adc_avg ( vcpmonitor6_t *ctx, uint8_t avg );
437 
450 err_t vcpmonitor6_get_bus_voltage ( vcpmonitor6_t *ctx, float *voltage );
451 
464 err_t vcpmonitor6_get_temperature ( vcpmonitor6_t *ctx, float *temperature );
465 
478 err_t vcpmonitor6_get_current ( vcpmonitor6_t *ctx, float *current );
479 
492 err_t vcpmonitor6_get_power ( vcpmonitor6_t *ctx, float *power );
493 
506 err_t vcpmonitor6_get_energy ( vcpmonitor6_t *ctx, float *energy );
507 
520 err_t vcpmonitor6_get_charge ( vcpmonitor6_t *ctx, float *charge );
521 
534 err_t vcpmonitor6_set_diag_flg_alr ( vcpmonitor6_t *ctx, uint16_t diag_flg_alr );
535 
548 err_t vcpmonitor6_get_indc_flg ( vcpmonitor6_t *ctx, uint16_t *indc_flg );
549 
562 
575 err_t vcpmonitor6_get_device_id ( vcpmonitor6_t *ctx, uint16_t *man_id );
576 
588 
589 #ifdef __cplusplus
590 }
591 #endif
592 #endif // VCPMONITOR6_H
593  // vcpmonitor6
595 
596 // ------------------------------------------------------------------------ END
vcpmonitor6_set_diag_flg_alr
err_t vcpmonitor6_set_diag_flg_alr(vcpmonitor6_t *ctx, uint16_t diag_flg_alr)
VCP Monitor 6 set diagnostic function.
vcpmonitor6_wait_conv_cmpl
err_t vcpmonitor6_wait_conv_cmpl(vcpmonitor6_t *ctx)
VCP Monitor 6 wait conversion function.
vcpmonitor6_sw_reset
err_t vcpmonitor6_sw_reset(vcpmonitor6_t *ctx)
VCP Monitor 6 SW reset writing function.
vcpmonitor6_set_conv_dly
err_t vcpmonitor6_set_conv_dly(vcpmonitor6_t *ctx, uint16_t dly_ms)
VCP Monitor 6 set conversion delay function.
vcpmonitor6_t::alr
digital_in_t alr
Definition: vcpmonitor6.h:220
vcpmonitor6_t::i2c
i2c_master_t i2c
Definition: vcpmonitor6.h:223
vcpmonitor6_cfg_t::alr
pin_name_t alr
Definition: vcpmonitor6.h:239
vcpmonitor6_cfg_t::sda
pin_name_t sda
Definition: vcpmonitor6.h:237
vcpmonitor6_cfg_setup
void vcpmonitor6_cfg_setup(vcpmonitor6_cfg_t *cfg)
VCP Monitor 6 configuration object setup function.
vcpmonitor6_get_energy
err_t vcpmonitor6_get_energy(vcpmonitor6_t *ctx, float *energy)
VCP Monitor 6 get the energy function.
vcpmonitor6_get_alarm
uint8_t vcpmonitor6_get_alarm(vcpmonitor6_t *ctx)
VCP Monitor 6 get alarm function.
vcpmonitor6_set_adc_avg
err_t vcpmonitor6_set_adc_avg(vcpmonitor6_t *ctx, uint8_t avg)
VCP Monitor 6 set the ADC sample function.
vcpmonitor6_get_bus_voltage
err_t vcpmonitor6_get_bus_voltage(vcpmonitor6_t *ctx, float *voltage)
VCP Monitor 6 get the voltage function.
vcpmonitor6_generic_write
err_t vcpmonitor6_generic_write(vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
VCP Monitor 6 I2C writing function.
vcpmonitor6_set_op_mode
err_t vcpmonitor6_set_op_mode(vcpmonitor6_t *ctx, uint8_t op_mode)
VCP Monitor 6 set the operating mode function.
vcpmonitor6_reg_read
err_t vcpmonitor6_reg_read(vcpmonitor6_t *ctx, uint8_t reg, uint16_t *data_out)
VCP Monitor 6 register reading function.
vcpmonitor6_get_power
err_t vcpmonitor6_get_power(vcpmonitor6_t *ctx, float *power)
VCP Monitor 6 get the power function.
vcpmonitor6_get_indc_flg
err_t vcpmonitor6_get_indc_flg(vcpmonitor6_t *ctx, uint16_t *indc_flg)
VCP Monitor 6 get diagnostic indicates function.
vcpmonitor6_default_cfg
err_t vcpmonitor6_default_cfg(vcpmonitor6_t *ctx)
VCP Monitor 6 default configuration function.
vcpmonitor6_t::slave_address
uint8_t slave_address
Definition: vcpmonitor6.h:226
vcpmonitor6_reg_write
err_t vcpmonitor6_reg_write(vcpmonitor6_t *ctx, uint8_t reg, uint16_t data_in)
VCP Monitor 6 register writing function.
vcpmonitor6_get_device_id
err_t vcpmonitor6_get_device_id(vcpmonitor6_t *ctx, uint16_t *man_id)
VCP Monitor 6 get device ID function.
vcpmonitor6_set_conv_time
err_t vcpmonitor6_set_conv_time(vcpmonitor6_t *ctx, uint8_t vbusct, uint8_t vsenct, uint8_t tct)
VCP Monitor 6 set the conversion time function.
VCPMONITOR6_ERROR
@ VCPMONITOR6_ERROR
Definition: vcpmonitor6.h:253
VCPMONITOR6_OK
@ VCPMONITOR6_OK
Definition: vcpmonitor6.h:252
vcpmonitor6_get_temperature
err_t vcpmonitor6_get_temperature(vcpmonitor6_t *ctx, float *temperature)
VCP Monitor 6 get the temperature function.
vcpmonitor6_generic_read
err_t vcpmonitor6_generic_read(vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
VCP Monitor 6 I2C reading function.
vcpmonitor6_return_value_t
vcpmonitor6_return_value_t
VCP Monitor 6 Click return value data.
Definition: vcpmonitor6.h:251
vcpmonitor6_init
err_t vcpmonitor6_init(vcpmonitor6_t *ctx, vcpmonitor6_cfg_t *cfg)
VCP Monitor 6 initialization function.
vcpmonitor6_cfg_t
VCP Monitor 6 Click configuration object.
Definition: vcpmonitor6.h:235
vcpmonitor6_cfg_t::i2c_address
uint8_t i2c_address
Definition: vcpmonitor6.h:242
vcpmonitor6_cfg_t::scl
pin_name_t scl
Definition: vcpmonitor6.h:236
vcpmonitor6_get_current
err_t vcpmonitor6_get_current(vcpmonitor6_t *ctx, float *current)
VCP Monitor 6 get the current function.
vcpmonitor6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vcpmonitor6.h:241
vcpmonitor6_get_charge
err_t vcpmonitor6_get_charge(vcpmonitor6_t *ctx, float *charge)
VCP Monitor 6 get the charge function.
vcpmonitor6_t
VCP Monitor 6 Click context object.
Definition: vcpmonitor6.h:218