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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_analog_in.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
43 
53 #define AMBIENT_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.an_pin = MIKROBUS( mikrobus, MIKROBUS_AN )
55 
61 #define AMBIENT_OK 0
62 #define AMBIENT_ERROR -1
63 
69 #define AMBIENT_VCC_5_0 5.0f
70 #define AMBIENT_VCC_3_3 3.3f
71 #define AMBIENT_VOLTS_TO_MILLIVOLTS 1000.0f
72 #define AMBIENT_GAIN 7
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Modules
88  analog_in_t adc;
89 
90 } ambient_t;
91 
95 typedef struct
96 {
97  // Communication gpio pins
98  pin_name_t an_pin;
99 
100  // static variable
101  analog_in_resolution_t resolution; // Resolution
102  float vref; // VRef
103 
104 } ambient_cfg_t;
105  // End types group
107 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
108 
114 #ifdef __cplusplus
115 extern "C"{
116 #endif
117 
127 
136 err_t ambient_init ( ambient_t *ctx, ambient_cfg_t *cfg );
137 
149 err_t ambient_read_an_pin_value ( ambient_t *ctx, uint16_t *data_out );
150 
164 err_t ambient_read_an_pin_voltage ( ambient_t *ctx, float *data_out );
165 
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 #endif // _AMBIENT_H_
181  // End public_function group
184 
185 // ------------------------------------------------------------------------ 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:96
ambient_t::adc
analog_in_t adc
Definition: ambient.h:88
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:86
ambient_cfg_t::an_pin
pin_name_t an_pin
Definition: ambient.h:98
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:102
ambient_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient.h:101