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
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 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  // 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  // current5_map // current5
117 
122 typedef 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 
141 typedef 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 
164 typedef enum
165 {
167  CURRENT5_ERROR = -1
168 
170 
187 
203 
218 
232 err_t current5_generic_read ( current5_t *ctx, uint8_t *data_out, uint8_t len );
233 
243 
253 void current5_set_rst ( current5_t *ctx, uint8_t state );
254 
266 err_t current5_get_adc ( current5_t *ctx, uint16_t *adc_data );
267 
279 err_t current5_get_voltage ( current5_t *ctx, float *vout );
280 
292 err_t current5_get_current ( current5_t *ctx, float *current );
293 
294 #ifdef __cplusplus
295 }
296 #endif
297 #endif // CURRENT5_H
298  // current5
300 
301 // ------------------------------------------------------------------------ END
current5_t::spi
spi_master_t spi
Definition: current5.h:131
current5_t::rst
digital_out_t rst
Definition: current5.h:125
current5_generic_read
err_t current5_generic_read(current5_t *ctx, uint8_t *data_out, uint8_t len)
Current 5 data reading function.
current5_get_alert
uint8_t current5_get_alert(current5_t *ctx)
Get alert pin state.
current5_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: current5.h:155
current5_cfg_t::mosi
pin_name_t mosi
Definition: current5.h:145
current5_cfg_t::sck
pin_name_t sck
Definition: current5.h:146
spi_specifics.h
This file contains SPI specific macros, functions, etc.
current5_cfg_t::alert
pin_name_t alert
Definition: current5.h:151
current5_cfg_t
Current 5 Click configuration object.
Definition: current5.h:142
current5_get_adc
err_t current5_get_adc(current5_t *ctx, uint16_t *adc_data)
Read raw adc value.
CURRENT5_ERROR
@ CURRENT5_ERROR
Definition: current5.h:167
current5_return_value_t
current5_return_value_t
Current 5 Click return value data.
Definition: current5.h:165
current5_cfg_t::rst
pin_name_t rst
Definition: current5.h:150
current5_t::chip_select
pin_name_t chip_select
Definition: current5.h:133
current5_set_rst
void current5_set_rst(current5_t *ctx, uint8_t state)
Mode selection.
current5_get_voltage
err_t current5_get_voltage(current5_t *ctx, float *vout)
Get voltage.
current5_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: current5.h:156
current5_get_current
err_t current5_get_current(current5_t *ctx, float *current)
Get current.
current5_cfg_t::miso
pin_name_t miso
Definition: current5.h:144
current5_cfg_t::cs
pin_name_t cs
Definition: current5.h:147
CURRENT5_OK
@ CURRENT5_OK
Definition: current5.h:166
current5_cfg_t::spi_speed
uint32_t spi_speed
Definition: current5.h:154
current5_t
Current 5 Click context object.
Definition: current5.h:123
current5_default_cfg
err_t current5_default_cfg(current5_t *ctx)
Current 5 default configuration function.
current5_t::alert
digital_in_t alert
Definition: current5.h:128
current5_cfg_setup
void current5_cfg_setup(current5_cfg_t *cfg)
Current 5 configuration object setup function.
current5_init
err_t current5_init(current5_t *ctx, current5_cfg_t *cfg)
Current 5 initialization function.