current5 2.0.0.0
current5.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 CURRENT5_H
29#define CURRENT5_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 CURRENT5_VOLTAGE_GAIN 200.0
75#define CURRENT5_VREF_mV 3300.0
76#define CURRENT5_RESOLUTION 4096.0
77#define CURRENT5_RSHUNT_mOHM 2.0
78#define CURRENT5_GAIN_ERROR_PERCENTS 6.0
79
88#define CURRENT5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
89#define CURRENT5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
90
91 // current5_set
92
107#define CURRENT5_MAP_MIKROBUS( cfg, mikrobus ) \
108 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
109 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
110 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
111 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
112 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
113 cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
114
115 // current5_map
116 // current5
117
122typedef struct
123{
124 // Output pins
125 digital_out_t rst;
127 // Input pins
128 digital_in_t alert;
130 // Modules
131 spi_master_t spi;
133 pin_name_t chip_select;
135} current5_t;
136
141typedef struct
142{
143 // Communication gpio pins
144 pin_name_t miso;
145 pin_name_t mosi;
146 pin_name_t sck;
147 pin_name_t cs;
149 // Additional gpio pins
150 pin_name_t rst;
151 pin_name_t alert;
153 // static variable
154 uint32_t spi_speed;
155 spi_master_mode_t spi_mode;
156 spi_master_chip_select_polarity_t cs_polarity;
159
164typedef enum
165{
167 CURRENT5_ERROR = -1
168
170
187
203
218
232err_t current5_generic_read ( current5_t *ctx, uint8_t *data_out, uint8_t len );
233
243
253void current5_set_rst ( current5_t *ctx, uint8_t state );
254
266err_t current5_get_adc ( current5_t *ctx, uint16_t *adc_data );
267
279err_t current5_get_voltage ( current5_t *ctx, float *vout );
280
292err_t current5_get_current ( current5_t *ctx, float *current );
293
294#ifdef __cplusplus
295}
296#endif
297#endif // CURRENT5_H
298
299 // current5
300
301// ------------------------------------------------------------------------ END
current5_return_value_t
Current 5 Click return value data.
Definition current5.h:165
@ CURRENT5_ERROR
Definition current5.h:167
@ CURRENT5_OK
Definition current5.h:166
err_t current5_init(current5_t *ctx, current5_cfg_t *cfg)
Current 5 initialization function.
void current5_set_rst(current5_t *ctx, uint8_t state)
Mode selection.
err_t current5_generic_read(current5_t *ctx, uint8_t *data_out, uint8_t len)
Current 5 data reading function.
uint8_t current5_get_alert(current5_t *ctx)
Get alert pin state.
err_t current5_default_cfg(current5_t *ctx)
Current 5 default configuration function.
err_t current5_get_voltage(current5_t *ctx, float *vout)
Get voltage.
err_t current5_get_current(current5_t *ctx, float *current)
Get current.
void current5_cfg_setup(current5_cfg_t *cfg)
Current 5 configuration object setup function.
err_t current5_get_adc(current5_t *ctx, uint16_t *adc_data)
Read raw adc value.
This file contains SPI specific macros, functions, etc.
Current 5 Click configuration object.
Definition current5.h:142
pin_name_t alert
Definition current5.h:151
spi_master_chip_select_polarity_t cs_polarity
Definition current5.h:156
pin_name_t sck
Definition current5.h:146
spi_master_mode_t spi_mode
Definition current5.h:155
pin_name_t mosi
Definition current5.h:145
uint32_t spi_speed
Definition current5.h:154
pin_name_t miso
Definition current5.h:144
pin_name_t rst
Definition current5.h:150
pin_name_t cs
Definition current5.h:147
Current 5 Click context object.
Definition current5.h:123
spi_master_t spi
Definition current5.h:131
digital_in_t alert
Definition current5.h:128
digital_out_t rst
Definition current5.h:125
pin_name_t chip_select
Definition current5.h:133