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 
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 CURRENT5_VOLTAGE_GAIN 200.0
71 #define CURRENT5_VREF_mV 3300.0
72 #define CURRENT5_RESOLUTION 4096.0
73 #define CURRENT5_RSHUNT_mOHM 2.0
74 #define CURRENT5_GAIN_ERROR_PERCENTS 6.0
75 
84 #define CURRENT5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
85 #define CURRENT5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
86  // current5_set
88 
103 #define CURRENT5_MAP_MIKROBUS( cfg, mikrobus ) \
104  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
105  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
106  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
107  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
108  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
109  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
110  // current5_map // current5
113 
118 typedef struct
119 {
120  // Output pins
121  digital_out_t rst;
123  // Input pins
124  digital_in_t alert;
126  // Modules
127  spi_master_t spi;
129  pin_name_t chip_select;
131 } current5_t;
132 
137 typedef struct
138 {
139  // Communication gpio pins
140  pin_name_t miso;
141  pin_name_t mosi;
142  pin_name_t sck;
143  pin_name_t cs;
145  // Additional gpio pins
146  pin_name_t rst;
147  pin_name_t alert;
149  // static variable
150  uint32_t spi_speed;
151  spi_master_mode_t spi_mode;
152  spi_master_chip_select_polarity_t cs_polarity;
155 
160 typedef enum
161 {
163  CURRENT5_ERROR = -1
164 
166 
183 
199 
214 
228 err_t current5_generic_read ( current5_t *ctx, uint8_t *data_out, uint8_t len );
229 
239 
249 void current5_set_rst ( current5_t *ctx, uint8_t state );
250 
262 err_t current5_get_adc ( current5_t *ctx, uint16_t *adc_data );
263 
275 err_t current5_get_voltage ( current5_t *ctx, float *vout );
276 
288 err_t current5_get_current ( current5_t *ctx, float *current );
289 
290 #ifdef __cplusplus
291 }
292 #endif
293 #endif // CURRENT5_H
294  // current5
296 
297 // ------------------------------------------------------------------------ END
current5_t::spi
spi_master_t spi
Definition: current5.h:127
current5_t::rst
digital_out_t rst
Definition: current5.h:121
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:151
current5_cfg_t::mosi
pin_name_t mosi
Definition: current5.h:141
current5_cfg_t::sck
pin_name_t sck
Definition: current5.h:142
spi_specifics.h
This file contains SPI specific macros, functions, etc.
current5_cfg_t::alert
pin_name_t alert
Definition: current5.h:147
current5_cfg_t
Current 5 Click configuration object.
Definition: current5.h:138
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:163
current5_return_value_t
current5_return_value_t
Current 5 Click return value data.
Definition: current5.h:161
current5_cfg_t::rst
pin_name_t rst
Definition: current5.h:146
current5_t::chip_select
pin_name_t chip_select
Definition: current5.h:129
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:152
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:140
current5_cfg_t::cs
pin_name_t cs
Definition: current5.h:143
CURRENT5_OK
@ CURRENT5_OK
Definition: current5.h:162
current5_cfg_t::spi_speed
uint32_t spi_speed
Definition: current5.h:150
current5_t
Current 5 Click context object.
Definition: current5.h:119
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:124
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.