ambient  2.0.0.0
ambient.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 
35 #ifndef AMBIENT_H
36 #define AMBIENT_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_digital_in.h"
50 #include "drv_analog_in.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
53 
63 #define AMBIENT_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
65 
71 #define AMBIENT_OK 0
72 #define AMBIENT_ERROR -1
73 
79 #define AMBIENT_VCC_5_0 5.0f
80 #define AMBIENT_VCC_3_3 3.3f
81 #define AMBIENT_VOLTS_TO_MILLIVOLTS 1000.0f
82 #define AMBIENT_GAIN 7
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Modules
98  analog_in_t adc;
99 
100 } ambient_t;
101 
105 typedef struct
106 {
107  // Communication gpio pins
108  pin_name_t an_pin;
109 
110  // static variable
111  analog_in_resolution_t resolution; // Resolution
112  float vref; // VRef
113 
114 } ambient_cfg_t;
115  // End types group
117 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
118 
124 #ifdef __cplusplus
125 extern "C"{
126 #endif
127 
137 
146 err_t ambient_init ( ambient_t *ctx, ambient_cfg_t *cfg );
147 
159 err_t ambient_read_an_pin_value ( ambient_t *ctx, uint16_t *data_out );
160 
174 err_t ambient_read_an_pin_voltage ( ambient_t *ctx, float *data_out );
175 
186 
187 #ifdef __cplusplus
188 }
189 #endif
190 #endif // _AMBIENT_H_
191  // End public_function group
194 
195 // ------------------------------------------------------------------------ END
ambient_cfg_setup
void ambient_cfg_setup(ambient_cfg_t *cfg)
Config Object Initialization function.
ambient_cfg_t
Click configuration structure definition.
Definition: ambient.h:106
ambient_t::adc
analog_in_t adc
Definition: ambient.h:98
ambient_read_an_pin_value
err_t ambient_read_an_pin_value(ambient_t *ctx, uint16_t *data_out)
Ambient read AN pin value function.
ambient_init
err_t ambient_init(ambient_t *ctx, ambient_cfg_t *cfg)
Initialization function.
ambient_t
Click ctx object definition.
Definition: ambient.h:96
ambient_cfg_t::an_pin
pin_name_t an_pin
Definition: ambient.h:108
ambient_read_an_pin_voltage
err_t ambient_read_an_pin_voltage(ambient_t *ctx, float *data_out)
Ambient read AN pin voltage level function.
ambient_get_light_intensity
uint16_t ambient_get_light_intensity(ambient_t *ctx)
Calculate light intensity function.
ambient_cfg_t::vref
float vref
Definition: ambient.h:112
ambient_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient.h:111