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 "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 
70 #define AMBIENT18_MODE_SHUTDOWN 0
71 #define AMBIENT18_MODE_H_GAIN 1
72 #define AMBIENT18_MODE_M_GAIN 2
73 #define AMBIENT18_MODE_L_GAIN 3
74 
79 #define AMBIENT18_ADC_RESOLUTION 0x0FFF
80 #define AMBIENT18_VREF_3V3 3.3
81 #define AMBIENT18_VREF_5V 5.0
82 
87 #define AMBIENT18_IOUT_CURRENT_H_GAIN 6.1
88 #define AMBIENT18_IOUT_CURRENT_M_GAIN 0.61
89 #define AMBIENT18_IOUT_CURRENT_L_GAIN 0.061
90 #define AMBIENT18_MICROAMPER_TO_AMPER 0.000001
91 #define AMBIENT18_IOUT_RESISTOR 5420
92 
98 #define AMBIENT18_SET_DEV_ADDR 0x4D
99  // ambient18_set
101 
116 #define AMBIENT18_MAP_MIKROBUS( cfg, mikrobus ) \
117  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
118  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
119  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
120  cfg.gc1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.gc2 = MIKROBUS( mikrobus, MIKROBUS_PWM )
122  // ambient18_map // ambient18
125 
130 typedef enum
131 {
136 
141 typedef struct
142 {
143  digital_out_t gc1;
144  digital_out_t gc2;
146  analog_in_t adc;
147  i2c_master_t i2c;
149  uint8_t slave_address;
150  pin_name_t chip_select;
151  float vref;
153  uint8_t gain_mode;
155 } ambient18_t;
156 
161 typedef struct
162 {
163  pin_name_t an;
164  pin_name_t scl;
165  pin_name_t sda;
166  pin_name_t gc1;
167  pin_name_t gc2;
169  analog_in_resolution_t resolution;
170  float vref;
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
178 
183 typedef enum
184 {
186  AMBIENT18_ERROR = -1
187 
189 
206 
222 
238 
251 err_t ambient18_read_raw_adc ( ambient18_t *ctx, uint16_t *raw_adc );
252 
265 err_t ambient18_read_voltage ( ambient18_t *ctx, float *voltage );
266 
279 err_t ambient18_set_vref ( ambient18_t *ctx, float vref );
280 
293 void ambient18_set_gain_mode ( ambient18_t *ctx, uint8_t mode );
294 
303 int32_t ambient18_voltage_to_lux ( ambient18_t *ctx, float voltage );
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 #endif // AMBIENT18_H
309  // ambient18
311 
312 // ------------------------------------------------------------------------ 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:144
ambient18_cfg_t::gc2
pin_name_t gc2
Definition: ambient18.h:167
ambient18_t::gc1
digital_out_t gc1
Definition: ambient18.h:143
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:162
ambient18_cfg_t::vref
float vref
Definition: ambient18.h:170
ambient18_cfg_t::gc1
pin_name_t gc1
Definition: ambient18.h:166
ambient18_t::adc
analog_in_t adc
Definition: ambient18.h:146
ambient18_t::chip_select
pin_name_t chip_select
Definition: ambient18.h:150
ambient18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient18.h:172
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:175
ambient18_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient18.h:173
ambient18_return_value_t
ambient18_return_value_t
Ambient 18 Click return value data.
Definition: ambient18.h:184
ambient18_t
Ambient 18 Click context object.
Definition: ambient18.h:142
ambient18_t::vref
float vref
Definition: ambient18.h:151
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:132
ambient18_cfg_t::sda
pin_name_t sda
Definition: ambient18.h:165
ambient18_drv_t
ambient18_drv_t
Ambient 18 Click driver selector.
Definition: ambient18.h:131
ambient18_t::i2c
i2c_master_t i2c
Definition: ambient18.h:147
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:152
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:163
ambient18_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient18.h:169
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:153
AMBIENT18_OK
@ AMBIENT18_OK
Definition: ambient18.h:185
ambient18_t::slave_address
uint8_t slave_address
Definition: ambient18.h:149
ambient18_cfg_t::scl
pin_name_t scl
Definition: ambient18.h:164
AMBIENT18_DRV_SEL_I2C
@ AMBIENT18_DRV_SEL_I2C
Definition: ambient18.h:133
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:186