ambient22 2.1.0.0
ambient22.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 AMBIENT22_H
29#define AMBIENT22_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 AMBIENT22_REG_RESULT 0x00
74#define AMBIENT22_REG_CONFIGURATION 0x01
75#define AMBIENT22_REG_LOW_LIMIT 0x02
76#define AMBIENT22_REG_HIGH_LIMIT 0x03
77#define AMBIENT22_REG_MANUFACTURER_ID 0x7E
78#define AMBIENT22_REG_DEVICE_ID 0x7F
79
80 // ambient22_reg
81
96#define AMBIENT22_CONFIG_RN_AUTO_SCALE 0xC000u
97#define AMBIENT22_CONFIG_RN_MASK 0xF000u
98#define AMBIENT22_CONFIG_CT_100_mS 0x0000u
99#define AMBIENT22_CONFIG_CT_800_mS 0x0800u
100#define AMBIENT22_CONFIG_CT_MASK 0x0800u
101#define AMBIENT22_CONFIG_M_SHUTDOWN 0x0000u
102#define AMBIENT22_CONFIG_M_SINGLE 0x0200u
103#define AMBIENT22_CONFIG_M_CONTINUOUS 0x0400u
104#define AMBIENT22_CONFIG_M_MASK 0x0600u
105#define AMBIENT22_CONFIG_OVF_MASK 0x0100u
106#define AMBIENT22_CONFIG_CRF_MASK 0x0080u
107#define AMBIENT22_CONFIG_FH_MASK 0x0040u
108#define AMBIENT22_CONFIG_FL_MASK 0x0020u
109#define AMBIENT22_CONFIG_L_TRANSPARENT 0x0000u
110#define AMBIENT22_CONFIG_L_LATCH 0x0010u
111#define AMBIENT22_CONFIG_L_MASK 0x0010u
112#define AMBIENT22_CONFIG_POL_LOW 0x0000u
113#define AMBIENT22_CONFIG_POL_HIGH 0x0008u
114#define AMBIENT22_CONFIG_POL_MASK 0x0008u
115#define AMBIENT22_CONFIG_ME_MASK 0x0004u
116#define AMBIENT22_CONFIG_FC_ONE 0x0000u
117#define AMBIENT22_CONFIG_FC_TWO 0x0001u
118#define AMBIENT22_CONFIG_FC_FOUR 0x0002u
119#define AMBIENT22_CONFIG_FC_EIGHT 0x0003u
120#define AMBIENT22_CONFIG_FC_MASK 0x0003u
121
126#define AMBIENT22_RESULT_EXP 0xF000u
127#define AMBIENT22_RESULT_FRACT 0x0FFFu
128#define AMBIENT22_RESULT_MIN 0x0000u
129#define AMBIENT22_RESULT_MAX 0xBFFFu
130#define AMBIENT22_RESULT_LUX_PER_LSB 0.02f
131
136#define AMBIENT22_MANUFACTURER_ID 0x5449u
137#define AMBIENT22_DEVICE_ID 0x3001u
138
144#define AMBIENT22_DEVICE_ADDRESS_0 0x44
145#define AMBIENT22_DEVICE_ADDRESS_1 0x45
146
147 // ambient22_set
148
163#define AMBIENT22_MAP_MIKROBUS( cfg, mikrobus ) \
164 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
165 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
166 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
167
168 // ambient22_map
169 // ambient22
170
175typedef struct
176{
177 // Input pins
178 digital_in_t int_pin;
180 // Modules
181 i2c_master_t i2c;
183 // I2C slave address
187
192typedef struct
193{
194 pin_name_t scl;
195 pin_name_t sda;
197 pin_name_t int_pin;
199 uint32_t i2c_speed;
200 uint8_t i2c_address;
203
214
231
246
260
273err_t ambient22_write_register ( ambient22_t *ctx, uint8_t reg, uint16_t data_in );
274
287err_t ambient22_read_register ( ambient22_t *ctx, uint8_t reg, uint16_t *data_out );
288
301
314err_t ambient22_read_lux ( ambient22_t *ctx, float *lux );
315
325
326#ifdef __cplusplus
327}
328#endif
329#endif // AMBIENT22_H
330
331 // ambient22
332
333// ------------------------------------------------------------------------ END
ambient22_return_value_t
Ambient 22 Click return value data.
Definition ambient22.h:209
@ AMBIENT22_OK
Definition ambient22.h:210
@ AMBIENT22_ERROR
Definition ambient22.h:211
err_t ambient22_write_register(ambient22_t *ctx, uint8_t reg, uint16_t data_in)
Ambient 22 write register function.
err_t ambient22_default_cfg(ambient22_t *ctx)
Ambient 22 default configuration function.
err_t ambient22_read_lux(ambient22_t *ctx, float *lux)
Ambient 22 read lux function.
err_t ambient22_init(ambient22_t *ctx, ambient22_cfg_t *cfg)
Ambient 22 initialization function.
err_t ambient22_read_register(ambient22_t *ctx, uint8_t reg, uint16_t *data_out)
Ambient 22 read register function.
void ambient22_cfg_setup(ambient22_cfg_t *cfg)
Ambient 22 configuration object setup function.
uint8_t ambient22_get_int_pin(ambient22_t *ctx)
Ambient 22 get int pin function.
err_t ambient22_check_communication(ambient22_t *ctx)
Ambient 22 check communication function.
Ambient 22 Click configuration object.
Definition ambient22.h:193
uint32_t i2c_speed
Definition ambient22.h:199
pin_name_t scl
Definition ambient22.h:194
pin_name_t int_pin
Definition ambient22.h:197
pin_name_t sda
Definition ambient22.h:195
uint8_t i2c_address
Definition ambient22.h:200
Ambient 22 Click context object.
Definition ambient22.h:176
digital_in_t int_pin
Definition ambient22.h:178
i2c_master_t i2c
Definition ambient22.h:181
uint8_t slave_address
Definition ambient22.h:184