hallcurrent21  2.1.0.0
hallcurrent21.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 HALLCURRENT21_H
29 #define HALLCURRENT21_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 // TODO -- dodati makroe koji definisu adrese registara
75  // hallcurrent21_reg
77 
92 #define HALLCURRENT21_INPUT_CHANNEL_VREF 0
93 #define HALLCURRENT21_INPUT_CHANNEL_VOUT 1
94 
99 #define HALLCURRENT21_NUM_CONVERSIONS 200
100 
105 #define HALLCURRENT21_ADC_RESOLUTION 0x0FFF
106 #define HALLCURRENT21_VREF_3V3 3.3
107 #define HALLCURRENT21_VREF_5V 5.0
108 
113 #define HALLCURRENT21_TIMEOUT_MS 2000
114 
123 #define HALLCURRENT21_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
124 #define HALLCURRENT21_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
125  // hallcurrent21_set
127 
142 #define HALLCURRENT21_MAP_MIKROBUS( cfg, mikrobus ) \
143  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
144  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
145  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
146  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
147  // hallcurrent21_map // hallcurrent21
150 
155 typedef struct
156 {
157  // Modules
158  spi_master_t spi;
160  pin_name_t chip_select;
161  float vref;
162  float sensor_vref;
166 
171 typedef struct
172 {
173  // Communication gpio pins
174  pin_name_t miso;
175  pin_name_t mosi;
176  pin_name_t sck;
177  pin_name_t cs;
179  // static variable
180  uint32_t spi_speed;
181  spi_master_mode_t spi_mode;
182  spi_master_chip_select_polarity_t cs_polarity;
184  float vref;
187 
192 typedef enum
193 {
196 
198 
215 
230 
243 err_t hallcurrent21_read_raw_adc ( hallcurrent21_t *ctx, uint8_t channel, uint16_t *raw_adc );
244 
258 err_t hallcurrent21_read_voltage ( hallcurrent21_t *ctx, uint8_t channel, float *voltage );
259 
274 err_t hallcurrent21_read_voltage_avg ( hallcurrent21_t *ctx, uint8_t channel, uint16_t num_conv, float *voltage_avg );
275 
285 void hallcurrent21_set_vref ( hallcurrent21_t *ctx, float vref );
286 
299 err_t hallcurrent21_calib_resolution ( hallcurrent21_t *ctx, float calib_current );
300 
313 err_t hallcurrent21_read_current ( hallcurrent21_t *ctx, float *current );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // HALLCURRENT21_H
319  // hallcurrent21
321 
322 // ------------------------------------------------------------------------ END
hallcurrent21_cfg_t
Hall Current 21 Click configuration object.
Definition: hallcurrent21.h:172
HALLCURRENT21_ERROR
@ HALLCURRENT21_ERROR
Definition: hallcurrent21.h:195
hallcurrent21_cfg_t::mosi
pin_name_t mosi
Definition: hallcurrent21.h:175
hallcurrent21_cfg_t::spi_speed
uint32_t spi_speed
Definition: hallcurrent21.h:180
hallcurrent21_read_current
err_t hallcurrent21_read_current(hallcurrent21_t *ctx, float *current)
Hall Current 21 read current function.
hallcurrent21_t::spi
spi_master_t spi
Definition: hallcurrent21.h:158
hallcurrent21_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: hallcurrent21.h:182
spi_specifics.h
This file contains SPI specific macros, functions, etc.
hallcurrent21_cfg_t::vref
float vref
Definition: hallcurrent21.h:184
hallcurrent21_return_value_t
hallcurrent21_return_value_t
Hall Current 21 Click return value data.
Definition: hallcurrent21.h:193
hallcurrent21_read_voltage
err_t hallcurrent21_read_voltage(hallcurrent21_t *ctx, uint8_t channel, float *voltage)
Hall Current 21 read voltage level function.
hallcurrent21_t
Hall Current 21 Click context object.
Definition: hallcurrent21.h:156
hallcurrent21_cfg_t::miso
pin_name_t miso
Definition: hallcurrent21.h:174
hallcurrent21_read_raw_adc
err_t hallcurrent21_read_raw_adc(hallcurrent21_t *ctx, uint8_t channel, uint16_t *raw_adc)
Hall Current 21 read raw ADC value function.
hallcurrent21_calib_resolution
err_t hallcurrent21_calib_resolution(hallcurrent21_t *ctx, float calib_current)
Hall Current 21 calib resolution function.
hallcurrent21_cfg_t::sck
pin_name_t sck
Definition: hallcurrent21.h:176
HALLCURRENT21_OK
@ HALLCURRENT21_OK
Definition: hallcurrent21.h:194
hallcurrent21_t::data_resolution
float data_resolution
Definition: hallcurrent21.h:163
hallcurrent21_t::sensor_vref
float sensor_vref
Definition: hallcurrent21.h:162
hallcurrent21_set_vref
void hallcurrent21_set_vref(hallcurrent21_t *ctx, float vref)
Hall Current 21 set vref function.
hallcurrent21_t::chip_select
pin_name_t chip_select
Definition: hallcurrent21.h:160
hallcurrent21_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: hallcurrent21.h:181
hallcurrent21_cfg_t::cs
pin_name_t cs
Definition: hallcurrent21.h:177
hallcurrent21_cfg_setup
void hallcurrent21_cfg_setup(hallcurrent21_cfg_t *cfg)
Hall Current 21 configuration object setup function.
hallcurrent21_init
err_t hallcurrent21_init(hallcurrent21_t *ctx, hallcurrent21_cfg_t *cfg)
Hall Current 21 initialization function.
hallcurrent21_t::vref
float vref
Definition: hallcurrent21.h:161
hallcurrent21_read_voltage_avg
err_t hallcurrent21_read_voltage_avg(hallcurrent21_t *ctx, uint8_t channel, uint16_t num_conv, float *voltage_avg)
Hall Current 21 read average voltage level function.