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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define AMBIENT8_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
62#define AMBIENT8_RETVAL uint8_t
63
64#define AMBIENT8_OK 0x00
65#define AMBIENT8_INIT_ERROR 0xFF
71#define AMBIENT8_DEVICE_ADDRESS 0x29 // End group device_address
73
78#define AMBIENT8_ALS_CONTROL 0x80
79#define AMBIENT8_ALS_MEASUREMENT_RATE 0x85
80#define AMBIENT8_PART_ID 0x86
81#define AMBIENT8_MANUFACTURER_ID 0x87
82#define AMBIENT8_ALS_DATA_CH1_0 0x88
83#define AMBIENT8_ALS_DATA_CH1_1 0x89
84#define AMBIENT8_ALS_DATA_CH0_0 0x8A
85#define AMBIENT8_ALS_DATA_CH0_1 0x8B
86#define AMBIENT8_ALS_STATUS 0x8C // End group register_address
88
93#define AMBIENT8_ALS_GAIN_1X 0x00
94#define AMBIENT8_ALS_GAIN_2X 0x04
95#define AMBIENT8_ALS_GAIN_4X 0x08
96#define AMBIENT8_ALS_GAIN_8X 0x0C
97#define AMBIENT8_ALS_GAIN_48X 0x18
98#define AMBIENT8_ALS_GAIN_96X 0x1C
99#define AMBIENT8_SW_RESET 0x02
100#define AMBIENT8_ALS_MODE_STANDBY 0x00
101#define AMBIENT8_ALS_MODE_ACTIVE 0x01 // End group als_control_register
103
108#define AMBIENT8_ALS_INTEGRATION_TIME_100ms 0x00
109#define AMBIENT8_ALS_INTEGRATION_TIME_50ms 0x08
110#define AMBIENT8_ALS_INTEGRATION_TIME_200ms 0x10
111#define AMBIENT8_ALS_INTEGRATION_TIME_400ms 0x18
112#define AMBIENT8_ALS_INTEGRATION_TIME_150ms 0x20
113#define AMBIENT8_ALS_INTEGRATION_TIME_250ms 0x28
114#define AMBIENT8_ALS_INTEGRATION_TIME_300ms 0x30
115#define AMBIENT8_ALS_INTEGRATION_TIME_350ms 0x38
116#define AMBIENT8_ALS_MEASUREMENT_RATE_50 0x00
117#define AMBIENT8_ALS_MEASUREMENT_RATE_100 0x01
118#define AMBIENT8_ALS_MEASUREMENT_RATE_200 0x02
119#define AMBIENT8_ALS_MEASUREMENT_RATE_500 0x03
120#define AMBIENT8_ALS_MEASUREMENT_RATE_1000 0x04
121#define AMBIENT8_ALS_MEASUREMENT_RATE_2000 0x07 // End group als_measurement_rate_register // End group macro
124// --------------------------------------------------------------- PUBLIC TYPES
133typedef struct
134{
135
136 // Modules
137
138 i2c_master_t i2c;
139
140 // ctx variable
141
143
144} ambient8_t;
145
149typedef struct
150{
151 // Communication gpio pins
152
153 pin_name_t scl;
154 pin_name_t sda;
155
156 // static variable
157
158 uint32_t i2c_speed;
159 uint8_t i2c_address;
160
162 // End types group
164// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165
171#ifdef __cplusplus
172extern "C"{
173#endif
174
185
196
206void ambient8_set_register ( ambient8_t* ctx, uint8_t* write_buf, uint8_t n_bytes );
207
218void ambient8_get_register ( ambient8_t* ctx, uint8_t reg_addr, uint8_t n_bytes );
219
229
241AMBIENT8_RETVAL ambient8_get_als_data ( ambient8_t* ctx, uint16_t* als_data_ch1,
242 uint16_t* als_data_ch0);
243
261 float window_factor, float IR_factor );
262
263#ifdef __cplusplus
264}
265#endif
266#endif // _AMBIENT8_H_
267 // End public_function group
270
271// ------------------------------------------------------------------------- END
#define AMBIENT8_RETVAL
Definition: ambient8.h:62
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 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:150
uint32_t i2c_speed
Definition: ambient8.h:158
pin_name_t scl
Definition: ambient8.h:153
pin_name_t sda
Definition: ambient8.h:154
uint8_t i2c_address
Definition: ambient8.h:159
Click ctx object definition.
Definition: ambient8.h:134
i2c_master_t i2c
Definition: ambient8.h:138
uint8_t slave_address
Definition: ambient8.h:142