vcpmonitor4 2.0.0.0
vcpmonitor4.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 vcpmonitor4_H
29#define vcpmonitor4_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_spi_master.h"
52#include "spi_specifics.h"
53
74#define VCPMONITOR4_REG_CONFIG 0x00
75#define VCPMONITOR4_REG_ADC_CONFIG 0x01
76#define VCPMONITOR4_REG_SHUNT_CAL 0x02
77#define VCPMONITOR4_REG_VSHUNT 0x04
78#define VCPMONITOR4_REG_VBUS 0x05
79#define VCPMONITOR4_REG_DIETEMP 0x06
80#define VCPMONITOR4_REG_CURRENT 0x07
81#define VCPMONITOR4_REG_POWER 0x08
82#define VCPMONITOR4_REG_DIAG_ALERT 0x0B
83#define VCPMONITOR4_REG_SOVL 0x0C
84#define VCPMONITOR4_REG_SUVL 0x0D
85#define VCPMONITOR4_REG_BOVL 0x0E
86#define VCPMONITOR4_REG_BUVL 0x0F
87#define VCPMONITOR4_REG_TEMP_LIMIT 0x10
88#define VCPMONITOR4_REG_PWR_LIMIT 0x11
89#define VCPMONITOR4_REG_MANUFACTURER_ID 0x3E
90#define VCPMONITOR4_REG_DEVICE_ID 0x3F
91
92 // vcpmonitor4_reg
93
108#define VCPMONITOR4_CURRENT_LSB 0.000305
109
118#define VCPMONITOR4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
119#define VCPMONITOR4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
120
121 // vcpmonitor4_set
122
137#define VCPMONITOR4_MAP_MIKROBUS( cfg, mikrobus ) \
138 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
139 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
140 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
141 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
142 cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
143
144 // vcpmonitor4_map
145 // vcpmonitor4
146
151typedef struct
152{
153 // Input pins
154 digital_in_t alr;
156 // Modules
157 spi_master_t spi;
159 pin_name_t chip_select;
162
167typedef struct
168{
169 // Communication gpio pins
170 pin_name_t miso;
171 pin_name_t mosi;
172 pin_name_t sck;
173 pin_name_t cs;
175 // Additional gpio pins
176 pin_name_t alr;
178 // static variable
179 uint32_t spi_speed;
180 spi_master_mode_t spi_mode;
181 spi_master_chip_select_polarity_t cs_polarity;
184
195
212
228
243
257err_t vcpmonitor4_generic_write ( vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in );
258
272err_t vcpmonitor4_generic_read ( vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out ) ;
273
286
299err_t vcpmonitor4_get_temperature ( vcpmonitor4_t *ctx, float *temperature );
300
313err_t vcpmonitor4_get_vbus ( vcpmonitor4_t *ctx, float *vbus );
314
327err_t vcpmonitor4_get_vshunt ( vcpmonitor4_t *ctx, float *vshunt );
328
341err_t vcpmonitor4_get_current ( vcpmonitor4_t *ctx, float *current );
342
355err_t vcpmonitor4_get_power ( vcpmonitor4_t *ctx, float *power );
356
357#ifdef __cplusplus
358}
359#endif
360#endif // vcpmonitor4_H
361
362 // vcpmonitor4
363
364// ------------------------------------------------------------------------ END
err_t vcpmonitor4_get_temperature(vcpmonitor4_t *ctx, float *temperature)
Get device temperature.
err_t vcpmonitor4_default_cfg(vcpmonitor4_t *ctx)
VCP Monitor 4 default configuration function.
err_t vcpmonitor4_generic_read(vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out)
VCP Monitor 4 data reading function.
err_t vcpmonitor4_get_power(vcpmonitor4_t *ctx, float *power)
Get Shunt voltage.
void vcpmonitor4_cfg_setup(vcpmonitor4_cfg_t *cfg)
VCP Monitor 4 configuration object setup function.
err_t vcpmonitor4_generic_write(vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in)
VCP Monitor 4 data writing function.
uint8_t vcpmonitor4_get_alert(vcpmonitor4_t *ctx)
Get alert pin state.
err_t vcpmonitor4_get_vbus(vcpmonitor4_t *ctx, float *vbus)
Get BUS voltage.
err_t vcpmonitor4_get_current(vcpmonitor4_t *ctx, float *current)
Get Current.
err_t vcpmonitor4_init(vcpmonitor4_t *ctx, vcpmonitor4_cfg_t *cfg)
VCP Monitor 4 initialization function.
err_t vcpmonitor4_get_vshunt(vcpmonitor4_t *ctx, float *vshunt)
Get Shunt voltage.
This file contains SPI specific macros, functions, etc.
VCP Monitor 4 Click configuration object.
Definition vcpmonitor4.h:168
pin_name_t alr
Definition vcpmonitor4.h:176
spi_master_chip_select_polarity_t cs_polarity
Definition vcpmonitor4.h:181
pin_name_t sck
Definition vcpmonitor4.h:172
spi_master_mode_t spi_mode
Definition vcpmonitor4.h:180
pin_name_t mosi
Definition vcpmonitor4.h:171
uint32_t spi_speed
Definition vcpmonitor4.h:179
pin_name_t miso
Definition vcpmonitor4.h:170
pin_name_t cs
Definition vcpmonitor4.h:173
VCP Monitor 4 Click context object.
Definition vcpmonitor4.h:152
spi_master_t spi
Definition vcpmonitor4.h:157
digital_in_t alr
Definition vcpmonitor4.h:154
pin_name_t chip_select
Definition vcpmonitor4.h:159
vcpmonitor4_return_value_t
VCP Monitor 4 Click return value data.
Definition vcpmonitor4.h:190
@ vcpmonitor4_OK
Definition vcpmonitor4.h:191
@ vcpmonitor4_ERROR
Definition vcpmonitor4.h:192