ambient2 2.0.0.0
ambient2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
32// ----------------------------------------------------------------------------
33
34#ifndef _AMBIENT2_H_
35#define _AMBIENT2_H_
36
37#include "drv_digital_in.h"
38#include "drv_i2c_master.h"
39
40// -------------------------------------------------------------- PUBLIC MACROS
50#define AMBIENT2_CFG_RANGE_40_95_LX_MIN 0x0
51#define AMBIENT2_CFG_RANGE_81_9_LX 0x1000
52#define AMBIENT2_CFG_RANGE_163_8_LX 0x2000
53#define AMBIENT2_CFG_RANGE_327_6_LX 0x3000
54#define AMBIENT2_CFG_RANGE_655_2_LX 0x4000
55#define AMBIENT2_CFG_RANGE_1310_4_LX 0x5000
56#define AMBIENT2_CFG_RANGE_2620_8_LX 0x6000
57#define AMBIENT2_CFG_RANGE_5241_6_LX 0x7000
58#define AMBIENT2_CFG_RANGE_10483_2_LX 0x8000
59#define AMBIENT2_CFG_RANGE_20966_4_LX 0x9000
60#define AMBIENT2_CFG_RANGE_41932_8_LX 0xA000
61#define AMBIENT2_CFG_RANGE_83865_6_LX_MAX 0xB000
62#define AMBIENT2_CFG_RANGE_AUTO_SCALE 0xC000
69#define AMBIENT2_CFG_CONV_TIME_100MS 0x0
70#define AMBIENT2_CFG_CONV_TIME_800MS 0x800
77#define AMBIENT2_CFG_CONV_MODE_SHUTDOWN 0x0
78#define AMBIENT2_CFG_CONV_MODE_SINGLE_SHOT 0x200
79#define AMBIENT2_CFG_CONV_MODE_CONT_CONV 0x400
86#define AMBIENT2_CFG_LATCH_COMP_HYSTERESIS_STYLE 0x0
87#define AMBIENT2_CFG_LATCH_COMP_WINDOW_STYLE 0x10
94#define AMBIENT2_CFG_POL_INT_ACTIVE_LOW 0x0
95#define AMBIENT2_CFG_POL_INT_ACTIVE_HIGH 0x8
102#define AMBIENT2_CFG_MASK_EXPONENT 0x4
109#define AMBIENT2_CFG_FAULT_1_COUNT 0x0
110#define AMBIENT2_CFG_FAULT_2_COUNTS 0x1
111#define AMBIENT2_CFG_FAULT_4_COUNTS 0x2
112#define AMBIENT2_CFG_FAULT_8_COUNTS 0x3
119#define AMBIENT2_FLAG_MASK_OVERFLOW 0x100
120#define AMBIENT2_FLAG_MASK_CONV_READY 0x80
121#define AMBIENT2_FLAG_MASK_HIGH 0x40
122#define AMBIENT2_FLAG_MASK_LOW 0x20
129#define AMBIENT2_ID_MANUFACTURER 0x5449
130#define AMBIENT2_ID_DEVICE 0x3001
137#define AMBIENT2_MAP_MIKROBUS( cfg, mikrobus ) \
138 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
139 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
140 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT ) // End macros group
144// --------------------------------------------------------------- PUBLIC TYPES
153typedef uint16_t ambient2_data_t;
154
158typedef enum
159{
163
165
169typedef enum
170{
175
177
181typedef enum
182{
189
191
195typedef struct
196{
200
202
206typedef struct
207{
208 // Event pin.
209 digital_in_t int_pin;
210
211 // Module.
212 i2c_master_t i2c;
213
214 // Device slave address.
215 uint8_t slave_addr;
216
217 // Ambient light sensor data.
219
220} ambient2_t;
221
225typedef struct
226{
227 // Communication gpio pins.
228 pin_name_t scl;
229 pin_name_t sda;
230
231 // Additional gpio pin.
232 pin_name_t int_pin;
233
234 // Module configuration variables.
235 uint32_t i2c_speed;
236 uint8_t i2c_addr;
237
239 // End types group
241// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
247#ifdef __cplusplus
248extern "C"{
249#endif
250
260
272
281
293
306
317
328
329#ifdef __cplusplus
330}
331#endif
332#endif // _AMBIENT2_H_
333 // End public_function group
336
337// ------------------------------------------------------------------------ END
ambient2_err_t ambient2_init(ambient2_t *ctx, ambient2_cfg_t *cfg)
Click Initialization function.
void ambient2_cfg_setup(ambient2_cfg_t *cfg)
Configuration Object Setup function.
void ambient2_default_cfg(ambient2_t *ctx)
Click Default Configuration function.
void ambient2_generic_write(ambient2_t *ctx, ambient2_reg_addr_t reg_addr, ambient2_data_t data_in)
Generic Write function.
uint8_t ambient2_get_int(ambient2_t *ctx)
INT Pin Check function.
void ambient2_get_sens_results(ambient2_t *ctx)
Sensor Results Read function.
ambient2_data_t ambient2_generic_read(ambient2_t *ctx, ambient2_reg_addr_t reg_addr)
Generic Read function.
uint16_t ambient2_data_t
Click registers data type.
Definition: ambient2.h:153
ambient2_reg_addr_t
Click register address selection.
Definition: ambient2.h:182
ambient2_err_t
Click error code definition.
Definition: ambient2.h:159
ambient_addr_t
Click I2C address selection.
Definition: ambient2.h:170
@ AMBIENT2_REG_LOW_LIMIT
Definition: ambient2.h:185
@ AMBIENT2_REG_MANUFACTURER_ID
Definition: ambient2.h:187
@ AMBIENT2_REG_HIGH_LIMIT
Definition: ambient2.h:186
@ AMBIENT2_REG_RESULT
Definition: ambient2.h:183
@ AMBIENT2_REG_DEVICE_ID
Definition: ambient2.h:188
@ AMBIENT2_REG_CONFIGURATION
Definition: ambient2.h:184
@ AMBIENT2_OK
Definition: ambient2.h:160
@ AMBIENT2_ERR_INIT_DRV
Definition: ambient2.h:161
@ AMBIENT2_ERR_UNSUPPORTED_PIN
Definition: ambient2.h:162
@ AMBIENT2_I2C_ADDRESS_VDD
Definition: ambient2.h:172
@ AMBIENT2_I2C_ADDRESS_SCL
Definition: ambient2.h:174
@ AMBIENT2_I2C_ADDRESS_GND
Definition: ambient2.h:171
@ AMBIENT2_I2C_ADDRESS_SDA
Definition: ambient2.h:173
Click configuration structure definition.
Definition: ambient2.h:226
uint8_t i2c_addr
Definition: ambient2.h:236
uint32_t i2c_speed
Definition: ambient2.h:235
pin_name_t scl
Definition: ambient2.h:228
pin_name_t int_pin
Definition: ambient2.h:232
pin_name_t sda
Definition: ambient2.h:229
Click sensor data definition.
Definition: ambient2.h:196
float amb_light_lx
Definition: ambient2.h:197
uint8_t amb_light_per
Definition: ambient2.h:199
float amb_light_range
Definition: ambient2.h:198
Click context object definition.
Definition: ambient2.h:207
digital_in_t int_pin
Definition: ambient2.h:209
i2c_master_t i2c
Definition: ambient2.h:212
uint8_t slave_addr
Definition: ambient2.h:215
ambient2_sens_data_t sens_data
Definition: ambient2.h:218