ambient20  2.1.0.0
ambient20.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 AMBIENT20_H
29 #define AMBIENT20_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_i2c_master.h"
48 
69 #define AMBIENT20_SYSTEM_CONTROL_REG 0x40
70 #define AMBIENT20_MODE_CONTROL1_REG 0x41
71 #define AMBIENT20_MODE_CONTROL2_REG 0x42
72 #define AMBIENT20_MODE_CONTROL3_REG 0x43
73 #define AMBIENT20_DATA0_LSB_REG 0x50
74 #define AMBIENT20_DATA0_MSB_REG 0x51
75 #define AMBIENT20_DATA1_LSB_REG 0x52
76 #define AMBIENT20_DATA1_MSB_REG 0x53
77 #define AMBIENT20_MANUFACTURER_ID_REG 0x92
78  // ambient20_reg
80 
95 #define AMBIENT20_GAIN_X1 0x02
96 #define AMBIENT20_GAIN_X32 0x0A
97 #define AMBIENT20_GAIN_X256 0x0C
98 #define AMBIENT20_100mS_MODE 0x00
99 #define AMBIENT20_55mS_MODE 0x01
100 #define AMBIENT20_VALID_MASK 0x80
101 #define AMBIENT20_ENABLE 0x01
102 #define AMBIENT20_DISABLE 0x00
103 #define AMBIENT20_MANUFACTURER_ID 0xE0
104 #define AMBIENT20_PART_ID 0x12
105 #define AMBIENT20_PART_ID_MASK 0x3F
106 
113 #define AMBIENT20_DATA0_CONVERSION_COEF 0.169491525
114 #define AMBIENT20_DATA1_CONVERSION_COEF 0.689655172
115 
121 #define AMBIENT20_DEVICE_ADDRESS 0x38
122  // ambient20_set
124 
139 #define AMBIENT20_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
142  // ambient20_map // ambient20
145 
150 typedef struct
151 {
152  // Modules
153  i2c_master_t i2c;
155  // I2C slave address
156  uint8_t slave_address;
158  uint8_t data0_gain;
159  uint8_t data1_gain;
160 
161 } ambient20_t;
162 
167 typedef struct
168 {
169  pin_name_t scl;
170  pin_name_t sda;
172  uint32_t i2c_speed;
173  uint8_t i2c_address;
176 
181 typedef enum
182 {
184  AMBIENT20_ERROR = -1
185 
187 
204 
219 
233 
248 err_t ambient20_generic_write ( ambient20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
249 
264 err_t ambient20_generic_read ( ambient20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
265 
278 
291 err_t ambient20_get_manufacturer_id ( ambient20_t *ctx, uint8_t *manufacturer_id );
292 
305 err_t ambient20_get_part_id ( ambient20_t *ctx, uint8_t *part_id );
306 
319 
332 
345 err_t ambient20_set_meas_mode ( ambient20_t *ctx, uint8_t meas_mode );
346 
360 err_t ambient20_set_gain ( ambient20_t *ctx, uint8_t data0_gain, uint8_t data1_gain );
361 
373 
385 
398 
410 err_t ambient20_read_data0 ( ambient20_t *ctx, uint16_t *data0_out );
411 
423 err_t ambient20_read_data1 ( ambient20_t *ctx, uint16_t *data1_out );
424 
437 err_t ambient20_get_data_lux ( ambient20_t *ctx, float *data0_out ,float *data1_out );
438 
439 #ifdef __cplusplus
440 }
441 #endif
442 #endif // AMBIENT20_H
443  // ambient20
445 
446 // ------------------------------------------------------------------------ END
ambient20_t::data1_gain
uint8_t data1_gain
Definition: ambient20.h:159
ambient20_disable_meas
err_t ambient20_disable_meas(ambient20_t *ctx)
Ambient 20 disable measurements function.
ambient20_cfg_t::sda
pin_name_t sda
Definition: ambient20.h:170
ambient20_disable_wait_mode
err_t ambient20_disable_wait_mode(ambient20_t *ctx)
Ambient 20 disable wait mode function.
ambient20_read_data0
err_t ambient20_read_data0(ambient20_t *ctx, uint16_t *data0_out)
Ambient 20 read data0 function.
ambient20_cfg_t
Ambient 20 Click configuration object.
Definition: ambient20.h:168
ambient20_default_cfg
err_t ambient20_default_cfg(ambient20_t *ctx)
Ambient 20 default configuration function.
ambient20_get_data_lux
err_t ambient20_get_data_lux(ambient20_t *ctx, float *data0_out, float *data1_out)
Ambient 20 read light function.
ambient20_t::i2c
i2c_master_t i2c
Definition: ambient20.h:153
ambient20_t::slave_address
uint8_t slave_address
Definition: ambient20.h:156
ambient20_check_valid
err_t ambient20_check_valid(ambient20_t *ctx)
Ambient 20 check valid bit function.
ambient20_t
Ambient 20 Click context object.
Definition: ambient20.h:151
ambient20_cfg_setup
void ambient20_cfg_setup(ambient20_cfg_t *cfg)
Ambient 20 configuration object setup function.
ambient20_enable_wait_mode
err_t ambient20_enable_wait_mode(ambient20_t *ctx)
Ambient 20 enable wait mode function.
ambient20_t::data0_gain
uint8_t data0_gain
Definition: ambient20.h:158
ambient20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient20.h:172
ambient20_get_manufacturer_id
err_t ambient20_get_manufacturer_id(ambient20_t *ctx, uint8_t *manufacturer_id)
Ambient 20 read manufacturer id function.
ambient20_enable_meas
err_t ambient20_enable_meas(ambient20_t *ctx)
Ambient 20 enable measurements function.
ambient20_generic_read
err_t ambient20_generic_read(ambient20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Ambient 20 I2C reading function.
ambient20_generic_write
err_t ambient20_generic_write(ambient20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Ambient 20 I2C writing function.
ambient20_read_data1
err_t ambient20_read_data1(ambient20_t *ctx, uint16_t *data1_out)
Ambient 20 read data1 function.
ambient20_cfg_t::scl
pin_name_t scl
Definition: ambient20.h:169
ambient20_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient20.h:173
ambient20_set_meas_mode
err_t ambient20_set_meas_mode(ambient20_t *ctx, uint8_t meas_mode)
Ambient 20 set measurement mode function.
AMBIENT20_OK
@ AMBIENT20_OK
Definition: ambient20.h:183
ambient20_set_gain
err_t ambient20_set_gain(ambient20_t *ctx, uint8_t data0_gain, uint8_t data1_gain)
Ambient 20 set data gain function.
ambient20_init
err_t ambient20_init(ambient20_t *ctx, ambient20_cfg_t *cfg)
Ambient 20 initialization function.
ambient20_sw_reset
err_t ambient20_sw_reset(ambient20_t *ctx)
Ambient 20 software reset function.
ambient20_get_part_id
err_t ambient20_get_part_id(ambient20_t *ctx, uint8_t *part_id)
Ambient 20 read part id function.
AMBIENT20_ERROR
@ AMBIENT20_ERROR
Definition: ambient20.h:184
ambient20_return_value_t
ambient20_return_value_t
Ambient 20 Click return value data.
Definition: ambient20.h:182