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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define CURRENT5_VOLTAGE_GAIN 200.0
61 #define CURRENT5_VREF_mV 3300.0
62 #define CURRENT5_RESOLUTION 4096.0
63 #define CURRENT5_RSHUNT_mOHM 2.0
64 #define CURRENT5_GAIN_ERROR_PERCENTS 6.0
65 
74 #define CURRENT5_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
75 #define CURRENT5_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
76  // current5_set
78 
93 #define CURRENT5_MAP_MIKROBUS( cfg, mikrobus ) \
94  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
95  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
96  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
97  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
98  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
99  cfg.alert = MIKROBUS( mikrobus, MIKROBUS_INT )
100  // current5_map // current5
103 
108 typedef struct
109 {
110  // Output pins
111  digital_out_t rst;
113  // Input pins
114  digital_in_t alert;
116  // Modules
117  spi_master_t spi;
119  pin_name_t chip_select;
121 } current5_t;
122 
127 typedef struct
128 {
129  // Communication gpio pins
130  pin_name_t miso;
131  pin_name_t mosi;
132  pin_name_t sck;
133  pin_name_t cs;
135  // Additional gpio pins
136  pin_name_t rst;
137  pin_name_t alert;
139  // static variable
140  uint32_t spi_speed;
141  spi_master_mode_t spi_mode;
142  spi_master_chip_select_polarity_t cs_polarity;
145 
150 typedef enum
151 {
153  CURRENT5_ERROR = -1
154 
156 
173 
189 
204 
218 err_t current5_generic_read ( current5_t *ctx, uint8_t *data_out, uint8_t len );
219 
229 
239 void current5_set_rst ( current5_t *ctx, uint8_t state );
240 
252 err_t current5_get_adc ( current5_t *ctx, uint16_t *adc_data );
253 
265 err_t current5_get_voltage ( current5_t *ctx, float *vout );
266 
278 err_t current5_get_current ( current5_t *ctx, float *current );
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 #endif // CURRENT5_H
284  // current5
286 
287 // ------------------------------------------------------------------------ END
current5_t::spi
spi_master_t spi
Definition: current5.h:117
current5_t::rst
digital_out_t rst
Definition: current5.h:111
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:141
current5_cfg_t::mosi
pin_name_t mosi
Definition: current5.h:131
current5_cfg_t::sck
pin_name_t sck
Definition: current5.h:132
spi_specifics.h
This file contains SPI specific macros, functions, etc.
current5_cfg_t::alert
pin_name_t alert
Definition: current5.h:137
current5_cfg_t
Current 5 Click configuration object.
Definition: current5.h:128
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:153
current5_return_value_t
current5_return_value_t
Current 5 Click return value data.
Definition: current5.h:151
current5_cfg_t::rst
pin_name_t rst
Definition: current5.h:136
current5_t::chip_select
pin_name_t chip_select
Definition: current5.h:119
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:142
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:130
current5_cfg_t::cs
pin_name_t cs
Definition: current5.h:133
CURRENT5_OK
@ CURRENT5_OK
Definition: current5.h:152
current5_cfg_t::spi_speed
uint32_t spi_speed
Definition: current5.h:140
current5_t
Current 5 Click context object.
Definition: current5.h:109
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:114
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.