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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_analog_in.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define IRDISTANCE_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.out = MIKROBUS( mikrobus, MIKROBUS_AN ); \
63  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
64  // End group macro
67 // --------------------------------------------------------------- PUBLIC TYPES
76 typedef struct
77 {
78  // Output pins
79 
80  digital_out_t en;
81 
82  // Modules
83 
84  analog_in_t adc;
85 
86 } irdistance_t;
87 
91 typedef struct
92 {
93  // Additional gpio pins
94 
95  pin_name_t out;
96  pin_name_t en;
97 
98  // Static variable
99 
100  analog_in_resolution_t resolution;
101  float vref;
104  // End types group
106 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
107 
113 #ifdef __cplusplus
114 extern "C"{
115 #endif
116 
127 
142 
152 
162 
173 err_t irdistance_read_adc ( irdistance_t *ctx, uint16_t *data_out );
174 
185 err_t irdistance_get_pin_voltage ( irdistance_t *ctx, float *data_out );
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 #endif // _IRDISTANCE_H_
191  // End public_function group
194 
195 // ------------------------------------------------------------------------- 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:96
irdistance_t::adc
analog_in_t adc
Definition: irdistance.h:84
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:92
irdistance_init
err_t irdistance_init(irdistance_t *ctx, irdistance_cfg_t *cfg)
Initialization function.
irdistance_cfg_t::vref
float vref
Definition: irdistance.h:101
irdistance_cfg_t::resolution
analog_in_resolution_t resolution
Definition: irdistance.h:100
irdistance_t
Click ctx object definition.
Definition: irdistance.h:77
irdistance_cfg_t::out
pin_name_t out
Definition: irdistance.h:95
irdistance_t::en
digital_out_t en
Definition: irdistance.h:80
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.