ambient10  2.0.0.0
ambient10.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef AMBIENT10_H
29 #define AMBIENT10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_analog_in.h"
38 #include "drv_i2c_master.h"
39 
61 #define AMBIENT10_SET_DEV_ADDR 0x4D
62 
67 #define AMBIENT10_ADC_RESOLUTION 0x0FFF
68 #define AMBIENT10_VREF_3V3 3.3
69 #define AMBIENT10_VREF_5V 5.0
70 
76 #define AMBIENT10_MICROAMPER_TO_AMPER 0.000001
77 #define AMBIENT10_IOUT_TO_LUX 2.5
78 #define AMBIENT10_IOUT_RESISTOR 5100
79  // ambient10_set
81 
96 #define AMBIENT10_MAP_MIKROBUS( cfg, mikrobus ) \
97  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
98  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
99  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
100  // ambient10_map // ambient10
103 
108 typedef struct
109 {
110  analog_in_t adc;
111  i2c_master_t i2c;
113  uint8_t slave_address;
114  float vref;
116 } ambient10_t;
117 
122 typedef struct
123 {
124  pin_name_t an;
125  pin_name_t scl;
126  pin_name_t sda;
128  uint32_t i2c_speed;
129  uint8_t i2c_address;
131  analog_in_resolution_t resolution;
132  float vref;
135 
140 typedef enum
141 {
143  AMBIENT10_ERROR = -1
144 
146 
163 
178 err_t ambient10_init ( ambient10_t *ctx, ambient10_cfg_t *cfg );
179 
192 err_t ambient10_read_an_pin_value ( ambient10_t *ctx, uint16_t *data_out );
193 
208 err_t ambient10_read_an_pin_voltage ( ambient10_t *ctx, float *data_out );
209 
222 err_t ambient10_read_raw_adc ( ambient10_t *ctx, uint16_t *raw_adc );
223 
237 err_t ambient10_read_adc_voltage ( ambient10_t *ctx, float *voltage );
238 
249 err_t ambient10_set_vref ( ambient10_t *ctx, float vref );
250 
258 uint16_t ambient10_voltage_to_lux ( ambient10_t *ctx, float voltage );
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif // AMBIENT10_H
264  // ambient10
266 
267 // ------------------------------------------------------------------------ END
AMBIENT10_ERROR
Definition: ambient10.h:142
ambient10_return_value_t
ambient10_return_value_t
Ambient 10 Click return value data.
Definition: ambient10.h:139
ambient10_cfg_t
Ambient 10 Click configuration object.
Definition: ambient10.h:121
ambient10_cfg_setup
void ambient10_cfg_setup(ambient10_cfg_t *cfg)
Ambient 10 configuration object setup function.
ambient10_set_vref
err_t ambient10_set_vref(ambient10_t *ctx, float vref)
Ambient 10 set vref function.
ambient10_read_raw_adc
err_t ambient10_read_raw_adc(ambient10_t *ctx, uint16_t *raw_adc)
Ambient 10 read raw ADC function.
ambient10_read_adc_voltage
err_t ambient10_read_adc_voltage(ambient10_t *ctx, float *voltage)
Ambient 10 read ADC voltage function.
ambient10_init
err_t ambient10_init(ambient10_t *ctx, ambient10_cfg_t *cfg)
Ambient 10 initialization function.
ambient10_read_an_pin_voltage
err_t ambient10_read_an_pin_voltage(ambient10_t *ctx, float *data_out)
Ambient 10 read AN pin voltage level function.
AMBIENT10_OK
Definition: ambient10.h:141
ambient10_t
Ambient 10 Click context object.
Definition: ambient10.h:107
ambient10_read_an_pin_value
err_t ambient10_read_an_pin_value(ambient10_t *ctx, uint16_t *data_out)
Ambient 10 read AN pin value function.
ambient10_voltage_to_lux
uint16_t ambient10_voltage_to_lux(ambient10_t *ctx, float voltage)
Ambient 10 voltage to illuminance function.