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 
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 
60 #define AMBIENT18_MODE_SHUTDOWN 0
61 #define AMBIENT18_MODE_H_GAIN 1
62 #define AMBIENT18_MODE_M_GAIN 2
63 #define AMBIENT18_MODE_L_GAIN 3
64 
69 #define AMBIENT18_ADC_RESOLUTION 0x0FFF
70 #define AMBIENT18_VREF_3V3 3.3
71 #define AMBIENT18_VREF_5V 5.0
72 
77 #define AMBIENT18_IOUT_CURRENT_H_GAIN 6.1
78 #define AMBIENT18_IOUT_CURRENT_M_GAIN 0.61
79 #define AMBIENT18_IOUT_CURRENT_L_GAIN 0.061
80 #define AMBIENT18_MICROAMPER_TO_AMPER 0.000001
81 #define AMBIENT18_IOUT_RESISTOR 5420
82 
88 #define AMBIENT18_SET_DEV_ADDR 0x4D
89  // ambient18_set
91 
106 #define AMBIENT18_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  cfg.gc1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
111  cfg.gc2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
112  // ambient18_map // ambient18
115 
120 typedef enum
121 {
126 
131 typedef struct
132 {
133  digital_out_t gc1;
134  digital_out_t gc2;
136  analog_in_t adc;
137  i2c_master_t i2c;
139  uint8_t slave_address;
140  pin_name_t chip_select;
141  float vref;
143  uint8_t gain_mode;
145 } ambient18_t;
146 
151 typedef struct
152 {
153  pin_name_t an;
154  pin_name_t scl;
155  pin_name_t sda;
156  pin_name_t gc1;
157  pin_name_t gc2;
159  analog_in_resolution_t resolution;
160  float vref;
162  uint32_t i2c_speed;
163  uint8_t i2c_address;
168 
173 typedef enum
174 {
176  AMBIENT18_ERROR = -1
177 
179 
196 
212 
228 
241 err_t ambient18_read_raw_adc ( ambient18_t *ctx, uint16_t *raw_adc );
242 
255 err_t ambient18_read_voltage ( ambient18_t *ctx, float *voltage );
256 
269 err_t ambient18_set_vref ( ambient18_t *ctx, float vref );
270 
283 void ambient18_set_gain_mode ( ambient18_t *ctx, uint8_t mode );
284 
293 int32_t ambient18_voltage_to_lux ( ambient18_t *ctx, float voltage );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // AMBIENT18_H
299  // ambient18
301 
302 // ------------------------------------------------------------------------ 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:134
ambient18_cfg_t::gc2
pin_name_t gc2
Definition: ambient18.h:157
ambient18_t::gc1
digital_out_t gc1
Definition: ambient18.h:133
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:152
ambient18_cfg_t::vref
float vref
Definition: ambient18.h:160
ambient18_cfg_t::gc1
pin_name_t gc1
Definition: ambient18.h:156
ambient18_t::adc
analog_in_t adc
Definition: ambient18.h:136
ambient18_t::chip_select
pin_name_t chip_select
Definition: ambient18.h:140
ambient18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient18.h:162
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:165
ambient18_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient18.h:163
ambient18_return_value_t
ambient18_return_value_t
Ambient 18 Click return value data.
Definition: ambient18.h:174
ambient18_t
Ambient 18 Click context object.
Definition: ambient18.h:132
ambient18_t::vref
float vref
Definition: ambient18.h:141
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:122
ambient18_cfg_t::sda
pin_name_t sda
Definition: ambient18.h:155
ambient18_drv_t
ambient18_drv_t
Ambient 18 Click driver selector.
Definition: ambient18.h:121
ambient18_t::i2c
i2c_master_t i2c
Definition: ambient18.h:137
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:142
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:153
ambient18_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient18.h:159
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:143
AMBIENT18_OK
@ AMBIENT18_OK
Definition: ambient18.h:175
ambient18_t::slave_address
uint8_t slave_address
Definition: ambient18.h:139
ambient18_cfg_t::scl
pin_name_t scl
Definition: ambient18.h:154
AMBIENT18_DRV_SEL_I2C
@ AMBIENT18_DRV_SEL_I2C
Definition: ambient18.h:123
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:176