ambient21 2.1.0.0
ambient21.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 AMBIENT21_H
29#define AMBIENT21_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 AMBIENT21_REG_ENABLE 0x00
74#define AMBIENT21_REG_CONFIG 0x01
75#define AMBIENT21_REG_AILTL 0x04
76#define AMBIENT21_REG_AILTH 0x05
77#define AMBIENT21_REG_AIHTL 0x06
78#define AMBIENT21_REG_AIHTH 0x07
79#define AMBIENT21_REG_NPAILTL 0x08
80#define AMBIENT21_REG_NPAILTH 0x09
81#define AMBIENT21_REG_NPAIHTL 0x0A
82#define AMBIENT21_REG_NPAIHTH 0x0B
83#define AMBIENT21_REG_PERSIST 0x0C
84#define AMBIENT21_REG_PID 0x11
85#define AMBIENT21_REG_ID 0x12
86#define AMBIENT21_REG_STATUS 0x13
87#define AMBIENT21_REG_C0DATAL 0x14
88#define AMBIENT21_REG_C0DATAH 0x15
89#define AMBIENT21_REG_C1DATAL 0x16
90#define AMBIENT21_REG_C1DATAH 0x17
91
92 // ambient21_reg
93
108#define AMBIENT21_CMD_NORMAL_OP 0xA0
109#define AMBIENT21_CMD_SPEC_FUNC 0xE0
110#define AMBIENT21_SF_INT_SET 0x04
111#define AMBIENT21_SF_CLEAR_ALS_INT 0x06
112#define AMBIENT21_SF_CLEAR_ALS_NOPERS_INT 0x07
113#define AMBIENT21_SF_CLEAR_NOPERS_INT 0x0A
114#define AMBIENT21_ADDR_SF_MASK 0x1F
115
120#define AMBIENT21_ENABLE_NPIEN 0x80
121#define AMBIENT21_ENABLE_SAI 0x40
122#define AMBIENT21_ENABLE_AIEN 0x10
123#define AMBIENT21_ENABLE_AEN 0x02
124#define AMBIENT21_ENABLE_PON 0x01
125
130#define AMBIENT21_CONFIG_SRESET 0x80
131#define AMBIENT21_CONFIG_AGAIN_LOW 0x00
132#define AMBIENT21_CONFIG_AGAIN_MID 0x10
133#define AMBIENT21_CONFIG_AGAIN_HIGH 0x20
134#define AMBIENT21_CONFIG_AGAIN_MAX 0x30
135#define AMBIENT21_CONFIG_AGAIN_MASK 0x30
136#define AMBIENT21_CONFIG_ATIME_100MS 0x00
137#define AMBIENT21_CONFIG_ATIME_200MS 0x01
138#define AMBIENT21_CONFIG_ATIME_300MS 0x02
139#define AMBIENT21_CONFIG_ATIME_400MS 0x03
140#define AMBIENT21_CONFIG_ATIME_500MS 0x04
141#define AMBIENT21_CONFIG_ATIME_600MS 0x05
142#define AMBIENT21_CONFIG_ATIME_MASK 0x07
143
148#define AMBIENT21_PERSIST_EVERY 0x00
149#define AMBIENT21_PERSIST_ANY 0x01
150#define AMBIENT21_PERSIST_2 0x02
151#define AMBIENT21_PERSIST_3 0x03
152#define AMBIENT21_PERSIST_5 0x04
153#define AMBIENT21_PERSIST_10 0x05
154#define AMBIENT21_PERSIST_15 0x06
155#define AMBIENT21_PERSIST_20 0x07
156#define AMBIENT21_PERSIST_25 0x08
157#define AMBIENT21_PERSIST_30 0x09
158#define AMBIENT21_PERSIST_35 0x0A
159#define AMBIENT21_PERSIST_40 0x0B
160#define AMBIENT21_PERSIST_45 0x0C
161#define AMBIENT21_PERSIST_50 0x0D
162#define AMBIENT21_PERSIST_55 0x0E
163#define AMBIENT21_PERSIST_60 0x0F
164#define AMBIENT21_PERSIST_MASK 0x0F
165
170#define AMBIENT21_STATUS_NPINTR 0x20
171#define AMBIENT21_STATUS_AINT 0x10
172#define AMBIENT21_STATUS_AVALID 0x01
173
178#define AMBIENT21_DEVICE_ID 0x50
179
184#define AMBIENT21_AGAIN_LOW 0x00
185#define AMBIENT21_AGAIN_MID 0x01
186#define AMBIENT21_AGAIN_HIGH 0x02
187#define AMBIENT21_AGAIN_MAX 0x03
188#define AMBIENT21_ATIME_100MS 0x00
189#define AMBIENT21_ATIME_200MS 0x01
190#define AMBIENT21_ATIME_300MS 0x02
191#define AMBIENT21_ATIME_400MS 0x03
192#define AMBIENT21_ATIME_500MS 0x04
193#define AMBIENT21_ATIME_600MS 0x05
194
199#define AMBIENT21_GAIN_0 1.0f
200#define AMBIENT21_GAIN_1 25.0f
201#define AMBIENT21_GAIN_2 428.0f
202#define AMBIENT21_GAIN_3 9876.0f
203#define AMBIENT21_TIME_RES 100.0f
204#define AMBIENT21_LUX_GDF 900.0f
205#define AMBIENT21_LUX_COEF 1.0f
206
212#define AMBIENT21_DEVICE_ADDRESS 0x29
213
214 // ambient21_set
215
230#define AMBIENT21_MAP_MIKROBUS( cfg, mikrobus ) \
231 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
232 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
233 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
234
235 // ambient21_map
236 // ambient21
237
242typedef struct
243{
244 // Input pins
245 digital_in_t int_pin;
247 // Modules
248 i2c_master_t i2c;
250 // I2C slave address
253 float atime_ms;
254 float again;
255 float cpl;
258
263typedef struct
264{
265 pin_name_t scl;
266 pin_name_t sda;
268 pin_name_t int_pin;
270 uint32_t i2c_speed;
271 uint8_t i2c_address;
274
285
302
317
331
346err_t ambient21_generic_write ( ambient21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
347
362err_t ambient21_generic_read ( ambient21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
363
376err_t ambient21_write_register ( ambient21_t *ctx, uint8_t reg, uint8_t data_in );
377
390err_t ambient21_read_register ( ambient21_t *ctx, uint8_t reg, uint8_t *data_out );
391
403err_t ambient21_write_spec_func ( ambient21_t *ctx, uint8_t spec_func );
404
414
426
438
461err_t ambient21_set_config ( ambient21_t *ctx, uint8_t again, uint8_t atime );
462
475err_t ambient21_read_raw_data ( ambient21_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
476
490err_t ambient21_measure_light_level ( ambient21_t *ctx, uint16_t *lux );
491
492#ifdef __cplusplus
493}
494#endif
495#endif // AMBIENT21_H
496
497 // ambient21
498
499// ------------------------------------------------------------------------ END
ambient21_return_value_t
Ambient 21 Click return value data.
Definition ambient21.h:280
@ AMBIENT21_ERROR
Definition ambient21.h:282
@ AMBIENT21_OK
Definition ambient21.h:281
err_t ambient21_set_config(ambient21_t *ctx, uint8_t again, uint8_t atime)
Ambient 21 set config function.
err_t ambient21_init(ambient21_t *ctx, ambient21_cfg_t *cfg)
Ambient 21 initialization function.
err_t ambient21_read_register(ambient21_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 21 read register function.
err_t ambient21_measure_light_level(ambient21_t *ctx, uint16_t *lux)
Ambient 21 measure light level function.
err_t ambient21_check_communication(ambient21_t *ctx)
Ambient 21 check communication function.
void ambient21_cfg_setup(ambient21_cfg_t *cfg)
Ambient 21 configuration object setup function.
err_t ambient21_write_spec_func(ambient21_t *ctx, uint8_t spec_func)
Ambient 21 write spec func function.
err_t ambient21_generic_read(ambient21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Ambient 21 I2C reading function.
uint8_t ambient21_get_int_pin(ambient21_t *ctx)
Ambient 21 get int pin function.
err_t ambient21_generic_write(ambient21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Ambient 21 I2C writing function.
err_t ambient21_default_cfg(ambient21_t *ctx)
Ambient 21 default configuration function.
err_t ambient21_read_raw_data(ambient21_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 21 read raw data function.
err_t ambient21_write_register(ambient21_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 21 write register function.
err_t ambient21_clear_interrupts(ambient21_t *ctx)
Ambient 21 clear interrupts function.
Ambient 21 Click configuration object.
Definition ambient21.h:264
uint32_t i2c_speed
Definition ambient21.h:270
pin_name_t scl
Definition ambient21.h:265
pin_name_t int_pin
Definition ambient21.h:268
pin_name_t sda
Definition ambient21.h:266
uint8_t i2c_address
Definition ambient21.h:271
Ambient 21 Click context object.
Definition ambient21.h:243
digital_in_t int_pin
Definition ambient21.h:245
i2c_master_t i2c
Definition ambient21.h:248
uint8_t slave_address
Definition ambient21.h:251
float atime_ms
Definition ambient21.h:253
float cpl
Definition ambient21.h:255
float again
Definition ambient21.h:254