ambient23 2.1.0.0
ambient23.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 AMBIENT23_H
29#define AMBIENT23_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 AMBIENT23_REG_CONFIG 0x00
74#define AMBIENT23_REG_WHITE_DATA 0x04
75#define AMBIENT23_REG_ALS_DATA 0x05
76#define AMBIENT23_REG_DEVICE_ID 0x09
77
78 // ambient23_reg
79
94#define AMBIENT23_GAIN_1 0x0000u
95#define AMBIENT23_GAIN_2 0x0800u
96#define AMBIENT23_GAIN_4 0x1800u
97#define AMBIENT23_GAIN_MSK 0x1800u
98
103#define AMBIENT23_DATA_GAIN_1 0x0000u
104#define AMBIENT23_DATA_GAIN_2 0x2000u
105#define AMBIENT23_DATA_GAIN_MASK 0x2000u
106
111#define AMBIENT23_SDO_SHUTDOWN_ON 0x8000u
112#define AMBIENT23_SDO_SHUTDOWN_OFF 0x0000u
113#define AMBIENT23_SHUTDOWN_ON 0x0001u
114#define AMBIENT23_SHUTDOWN_OFF 0x0000u
115
120#define AMBIENT23_TRIGGER_ON 0x0004u
121#define AMBIENT23_TRIGGER_OFF 0x0000u
122
127#define AMBIENT23_AUTO_FORCE_MODE 0x0800u
128#define AMBIENT23_MANUAL_FORCE_MODE 0x0000u
129
134#define AMBIENT23_INTEGRATION_50_MS 0x0000u
135#define AMBIENT23_INTEGRATION_100_MS 0x0010u
136#define AMBIENT23_INTEGRATION_200_MS 0x0020u
137#define AMBIENT23_INTEGRATION_400_MS 0x0030u
138#define AMBIENT23_INTEGRATION_800_MS 0x0040u
139#define AMBIENT23_INTEGRATION_TIME_MSK 0x0070u
140
145#define AMBIENT23_CONFIG_DEF_VAL 0x0100u
146
151#define AMBIENT23_PART_ID 0x35
152
157#define AMBIENT23_TYPICAL_RESOLUTION 0.27264f
158
164#define AMBIENT23_DEVICE_ADDRESS 0x10
165
166 // ambient23_set
167
182#define AMBIENT23_MAP_MIKROBUS( cfg, mikrobus ) \
183 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
185
186 // ambient23_map
187 // ambient23
188
193typedef struct
194{
195 // Modules
196 i2c_master_t i2c;
198 // I2C slave address
202
207typedef struct
208{
209 pin_name_t scl;
210 pin_name_t sda;
212 uint32_t i2c_speed;
213 uint8_t i2c_address;
216
227
244
259
273
288err_t ambient23_generic_write ( ambient23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
289
304err_t ambient23_generic_read ( ambient23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
305
319err_t ambient23_reg_write ( ambient23_t *ctx, uint8_t reg, uint16_t data_in );
320
334err_t ambient23_reg_read ( ambient23_t *ctx, uint8_t reg, uint16_t *data_out );
335
348err_t ambient23_calculate_res ( ambient23_t *ctx, float *conversion_mul );
349
361err_t ambient23_read_light_data ( ambient23_t *ctx, float *light_data );
362
363#ifdef __cplusplus
364}
365#endif
366#endif // AMBIENT23_H
367
368 // ambient23
369
370// ------------------------------------------------------------------------ END
ambient23_return_value_t
Ambient 23 Click return value data.
Definition ambient23.h:222
@ AMBIENT23_ERROR
Definition ambient23.h:224
@ AMBIENT23_OK
Definition ambient23.h:223
void ambient23_cfg_setup(ambient23_cfg_t *cfg)
Ambient 23 configuration object setup function.
err_t ambient23_read_light_data(ambient23_t *ctx, float *light_data)
Ambient 23 get light data function.
err_t ambient23_generic_read(ambient23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Ambient 23 I2C reading function.
err_t ambient23_reg_write(ambient23_t *ctx, uint8_t reg, uint16_t data_in)
Ambient 23 register data writing function.
err_t ambient23_reg_read(ambient23_t *ctx, uint8_t reg, uint16_t *data_out)
Ambient 23 register reading function.
err_t ambient23_calculate_res(ambient23_t *ctx, float *conversion_mul)
Ambient 23 get conversion data function.
err_t ambient23_generic_write(ambient23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Ambient 23 I2C writing function.
err_t ambient23_init(ambient23_t *ctx, ambient23_cfg_t *cfg)
Ambient 23 initialization function.
err_t ambient23_default_cfg(ambient23_t *ctx)
Ambient 23 default configuration function.
Ambient 23 Click configuration object.
Definition ambient23.h:208
uint32_t i2c_speed
Definition ambient23.h:212
pin_name_t scl
Definition ambient23.h:209
pin_name_t sda
Definition ambient23.h:210
uint8_t i2c_address
Definition ambient23.h:213
Ambient 23 Click context object.
Definition ambient23.h:194
i2c_master_t i2c
Definition ambient23.h:196
uint8_t slave_address
Definition ambient23.h:199