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_RETVAL uint8_t
62 
63 #define AMBIENT_OK 0x00
64 #define AMBIENT_INIT_ERROR 0xFF
65 
71 #define AMBIENT_VCC_5_0 5000
72 #define AMBIENT_VCC_3_3 3300
73 #define AMBIENT_RES_10_BIT 1024
74 #define AMBIENT_RES_12_BIT 4096
75 #define AMBIENT_GAIN 7
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef uint16_t ambient_data_t;
89 
93 typedef struct
94 {
95  // Modules
96 
97  analog_in_t adc;
98 
99 } ambient_t;
100 
104 typedef struct
105 {
106  // Communication gpio pins
107 
108  pin_name_t an_pin;
109 
110  // static variable
111 
112  analog_in_resolution_t resolution; // Resolution
113  float vref; // VRef
114 
115 } ambient_cfg_t;
116  // End types group
118 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
119 
125 #ifdef __cplusplus
126 extern "C"{
127 #endif
128 
137 void ambient_cfg_setup ( ambient_cfg_t *cfg );
138 
148 
158 
170 uint16_t ambient_calculate_light_intensity ( ambient_t *ctx, uint16_t adc_data, uint16_t vcc_val, uint16_t adc_res );
171 
172 #ifdef __cplusplus
173 }
174 #endif
175 #endif // _AMBIENT_H_
176  // End public_function group
179 
180 // ------------------------------------------------------------------------ END
uint16_t ambient_data_t
Analog data type.
Definition: ambient.h:88
uint16_t ambient_calculate_light_intensity(ambient_t *ctx, uint16_t adc_data, uint16_t vcc_val, uint16_t adc_res)
Calculate light intensity function.
Click configuration structure definition.
Definition: ambient.h:104
void ambient_cfg_setup(ambient_cfg_t *cfg)
Config Object Initialization function.
analog_in_t adc
Definition: ambient.h:97
AMBIENT_RETVAL ambient_init(ambient_t *ctx, ambient_cfg_t *cfg)
Initialization function.
analog_in_resolution_t resolution
Definition: ambient.h:112
Click ctx object definition.
Definition: ambient.h:93
pin_name_t an_pin
Definition: ambient.h:108
float vref
Definition: ambient.h:113
ambient_data_t ambient_generic_read(ambient_t *ctx)
Generic read function.
#define AMBIENT_RETVAL
Definition: ambient.h:61