vcpmonitor6 2.2.0
Loading...
Searching...
No Matches
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
27
28#ifndef VCPMONITOR6_H
29#define VCPMONITOR6_H
30
31#ifdef __cplusplus
32extern "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
58
63
68
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
96
101
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
195
200
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
217typedef struct
218{
219 // Input pins
220 digital_in_t alr;
221
222 // Modules
223 i2c_master_t i2c;
224
225 // I2C slave address
227
229
234typedef struct
235{
236 pin_name_t scl;
237 pin_name_t sda;
238
239 pin_name_t alr;
240
241 uint32_t i2c_speed;
242 uint8_t i2c_address;
243
245
256
262
273
288
302
317err_t vcpmonitor6_generic_write ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
318
333err_t vcpmonitor6_generic_read ( vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
334
348err_t vcpmonitor6_reg_write ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t data_in );
349
363err_t vcpmonitor6_reg_read ( vcpmonitor6_t *ctx, uint8_t reg, uint16_t *data_out );
364
377
390err_t vcpmonitor6_set_conv_dly ( vcpmonitor6_t *ctx, uint16_t dly_ms );
391
405err_t vcpmonitor6_set_op_mode ( vcpmonitor6_t *ctx, uint8_t op_mode );
406
422err_t vcpmonitor6_set_conv_time ( vcpmonitor6_t *ctx, uint8_t vbusct, uint8_t vsenct, uint8_t tct );
423
436err_t vcpmonitor6_set_adc_avg ( vcpmonitor6_t *ctx, uint8_t avg );
437
450err_t vcpmonitor6_get_bus_voltage ( vcpmonitor6_t *ctx, float *voltage );
451
464err_t vcpmonitor6_get_temperature ( vcpmonitor6_t *ctx, float *temperature );
465
478err_t vcpmonitor6_get_current ( vcpmonitor6_t *ctx, float *current );
479
492err_t vcpmonitor6_get_power ( vcpmonitor6_t *ctx, float *power );
493
506err_t vcpmonitor6_get_energy ( vcpmonitor6_t *ctx, float *energy );
507
520err_t vcpmonitor6_get_charge ( vcpmonitor6_t *ctx, float *charge );
521
534err_t vcpmonitor6_set_diag_flg_alr ( vcpmonitor6_t *ctx, uint16_t diag_flg_alr );
535
548err_t vcpmonitor6_get_indc_flg ( vcpmonitor6_t *ctx, uint16_t *indc_flg );
549
562
575err_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
err_t vcpmonitor6_get_charge(vcpmonitor6_t *ctx, float *charge)
VCP Monitor 6 get the charge function.
void vcpmonitor6_cfg_setup(vcpmonitor6_cfg_t *cfg)
VCP Monitor 6 configuration object setup function.
err_t vcpmonitor6_set_conv_dly(vcpmonitor6_t *ctx, uint16_t dly_ms)
VCP Monitor 6 set conversion delay function.
err_t vcpmonitor6_get_bus_voltage(vcpmonitor6_t *ctx, float *voltage)
VCP Monitor 6 get the voltage function.
err_t vcpmonitor6_init(vcpmonitor6_t *ctx, vcpmonitor6_cfg_t *cfg)
VCP Monitor 6 initialization function.
err_t vcpmonitor6_reg_read(vcpmonitor6_t *ctx, uint8_t reg, uint16_t *data_out)
VCP Monitor 6 register reading function.
err_t vcpmonitor6_set_op_mode(vcpmonitor6_t *ctx, uint8_t op_mode)
VCP Monitor 6 set the operating mode function.
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.
err_t vcpmonitor6_wait_conv_cmpl(vcpmonitor6_t *ctx)
VCP Monitor 6 wait conversion function.
err_t vcpmonitor6_default_cfg(vcpmonitor6_t *ctx)
VCP Monitor 6 default configuration function.
err_t vcpmonitor6_get_temperature(vcpmonitor6_t *ctx, float *temperature)
VCP Monitor 6 get the temperature function.
err_t vcpmonitor6_set_diag_flg_alr(vcpmonitor6_t *ctx, uint16_t diag_flg_alr)
VCP Monitor 6 set diagnostic function.
err_t vcpmonitor6_get_power(vcpmonitor6_t *ctx, float *power)
VCP Monitor 6 get the power function.
err_t vcpmonitor6_generic_read(vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
VCP Monitor 6 I2C reading function.
err_t vcpmonitor6_reg_write(vcpmonitor6_t *ctx, uint8_t reg, uint16_t data_in)
VCP Monitor 6 register writing function.
err_t vcpmonitor6_generic_write(vcpmonitor6_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
VCP Monitor 6 I2C writing function.
err_t vcpmonitor6_get_energy(vcpmonitor6_t *ctx, float *energy)
VCP Monitor 6 get the energy function.
uint8_t vcpmonitor6_get_alarm(vcpmonitor6_t *ctx)
VCP Monitor 6 get alarm function.
err_t vcpmonitor6_sw_reset(vcpmonitor6_t *ctx)
VCP Monitor 6 SW reset writing function.
err_t vcpmonitor6_set_adc_avg(vcpmonitor6_t *ctx, uint8_t avg)
VCP Monitor 6 set the ADC sample function.
err_t vcpmonitor6_get_current(vcpmonitor6_t *ctx, float *current)
VCP Monitor 6 get the current function.
err_t vcpmonitor6_get_device_id(vcpmonitor6_t *ctx, uint16_t *man_id)
VCP Monitor 6 get device ID function.
err_t vcpmonitor6_get_indc_flg(vcpmonitor6_t *ctx, uint16_t *indc_flg)
VCP Monitor 6 get diagnostic indicates function.
VCP Monitor 6 Click configuration object.
Definition vcpmonitor6.h:235
pin_name_t alr
Definition vcpmonitor6.h:239
uint32_t i2c_speed
Definition vcpmonitor6.h:241
pin_name_t scl
Definition vcpmonitor6.h:236
pin_name_t sda
Definition vcpmonitor6.h:237
uint8_t i2c_address
Definition vcpmonitor6.h:242
VCP Monitor 6 Click context object.
Definition vcpmonitor6.h:218
digital_in_t alr
Definition vcpmonitor6.h:220
i2c_master_t i2c
Definition vcpmonitor6.h:223
uint8_t slave_address
Definition vcpmonitor6.h:226
vcpmonitor6_return_value_t
VCP Monitor 6 Click return value data.
Definition vcpmonitor6.h:251
@ VCPMONITOR6_ERROR
Definition vcpmonitor6.h:253
@ VCPMONITOR6_OK
Definition vcpmonitor6.h:252