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
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 VCTMONITOR_REG_STATUS 0x00
70 #define VCTMONITOR_REG_CONTROL 0x01
71 #define VCTMONITOR_REG_TRIGGER 0x02
72 #define VCTMONITOR_REG_AMB_TEMP_MSB 0x04
73 #define VCTMONITOR_REG_AMB_TEMP_LSB 0x05
74 #define VCTMONITOR_REG_V1_MSB 0x06
75 #define VCTMONITOR_REG_V1_LSB 0x07
76 #define VCTMONITOR_REG_V2_MSB 0x08
77 #define VCTMONITOR_REG_V2_LSB 0x09
78 #define VCTMONITOR_REG_V3_MSB 0x0A
79 #define VCTMONITOR_REG_V3_LSB 0x0B
80 #define VCTMONITOR_REG_V4_MSB 0x0C
81 #define VCTMONITOR_REG_V4_LSB 0x0D
82 #define VCTMONITOR_REG_VCC_MSB 0x0E
83 #define VCTMONITOR_REG_VCC_LSB 0x0F
84  // vctmonitor_reg
86 
101 #define VCTMONITOR_CTRL_TEMP_FORMAT_C 0x00
102 #define VCTMONITOR_CTRL_TEMP_FORMAT_K 0x80
103 #define VCTMONITOR_CTRL_REPEATED_MEAS 0x00
104 #define VCTMONITOR_CTRL_SINGLE_MEAS 0x40
105 #define VCTMONITOR_CTRL_MODE1_INT_TEMP 0x00
106 #define VCTMONITOR_CTRL_MODE1_V12 0x08
107 #define VCTMONITOR_CTRL_MODE1_V34 0x10
108 #define VCTMONITOR_CTRL_MODE1_ALL 0x18
109 
110 #define VCTMONITOR_CTRL_MODE2_V12_TR2 0x00
111 #define VCTMONITOR_CTRL_MODE2_V1_2_TR2 0x01
112 #define VCTMONITOR_CTRL_MODE2_V1_2_V34 0x02
113 #define VCTMONITOR_CTRL_MODE2_V34_TR1 0x03
114 #define VCTMONITOR_CTRL_MODE2_V3_4_TR1 0x04
115 #define VCTMONITOR_CTRL_MODE2_TR2_TR1 0x05
116 #define VCTMONITOR_CTRL_MODE2_V1_2_V3_4 0x06
117 #define VCTMONITOR_CTRL_MODE2_V1234 0x07
118 
119 #define VCTMONITOR_STATUS_VCC_READY 0x40
120 #define VCTMONITOR_STATUS_V4_READY 0x20
121 #define VCTMONITOR_STATUS_V3_READY 0x10
122 #define VCTMONITOR_STATUS_V2_READY 0x08
123 #define VCTMONITOR_STATUS_V1_READY 0x04
124 #define VCTMONITOR_STATUS_TINT_READY 0x02
125 #define VCTMONITOR_STATUS_BUSY 0x01
126 
127 
133 #define VCTMONITOR_SLAVE_ADDR_GND_GND 0x4C
134 #define VCTMONITOR_SLAVE_ADDR_GND_VCC 0x4D
135 #define VCTMONITOR_SLAVE_ADDR_VCC_VCC 0x4F
136 #define VCTMONITOR_SLAVE_ADDR_VCC_GND 0x4E
137  // vctmonitor_set
139 
154 #define VCTMONITOR_MAP_MIKROBUS( cfg, mikrobus ) \
155  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
156  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
157  // vctmonitor_map // vctmonitor
160 
165 typedef struct
166 {
167  // Modules
168  i2c_master_t i2c;
170  // I2C slave address
171  uint8_t slave_address;
173 } vctmonitor_t;
174 
179 typedef struct
180 {
181  pin_name_t scl;
182  pin_name_t sda;
184  uint32_t i2c_speed;
185  uint8_t i2c_address;
188 
193 typedef enum
194 {
196  VCTMONITOR_ERROR = -1
197 
199 
216 
231 
246 
261 err_t vctmonitor_generic_write ( vctmonitor_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
262 
277 err_t vctmonitor_generic_read ( vctmonitor_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
278 
287 
297 void vctmonitor_configuration ( vctmonitor_t *ctx, uint8_t cfg );
298 
307 
319 
331 float vctmonitor_read_voltage_single ( vctmonitor_t *ctx, uint8_t channel );
332 
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 #endif // VCTMONITOR_H
346  // vctmonitor
348 
349 // ------------------------------------------------------------------------ END
vctmonitor_cfg_t::i2c_address
uint8_t i2c_address
Definition: vctmonitor.h:185
vctmonitor_read_voltage_differential
float vctmonitor_read_voltage_differential(vctmonitor_t *ctx)
Differential voltage function.
vctmonitor_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vctmonitor.h:184
vctmonitor_cfg_t::scl
pin_name_t scl
Definition: vctmonitor.h:181
vctmonitor_generic_write
err_t vctmonitor_generic_write(vctmonitor_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
VCT Monitor I2C writing function.
vctmonitor_t::i2c
i2c_master_t i2c
Definition: vctmonitor.h:168
vctmonitor_read_current
float vctmonitor_read_current(vctmonitor_t *ctx)
Current function.
vctmonitor_read_temperature
float vctmonitor_read_temperature(vctmonitor_t *ctx)
Get temperature function.
vctmonitor_return_value_t
vctmonitor_return_value_t
VCT Monitor Click return value data.
Definition: vctmonitor.h:194
vctmonitor_default_cfg
err_t vctmonitor_default_cfg(vctmonitor_t *ctx)
VCT Monitor default configuration function.
VCTMONITOR_OK
@ VCTMONITOR_OK
Definition: vctmonitor.h:195
VCTMONITOR_ERROR
@ VCTMONITOR_ERROR
Definition: vctmonitor.h:196
vctmonitor_cfg_setup
void vctmonitor_cfg_setup(vctmonitor_cfg_t *cfg)
VCT Monitor configuration object setup function.
vctmonitor_t
VCT Monitor Click context object.
Definition: vctmonitor.h:166
vctmonitor_cfg_t
VCT Monitor Click configuration object.
Definition: vctmonitor.h:180
vctmonitor_init
err_t vctmonitor_init(vctmonitor_t *ctx, vctmonitor_cfg_t *cfg)
VCT Monitor initialization function.
vctmonitor_read_voltage_single
float vctmonitor_read_voltage_single(vctmonitor_t *ctx, uint8_t channel)
Single voltage function.
vctmonitor_t::slave_address
uint8_t slave_address
Definition: vctmonitor.h:171
vctmonitor_get_status
uint8_t vctmonitor_get_status(vctmonitor_t *ctx)
Gets status value.
vctmonitor_configuration
void vctmonitor_configuration(vctmonitor_t *ctx, uint8_t cfg)
Configuration function.
vctmonitor_cfg_t::sda
pin_name_t sda
Definition: vctmonitor.h:182
vctmonitor_generic_read
err_t vctmonitor_generic_read(vctmonitor_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
VCT Monitor I2C reading function.