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 
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 VCPMONITOR6_REG_CONFIG 0x00
70 #define VCPMONITOR6_REG_ADC_CONFIG 0x01
71 #define VCPMONITOR6_REG_VBUS 0x05
72 #define VCPMONITOR6_REG_DIETEMP 0x06
73 #define VCPMONITOR6_REG_CURRENT 0x07
74 #define VCPMONITOR6_REG_POWER 0x08
75 #define VCPMONITOR6_REG_ENERGY 0x09
76 #define VCPMONITOR6_REG_CHARGE 0x0A
77 #define VCPMONITOR6_REG_ALERT_DIAG 0x0B
78 #define VCPMONITOR6_REG_COL 0x0C
79 #define VCPMONITOR6_REG_CUL 0x0D
80 #define VCPMONITOR6_REG_BOVL 0x0E
81 #define VCPMONITOR6_REG_BUVL 0x0F
82 #define VCPMONITOR6_REG_TEMP_LIMIT 0x10
83 #define VCPMONITOR6_REG_PWR_LIMIT 0x11
84 #define VCPMONITOR6_REG_MANUFACTURER_ID 0x3E
85  // vcpmonitor6_reg
87 
102 #define VCPMONITOR6_CFG_RST 0x80
103 #define VCPMONITOR6_CFG_RSTACC 0x40
104 #define VCPMONITOR6_CFG_CONVDLY 0x01FEu
105 
110 #define VCPMONITOR6_ADC_CFG_MODE_SHD 0x00
111 #define VCPMONITOR6_ADC_CFG_MODE_TRG_BV 0x01
112 #define VCPMONITOR6_ADC_CFG_MODE_TRG_T 0x04
113 #define VCPMONITOR6_ADC_CFG_MODE_TRG_BV_T 0x05
114 #define VCPMONITOR6_ADC_CFG_MODE_TRG_T_C 0x06
115 #define VCPMONITOR6_ADC_CFG_MODE_TRG_ALL 0x07
116 #define VCPMONITOR6_ADC_CFG_MODE_SD 0x08
117 #define VCPMONITOR6_ADC_CFG_MODE_CNT_BV 0x09
118 #define VCPMONITOR6_ADC_CFG_MODE_CNT_T 0x0C
119 #define VCPMONITOR6_ADC_CFG_MODE_CNT_BV_T 0x0D
120 #define VCPMONITOR6_ADC_CFG_MODE_CNT_T_C 0x0E
121 #define VCPMONITOR6_ADC_CFG_MODE_CNT_ALL 0x0F
122 #define VCPMONITOR6_ADC_CFG_MODE_BITMASK 0x0FFFu
123 #define VCPMONITOR6_ADC_CFG_VBSTA 0x07
124 #define VCPMONITOR6_ADC_CFG_VBSTA_BITMASK 0xF007u
125 #define VCPMONITOR6_ADC_CFG_AVG 0x07
126 #define VCPMONITOR6_ADC_CFG_AVG_BITMASK 0xFFF8u
127 
132 #define VCPMONITOR6_ALR_DIAG_TRANSPARENT 0x0000u
133 #define VCPMONITOR6_ALR_DIAG_ALATCH 0x8000u
134 #define VCPMONITOR6_ALR_DIAG_CNVR_DIS 0x0000u
135 #define VCPMONITOR6_ALR_DIAG_CNVR_EN 0x4000u
136 #define VCPMONITOR6_ALR_DIAG_SLWALR_NAVG 0x0000u
137 #define VCPMONITOR6_ALR_DIAG_SLWALR_AVG 0x2000u
138 #define VCPMONITOR6_ALR_DIAG_APOL_NORMAL 0x0000u
139 #define VCPMONITOR6_ALR_DIAG_APOL_INV 0x1000u
140 #define VCPMONITOR6_ALR_DIAG_W_BITMASK 0xF000u
141 #define VCPMONITOR6_ALR_DIAG_ENERGYOF 0x0800u
142 #define VCPMONITOR6_ALR_DIAG_CHARGEOF 0x0400u
143 #define VCPMONITOR6_ALR_DIAG_MATHOF 0x0200u
144 #define VCPMONITOR6_ALR_DIAG_TMPOL 0x0080u
145 #define VCPMONITOR6_ALR_DIAG_CURRENTOL 0x0040u
146 #define VCPMONITOR6_ALR_DIAG_CURRENTUL 0x0020u
147 #define VCPMONITOR6_ALR_DIAG_BUSOL 0x0010u
148 #define VCPMONITOR6_ALR_DIAG_BUSUL 0x0008u
149 #define VCPMONITOR6_ALR_DIAG_POL 0x0004u
150 #define VCPMONITOR6_ALR_DIAG_CNVRF 0x0002u
151 #define VCPMONITOR6_ALR_DIAG_MEMSTAT 0x0001u
152 #define VCPMONITOR6_ALR_DIAG_R_BITMASK 0x0FFFu
153 
158 #define VCPMONITOR6_MANUFACTURER_ID 0x5449u
159 
164 #define VCPMONITOR6_CONV_FACT_VBUS 3.125f
165 #define VCPMONITOR6_CONV_FACT_DIETEMP 125.0f
166 #define VCPMONITOR6_CONV_FACT_CURRENT 2500.0f
167 #define VCPMONITOR6_CONV_FACT_POWER 480.0f
168 #define VCPMONITOR6_CONV_FACT_ENERGY 7.68f
169 #define VCPMONITOR6_CONV_FACT_CHARGE 150.0f
170 #define VCPMONITOR6_CALC_EN_CHRG_RES 256.0f
171 #define VCPMONITOR6_CALC_EN_CHRG 4.0f
172 #define VCPMONITOR6_UN_CONV_1K 1000.0f
173 #define VCPMONITOR6_UN_CONV_1M 1000000.0f
174 
180 #define VCPMONITOR6_DEVICE_ADDRESS_0 0x40
181 #define VCPMONITOR6_DEVICE_ADDRESS_1 0x41
182 #define VCPMONITOR6_DEVICE_ADDRESS_2 0x44
183 #define VCPMONITOR6_DEVICE_ADDRESS_3 0x45
184  // vcpmonitor6_set
186 
201 #define VCPMONITOR6_MAP_MIKROBUS( cfg, mikrobus ) \
202  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
203  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
204  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
205  // vcpmonitor6_map // vcpmonitor6
208 
213 typedef struct
214 {
215  // Input pins
216  digital_in_t alr;
218  // Modules
219  i2c_master_t i2c;
221  // I2C slave address
222  uint8_t slave_address;
224 } vcpmonitor6_t;
225 
230 typedef struct
231 {
232  pin_name_t scl;
233  pin_name_t sda;
235  pin_name_t alr;
237  uint32_t i2c_speed;
238  uint8_t i2c_address;
241 
246 typedef enum
247 {
249  VCPMONITOR6_ERROR = -1
250 
252 
269 
284 
298 
313 err_t vcpmonitor6_generic_write ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
314 
329 err_t vcpmonitor6_generic_read ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
330 
344 err_t vcpmonitor6_reg_write ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t data_in );
345 
359 err_t vcpmonitor6_reg_read ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t *data_out );
360 
373 
386 err_t vcpmonitor6_set_conv_dly ( vcpmonitor6_t *ctx, uint16_t dly_ms );
387 
401 err_t vcpmonitor6_set_op_mode ( vcpmonitor6_t *ctx, uint8_t op_mode );
402 
418 err_t vcpmonitor6_set_conv_time ( vcpmonitor6_t *ctx, uint8_t vbusct, uint8_t vsenct, uint8_t tct );
419 
432 err_t vcpmonitor6_set_adc_avg ( vcpmonitor6_t *ctx, uint8_t avg );
433 
446 err_t vcpmonitor6_get_bus_voltage ( vcpmonitor6_t *ctx, float *voltage );
447 
460 err_t vcpmonitor6_get_temperature ( vcpmonitor6_t *ctx, float *temperature );
461 
474 err_t vcpmonitor6_get_current ( vcpmonitor6_t *ctx, float *current );
475 
488 err_t vcpmonitor6_get_power ( vcpmonitor6_t *ctx, float *power );
489 
502 err_t vcpmonitor6_get_energy ( vcpmonitor6_t *ctx, float *energy );
503 
516 err_t vcpmonitor6_get_charge ( vcpmonitor6_t *ctx, float *charge );
517 
530 err_t vcpmonitor6_set_diag_flg_alr ( vcpmonitor6_t *ctx, uint16_t diag_flg_alr );
531 
544 err_t vcpmonitor6_get_indc_flg ( vcpmonitor6_t *ctx, uint16_t *indc_flg );
545 
558 
571 err_t vcpmonitor6_get_device_id ( vcpmonitor6_t *ctx, uint16_t *man_id );
572 
584 
585 #ifdef __cplusplus
586 }
587 #endif
588 #endif // VCPMONITOR6_H
589  // vcpmonitor6
591 
592 // ------------------------------------------------------------------------ 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:216
vcpmonitor6_t::i2c
i2c_master_t i2c
Definition: vcpmonitor6.h:219
vcpmonitor6_cfg_t::alr
pin_name_t alr
Definition: vcpmonitor6.h:235
vcpmonitor6_cfg_t::sda
pin_name_t sda
Definition: vcpmonitor6.h:233
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:222
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:249
VCPMONITOR6_OK
@ VCPMONITOR6_OK
Definition: vcpmonitor6.h:248
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:247
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:231
vcpmonitor6_cfg_t::i2c_address
uint8_t i2c_address
Definition: vcpmonitor6.h:238
vcpmonitor6_cfg_t::scl
pin_name_t scl
Definition: vcpmonitor6.h:232
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:237
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:214