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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_analog_in.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define IRDISTANCE_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.out = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef struct
81 {
82  // Output pins
83 
84  digital_out_t en;
85 
86  // Modules
87 
88  analog_in_t adc;
89 
90 } irdistance_t;
91 
95 typedef struct
96 {
97  // Additional gpio pins
98 
99  pin_name_t out;
100  pin_name_t en;
101 
102  // Static variable
103 
104  analog_in_resolution_t resolution;
105  float vref;
108  // End types group
110 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
111 
117 #ifdef __cplusplus
118 extern "C"{
119 #endif
120 
131 
146 
156 
166 
177 err_t irdistance_read_adc ( irdistance_t *ctx, uint16_t *data_out );
178 
189 err_t irdistance_get_pin_voltage ( irdistance_t *ctx, float *data_out );
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 #endif // _IRDISTANCE_H_
195  // End public_function group
198 
199 // ------------------------------------------------------------------------- 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:100
irdistance_t::adc
analog_in_t adc
Definition: irdistance.h:88
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:96
irdistance_init
err_t irdistance_init(irdistance_t *ctx, irdistance_cfg_t *cfg)
Initialization function.
irdistance_cfg_t::vref
float vref
Definition: irdistance.h:105
irdistance_cfg_t::resolution
analog_in_resolution_t resolution
Definition: irdistance.h:104
irdistance_t
Click ctx object definition.
Definition: irdistance.h:81
irdistance_cfg_t::out
pin_name_t out
Definition: irdistance.h:99
irdistance_t::en
digital_out_t en
Definition: irdistance.h:84
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.