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 
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_i2c_master.h"
52 
73 #define AMBIENT20_SYSTEM_CONTROL_REG 0x40
74 #define AMBIENT20_MODE_CONTROL1_REG 0x41
75 #define AMBIENT20_MODE_CONTROL2_REG 0x42
76 #define AMBIENT20_MODE_CONTROL3_REG 0x43
77 #define AMBIENT20_DATA0_LSB_REG 0x50
78 #define AMBIENT20_DATA0_MSB_REG 0x51
79 #define AMBIENT20_DATA1_LSB_REG 0x52
80 #define AMBIENT20_DATA1_MSB_REG 0x53
81 #define AMBIENT20_MANUFACTURER_ID_REG 0x92
82  // ambient20_reg
84 
99 #define AMBIENT20_GAIN_X1 0x02
100 #define AMBIENT20_GAIN_X32 0x0A
101 #define AMBIENT20_GAIN_X256 0x0C
102 #define AMBIENT20_100mS_MODE 0x00
103 #define AMBIENT20_55mS_MODE 0x01
104 #define AMBIENT20_VALID_MASK 0x80
105 #define AMBIENT20_ENABLE 0x01
106 #define AMBIENT20_DISABLE 0x00
107 #define AMBIENT20_MANUFACTURER_ID 0xE0
108 #define AMBIENT20_PART_ID 0x12
109 #define AMBIENT20_PART_ID_MASK 0x3F
110 
117 #define AMBIENT20_DATA0_CONVERSION_COEF 0.169491525
118 #define AMBIENT20_DATA1_CONVERSION_COEF 0.689655172
119 
125 #define AMBIENT20_DEVICE_ADDRESS 0x38
126  // ambient20_set
128 
143 #define AMBIENT20_MAP_MIKROBUS( cfg, mikrobus ) \
144  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
145  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
146  // ambient20_map // ambient20
149 
154 typedef struct
155 {
156  // Modules
157  i2c_master_t i2c;
159  // I2C slave address
160  uint8_t slave_address;
162  uint8_t data0_gain;
163  uint8_t data1_gain;
164 
165 } ambient20_t;
166 
171 typedef struct
172 {
173  pin_name_t scl;
174  pin_name_t sda;
176  uint32_t i2c_speed;
177  uint8_t i2c_address;
180 
185 typedef enum
186 {
188  AMBIENT20_ERROR = -1
189 
191 
208 
223 
237 
252 err_t ambient20_generic_write ( ambient20_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
253 
268 err_t ambient20_generic_read ( ambient20_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
269 
282 
295 err_t ambient20_get_manufacturer_id ( ambient20_t *ctx, uint8_t *manufacturer_id );
296 
309 err_t ambient20_get_part_id ( ambient20_t *ctx, uint8_t *part_id );
310 
323 
336 
349 err_t ambient20_set_meas_mode ( ambient20_t *ctx, uint8_t meas_mode );
350 
364 err_t ambient20_set_gain ( ambient20_t *ctx, uint8_t data0_gain, uint8_t data1_gain );
365 
377 
389 
402 
414 err_t ambient20_read_data0 ( ambient20_t *ctx, uint16_t *data0_out );
415 
427 err_t ambient20_read_data1 ( ambient20_t *ctx, uint16_t *data1_out );
428 
441 err_t ambient20_get_data_lux ( ambient20_t *ctx, float *data0_out ,float *data1_out );
442 
443 #ifdef __cplusplus
444 }
445 #endif
446 #endif // AMBIENT20_H
447  // ambient20
449 
450 // ------------------------------------------------------------------------ END
ambient20_t::data1_gain
uint8_t data1_gain
Definition: ambient20.h:163
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:174
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:172
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:157
ambient20_t::slave_address
uint8_t slave_address
Definition: ambient20.h:160
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:155
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:162
ambient20_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient20.h:176
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:173
ambient20_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient20.h:177
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:187
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:188
ambient20_return_value_t
ambient20_return_value_t
Ambient 20 Click return value data.
Definition: ambient20.h:186