ambient18  2.0.0.0
ambient18.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 AMBIENT18_H
29 #define AMBIENT18_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 
74 #define AMBIENT18_MODE_SHUTDOWN 0
75 #define AMBIENT18_MODE_H_GAIN 1
76 #define AMBIENT18_MODE_M_GAIN 2
77 #define AMBIENT18_MODE_L_GAIN 3
78 
83 #define AMBIENT18_ADC_RESOLUTION 0x0FFF
84 #define AMBIENT18_VREF_3V3 3.3
85 #define AMBIENT18_VREF_5V 5.0
86 
91 #define AMBIENT18_IOUT_CURRENT_H_GAIN 6.1
92 #define AMBIENT18_IOUT_CURRENT_M_GAIN 0.61
93 #define AMBIENT18_IOUT_CURRENT_L_GAIN 0.061
94 #define AMBIENT18_MICROAMPER_TO_AMPER 0.000001
95 #define AMBIENT18_IOUT_RESISTOR 5420
96 
102 #define AMBIENT18_SET_DEV_ADDR 0x4D
103  // ambient18_set
105 
120 #define AMBIENT18_MAP_MIKROBUS( cfg, mikrobus ) \
121  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
122  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
123  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
124  cfg.gc1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125  cfg.gc2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
126  // ambient18_map // ambient18
129 
134 typedef enum
135 {
140 
145 typedef struct
146 {
147  digital_out_t gc1;
148  digital_out_t gc2;
150  analog_in_t adc;
151  i2c_master_t i2c;
153  uint8_t slave_address;
154  pin_name_t chip_select;
155  float vref;
157  uint8_t gain_mode;
159 } ambient18_t;
160 
165 typedef struct
166 {
167  pin_name_t an;
168  pin_name_t scl;
169  pin_name_t sda;
170  pin_name_t gc1;
171  pin_name_t gc2;
173  analog_in_resolution_t resolution;
174  float vref;
176  uint32_t i2c_speed;
177  uint8_t i2c_address;
182 
187 typedef enum
188 {
190  AMBIENT18_ERROR = -1
191 
193 
210 
226 
242 
255 err_t ambient18_read_raw_adc ( ambient18_t *ctx, uint16_t *raw_adc );
256 
269 err_t ambient18_read_voltage ( ambient18_t *ctx, float *voltage );
270 
283 err_t ambient18_set_vref ( ambient18_t *ctx, float vref );
284 
297 void ambient18_set_gain_mode ( ambient18_t *ctx, uint8_t mode );
298 
307 int32_t ambient18_voltage_to_lux ( ambient18_t *ctx, float voltage );
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 #endif // AMBIENT18_H
313  // ambient18
315 
316 // ------------------------------------------------------------------------ END
ambient18_drv_interface_selection
void ambient18_drv_interface_selection(ambient18_cfg_t *cfg, ambient18_drv_t drv_sel)
Ambient 18 driver interface setup function.
ambient18_t::gc2
digital_out_t gc2
Definition: ambient18.h:148
ambient18_cfg_t::gc2
pin_name_t gc2
Definition: ambient18.h:171
ambient18_t::gc1
digital_out_t gc1
Definition: ambient18.h:147
ambient18_read_raw_adc
err_t ambient18_read_raw_adc(ambient18_t *ctx, uint16_t *raw_adc)
Ambient 18 read raw ADC value function.
ambient18_cfg_t
Ambient 18 Click configuration object.
Definition: ambient18.h:166
ambient18_cfg_t::vref
float vref
Definition: ambient18.h:174
ambient18_cfg_t::gc1
pin_name_t gc1
Definition: ambient18.h:170
ambient18_t::adc
analog_in_t adc
Definition: ambient18.h:150
ambient18_t::chip_select
pin_name_t chip_select
Definition: ambient18.h:154
ambient18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient18.h:176
ambient18_set_vref
err_t ambient18_set_vref(ambient18_t *ctx, float vref)
Ambient 18 set vref function.
ambient18_cfg_t::drv_sel
ambient18_drv_t drv_sel
Definition: ambient18.h:179
ambient18_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient18.h:177
ambient18_return_value_t
ambient18_return_value_t
Ambient 18 Click return value data.
Definition: ambient18.h:188
ambient18_t
Ambient 18 Click context object.
Definition: ambient18.h:146
ambient18_t::vref
float vref
Definition: ambient18.h:155
ambient18_init
err_t ambient18_init(ambient18_t *ctx, ambient18_cfg_t *cfg)
Ambient 18 initialization function.
AMBIENT18_DRV_SEL_ADC
@ AMBIENT18_DRV_SEL_ADC
Definition: ambient18.h:136
ambient18_cfg_t::sda
pin_name_t sda
Definition: ambient18.h:169
ambient18_drv_t
ambient18_drv_t
Ambient 18 Click driver selector.
Definition: ambient18.h:135
ambient18_t::i2c
i2c_master_t i2c
Definition: ambient18.h:151
ambient18_cfg_setup
void ambient18_cfg_setup(ambient18_cfg_t *cfg)
Ambient 18 configuration object setup function.
ambient18_t::drv_sel
ambient18_drv_t drv_sel
Definition: ambient18.h:156
ambient18_read_voltage
err_t ambient18_read_voltage(ambient18_t *ctx, float *voltage)
Ambient 18 read voltage level function.
ambient18_cfg_t::an
pin_name_t an
Definition: ambient18.h:167
ambient18_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient18.h:173
ambient18_voltage_to_lux
int32_t ambient18_voltage_to_lux(ambient18_t *ctx, float voltage)
Ambient 18 voltage to illuminance function.
ambient18_t::gain_mode
uint8_t gain_mode
Definition: ambient18.h:157
AMBIENT18_OK
@ AMBIENT18_OK
Definition: ambient18.h:189
ambient18_t::slave_address
uint8_t slave_address
Definition: ambient18.h:153
ambient18_cfg_t::scl
pin_name_t scl
Definition: ambient18.h:168
AMBIENT18_DRV_SEL_I2C
@ AMBIENT18_DRV_SEL_I2C
Definition: ambient18.h:137
ambient18_set_gain_mode
void ambient18_set_gain_mode(ambient18_t *ctx, uint8_t mode)
Ambient 18 set gain mode function.
AMBIENT18_ERROR
@ AMBIENT18_ERROR
Definition: ambient18.h:190