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 
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_digital_in.h"
54 #include "drv_analog_in.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
57 
67 #define AMBIENT_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
69 
75 #define AMBIENT_OK 0
76 #define AMBIENT_ERROR -1
77 
83 #define AMBIENT_VCC_5_0 5.0f
84 #define AMBIENT_VCC_3_3 3.3f
85 #define AMBIENT_VOLTS_TO_MILLIVOLTS 1000.0f
86 #define AMBIENT_GAIN 7
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101  // Modules
102  analog_in_t adc;
103 
104 } ambient_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112  pin_name_t an_pin;
113 
114  // static variable
115  analog_in_resolution_t resolution; // Resolution
116  float vref; // VRef
117 
118 } ambient_cfg_t;
119  // End types group
121 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
122 
128 #ifdef __cplusplus
129 extern "C"{
130 #endif
131 
141 
150 err_t ambient_init ( ambient_t *ctx, ambient_cfg_t *cfg );
151 
163 err_t ambient_read_an_pin_value ( ambient_t *ctx, uint16_t *data_out );
164 
178 err_t ambient_read_an_pin_voltage ( ambient_t *ctx, float *data_out );
179 
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 #endif // _AMBIENT_H_
195  // End public_function group
198 
199 // ------------------------------------------------------------------------ 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:110
ambient_t::adc
analog_in_t adc
Definition: ambient.h:102
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:100
ambient_cfg_t::an_pin
pin_name_t an_pin
Definition: ambient.h:112
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:116
ambient_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient.h:115