hallcurrent17  2.1.0.0
hallcurrent17.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 HALLCURRENT17_H
29 #define HALLCURRENT17_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 HALLCURRENT17_ADDR_IN_CH_SEL_1 0x00
61 #define HALLCURRENT17_ADDR_IN_CH_SEL_2 0x08
62 
63  // hallcurrent17_addr
65 
80 #define HALLCURRENT17_RESOLUTION_12BIT 0x0FFFu
81 
86 #define HALLCURRENT17_VREF_3V3 3.3f
87 #define HALLCURRENT17_VREF_5V 5.0f
88 
93 #define HALLCURRENT17_RES_R5_R7_100_KOHM 100.0f
94 #define HALLCURRENT17_RES_R6_R8_100_KOHM 100.0f
95 
100 #define HALLCURRENT17_NUM_OF_MEASURE 1000u
101 #define HALLCURRENT17_CONV_V_TO_MV 1000.0f
102 
107 #define HALLCURRENT17_SENSITIVITY_MV_A 40.0f
108 
117 #define HALLCURRENT17_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
118 #define HALLCURRENT17_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
119  // hallcurrent17_set
121 
136 #define HALLCURRENT17_MAP_MIKROBUS( cfg, mikrobus ) \
137  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
138  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
139  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
140  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
141  // hallcurrent17_map // hallcurrent17
144 
149 typedef struct
150 {
151  // Modules
152  spi_master_t spi;
154  pin_name_t chip_select;
156  float vref;
159 
164 typedef struct
165 {
166  // Communication gpio pins
167  pin_name_t miso;
168  pin_name_t mosi;
169  pin_name_t sck;
170  pin_name_t cs;
172  // static variable
173  uint32_t spi_speed;
174  spi_master_mode_t spi_mode;
175  spi_master_chip_select_polarity_t cs_polarity;
178 
183 typedef enum
184 {
187 
189 
206 
221 
235 
247 void hallcurrent17_set_adc_vref ( hallcurrent17_t *ctx, float vref );
248 
262 err_t hallcurrent17_get_voltage ( hallcurrent17_t *ctx, float *voltage );
263 
278 err_t hallcurrent17_get_vref ( hallcurrent17_t *ctx, float *adc_vref );
279 
294 err_t hallcurrent17_get_vout ( hallcurrent17_t *ctx, float *adc_vout );
295 
309 err_t hallcurrent17_get_current ( hallcurrent17_t *ctx, float *current );
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 #endif // HALLCURRENT17_H
315  // hallcurrent17
317 
318 // ------------------------------------------------------------------------ END
hallcurrent17_return_value_t
hallcurrent17_return_value_t
Hall Current 17 Click return value data.
Definition: hallcurrent17.h:184
hallcurrent17_get_vout
err_t hallcurrent17_get_vout(hallcurrent17_t *ctx, float *adc_vout)
Hall Current 17 get Vout function.
hallcurrent17_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent17.h:174
hallcurrent17_get_vref
err_t hallcurrent17_get_vref(hallcurrent17_t *ctx, float *adc_vref)
Hall Current 17 get Vref function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hallcurrent17_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent17.h:168
hallcurrent17_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent17.h:175
hallcurrent17_cfg_t
Hall Current 17 Click configuration object.
Definition: hallcurrent17.h:165
hallcurrent17_cfg_t::miso
pin_name_t miso
Definition: hallcurrent17.h:167
hallcurrent17_t::vref
float vref
Definition: hallcurrent17.h:156
hallcurrent17_default_cfg
err_t hallcurrent17_default_cfg(hallcurrent17_t *ctx)
Hall Current 17 default configuration function.
hallcurrent17_init
err_t hallcurrent17_init(hallcurrent17_t *ctx, hallcurrent17_cfg_t *cfg)
Hall Current 17 initialization function.
hallcurrent17_get_current
err_t hallcurrent17_get_current(hallcurrent17_t *ctx, float *current)
Hall Current 17 get current function.
hallcurrent17_set_adc_vref
void hallcurrent17_set_adc_vref(hallcurrent17_t *ctx, float vref)
Hall Current 17 set voltage reference function.
HALLCURRENT17_OK
@ HALLCURRENT17_OK
Definition: hallcurrent17.h:185
hallcurrent17_cfg_t::sck
pin_name_t sck
Definition: hallcurrent17.h:169
hallcurrent17_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent17.h:173
hallcurrent17_get_voltage
err_t hallcurrent17_get_voltage(hallcurrent17_t *ctx, float *voltage)
Hall Current 17 get voltage function.
hallcurrent17_cfg_t::cs
pin_name_t cs
Definition: hallcurrent17.h:170
hallcurrent17_t::spi
spi_master_t spi
Definition: hallcurrent17.h:152
hallcurrent17_t
Hall Current 17 Click context object.
Definition: hallcurrent17.h:150
HALLCURRENT17_ERROR
@ HALLCURRENT17_ERROR
Definition: hallcurrent17.h:186
hallcurrent17_t::chip_select
pin_name_t chip_select
Definition: hallcurrent17.h:154
hallcurrent17_cfg_setup
void hallcurrent17_cfg_setup(hallcurrent17_cfg_t *cfg)
Hall Current 17 configuration object setup function.