vctmonitor 2.0.0.0
vctmonitor.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2021 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 VCTMONITOR_H
29#define VCTMONITOR_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
73#define VCTMONITOR_REG_STATUS 0x00
74#define VCTMONITOR_REG_CONTROL 0x01
75#define VCTMONITOR_REG_TRIGGER 0x02
76#define VCTMONITOR_REG_AMB_TEMP_MSB 0x04
77#define VCTMONITOR_REG_AMB_TEMP_LSB 0x05
78#define VCTMONITOR_REG_V1_MSB 0x06
79#define VCTMONITOR_REG_V1_LSB 0x07
80#define VCTMONITOR_REG_V2_MSB 0x08
81#define VCTMONITOR_REG_V2_LSB 0x09
82#define VCTMONITOR_REG_V3_MSB 0x0A
83#define VCTMONITOR_REG_V3_LSB 0x0B
84#define VCTMONITOR_REG_V4_MSB 0x0C
85#define VCTMONITOR_REG_V4_LSB 0x0D
86#define VCTMONITOR_REG_VCC_MSB 0x0E
87#define VCTMONITOR_REG_VCC_LSB 0x0F
88
89 // vctmonitor_reg
90
105#define VCTMONITOR_CTRL_TEMP_FORMAT_C 0x00
106#define VCTMONITOR_CTRL_TEMP_FORMAT_K 0x80
107#define VCTMONITOR_CTRL_REPEATED_MEAS 0x00
108#define VCTMONITOR_CTRL_SINGLE_MEAS 0x40
109#define VCTMONITOR_CTRL_MODE1_INT_TEMP 0x00
110#define VCTMONITOR_CTRL_MODE1_V12 0x08
111#define VCTMONITOR_CTRL_MODE1_V34 0x10
112#define VCTMONITOR_CTRL_MODE1_ALL 0x18
113
114#define VCTMONITOR_CTRL_MODE2_V12_TR2 0x00
115#define VCTMONITOR_CTRL_MODE2_V1_2_TR2 0x01
116#define VCTMONITOR_CTRL_MODE2_V1_2_V34 0x02
117#define VCTMONITOR_CTRL_MODE2_V34_TR1 0x03
118#define VCTMONITOR_CTRL_MODE2_V3_4_TR1 0x04
119#define VCTMONITOR_CTRL_MODE2_TR2_TR1 0x05
120#define VCTMONITOR_CTRL_MODE2_V1_2_V3_4 0x06
121#define VCTMONITOR_CTRL_MODE2_V1234 0x07
122
123#define VCTMONITOR_STATUS_VCC_READY 0x40
124#define VCTMONITOR_STATUS_V4_READY 0x20
125#define VCTMONITOR_STATUS_V3_READY 0x10
126#define VCTMONITOR_STATUS_V2_READY 0x08
127#define VCTMONITOR_STATUS_V1_READY 0x04
128#define VCTMONITOR_STATUS_TINT_READY 0x02
129#define VCTMONITOR_STATUS_BUSY 0x01
130
131
137#define VCTMONITOR_SLAVE_ADDR_GND_GND 0x4C
138#define VCTMONITOR_SLAVE_ADDR_GND_VCC 0x4D
139#define VCTMONITOR_SLAVE_ADDR_VCC_VCC 0x4F
140#define VCTMONITOR_SLAVE_ADDR_VCC_GND 0x4E
141
142 // vctmonitor_set
143
158#define VCTMONITOR_MAP_MIKROBUS( cfg, mikrobus ) \
159 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
160 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
161
162 // vctmonitor_map
163 // vctmonitor
164
169typedef struct
170{
171 // Modules
172 i2c_master_t i2c;
174 // I2C slave address
178
183typedef struct
184{
185 pin_name_t scl;
186 pin_name_t sda;
188 uint32_t i2c_speed;
189 uint8_t i2c_address;
192
203
220
235
250
265err_t vctmonitor_generic_write ( vctmonitor_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
266
281err_t vctmonitor_generic_read ( vctmonitor_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
282
291
301void vctmonitor_configuration ( vctmonitor_t *ctx, uint8_t cfg );
302
311
323
335float vctmonitor_read_voltage_single ( vctmonitor_t *ctx, uint8_t channel );
336
345
346#ifdef __cplusplus
347}
348#endif
349#endif // VCTMONITOR_H
350
351 // vctmonitor
352
353// ------------------------------------------------------------------------ END
void vctmonitor_cfg_setup(vctmonitor_cfg_t *cfg)
VCT Monitor configuration object setup function.
err_t vctmonitor_default_cfg(vctmonitor_t *ctx)
VCT Monitor default configuration function.
err_t vctmonitor_init(vctmonitor_t *ctx, vctmonitor_cfg_t *cfg)
VCT Monitor initialization function.
void vctmonitor_configuration(vctmonitor_t *ctx, uint8_t cfg)
Configuration function.
err_t vctmonitor_generic_read(vctmonitor_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
VCT Monitor I2C reading function.
float vctmonitor_read_temperature(vctmonitor_t *ctx)
Get temperature function.
err_t vctmonitor_generic_write(vctmonitor_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
VCT Monitor I2C writing function.
float vctmonitor_read_voltage_differential(vctmonitor_t *ctx)
Differential voltage function.
float vctmonitor_read_current(vctmonitor_t *ctx)
Current function.
uint8_t vctmonitor_get_status(vctmonitor_t *ctx)
Gets status value.
float vctmonitor_read_voltage_single(vctmonitor_t *ctx, uint8_t channel)
Single voltage function.
VCT Monitor Click configuration object.
Definition vctmonitor.h:184
uint32_t i2c_speed
Definition vctmonitor.h:188
pin_name_t scl
Definition vctmonitor.h:185
pin_name_t sda
Definition vctmonitor.h:186
uint8_t i2c_address
Definition vctmonitor.h:189
VCT Monitor Click context object.
Definition vctmonitor.h:170
i2c_master_t i2c
Definition vctmonitor.h:172
uint8_t slave_address
Definition vctmonitor.h:175
vctmonitor_return_value_t
VCT Monitor Click return value data.
Definition vctmonitor.h:198
@ VCTMONITOR_OK
Definition vctmonitor.h:199
@ VCTMONITOR_ERROR
Definition vctmonitor.h:200