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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_analog_in.h"
48 #include "drv_i2c_master.h"
49 
71 #define AMBIENT10_SET_DEV_ADDR 0x4D
72 
77 #define AMBIENT10_ADC_RESOLUTION 0x0FFF
78 #define AMBIENT10_VREF_3V3 3.3
79 #define AMBIENT10_VREF_5V 5.0
80 
86 #define AMBIENT10_MICROAMPER_TO_AMPER 0.000001
87 #define AMBIENT10_IOUT_TO_LUX 2.5
88 #define AMBIENT10_IOUT_RESISTOR 5100
89  // ambient10_set
91 
106 #define AMBIENT10_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
109  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
110  // ambient10_map // ambient10
113 
118 typedef struct
119 {
120  analog_in_t adc;
121  i2c_master_t i2c;
123  uint8_t slave_address;
124  float vref;
126 } ambient10_t;
127 
132 typedef struct
133 {
134  pin_name_t an;
135  pin_name_t scl;
136  pin_name_t sda;
138  uint32_t i2c_speed;
139  uint8_t i2c_address;
141  analog_in_resolution_t resolution;
142  float vref;
145 
150 typedef enum
151 {
153  AMBIENT10_ERROR = -1
154 
156 
173 
189 
202 err_t ambient10_read_an_pin_value ( ambient10_t *ctx, uint16_t *data_out );
203 
218 err_t ambient10_read_an_pin_voltage ( ambient10_t *ctx, float *data_out );
219 
232 err_t ambient10_read_raw_adc ( ambient10_t *ctx, uint16_t *raw_adc );
233 
247 err_t ambient10_read_adc_voltage ( ambient10_t *ctx, float *voltage );
248 
259 err_t ambient10_set_vref ( ambient10_t *ctx, float vref );
260 
268 uint16_t ambient10_voltage_to_lux ( ambient10_t *ctx, float voltage );
269 
270 #ifdef __cplusplus
271 }
272 #endif
273 #endif // AMBIENT10_H
274  // ambient10
276 
277 // ------------------------------------------------------------------------ END
AMBIENT10_ERROR
@ AMBIENT10_ERROR
Definition: ambient10.h:153
ambient10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient10.h:138
ambient10_return_value_t
ambient10_return_value_t
Ambient 10 Click return value data.
Definition: ambient10.h:151
ambient10_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient10.h:139
ambient10_cfg_t::scl
pin_name_t scl
Definition: ambient10.h:135
ambient10_t::i2c
i2c_master_t i2c
Definition: ambient10.h:121
ambient10_cfg_t
Ambient 10 Click configuration object.
Definition: ambient10.h:133
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:123
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:152
ambient10_t
Ambient 10 Click context object.
Definition: ambient10.h:119
ambient10_t::adc
analog_in_t adc
Definition: ambient10.h:120
ambient10_cfg_t::sda
pin_name_t sda
Definition: ambient10.h:136
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:124
ambient10_cfg_t::an
pin_name_t an
Definition: ambient10.h:134
ambient10_cfg_t::vref
float vref
Definition: ambient10.h:142
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:141