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 
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  // 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  // 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  // vcpmonitor4_map // vcpmonitor4
146 
151 typedef struct
152 {
153  // Input pins
154  digital_in_t alr;
156  // Modules
157  spi_master_t spi;
159  pin_name_t chip_select;
161 } vcpmonitor4_t;
162 
167 typedef 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 
189 typedef enum
190 {
192  vcpmonitor4_ERROR = -1
193 
195 
212 
228 
243 
257 err_t vcpmonitor4_generic_write ( vcpmonitor4_t *ctx, uint8_t reg, uint16_t data_in );
258 
272 err_t vcpmonitor4_generic_read ( vcpmonitor4_t *ctx, uint8_t reg, uint32_t *data_out ) ;
273 
286 
299 err_t vcpmonitor4_get_temperature ( vcpmonitor4_t *ctx, float *temperature );
300 
313 err_t vcpmonitor4_get_vbus ( vcpmonitor4_t *ctx, float *vbus );
314 
327 err_t vcpmonitor4_get_vshunt ( vcpmonitor4_t *ctx, float *vshunt );
328 
341 err_t vcpmonitor4_get_current ( vcpmonitor4_t *ctx, float *current );
342 
355 err_t vcpmonitor4_get_power ( vcpmonitor4_t *ctx, float *power );
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 #endif // vcpmonitor4_H
361  // vcpmonitor4
363 
364 // ------------------------------------------------------------------------ END
vcpmonitor4_t
VCP Monitor 4 Click context object.
Definition: vcpmonitor4.h:152
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:157
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:180
vcpmonitor4_return_value_t
vcpmonitor4_return_value_t
VCP Monitor 4 Click return value data.
Definition: vcpmonitor4.h:190
vcpmonitor4_ERROR
@ vcpmonitor4_ERROR
Definition: vcpmonitor4.h:192
vcpmonitor4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: vcpmonitor4.h:181
vcpmonitor4_cfg_t::alr
pin_name_t alr
Definition: vcpmonitor4.h:176
vcpmonitor4_cfg_t::spi_speed
uint32_t spi_speed
Definition: vcpmonitor4.h:179
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:173
vcpmonitor4_cfg_t::mosi
pin_name_t mosi
Definition: vcpmonitor4.h:171
vcpmonitor4_t::chip_select
pin_name_t chip_select
Definition: vcpmonitor4.h:159
vcpmonitor4_cfg_t
VCP Monitor 4 Click configuration object.
Definition: vcpmonitor4.h:168
vcpmonitor4_cfg_t::sck
pin_name_t sck
Definition: vcpmonitor4.h:172
vcpmonitor4_get_power
err_t vcpmonitor4_get_power(vcpmonitor4_t *ctx, float *power)
Get Shunt voltage.
vcpmonitor4_OK
@ vcpmonitor4_OK
Definition: vcpmonitor4.h:191
vcpmonitor4_cfg_t::miso
pin_name_t miso
Definition: vcpmonitor4.h:170
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:154