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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define AMBIENT23_REG_CONFIG 0x00
60 #define AMBIENT23_REG_WHITE_DATA 0x04
61 #define AMBIENT23_REG_ALS_DATA 0x05
62 #define AMBIENT23_REG_DEVICE_ID 0x09
63  // ambient23_reg
65 
80 #define AMBIENT23_GAIN_1 0x0000u
81 #define AMBIENT23_GAIN_2 0x0800u
82 #define AMBIENT23_GAIN_4 0x1800u
83 #define AMBIENT23_GAIN_MSK 0x1800u
84 
89 #define AMBIENT23_DATA_GAIN_1 0x0000u
90 #define AMBIENT23_DATA_GAIN_2 0x2000u
91 #define AMBIENT23_DATA_GAIN_MASK 0x2000u
92 
97 #define AMBIENT23_SDO_SHUTDOWN_ON 0x8000u
98 #define AMBIENT23_SDO_SHUTDOWN_OFF 0x0000u
99 #define AMBIENT23_SHUTDOWN_ON 0x0001u
100 #define AMBIENT23_SHUTDOWN_OFF 0x0000u
101 
106 #define AMBIENT23_TRIGGER_ON 0x0004u
107 #define AMBIENT23_TRIGGER_OFF 0x0000u
108 
113 #define AMBIENT23_AUTO_FORCE_MODE 0x0800u
114 #define AMBIENT23_MANUAL_FORCE_MODE 0x0000u
115 
120 #define AMBIENT23_INTEGRATION_50_MS 0x0000u
121 #define AMBIENT23_INTEGRATION_100_MS 0x0010u
122 #define AMBIENT23_INTEGRATION_200_MS 0x0020u
123 #define AMBIENT23_INTEGRATION_400_MS 0x0030u
124 #define AMBIENT23_INTEGRATION_800_MS 0x0040u
125 #define AMBIENT23_INTEGRATION_TIME_MSK 0x0070u
126 
131 #define AMBIENT23_CONFIG_DEF_VAL 0x0100u
132 
137 #define AMBIENT23_PART_ID 0x35
138 
143 #define AMBIENT23_TYPICAL_RESOLUTION 0.27264f
144 
150 #define AMBIENT23_DEVICE_ADDRESS 0x10
151  // ambient23_set
153 
168 #define AMBIENT23_MAP_MIKROBUS( cfg, mikrobus ) \
169  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
170  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
171  // ambient23_map // ambient23
174 
179 typedef struct
180 {
181  // Modules
182  i2c_master_t i2c;
184  // I2C slave address
185  uint8_t slave_address;
187 } ambient23_t;
188 
193 typedef struct
194 {
195  pin_name_t scl;
196  pin_name_t sda;
198  uint32_t i2c_speed;
199  uint8_t i2c_address;
202 
207 typedef enum
208 {
210  AMBIENT23_ERROR = -1
211 
213 
230 
245 
259 
274 err_t ambient23_generic_write ( ambient23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
275 
290 err_t ambient23_generic_read ( ambient23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
291 
305 err_t ambient23_reg_write ( ambient23_t *ctx, uint8_t reg, uint16_t data_in );
306 
320 err_t ambient23_reg_read ( ambient23_t *ctx, uint8_t reg, uint16_t *data_out );
321 
334 err_t ambient23_calculate_res ( ambient23_t *ctx, float *conversion_mul );
335 
347 err_t ambient23_read_light_data ( ambient23_t *ctx, float *light_data );
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 #endif // AMBIENT23_H
353  // ambient23
355 
356 // ------------------------------------------------------------------------ END
ambient23_return_value_t
ambient23_return_value_t
Ambient 23 Click return value data.
Definition: ambient23.h:208
ambient23_init
err_t ambient23_init(ambient23_t *ctx, ambient23_cfg_t *cfg)
Ambient 23 initialization function.
ambient23_generic_read
err_t ambient23_generic_read(ambient23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Ambient 23 I2C reading function.
ambient23_cfg_t
Ambient 23 Click configuration object.
Definition: ambient23.h:194
ambient23_cfg_setup
void ambient23_cfg_setup(ambient23_cfg_t *cfg)
Ambient 23 configuration object setup function.
ambient23_default_cfg
err_t ambient23_default_cfg(ambient23_t *ctx)
Ambient 23 default configuration function.
ambient23_cfg_t::sda
pin_name_t sda
Definition: ambient23.h:196
AMBIENT23_ERROR
@ AMBIENT23_ERROR
Definition: ambient23.h:210
AMBIENT23_OK
@ AMBIENT23_OK
Definition: ambient23.h:209
ambient23_calculate_res
err_t ambient23_calculate_res(ambient23_t *ctx, float *conversion_mul)
Ambient 23 get conversion data function.
ambient23_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient23.h:199
ambient23_t::i2c
i2c_master_t i2c
Definition: ambient23.h:182
ambient23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient23.h:198
ambient23_t::slave_address
uint8_t slave_address
Definition: ambient23.h:185
ambient23_read_light_data
err_t ambient23_read_light_data(ambient23_t *ctx, float *light_data)
Ambient 23 get light data function.
ambient23_reg_write
err_t ambient23_reg_write(ambient23_t *ctx, uint8_t reg, uint16_t data_in)
Ambient 23 register data writing function.
ambient23_t
Ambient 23 Click context object.
Definition: ambient23.h:180
ambient23_cfg_t::scl
pin_name_t scl
Definition: ambient23.h:195
ambient23_reg_read
err_t ambient23_reg_read(ambient23_t *ctx, uint8_t reg, uint16_t *data_out)
Ambient 23 register reading function.
ambient23_generic_write
err_t ambient23_generic_write(ambient23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Ambient 23 I2C writing function.