ambient15 2.0.0.0
ambient15.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 AMBIENT15_H
29#define AMBIENT15_H
30
31#ifdef __cplusplus
32extern "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 AMBIENT15_REG_CONTROL 0x00
74#define AMBIENT15_REG_TIMING 0x01
75#define AMBIENT15_REG_INTERRUPT 0x02
76#define AMBIENT15_REG_THL_LOW 0x03
77#define AMBIENT15_REG_THL_HIGH 0x04
78#define AMBIENT15_REG_THH_LOW 0x05
79#define AMBIENT15_REG_THH_HIGH 0x06
80#define AMBIENT15_REG_ANALOG 0x07
81#define AMBIENT15_REG_ID 0x12
82#define AMBIENT15_REG_DATA0_LOW 0x14
83#define AMBIENT15_REG_DATA0_HIGH 0x15
84#define AMBIENT15_REG_DATA1_LOW 0x16
85#define AMBIENT15_REG_DATA1_HIGH 0x17
86#define AMBIENT15_REG_TIMER_LOW 0x18
87#define AMBIENT15_REG_TIMER_HIGH 0x19
88#define AMBIENT15_REG_ID2 0x1E
89
90 // ambient15_reg
91
106#define AMBIENT15_CMD_BIT 0x80
107#define AMBIENT15_TRANSACTION_REPEATED 0x00
108#define AMBIENT15_TRANSACTION_AUTO_INC 0x20
109#define AMBIENT15_TRANSACTION_SPEC_FUNC 0x60
110#define AMBIENT15_SPEC_FUNC_INT_CLEAR 0x01
111#define AMBIENT15_SPEC_FUNC_STOP_MAN_INT 0x02
112#define AMBIENT15_SPEC_FUNC_START_MAN_INT 0x03
113
118#define AMBIENT15_CONTROL_ADC_INTR 0x20
119#define AMBIENT15_CONTROL_ADC_VALID 0x10
120#define AMBIENT15_CONTROL_ADC_ENABLE 0x02
121#define AMBIENT15_CONTROL_POWER_ON 0x01
122
127#define AMBIENT15_ATIME_MAX 688.5
128#define AMBIENT15_ATIME_MIN 2.7
129#define AMBIENT15_ATIME_STEP 2.7
130#define AMBIENT15_DEFAULT_ATIME 200.0
131
136#define AMBIENT15_ENABLE_INTERRUPT 0x10
137
142#define AMBIENT15_GAIN_1X 0x00
143#define AMBIENT15_GAIN_8X 0x01
144#define AMBIENT15_GAIN_16X 0x02
145#define AMBIENT15_GAIN_111X 0x03
146
151#define AMBIENT15_ID_PARTNO 0x90
152#define AMBIENT15_ID2 0x80
153
158#define AMBIENT15_CH0_COFF0 1000ul
159#define AMBIENT15_CH1_COFF0 2160ul
160#define AMBIENT15_CH0_COFF1 950ul
161#define AMBIENT15_CH1_COFF1 1110ul
162
168#define AMBIENT15_SET_DEV_ADDR_GND 0x29
169#define AMBIENT15_SET_DEV_ADDR_FLOAT 0x39
170#define AMBIENT15_SET_DEV_ADDR_VCC 0x49
171
172 // ambient15_set
173
188#define AMBIENT15_MAP_MIKROBUS( cfg, mikrobus ) \
189 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
190 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
191 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
192
193 // ambient15_map
194 // ambient15
195
200typedef struct
201{
202 // Input pins
203 digital_in_t int_pin;
205 // Modules
206 i2c_master_t i2c;
208 // I2C slave address
211 float atime_ms;
212 uint8_t gain;
215
220typedef struct
221{
222 pin_name_t scl;
223 pin_name_t sda;
225 pin_name_t int_pin;
227 uint32_t i2c_speed;
228 uint8_t i2c_address;
231
242
259
275
290
306err_t ambient15_generic_write ( ambient15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
307
323err_t ambient15_generic_read ( ambient15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
324
338err_t ambient15_write_register ( ambient15_t *ctx, uint8_t reg, uint8_t data_in );
339
353err_t ambient15_read_register ( ambient15_t *ctx, uint8_t reg, uint8_t *data_out );
354
364
377
390err_t ambient15_set_atime ( ambient15_t *ctx, float atime_ms );
391
404err_t ambient15_set_gain ( ambient15_t *ctx, uint8_t gain );
405
419err_t ambient15_read_raw_data ( ambient15_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
420
434err_t ambient15_measure_light_level ( ambient15_t *ctx, uint16_t *lux );
435
436#ifdef __cplusplus
437}
438#endif
439#endif // AMBIENT15_H
440
441 // ambient15
442
443// ------------------------------------------------------------------------ END
ambient15_return_value_t
Ambient 15 Click return value data.
Definition ambient15.h:237
@ AMBIENT15_OK
Definition ambient15.h:238
@ AMBIENT15_ERROR
Definition ambient15.h:239
err_t ambient15_write_register(ambient15_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 15 write register function.
uint8_t ambient15_get_int_pin(ambient15_t *ctx)
Ambient 15 get int pin function.
err_t ambient15_default_cfg(ambient15_t *ctx)
Ambient 15 default configuration function.
err_t ambient15_generic_read(ambient15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ambient 15 I2C reading function.
err_t ambient15_read_raw_data(ambient15_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 15 read raw data function.
err_t ambient15_init(ambient15_t *ctx, ambient15_cfg_t *cfg)
Ambient 15 initialization function.
err_t ambient15_check_communication(ambient15_t *ctx)
Ambient 15 check communication function.
err_t ambient15_read_register(ambient15_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 15 read register function.
err_t ambient15_set_gain(ambient15_t *ctx, uint8_t gain)
Ambient 15 set gain function.
err_t ambient15_generic_write(ambient15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ambient 15 I2C writing function.
void ambient15_cfg_setup(ambient15_cfg_t *cfg)
Ambient 15 configuration object setup function.
err_t ambient15_set_atime(ambient15_t *ctx, float atime_ms)
Ambient 15 set atime function.
err_t ambient15_measure_light_level(ambient15_t *ctx, uint16_t *lux)
Ambient 15 measure light level function.
Ambient 15 Click configuration object.
Definition ambient15.h:221
uint32_t i2c_speed
Definition ambient15.h:227
pin_name_t scl
Definition ambient15.h:222
pin_name_t int_pin
Definition ambient15.h:225
pin_name_t sda
Definition ambient15.h:223
uint8_t i2c_address
Definition ambient15.h:228
Ambient 15 Click context object.
Definition ambient15.h:201
uint8_t gain
Definition ambient15.h:212
digital_in_t int_pin
Definition ambient15.h:203
i2c_master_t i2c
Definition ambient15.h:206
uint8_t slave_address
Definition ambient15.h:209
float atime_ms
Definition ambient15.h:211