vcpmonitor2  2.0.0.0
vcpmonitor2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef VCPMONITOR2_H
36 #define VCPMONITOR2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define VCPMONITOR2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
56 
63 #define VCPMONITOR2_RETVAL uint8_t
64 
65 #define VCPMONITOR2_OK 0x00
66 #define VCPMONITOR2_INIT_ERROR 0xFF
67 
73 #define VCPMONITOR2_DEVICE_SLAVE_ADDR_GND 0x40
74 #define VCPMONITOR2_DEVICE_SLAVE_ADDR_VCC 0x41
75 #define VCPMONITOR2_DEVICE_SLAVE_ADDR_SCL 0x42
76 #define VCPMONITOR2_DEVICE_SLAVE_ADDR_SDA 0x43
77 
83 #define VCPMONITOR2_STATUS_ADDR_GND_GND 0x70
84 #define VCPMONITOR2_STATUS_ADDR_VCC_GND 0x72
85 #define VCPMONITOR2_STATUS_ADDR_GND_VCC 0x71
86 #define VCPMONITOR2_STATUS_ADDR_VCC_VCC 0x73
87 
93 #define VCPMONITOR2_ALERT_REG_INPUT 0x00
94 #define VCPMONITOR2_ALERT_REG_POLARITY 0x02
95 #define VCPMONITOR2_ALERT_REG_CONFIG 0x03
96 
102 #define VCPMONITOR2_REG_CONFIGURATION 0x00
103 #define VCPMONITOR2_REG_CH_1_SHUNT_VOLT 0x01
104 #define VCPMONITOR2_REG_CH_1_BUS_VOLT 0x02
105 #define VCPMONITOR2_REG_CH_2_SHUNT_VOLT 0x03
106 #define VCPMONITOR2_REG_CH_2_BUS_VOLT 0x04
107 #define VCPMONITOR2_REG_CH_3_SHUNT_VOLT 0x05
108 #define VCPMONITOR2_REG_CH_3_BUS_VOLT 0x06
109 #define VCPMONITOR2_REG_CH_1_CRITICAL_ALT 0x07
110 #define VCPMONITOR2_REG_CH_1_WARNING_ALT 0x08
111 #define VCPMONITOR2_REG_CH_2_CRITICAL_ALT 0x09
112 #define VCPMONITOR2_REG_CH_2_WARNING_ALT 0x0A
113 #define VCPMONITOR2_REG_CH_3_CRITICAL_ALT 0x0B
114 #define VCPMONITOR2_REG_CH_3_WARNING_ALT 0x0C
115 #define VCPMONITOR2_REG_SHUNT_VOLT_SUM 0x0D
116 #define VCPMONITOR2_REG_SHUNT_VOLT_SUM_LIMIT 0x0E
117 #define VCPMONITOR2_REG_MASK_ENABLE 0x0F
118 #define VCPMONITOR2_REG_PWR_UPPER_LIMIT 0x10
119 #define VCPMONITOR2_REG_PWR_LOWER_LIMIT 0x11
120 #define VCPMONITOR2_REG_MANUFACTURER_ID 0xFE
121 #define VCPMONITOR2_REG_DIE_ID 0xFF
122 
128 #define VCPMONITOR2_DEF_MANUFACTURE_ID 0x5449
129 #define VCPMONITOR2_DEF_DIE_ID 0x3220
130 #define VCPMONITOR2_DEF_PWR_LOWER_LIMIT 0x2328
131 #define VCPMONITOR2_DEF_PWR_UPPER_LIMIT 0x2F10
132 #define VCPMONITOR2_DEF_MASK_ENABLE 0x0002
133 #define VCPMONITOR2_DEF_SHUNT_VOLT_SUM_LIMIT 0x7FFE
134 #define VCPMONITOR2_DEF_CONFIGURATION 0x7127
135 #define VCPMONITOR2_DEF_CH_1234_ALERT 0x7FF8
136 
142 #define VCPMONITOR2_CFG_SW_RESET 0x8000
143 #define VCPMONITOR2_CFG_CH_1_ENABLE 0x4000
144 #define VCPMONITOR2_CFG_CH_1_DISABLE 0x0000
145 #define VCPMONITOR2_CFG_CH_2_ENABLE 0x2000
146 #define VCPMONITOR2_CFG_CH_2_DISABLE 0x0000
147 #define VCPMONITOR2_CFG_CH_3_ENABLE 0x1000
148 #define VCPMONITOR2_CFG_CH_3_DISABLE 0x0000
149 #define VCPMONITOR2_CFG_AVG_1 0x0000
150 #define VCPMONITOR2_CFG_AVG_4 0x0200
151 #define VCPMONITOR2_CFG_AVG_16 0x0400
152 #define VCPMONITOR2_CFG_AVG_64 0x0600
153 #define VCPMONITOR2_CFG_AVG_128 0x0800
154 #define VCPMONITOR2_CFG_AVG_256 0x0A00
155 #define VCPMONITOR2_CFG_AVG_512 0x0C00
156 #define VCPMONITOR2_CFG_AVG_1024 0x0D00
157 
158 #define VCPMONITOR2_CFG_VBUS_CT_140us 0x0000
159 #define VCPMONITOR2_CFG_VBUS_CT_204us 0x0040
160 #define VCPMONITOR2_CFG_VBUS_CT_332us 0x0080
161 #define VCPMONITOR2_CFG_VBUS_CT_588us 0x00C0
162 #define VCPMONITOR2_CFG_VBUS_CT_1100us 0x0100
163 #define VCPMONITOR2_CFG_VBUS_CT_2116us 0x0140
164 #define VCPMONITOR2_CFG_VBUS_CT_4156us 0x0180
165 #define VCPMONITOR2_CFG_VBUS_CT_8244us 0x01C0
166 #define VCPMONITOR2_CFG_VSH_CT_140us 0x0000
167 #define VCPMONITOR2_CFG_VSH_CT_204us 0x0008
168 #define VCPMONITOR2_CFG_VSH_CT_332us 0x0010
169 #define VCPMONITOR2_CFG_VSH_CT_588us 0x0018
170 #define VCPMONITOR2_CFG_VSH_CT_1100us 0x0020
171 #define VCPMONITOR2_CFG_VSH_CT_2116us 0x0028
172 #define VCPMONITOR2_CFG_VSH_CT_4156us 0x0030
173 #define VCPMONITOR2_CFG_VSH_CT_8244us 0x0038
174 
175 #define VCPMONITOR2_CFG_MODE_POWER_DOWN 0x0000
176 #define VCPMONITOR2_CFG_MODE_SS_SHUNT_VOLT 0x0001
177 #define VCPMONITOR2_CFG_MODE_SS_BUS_VOLT 0x0002
178 #define VCPMONITOR2_CFG_MODE_SS_SHUNT_BUS_VOLT 0x0003
179 #define VCPMONITOR2_CFG_MODE_CONT_SHUNT_VOLT 0x0005
180 #define VCPMONITOR2_CFG_MODE_CONT_BUS_VOLT 0x0006
181 #define VCPMONITOR2_CFG_MODE_CONT_SHUNT_BUS_VOLT 0x0007
182 
188 #define VCPMONITOR2_CFG_MASK_SCC_1_ENABLE 0x4000
189 #define VCPMONITOR2_CFG_MASK_SCC_2_ENABLE 0x2000
190 #define VCPMONITOR2_CFG_MASK_SCC_3_ENABLE 0x1000
191 #define VCPMONITOR2_CFG_MASK_SCC_1_DISABLE 0x0000
192 #define VCPMONITOR2_CFG_MASK_SCC_2_DISABLE 0x0000
193 #define VCPMONITOR2_CFG_MASK_SCC_3_DISABLE 0x0000
194 #define VCPMONITOR2_CFG_MASK_WEN_TRANSPARENT 0x0000
195 #define VCPMONITOR2_CFG_MASK_WEN_LATCH_ENABLED 0x0800
196 #define VCPMONITOR2_CFG_MASK_CEN_TRANSPARENT 0x0000
197 #define VCPMONITOR2_CFG_MASK_CEN_LATCH_ENABLED 0x0400
198 #define VCPMONITOR2_CFG_MASK_CF_1_ENABLE 0x0080
199 #define VCPMONITOR2_CFG_MASK_CF_2_ENABLE 0x0100
200 #define VCPMONITOR2_CFG_MASK_CF_3_ENABLE 0x0200
201 #define VCPMONITOR2_CFG_MASK_CF_1_DISABLE 0x0000
202 #define VCPMONITOR2_CFG_MASK_CF_2_DISABLE 0x0000
203 #define VCPMONITOR2_CFG_MASK_CF_3_DISABLE 0x0000
204 #define VCPMONITOR2_CFG_MASK_SF_ENABLE 0x0040
205 #define VCPMONITOR2_CFG_MASK_SF_DISABLE 0x0000
206 #define VCPMONITOR2_CFG_MASK_VF_1_ENABLE 0x0008
207 #define VCPMONITOR2_CFG_MASK_VF_2_ENABLE 0x0010
208 #define VCPMONITOR2_CFG_MASK_VF_3_ENABLE 0x0020
209 #define VCPMONITOR2_CFG_MASK_VF_1_DISABLE 0x0000
210 #define VCPMONITOR2_CFG_MASK_VF_2_DISABLE 0x0000
211 #define VCPMONITOR2_CFG_MASK_VF_3_DISABLE 0x0000
212 #define VCPMONITOR2_CFG_MASK_PVF_ENABLE 0x0004
213 #define VCPMONITOR2_CFG_MASK_TCF_ENABLE 0x0002
214 #define VCPMONITOR2_CFG_MASK_CVRF_ENABLE 0x0001
215 #define VCPMONITOR2_CFG_MASK_PVF_DISABLE 0x0000
216 #define VCPMONITOR2_CFG_MASK_TCF_DISABLE 0x0000
217 #define VCPMONITOR2_CFG_MASK_CVRF_DISABLE 0x0000
218 
224 #define VCPMONITOR2_CHANNEL_1 0x01
225 #define VCPMONITOR2_CHANNEL_2 0x02
226 #define VCPMONITOR2_CHANNEL_3 0x03
227 
233 #define VCPMONITOR2_ALERT_PVALID 0x01
234 #define VCPMONITOR2_ALERT_WRNG 0x02
235 #define VCPMONITOR2_ALERT_CRTCL 0x04
236 #define VCPMONITOR2_ALERT_TCTRL 0x08
237 
239 #define DEVICE_OK 0
240 #define DEVICE_ERROR 1
241  // End group macro
243 // --------------------------------------------------------------- PUBLIC TYPES
252 typedef struct
253 {
254  // Output pins
255 
256  digital_out_t rst;
257 
258  // Modules
259 
260  i2c_master_t i2c;
261 
262  // ctx variable
263 
266 
267 } vcpmonitor2_t;
268 
272 typedef struct
273 {
274  // Communication gpio pins
275 
276  pin_name_t scl;
277  pin_name_t sda;
278 
279  // Additional gpio pins
280 
281  pin_name_t rst;
282 
283  // static variable
284 
285  uint32_t i2c_speed;
288 
290  // End types group
292 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
293 
299 #ifdef __cplusplus
300 extern "C"{
301 #endif
302 
312 
322 
331 
342 void vcpmonitor2_generic_write ( vcpmonitor2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
343 
354 void vcpmonitor2_generic_read ( vcpmonitor2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
355 
364 
372 uint16_t vcpmonitor2_get_die_id ( vcpmonitor2_t *ctx );
373 
382 float vcpmonitor2_get_bus_voltage ( vcpmonitor2_t *ctx, uint8_t channel );
383 
392 float vcpmonitor2_get_shunt_voltage ( vcpmonitor2_t *ctx, uint8_t channel );
393 
402 float vcpmonitor2_get_current ( vcpmonitor2_t *ctx, uint8_t channel );
403 
412 float vcpmonitor2_get_power ( vcpmonitor2_t *ctx, uint8_t channel );
413 
427 void vcpmonitor2_configuration ( vcpmonitor2_t *ctx, uint16_t cfg );
428 
437 
445 
460 void vcpmonitor2_alert_config ( vcpmonitor2_t *ctx, uint8_t cfg );
461 
462 #ifdef __cplusplus
463 }
464 #endif
465 #endif // _VCPMONITOR2_H_
466  // End public_function group
469 
470 // ------------------------------------------------------------------------- END
vcpmonitor2_get_alert_status
uint8_t vcpmonitor2_get_alert_status(vcpmonitor2_t *ctx)
Get Alert status.
vcpmonitor2_alert_config
void vcpmonitor2_alert_config(vcpmonitor2_t *ctx, uint8_t cfg)
Alert configuration ( Enable / Disable )
vcpmonitor2_get_manifacture_id
uint16_t vcpmonitor2_get_manifacture_id(vcpmonitor2_t *ctx)
Get Manufacture ID.
vcpmonitor2_generic_write
void vcpmonitor2_generic_write(vcpmonitor2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
vcpmonitor2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vcpmonitor2.h:285
vcpmonitor2_get_power
float vcpmonitor2_get_power(vcpmonitor2_t *ctx, uint8_t channel)
Get Power in W.
vcpmonitor2_cfg_t::scl
pin_name_t scl
Definition: vcpmonitor2.h:276
vcpmonitor2_cfg_t::device_status_address
uint8_t device_status_address
Definition: vcpmonitor2.h:287
vcpmonitor2_generic_read
void vcpmonitor2_generic_read(vcpmonitor2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
vcpmonitor2_configuration
void vcpmonitor2_configuration(vcpmonitor2_t *ctx, uint16_t cfg)
Configuration function.
vcpmonitor2_cfg_setup
void vcpmonitor2_cfg_setup(vcpmonitor2_cfg_t *cfg)
Config Object Initialization function.
vcpmonitor2_default_cfg
void vcpmonitor2_default_cfg(vcpmonitor2_t *ctx)
Click Default Configuration function.
vcpmonitor2_t::device_status_address
uint8_t device_status_address
Definition: vcpmonitor2.h:265
vcpmonitor2_t::device_slave_address
uint8_t device_slave_address
Definition: vcpmonitor2.h:264
vcpmonitor2_get_die_id
uint16_t vcpmonitor2_get_die_id(vcpmonitor2_t *ctx)
Get DIE ID.
vcpmonitor2_get_current
float vcpmonitor2_get_current(vcpmonitor2_t *ctx, uint8_t channel)
Get Current data in mA.
vcpmonitor2_cfg_t::sda
pin_name_t sda
Definition: vcpmonitor2.h:277
vcpmonitor2_cfg_t
Click configuration structure definition.
Definition: vcpmonitor2.h:272
vcpmonitor2_init
VCPMONITOR2_RETVAL vcpmonitor2_init(vcpmonitor2_t *ctx, vcpmonitor2_cfg_t *cfg)
Initialization function.
vcpmonitor2_cfg_t::device_slave_address
uint8_t device_slave_address
Definition: vcpmonitor2.h:286
vcpmonitor2_t
Click ctx object definition.
Definition: vcpmonitor2.h:252
vcpmonitor2_cfg_t::rst
pin_name_t rst
Definition: vcpmonitor2.h:281
vcpmonitor2_get_shunt_voltage
float vcpmonitor2_get_shunt_voltage(vcpmonitor2_t *ctx, uint8_t channel)
Get Shunt voltage in mV.
vcpmonitor2_t::i2c
i2c_master_t i2c
Definition: vcpmonitor2.h:260
vcpmonitor2_reset_alert
void vcpmonitor2_reset_alert(vcpmonitor2_t *ctx)
Alert reset.
vcpmonitor2_t::rst
digital_out_t rst
Definition: vcpmonitor2.h:256
vcpmonitor2_get_bus_voltage
float vcpmonitor2_get_bus_voltage(vcpmonitor2_t *ctx, uint8_t channel)
Get BUS voltage in mV.
VCPMONITOR2_RETVAL
#define VCPMONITOR2_RETVAL
Definition: vcpmonitor2.h:63