ambient8 2.0.0.0
ambient8.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 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef AMBIENT8_H
36#define AMBIENT8_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define AMBIENT8_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
76#define AMBIENT8_RETVAL uint8_t
77
78#define AMBIENT8_OK 0x00
79#define AMBIENT8_INIT_ERROR 0xFF
85#define AMBIENT8_DEVICE_ADDRESS 0x29
86 // End group device_address
87
92#define AMBIENT8_ALS_CONTROL 0x80
93#define AMBIENT8_ALS_MEASUREMENT_RATE 0x85
94#define AMBIENT8_PART_ID 0x86
95#define AMBIENT8_MANUFACTURER_ID 0x87
96#define AMBIENT8_ALS_DATA_CH1_0 0x88
97#define AMBIENT8_ALS_DATA_CH1_1 0x89
98#define AMBIENT8_ALS_DATA_CH0_0 0x8A
99#define AMBIENT8_ALS_DATA_CH0_1 0x8B
100#define AMBIENT8_ALS_STATUS 0x8C
101 // End group register_address
102
107#define AMBIENT8_ALS_GAIN_1X 0x00
108#define AMBIENT8_ALS_GAIN_2X 0x04
109#define AMBIENT8_ALS_GAIN_4X 0x08
110#define AMBIENT8_ALS_GAIN_8X 0x0C
111#define AMBIENT8_ALS_GAIN_48X 0x18
112#define AMBIENT8_ALS_GAIN_96X 0x1C
113#define AMBIENT8_SW_RESET 0x02
114#define AMBIENT8_ALS_MODE_STANDBY 0x00
115#define AMBIENT8_ALS_MODE_ACTIVE 0x01
116 // End group als_control_register
117
122#define AMBIENT8_ALS_INTEGRATION_TIME_100ms 0x00
123#define AMBIENT8_ALS_INTEGRATION_TIME_50ms 0x08
124#define AMBIENT8_ALS_INTEGRATION_TIME_200ms 0x10
125#define AMBIENT8_ALS_INTEGRATION_TIME_400ms 0x18
126#define AMBIENT8_ALS_INTEGRATION_TIME_150ms 0x20
127#define AMBIENT8_ALS_INTEGRATION_TIME_250ms 0x28
128#define AMBIENT8_ALS_INTEGRATION_TIME_300ms 0x30
129#define AMBIENT8_ALS_INTEGRATION_TIME_350ms 0x38
130#define AMBIENT8_ALS_MEASUREMENT_RATE_50 0x00
131#define AMBIENT8_ALS_MEASUREMENT_RATE_100 0x01
132#define AMBIENT8_ALS_MEASUREMENT_RATE_200 0x02
133#define AMBIENT8_ALS_MEASUREMENT_RATE_500 0x03
134#define AMBIENT8_ALS_MEASUREMENT_RATE_1000 0x04
135#define AMBIENT8_ALS_MEASUREMENT_RATE_2000 0x07
136 // End group als_measurement_rate_register
137 // End group macro
138// --------------------------------------------------------------- PUBLIC TYPES
147typedef struct
148{
149
150 // Modules
151
152 i2c_master_t i2c;
153
154 // ctx variable
155
157
158} ambient8_t;
159
163typedef struct
164{
165 // Communication gpio pins
166
167 pin_name_t scl;
168 pin_name_t sda;
169
170 // static variable
171
172 uint32_t i2c_speed;
173 uint8_t i2c_address;
174
176
177 // End types group
178// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179
185#ifdef __cplusplus
186extern "C"{
187#endif
188
199
210
220void ambient8_set_register ( ambient8_t* ctx, uint8_t* write_buf, uint8_t n_bytes );
221
232void ambient8_get_register ( ambient8_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t n_bytes );
233
243
255AMBIENT8_RETVAL ambient8_get_als_data ( ambient8_t* ctx, uint16_t* als_data_ch1,
256 uint16_t* als_data_ch0);
257
275 float window_factor, float IR_factor );
276
277#ifdef __cplusplus
278}
279#endif
280#endif // _AMBIENT8_H_
281
282 // End public_function group
284
285// ------------------------------------------------------------------------- END
#define AMBIENT8_RETVAL
Definition ambient8.h:76
AMBIENT8_RETVAL ambient8_init(ambient8_t *ctx, ambient8_cfg_t *cfg)
Initialization function.
void ambient8_get_register(ambient8_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t n_bytes)
Reading register value(s).
void ambient8_cfg_setup(ambient8_cfg_t *cfg)
Config Object Initialization function.
void ambient8_set_register(ambient8_t *ctx, uint8_t *write_buf, uint8_t n_bytes)
Writing to device registers.
void ambient8_set_constants(ambient8_t *ctx)
Setting constants for lux level calculation.
AMBIENT8_RETVAL ambient8_get_als_data(ambient8_t *ctx, uint16_t *als_data_ch1, uint16_t *als_data_ch0)
Reading ALS data.
AMBIENT8_RETVAL ambient8_get_lux_level(ambient8_t *ctx, float *lux_level, float window_factor, float IR_factor)
Calculating lux level.
Click configuration structure definition.
Definition ambient8.h:164
uint32_t i2c_speed
Definition ambient8.h:172
pin_name_t scl
Definition ambient8.h:167
pin_name_t sda
Definition ambient8.h:168
uint8_t i2c_address
Definition ambient8.h:173
Click ctx object definition.
Definition ambient8.h:148
i2c_master_t i2c
Definition ambient8.h:152
uint8_t slave_address
Definition ambient8.h:156