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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define VCPMONITOR4_REG_CONFIG 0x00
61 #define VCPMONITOR4_REG_ADC_CONFIG 0x01
62 #define VCPMONITOR4_REG_SHUNT_CAL 0x02
63 #define VCPMONITOR4_REG_VSHUNT 0x04
64 #define VCPMONITOR4_REG_VBUS 0x05
65 #define VCPMONITOR4_REG_DIETEMP 0x06
66 #define VCPMONITOR4_REG_CURRENT 0x07
67 #define VCPMONITOR4_REG_POWER 0x08
68 #define VCPMONITOR4_REG_DIAG_ALERT 0x0B
69 #define VCPMONITOR4_REG_SOVL 0x0C
70 #define VCPMONITOR4_REG_SUVL 0x0D
71 #define VCPMONITOR4_REG_BOVL 0x0E
72 #define VCPMONITOR4_REG_BUVL 0x0F
73 #define VCPMONITOR4_REG_TEMP_LIMIT 0x10
74 #define VCPMONITOR4_REG_PWR_LIMIT 0x11
75 #define VCPMONITOR4_REG_MANUFACTURER_ID 0x3E
76 #define VCPMONITOR4_REG_DEVICE_ID 0x3F
77  // vcpmonitor4_reg
79 
94 #define VCPMONITOR4_CURRENT_LSB 0.000305
95 
104 #define VCPMONITOR4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
105 #define VCPMONITOR4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
106  // vcpmonitor4_set
108 
123 #define VCPMONITOR4_MAP_MIKROBUS( cfg, mikrobus ) \
124  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
125  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
126  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
127  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
129  // vcpmonitor4_map // vcpmonitor4
132 
137 typedef struct
138 {
139  // Input pins
140  digital_in_t alr;
142  // Modules
143  spi_master_t spi;
145  pin_name_t chip_select;
147 } vcpmonitor4_t;
148 
153 typedef struct
154 {
155  // Communication gpio pins
156  pin_name_t miso;
157  pin_name_t mosi;
158  pin_name_t sck;
159  pin_name_t cs;
161  // Additional gpio pins
162  pin_name_t alr;
164  // static variable
165  uint32_t spi_speed;
166  spi_master_mode_t spi_mode;
167  spi_master_chip_select_polarity_t cs_polarity;
170 
175 typedef enum
176 {
178  vcpmonitor4_ERROR = -1
179 
181 
198 
214 
229 
243 err_t vcpmonitor4_generic_write ( vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in );
244 
258 err_t vcpmonitor4_generic_read ( vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out ) ;
259 
272 
285 err_t vcpmonitor4_get_temperature ( vcpmonitor4_t *ctx, float *temperature );
286 
299 err_t vcpmonitor4_get_vbus ( vcpmonitor4_t *ctx, float *vbus );
300 
313 err_t vcpmonitor4_get_vshunt ( vcpmonitor4_t *ctx, float *vshunt );
314 
327 err_t vcpmonitor4_get_current ( vcpmonitor4_t *ctx, float *current );
328 
341 err_t vcpmonitor4_get_power ( vcpmonitor4_t *ctx, float *power );
342 
343 #ifdef __cplusplus
344 }
345 #endif
346 #endif // vcpmonitor4_H
347  // vcpmonitor4
349 
350 // ------------------------------------------------------------------------ END
vcpmonitor4_t
VCP Monitor 4 Click context object.
Definition: vcpmonitor4.h:138
vcpmonitor4_get_vbus
err_t vcpmonitor4_get_vbus(vcpmonitor4_t *ctx, float *vbus)
Get BUS voltage.
vcpmonitor4_get_current
err_t vcpmonitor4_get_current(vcpmonitor4_t *ctx, float *current)
Get Current.
vcpmonitor4_default_cfg
err_t vcpmonitor4_default_cfg(vcpmonitor4_t *ctx)
VCP Monitor 4 default configuration function.
vcpmonitor4_generic_write
err_t vcpmonitor4_generic_write(vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in)
VCP Monitor 4 data writing function.
vcpmonitor4_init
err_t vcpmonitor4_init(vcpmonitor4_t *ctx, vcpmonitor4_cfg_t *cfg)
VCP Monitor 4 initialization function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
vcpmonitor4_t::spi
spi_master_t spi
Definition: vcpmonitor4.h:143
vcpmonitor4_get_alert
uint8_t vcpmonitor4_get_alert(vcpmonitor4_t *ctx)
Get alert pin state.
vcpmonitor4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: vcpmonitor4.h:166
vcpmonitor4_return_value_t
vcpmonitor4_return_value_t
VCP Monitor 4 Click return value data.
Definition: vcpmonitor4.h:176
vcpmonitor4_ERROR
@ vcpmonitor4_ERROR
Definition: vcpmonitor4.h:178
vcpmonitor4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vcpmonitor4.h:167
vcpmonitor4_cfg_t::alr
pin_name_t alr
Definition: vcpmonitor4.h:162
vcpmonitor4_cfg_t::spi_speed
uint32_t spi_speed
Definition: vcpmonitor4.h:165
vcpmonitor4_get_temperature
err_t vcpmonitor4_get_temperature(vcpmonitor4_t *ctx, float *temperature)
Get device temperature.
vcpmonitor4_get_vshunt
err_t vcpmonitor4_get_vshunt(vcpmonitor4_t *ctx, float *vshunt)
Get Shunt voltage.
vcpmonitor4_cfg_t::cs
pin_name_t cs
Definition: vcpmonitor4.h:159
vcpmonitor4_cfg_t::mosi
pin_name_t mosi
Definition: vcpmonitor4.h:157
vcpmonitor4_t::chip_select
pin_name_t chip_select
Definition: vcpmonitor4.h:145
vcpmonitor4_cfg_t
VCP Monitor 4 Click configuration object.
Definition: vcpmonitor4.h:154
vcpmonitor4_cfg_t::sck
pin_name_t sck
Definition: vcpmonitor4.h:158
vcpmonitor4_get_power
err_t vcpmonitor4_get_power(vcpmonitor4_t *ctx, float *power)
Get Shunt voltage.
vcpmonitor4_OK
@ vcpmonitor4_OK
Definition: vcpmonitor4.h:177
vcpmonitor4_cfg_t::miso
pin_name_t miso
Definition: vcpmonitor4.h:156
vcpmonitor4_generic_read
err_t vcpmonitor4_generic_read(vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out)
VCP Monitor 4 data reading function.
vcpmonitor4_cfg_setup
void vcpmonitor4_cfg_setup(vcpmonitor4_cfg_t *cfg)
VCP Monitor 4 configuration object setup function.
vcpmonitor4_t::alr
digital_in_t alr
Definition: vcpmonitor4.h:140