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
32extern "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
104 // 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
127 // ambient18_map
128 // ambient18
129
140
145typedef struct
146{
147 digital_out_t gc1;
148 digital_out_t gc2;
150 analog_in_t adc;
151 i2c_master_t i2c;
154 pin_name_t chip_select;
155 float vref;
157 uint8_t gain_mode;
160
165typedef 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
193
210
226
242
255err_t ambient18_read_raw_adc ( ambient18_t *ctx, uint16_t *raw_adc );
256
269err_t ambient18_read_voltage ( ambient18_t *ctx, float *voltage );
270
283err_t ambient18_set_vref ( ambient18_t *ctx, float vref );
284
297void ambient18_set_gain_mode ( ambient18_t *ctx, uint8_t mode );
298
307int32_t ambient18_voltage_to_lux ( ambient18_t *ctx, float voltage );
308
309#ifdef __cplusplus
310}
311#endif
312#endif // AMBIENT18_H
313
314 // ambient18
315
316// ------------------------------------------------------------------------ END
ambient18_drv_t
Ambient 18 Click driver selector.
Definition ambient18.h:135
@ AMBIENT18_DRV_SEL_I2C
Definition ambient18.h:137
@ AMBIENT18_DRV_SEL_ADC
Definition ambient18.h:136
ambient18_return_value_t
Ambient 18 Click return value data.
Definition ambient18.h:188
@ AMBIENT18_ERROR
Definition ambient18.h:190
@ AMBIENT18_OK
Definition ambient18.h:189
void ambient18_drv_interface_selection(ambient18_cfg_t *cfg, ambient18_drv_t drv_sel)
Ambient 18 driver interface setup function.
err_t ambient18_set_vref(ambient18_t *ctx, float vref)
Ambient 18 set vref function.
void ambient18_cfg_setup(ambient18_cfg_t *cfg)
Ambient 18 configuration object setup function.
err_t ambient18_read_raw_adc(ambient18_t *ctx, uint16_t *raw_adc)
Ambient 18 read raw ADC value function.
void ambient18_set_gain_mode(ambient18_t *ctx, uint8_t mode)
Ambient 18 set gain mode function.
int32_t ambient18_voltage_to_lux(ambient18_t *ctx, float voltage)
Ambient 18 voltage to illuminance function.
err_t ambient18_read_voltage(ambient18_t *ctx, float *voltage)
Ambient 18 read voltage level function.
err_t ambient18_init(ambient18_t *ctx, ambient18_cfg_t *cfg)
Ambient 18 initialization function.
Ambient 18 Click configuration object.
Definition ambient18.h:166
pin_name_t gc1
Definition ambient18.h:170
analog_in_resolution_t resolution
Definition ambient18.h:173
float vref
Definition ambient18.h:174
uint32_t i2c_speed
Definition ambient18.h:176
pin_name_t scl
Definition ambient18.h:168
pin_name_t gc2
Definition ambient18.h:171
ambient18_drv_t drv_sel
Definition ambient18.h:179
pin_name_t sda
Definition ambient18.h:169
pin_name_t an
Definition ambient18.h:167
uint8_t i2c_address
Definition ambient18.h:177
Ambient 18 Click context object.
Definition ambient18.h:146
digital_out_t gc1
Definition ambient18.h:147
float vref
Definition ambient18.h:155
i2c_master_t i2c
Definition ambient18.h:151
uint8_t gain_mode
Definition ambient18.h:157
uint8_t slave_address
Definition ambient18.h:153
ambient18_drv_t drv_sel
Definition ambient18.h:156
digital_out_t gc2
Definition ambient18.h:148
pin_name_t chip_select
Definition ambient18.h:154
analog_in_t adc
Definition ambient18.h:150