hallcurrent5  2.0.0.0
hallcurrent5.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
34 #ifndef HALLCURRENT5_H
35 #define HALLCURRENT5_H
36 
37 #include "drv_digital_in.h"
38 #include "drv_analog_in.h"
39 
40 // -------------------------------------------------------------- PUBLIC MACROS
41 
51 #define HALLCURRENT5_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
54 
60 #define HALLCURRENT5_RETVAL uint8_t
61 
62 #define HALLCURRENT5_OK 0x00
63 #define HALLCURRENT5_INIT_ERROR 0xFF
64 
70 #define HALLCURRENT5_ADC_RESOLUTION_10bit 1023.0
71 #define HALLCURRENT5_ADC_RESOLUTION_12bit 4095.0
72  // End group macro
75 // --------------------------------------------------------------- PUBLIC TYPES
84 typedef analog_in_data_t hallcurrent5_data_t;
85 
89 typedef struct
90 {
91  // Input pins
92 
93  digital_in_t int_pin;
94 
95  // Modules
96 
97  analog_in_t adc;
98 
100  uint16_t dev_init_volt;
101 
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t an_pin;
112 
113  // Additional gpio pins
114 
115  pin_name_t int_pin;
116 
117  // static variable
118 
119  hal_adc_channel_t channel; // Channel
120  hal_adc_resolution_t resolution; // Resolution
121  hal_adc_voltage_reference_t vref; // VRef
122 
124  uint16_t init_volt;
125 
127  // End types group
129 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
130 
136 #ifdef __cplusplus
137 extern "C"{
138 #endif
139 
149 
158 
168 
177 void hallcurrent5_set_adc_resolution ( hallcurrent5_t *ctx, float adc_res );
178 
187 float hallcurrent5_get_adc_voltage ( hallcurrent5_t *ctx, uint16_t adc_value );
188 
197 float hallcurrent5_get_current ( hallcurrent5_t *ctx, uint16_t adc_value );
198 
206 uint8_t hallcurrent5_get_fault ( hallcurrent5_t *ctx );
207 
216 void hallcurrent5_set_init_voltage ( hallcurrent5_t *ctx, uint16_t voltage );
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif // _HALLCURRENT5_H_
222  // End public_function group
225 
226 // ------------------------------------------------------------------------ END
digital_in_t int_pin
Definition: hallcurrent5.h:93
HALLCURRENT5_RETVAL hallcurrent5_init(hallcurrent5_t *ctx, hallcurrent5_cfg_t *cfg)
Initialization function.
hal_adc_voltage_reference_t vref
Definition: hallcurrent5.h:121
void hallcurrent5_set_adc_resolution(hallcurrent5_t *ctx, float adc_res)
Set ADC resolution function.
hallcurrent5_data_t hallcurrent5_generic_read(hallcurrent5_t *ctx)
Generic read function.
hal_adc_channel_t channel
Definition: hallcurrent5.h:119
#define HALLCURRENT5_RETVAL
Definition: hallcurrent5.h:60
void hallcurrent5_cfg_setup(hallcurrent5_cfg_t *cfg)
Config Object Initialization function.
uint8_t hallcurrent5_get_fault(hallcurrent5_t *ctx)
Get ADC fault function.
Click ctx object definition.
Definition: hallcurrent5.h:89
analog_in_t adc
Definition: hallcurrent5.h:97
pin_name_t int_pin
Definition: hallcurrent5.h:115
float dev_resolution
Definition: hallcurrent5.h:99
uint16_t dev_init_volt
Definition: hallcurrent5.h:100
float hallcurrent5_get_adc_voltage(hallcurrent5_t *ctx, uint16_t adc_value)
Get ADC voltage function.
float device_resolution
Definition: hallcurrent5.h:123
analog_in_data_t hallcurrent5_data_t
Analog data type.
Definition: hallcurrent5.h:84
Click configuration structure definition.
Definition: hallcurrent5.h:107
hal_adc_resolution_t resolution
Definition: hallcurrent5.h:120
void hallcurrent5_set_init_voltage(hallcurrent5_t *ctx, uint16_t voltage)
Get ADC current value function.
pin_name_t an_pin
Definition: hallcurrent5.h:111
uint16_t init_volt
Definition: hallcurrent5.h:124
float hallcurrent5_get_current(hallcurrent5_t *ctx, uint16_t adc_value)
Get ADC current value function.