irdistance  2.0.0.0
irdistance.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef IRDISTANCE_H
36 #define IRDISTANCE_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_analog_in.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define IRDISTANCE_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.out = MIKROBUS( mikrobus, MIKROBUS_AN ); \
53  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
54  // End group macro
57 // --------------------------------------------------------------- PUBLIC TYPES
66 typedef struct
67 {
68  // Output pins
69 
70  digital_out_t en;
71 
72  // Modules
73 
74  analog_in_t adc;
75 
76 } irdistance_t;
77 
81 typedef struct
82 {
83  // Additional gpio pins
84 
85  pin_name_t out;
86  pin_name_t en;
87 
88  // Static variable
89 
90  analog_in_resolution_t resolution;
91  float vref;
94  // End types group
96 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
97 
103 #ifdef __cplusplus
104 extern "C"{
105 #endif
106 
117 
131 err_t irdistance_init ( irdistance_t *ctx, irdistance_cfg_t *cfg );
132 
142 
152 
163 err_t irdistance_read_adc ( irdistance_t *ctx, uint16_t *data_out );
164 
175 err_t irdistance_get_pin_voltage ( irdistance_t *ctx, float *data_out );
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 #endif // _IRDISTANCE_H_
181  // End public_function group
184 
185 // ------------------------------------------------------------------------- END
irdistance_enable_device
void irdistance_enable_device(irdistance_t *ctx)
Enable IR sensor function.
irdistance_cfg_t::en
pin_name_t en
Definition: irdistance.h:86
irdistance_t::adc
analog_in_t adc
Definition: irdistance.h:74
irdistance_cfg_setup
void irdistance_cfg_setup(irdistance_cfg_t *cfg)
Config Object Initialization function.
irdistance_read_adc
err_t irdistance_read_adc(irdistance_t *ctx, uint16_t *data_out)
Generic read function.
irdistance_cfg_t
Click configuration structure definition.
Definition: irdistance.h:81
irdistance_init
err_t irdistance_init(irdistance_t *ctx, irdistance_cfg_t *cfg)
Initialization function.
irdistance_cfg_t::vref
float vref
Definition: irdistance.h:91
irdistance_cfg_t::resolution
analog_in_resolution_t resolution
Definition: irdistance.h:90
irdistance_t
Click ctx object definition.
Definition: irdistance.h:66
irdistance_cfg_t::out
pin_name_t out
Definition: irdistance.h:85
irdistance_t::en
digital_out_t en
Definition: irdistance.h:70
irdistance_disable_device
void irdistance_disable_device(irdistance_t *ctx)
Disable IR sensor function.
irdistance_get_pin_voltage
err_t irdistance_get_pin_voltage(irdistance_t *ctx, float *data_out)
Get the voltage output of the sensor function.