ambient17 2.0.0.0
ambient17.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 AMBIENT17_H
29#define AMBIENT17_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 AMBIENT17_REG_ENABLE 0x00
74#define AMBIENT17_REG_ATIME 0x01
75#define AMBIENT17_REG_WTIME 0x03
76#define AMBIENT17_REG_AILTL 0x04
77#define AMBIENT17_REG_AILTH 0x05
78#define AMBIENT17_REG_AIHTL 0x06
79#define AMBIENT17_REG_AIHTH 0x07
80#define AMBIENT17_REG_PERS 0x0C
81#define AMBIENT17_REG_CONFIG 0x0D
82#define AMBIENT17_REG_CONTROL 0x0F
83#define AMBIENT17_REG_ID 0x12
84#define AMBIENT17_REG_STATUS 0x13
85#define AMBIENT17_REG_C0DATA 0x14
86#define AMBIENT17_REG_C0DATAH 0x15
87#define AMBIENT17_REG_C1DATA 0x16
88#define AMBIENT17_REG_C1DATAH 0x17
89
90 // ambient17_reg
91
106#define AMBIENT17_CMD_BIT 0x80
107#define AMBIENT17_TYPE_REPEATED 0x00
108#define AMBIENT17_TYPE_AUTO_INC 0x20
109#define AMBIENT17_TYPE_SPEC_FUNC 0x60
110#define AMBIENT17_SPEC_FUNC_INT_CLEAR 0x06
111
116#define AMBIENT17_ENABLE_SLEEP_AFTER_INT 0x40
117#define AMBIENT17_ENABLE_ALS_INT 0x10
118#define AMBIENT17_ENABLE_WAIT 0x08
119#define AMBIENT17_ENABLE_ALS 0x02
120#define AMBIENT17_ENABLE_OSC 0x01
121
126#define AMBIENT17_STATUS_AINT 0x10
127#define AMBIENT17_STATUS_AVALID 0x01
128
133#define AMBIENT17_ATIME_MAX 699.88
134#define AMBIENT17_ATIME_MIN 2.73
135#define AMBIENT17_ATIME_STEP 2.73
136#define AMBIENT17_DEFAULT_ATIME 200.0
137
142#define AMBIENT17_WTIME_MAX 699.88
143#define AMBIENT17_WTIME_MIN 2.73
144#define AMBIENT17_WTIME_STEP 2.73
145#define AMBIENT17_DEFAULT_WTIME 200.0
146
151#define AMBIENT17_AGAIN_1X 0x00
152#define AMBIENT17_AGAIN_8X 0x01
153#define AMBIENT17_AGAIN_16X 0x02
154#define AMBIENT17_AGAIN_120X 0x03
155
160#define AMBIENT17_CH0_COFF0 1.0
161#define AMBIENT17_CH1_COFF0 1.87
162#define AMBIENT17_CH0_COFF1 0.63
163#define AMBIENT17_CH1_COFF1 1.0
164#define AMBIENT17_GA_VALUE 1.0
165#define AMBIENT17_GA_MULTIPLIER 60.0
166
171#define AMBIENT17_DEVICE_ID 0x34
172
178#define AMBIENT17_DEVICE_ADDRESS 0x39
179
180 // ambient17_set
181
196#define AMBIENT17_MAP_MIKROBUS( cfg, mikrobus ) \
197 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
198 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
199 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
200
201 // ambient17_map
202 // ambient17
203
208typedef struct
209{
210 // Input pins
211 digital_in_t int_pin;
213 // Modules
214 i2c_master_t i2c;
216 // I2C slave address
219 float atime_ms;
220 uint8_t again;
221 float cpl;
224
229typedef struct
230{
231 pin_name_t scl;
232 pin_name_t sda;
234 pin_name_t int_pin;
236 uint32_t i2c_speed;
237 uint8_t i2c_address;
240
251
268
283
297
312err_t ambient17_generic_write ( ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
313
328err_t ambient17_generic_read ( ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
329
342err_t ambient17_write_register ( ambient17_t *ctx, uint8_t reg, uint8_t data_in );
343
356err_t ambient17_read_register ( ambient17_t *ctx, uint8_t reg, uint8_t *data_out );
357
369
379
391
403err_t ambient17_set_atime ( ambient17_t *ctx, float atime_ms );
404
416err_t ambient17_set_wtime ( ambient17_t *ctx, float wtime_ms );
417
433err_t ambient17_set_again ( ambient17_t *ctx, uint8_t again );
434
447err_t ambient17_read_raw_data ( ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
448
461err_t ambient17_measure_light_level ( ambient17_t *ctx, uint16_t *lux );
462
463#ifdef __cplusplus
464}
465#endif
466#endif // AMBIENT17_H
467
468 // ambient17
469
470// ------------------------------------------------------------------------ END
ambient17_return_value_t
Ambient 17 Click return value data.
Definition ambient17.h:246
@ AMBIENT17_OK
Definition ambient17.h:247
@ AMBIENT17_ERROR
Definition ambient17.h:248
err_t ambient17_generic_write(ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ambient 17 I2C writing function.
err_t ambient17_clear_interrupts(ambient17_t *ctx)
Ambient 17 clear interrupts function.
err_t ambient17_set_atime(ambient17_t *ctx, float atime_ms)
Ambient 17 set atime function.
err_t ambient17_read_register(ambient17_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 17 read register function.
err_t ambient17_init(ambient17_t *ctx, ambient17_cfg_t *cfg)
Ambient 17 initialization function.
err_t ambient17_default_cfg(ambient17_t *ctx)
Ambient 17 default configuration function.
err_t ambient17_set_wtime(ambient17_t *ctx, float wtime_ms)
Ambient 17 set wtime function.
uint8_t ambient17_get_int_pin(ambient17_t *ctx)
Ambient 17 get INT pin function.
void ambient17_cfg_setup(ambient17_cfg_t *cfg)
Ambient 17 configuration object setup function.
err_t ambient17_generic_read(ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ambient 17 I2C reading function.
err_t ambient17_check_communication(ambient17_t *ctx)
Ambient 17 check communication function.
err_t ambient17_read_raw_data(ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 17 read raw data function.
err_t ambient17_measure_light_level(ambient17_t *ctx, uint16_t *lux)
Ambient 17 measure light level function.
err_t ambient17_write_register(ambient17_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 17 write register function.
err_t ambient17_set_again(ambient17_t *ctx, uint8_t again)
Ambient 17 set again function.
Ambient 17 Click configuration object.
Definition ambient17.h:230
uint32_t i2c_speed
Definition ambient17.h:236
pin_name_t scl
Definition ambient17.h:231
pin_name_t int_pin
Definition ambient17.h:234
pin_name_t sda
Definition ambient17.h:232
uint8_t i2c_address
Definition ambient17.h:237
Ambient 17 Click context object.
Definition ambient17.h:209
uint8_t again
Definition ambient17.h:220
digital_in_t int_pin
Definition ambient17.h:211
i2c_master_t i2c
Definition ambient17.h:214
uint8_t slave_address
Definition ambient17.h:217
float atime_ms
Definition ambient17.h:219
float cpl
Definition ambient17.h:221