ambient12  2.0.0.0
ambient12.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 AMBIENT12_H
29 #define AMBIENT12_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 AMBIENT12_SET_DEV_ADDR 0x4D
72 
77 #define AMBIENT12_ADC_RESOLUTION 0x0FFF
78 #define AMBIENT12_VREF_3V3 3.3
79 
84 #define AMBIENT12_IOUT_CURRENT_H_GAIN 0.57
85 #define AMBIENT12_IOUT_CURRENT_M_GAIN 0.057
86 #define AMBIENT12_IOUT_CURRENT_L_GAIN 0.0057
87 #define AMBIENT12_MICROAMPER_TO_AMPER 0.000001
88 #define AMBIENT12_IOUT_RESISTOR 5700
89  // ambient12_set
91 
106 #define AMBIENT12_MAP_MIKROBUS( cfg, mikrobus ) \
107  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
108  cfg.gc1 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109  cfg.gc2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
110  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
111  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
112  // ambient12_map // ambient12
115 
120 typedef enum
121 {
126 
128 
133 typedef struct
134 {
135  digital_out_t gc1;
136  digital_out_t gc2;
138  analog_in_t adc;
139  i2c_master_t i2c;
141  uint8_t slave_address;
143 
144 } ambient12_t;
145 
150 typedef struct
151 {
152  pin_name_t an;
153  pin_name_t gc1;
154  pin_name_t gc2;
155  pin_name_t scl;
156  pin_name_t sda;
158  uint32_t i2c_speed;
159  uint8_t i2c_address;
161  analog_in_resolution_t resolution;
162  float vref;
165 
170 typedef enum
171 {
173  AMBIENT12_ERROR = -1
174 
176 
193 
209 
222 err_t ambient12_read_an_pin_value ( ambient12_t *ctx, uint16_t *data_out );
223 
238 err_t ambient12_read_an_pin_voltage ( ambient12_t *ctx, float *data_out );
239 
252 err_t ambient12_read_raw_adc ( ambient12_t *ctx, uint16_t *raw_adc );
253 
267 err_t ambient12_read_adc_voltage ( ambient12_t *ctx, float *voltage );
268 
278 void ambient12_set_gc1_pin ( ambient12_t *ctx, uint8_t state );
279 
289 void ambient12_set_gc2_pin ( ambient12_t *ctx, uint8_t state );
290 
303 void ambient12_set_gain_mode ( ambient12_t *ctx, uint8_t mode );
304 
313 int32_t ambient12_voltage_to_lux ( ambient12_t *ctx, float voltage );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // AMBIENT12_H
319  // ambient12
321 
322 // ------------------------------------------------------------------------ END
ambient12_set_gc2_pin
void ambient12_set_gc2_pin(ambient12_t *ctx, uint8_t state)
Ambient 12 set GC2 pin state function.
ambient12_cfg_t::sda
pin_name_t sda
Definition: ambient12.h:156
ambient12_read_an_pin_value
err_t ambient12_read_an_pin_value(ambient12_t *ctx, uint16_t *data_out)
Ambient 12 read AN pin value function.
ambient12_t::adc
analog_in_t adc
Definition: ambient12.h:138
ambient12_cfg_t
Ambient 12 Click configuration object.
Definition: ambient12.h:151
ambient12_gain_mode_t
ambient12_gain_mode_t
Ambient 12 Click gain mode setting.
Definition: ambient12.h:121
ambient12_init
err_t ambient12_init(ambient12_t *ctx, ambient12_cfg_t *cfg)
Ambient 12 initialization function.
ambient12_cfg_t::an
pin_name_t an
Definition: ambient12.h:152
ambient12_t::gc1
digital_out_t gc1
Definition: ambient12.h:135
AMBIENT12_ERROR
@ AMBIENT12_ERROR
Definition: ambient12.h:173
ambient12_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ambient12.h:161
ambient12_cfg_t::scl
pin_name_t scl
Definition: ambient12.h:155
AMBIENT12_MODE_M_GAIN
@ AMBIENT12_MODE_M_GAIN
Definition: ambient12.h:124
ambient12_read_an_pin_voltage
err_t ambient12_read_an_pin_voltage(ambient12_t *ctx, float *data_out)
Ambient 12 read AN pin voltage level function.
ambient12_set_gain_mode
void ambient12_set_gain_mode(ambient12_t *ctx, uint8_t mode)
Ambient 12 set gain mode function.
ambient12_read_adc_voltage
err_t ambient12_read_adc_voltage(ambient12_t *ctx, float *voltage)
Ambient 12 read ADC voltage function.
ambient12_return_value_t
ambient12_return_value_t
Ambient 12 Click return value data.
Definition: ambient12.h:171
AMBIENT12_MODE_SHUTDOWN
@ AMBIENT12_MODE_SHUTDOWN
Definition: ambient12.h:122
AMBIENT12_OK
@ AMBIENT12_OK
Definition: ambient12.h:172
ambient12_cfg_t::gc2
pin_name_t gc2
Definition: ambient12.h:154
ambient12_t::slave_address
uint8_t slave_address
Definition: ambient12.h:141
ambient12_read_raw_adc
err_t ambient12_read_raw_adc(ambient12_t *ctx, uint16_t *raw_adc)
Ambient 12 read raw ADC function.
ambient12_t
Ambient 12 Click context object.
Definition: ambient12.h:134
ambient12_cfg_setup
void ambient12_cfg_setup(ambient12_cfg_t *cfg)
Ambient 12 configuration object setup function.
AMBIENT12_MODE_L_GAIN
@ AMBIENT12_MODE_L_GAIN
Definition: ambient12.h:125
ambient12_voltage_to_lux
int32_t ambient12_voltage_to_lux(ambient12_t *ctx, float voltage)
Ambient 12 voltage to illuminance function.
ambient12_cfg_t::gc1
pin_name_t gc1
Definition: ambient12.h:153
ambient12_t::i2c
i2c_master_t i2c
Definition: ambient12.h:139
ambient12_t::gain_mode
ambient12_gain_mode_t gain_mode
Definition: ambient12.h:142
ambient12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient12.h:158
AMBIENT12_MODE_H_GAIN
@ AMBIENT12_MODE_H_GAIN
Definition: ambient12.h:123
ambient12_cfg_t::vref
float vref
Definition: ambient12.h:162
ambient12_set_gc1_pin
void ambient12_set_gc1_pin(ambient12_t *ctx, uint8_t state)
Ambient 12 set GC1 pin state function.
ambient12_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient12.h:159
ambient12_t::gc2
digital_out_t gc2
Definition: ambient12.h:136