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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define AMBIENT23_REG_CONFIG 0x00
70 #define AMBIENT23_REG_WHITE_DATA 0x04
71 #define AMBIENT23_REG_ALS_DATA 0x05
72 #define AMBIENT23_REG_DEVICE_ID 0x09
73  // ambient23_reg
75 
90 #define AMBIENT23_GAIN_1 0x0000u
91 #define AMBIENT23_GAIN_2 0x0800u
92 #define AMBIENT23_GAIN_4 0x1800u
93 #define AMBIENT23_GAIN_MSK 0x1800u
94 
99 #define AMBIENT23_DATA_GAIN_1 0x0000u
100 #define AMBIENT23_DATA_GAIN_2 0x2000u
101 #define AMBIENT23_DATA_GAIN_MASK 0x2000u
102 
107 #define AMBIENT23_SDO_SHUTDOWN_ON 0x8000u
108 #define AMBIENT23_SDO_SHUTDOWN_OFF 0x0000u
109 #define AMBIENT23_SHUTDOWN_ON 0x0001u
110 #define AMBIENT23_SHUTDOWN_OFF 0x0000u
111 
116 #define AMBIENT23_TRIGGER_ON 0x0004u
117 #define AMBIENT23_TRIGGER_OFF 0x0000u
118 
123 #define AMBIENT23_AUTO_FORCE_MODE 0x0800u
124 #define AMBIENT23_MANUAL_FORCE_MODE 0x0000u
125 
130 #define AMBIENT23_INTEGRATION_50_MS 0x0000u
131 #define AMBIENT23_INTEGRATION_100_MS 0x0010u
132 #define AMBIENT23_INTEGRATION_200_MS 0x0020u
133 #define AMBIENT23_INTEGRATION_400_MS 0x0030u
134 #define AMBIENT23_INTEGRATION_800_MS 0x0040u
135 #define AMBIENT23_INTEGRATION_TIME_MSK 0x0070u
136 
141 #define AMBIENT23_CONFIG_DEF_VAL 0x0100u
142 
147 #define AMBIENT23_PART_ID 0x35
148 
153 #define AMBIENT23_TYPICAL_RESOLUTION 0.27264f
154 
160 #define AMBIENT23_DEVICE_ADDRESS 0x10
161  // ambient23_set
163 
178 #define AMBIENT23_MAP_MIKROBUS( cfg, mikrobus ) \
179  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
180  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
181  // ambient23_map // ambient23
184 
189 typedef struct
190 {
191  // Modules
192  i2c_master_t i2c;
194  // I2C slave address
195  uint8_t slave_address;
197 } ambient23_t;
198 
203 typedef struct
204 {
205  pin_name_t scl;
206  pin_name_t sda;
208  uint32_t i2c_speed;
209  uint8_t i2c_address;
212 
217 typedef enum
218 {
220  AMBIENT23_ERROR = -1
221 
223 
240 
255 
269 
284 err_t ambient23_generic_write ( ambient23_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
285 
300 err_t ambient23_generic_read ( ambient23_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
301 
315 err_t ambient23_reg_write ( ambient23_t *ctx, uint8_t reg, uint16_t data_in );
316 
330 err_t ambient23_reg_read ( ambient23_t *ctx, uint8_t reg, uint16_t *data_out );
331 
344 err_t ambient23_calculate_res ( ambient23_t *ctx, float *conversion_mul );
345 
357 err_t ambient23_read_light_data ( ambient23_t *ctx, float *light_data );
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 #endif // AMBIENT23_H
363  // ambient23
365 
366 // ------------------------------------------------------------------------ END
ambient23_return_value_t
ambient23_return_value_t
Ambient 23 Click return value data.
Definition: ambient23.h:218
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:204
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:206
AMBIENT23_ERROR
@ AMBIENT23_ERROR
Definition: ambient23.h:220
AMBIENT23_OK
@ AMBIENT23_OK
Definition: ambient23.h:219
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:209
ambient23_t::i2c
i2c_master_t i2c
Definition: ambient23.h:192
ambient23_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient23.h:208
ambient23_t::slave_address
uint8_t slave_address
Definition: ambient23.h:195
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:190
ambient23_cfg_t::scl
pin_name_t scl
Definition: ambient23.h:205
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.