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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_analog_in.h"
52 #include "drv_i2c_master.h"
53 
75 #define AMBIENT10_SET_DEV_ADDR 0x4D
76 
81 #define AMBIENT10_ADC_RESOLUTION 0x0FFF
82 #define AMBIENT10_VREF_3V3 3.3
83 #define AMBIENT10_VREF_5V 5.0
84 
90 #define AMBIENT10_MICROAMPER_TO_AMPER 0.000001
91 #define AMBIENT10_IOUT_TO_LUX 2.5
92 #define AMBIENT10_IOUT_RESISTOR 5100
93  // ambient10_set
95 
110 #define AMBIENT10_MAP_MIKROBUS( cfg, mikrobus ) \
111  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
112  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
113  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
114  // ambient10_map // ambient10
117 
122 typedef struct
123 {
124  analog_in_t adc;
125  i2c_master_t i2c;
127  uint8_t slave_address;
128  float vref;
130 } ambient10_t;
131 
136 typedef struct
137 {
138  pin_name_t an;
139  pin_name_t scl;
140  pin_name_t sda;
142  uint32_t i2c_speed;
143  uint8_t i2c_address;
145  analog_in_resolution_t resolution;
146  float vref;
149 
154 typedef enum
155 {
157  AMBIENT10_ERROR = -1
158 
160 
177 
193 
206 err_t ambient10_read_an_pin_value ( ambient10_t *ctx, uint16_t *data_out );
207 
222 err_t ambient10_read_an_pin_voltage ( ambient10_t *ctx, float *data_out );
223 
236 err_t ambient10_read_raw_adc ( ambient10_t *ctx, uint16_t *raw_adc );
237 
251 err_t ambient10_read_adc_voltage ( ambient10_t *ctx, float *voltage );
252 
263 err_t ambient10_set_vref ( ambient10_t *ctx, float vref );
264 
272 uint16_t ambient10_voltage_to_lux ( ambient10_t *ctx, float voltage );
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // AMBIENT10_H
278  // ambient10
280 
281 // ------------------------------------------------------------------------ END
AMBIENT10_ERROR
@ AMBIENT10_ERROR
Definition: ambient10.h:157
ambient10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient10.h:142
ambient10_return_value_t
ambient10_return_value_t
Ambient 10 Click return value data.
Definition: ambient10.h:155
ambient10_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient10.h:143
ambient10_cfg_t::scl
pin_name_t scl
Definition: ambient10.h:139
ambient10_t::i2c
i2c_master_t i2c
Definition: ambient10.h:125
ambient10_cfg_t
Ambient 10 Click configuration object.
Definition: ambient10.h:137
ambient10_cfg_setup
void ambient10_cfg_setup(ambient10_cfg_t *cfg)
Ambient 10 configuration object setup function.
ambient10_t::slave_address
uint8_t slave_address
Definition: ambient10.h:127
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
@ AMBIENT10_OK
Definition: ambient10.h:156
ambient10_t
Ambient 10 Click context object.
Definition: ambient10.h:123
ambient10_t::adc
analog_in_t adc
Definition: ambient10.h:124
ambient10_cfg_t::sda
pin_name_t sda
Definition: ambient10.h:140
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_t::vref
float vref
Definition: ambient10.h:128
ambient10_cfg_t::an
pin_name_t an
Definition: ambient10.h:138
ambient10_cfg_t::vref
float vref
Definition: ambient10.h:146
ambient10_voltage_to_lux
uint16_t ambient10_voltage_to_lux(ambient10_t *ctx, float voltage)
Ambient 10 voltage to illuminance function.
ambient10_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient10.h:145