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 "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_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define VCPMONITOR4_REG_CONFIG 0x00
71 #define VCPMONITOR4_REG_ADC_CONFIG 0x01
72 #define VCPMONITOR4_REG_SHUNT_CAL 0x02
73 #define VCPMONITOR4_REG_VSHUNT 0x04
74 #define VCPMONITOR4_REG_VBUS 0x05
75 #define VCPMONITOR4_REG_DIETEMP 0x06
76 #define VCPMONITOR4_REG_CURRENT 0x07
77 #define VCPMONITOR4_REG_POWER 0x08
78 #define VCPMONITOR4_REG_DIAG_ALERT 0x0B
79 #define VCPMONITOR4_REG_SOVL 0x0C
80 #define VCPMONITOR4_REG_SUVL 0x0D
81 #define VCPMONITOR4_REG_BOVL 0x0E
82 #define VCPMONITOR4_REG_BUVL 0x0F
83 #define VCPMONITOR4_REG_TEMP_LIMIT 0x10
84 #define VCPMONITOR4_REG_PWR_LIMIT 0x11
85 #define VCPMONITOR4_REG_MANUFACTURER_ID 0x3E
86 #define VCPMONITOR4_REG_DEVICE_ID 0x3F
87  // vcpmonitor4_reg
89 
104 #define VCPMONITOR4_CURRENT_LSB 0.000305
105 
114 #define VCPMONITOR4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
115 #define VCPMONITOR4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
116  // vcpmonitor4_set
118 
133 #define VCPMONITOR4_MAP_MIKROBUS( cfg, mikrobus ) \
134  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
135  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
136  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
137  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
138  cfg.alr = MIKROBUS( mikrobus, MIKROBUS_INT )
139  // vcpmonitor4_map // vcpmonitor4
142 
147 typedef struct
148 {
149  // Input pins
150  digital_in_t alr;
152  // Modules
153  spi_master_t spi;
155  pin_name_t chip_select;
157 } vcpmonitor4_t;
158 
163 typedef struct
164 {
165  // Communication gpio pins
166  pin_name_t miso;
167  pin_name_t mosi;
168  pin_name_t sck;
169  pin_name_t cs;
171  // Additional gpio pins
172  pin_name_t alr;
174  // static variable
175  uint32_t spi_speed;
176  spi_master_mode_t spi_mode;
177  spi_master_chip_select_polarity_t cs_polarity;
180 
185 typedef enum
186 {
188  vcpmonitor4_ERROR = -1
189 
191 
208 
224 
239 
253 err_t vcpmonitor4_generic_write ( vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in );
254 
268 err_t vcpmonitor4_generic_read ( vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out ) ;
269 
282 
295 err_t vcpmonitor4_get_temperature ( vcpmonitor4_t *ctx, float *temperature );
296 
309 err_t vcpmonitor4_get_vbus ( vcpmonitor4_t *ctx, float *vbus );
310 
323 err_t vcpmonitor4_get_vshunt ( vcpmonitor4_t *ctx, float *vshunt );
324 
337 err_t vcpmonitor4_get_current ( vcpmonitor4_t *ctx, float *current );
338 
351 err_t vcpmonitor4_get_power ( vcpmonitor4_t *ctx, float *power );
352 
353 #ifdef __cplusplus
354 }
355 #endif
356 #endif // vcpmonitor4_H
357  // vcpmonitor4
359 
360 // ------------------------------------------------------------------------ END
vcpmonitor4_t
VCP Monitor 4 Click context object.
Definition: vcpmonitor4.h:148
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:153
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:176
vcpmonitor4_return_value_t
vcpmonitor4_return_value_t
VCP Monitor 4 Click return value data.
Definition: vcpmonitor4.h:186
vcpmonitor4_ERROR
@ vcpmonitor4_ERROR
Definition: vcpmonitor4.h:188
vcpmonitor4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vcpmonitor4.h:177
vcpmonitor4_cfg_t::alr
pin_name_t alr
Definition: vcpmonitor4.h:172
vcpmonitor4_cfg_t::spi_speed
uint32_t spi_speed
Definition: vcpmonitor4.h:175
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:169
vcpmonitor4_cfg_t::mosi
pin_name_t mosi
Definition: vcpmonitor4.h:167
vcpmonitor4_t::chip_select
pin_name_t chip_select
Definition: vcpmonitor4.h:155
vcpmonitor4_cfg_t
VCP Monitor 4 Click configuration object.
Definition: vcpmonitor4.h:164
vcpmonitor4_cfg_t::sck
pin_name_t sck
Definition: vcpmonitor4.h:168
vcpmonitor4_get_power
err_t vcpmonitor4_get_power(vcpmonitor4_t *ctx, float *power)
Get Shunt voltage.
vcpmonitor4_OK
@ vcpmonitor4_OK
Definition: vcpmonitor4.h:187
vcpmonitor4_cfg_t::miso
pin_name_t miso
Definition: vcpmonitor4.h:166
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:150