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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define AMBIENT8_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
66 
72 #define AMBIENT8_RETVAL uint8_t
73 
74 #define AMBIENT8_OK 0x00
75 #define AMBIENT8_INIT_ERROR 0xFF
76 
81 #define AMBIENT8_DEVICE_ADDRESS 0x29
82  // End group device_address
83 
88 #define AMBIENT8_ALS_CONTROL 0x80
89 #define AMBIENT8_ALS_MEASUREMENT_RATE 0x85
90 #define AMBIENT8_PART_ID 0x86
91 #define AMBIENT8_MANUFACTURER_ID 0x87
92 #define AMBIENT8_ALS_DATA_CH1_0 0x88
93 #define AMBIENT8_ALS_DATA_CH1_1 0x89
94 #define AMBIENT8_ALS_DATA_CH0_0 0x8A
95 #define AMBIENT8_ALS_DATA_CH0_1 0x8B
96 #define AMBIENT8_ALS_STATUS 0x8C
97  // End group register_address
98 
103 #define AMBIENT8_ALS_GAIN_1X 0x00
104 #define AMBIENT8_ALS_GAIN_2X 0x04
105 #define AMBIENT8_ALS_GAIN_4X 0x08
106 #define AMBIENT8_ALS_GAIN_8X 0x0C
107 #define AMBIENT8_ALS_GAIN_48X 0x18
108 #define AMBIENT8_ALS_GAIN_96X 0x1C
109 #define AMBIENT8_SW_RESET 0x02
110 #define AMBIENT8_ALS_MODE_STANDBY 0x00
111 #define AMBIENT8_ALS_MODE_ACTIVE 0x01
112  // End group als_control_register
113 
118 #define AMBIENT8_ALS_INTEGRATION_TIME_100ms 0x00
119 #define AMBIENT8_ALS_INTEGRATION_TIME_50ms 0x08
120 #define AMBIENT8_ALS_INTEGRATION_TIME_200ms 0x10
121 #define AMBIENT8_ALS_INTEGRATION_TIME_400ms 0x18
122 #define AMBIENT8_ALS_INTEGRATION_TIME_150ms 0x20
123 #define AMBIENT8_ALS_INTEGRATION_TIME_250ms 0x28
124 #define AMBIENT8_ALS_INTEGRATION_TIME_300ms 0x30
125 #define AMBIENT8_ALS_INTEGRATION_TIME_350ms 0x38
126 #define AMBIENT8_ALS_MEASUREMENT_RATE_50 0x00
127 #define AMBIENT8_ALS_MEASUREMENT_RATE_100 0x01
128 #define AMBIENT8_ALS_MEASUREMENT_RATE_200 0x02
129 #define AMBIENT8_ALS_MEASUREMENT_RATE_500 0x03
130 #define AMBIENT8_ALS_MEASUREMENT_RATE_1000 0x04
131 #define AMBIENT8_ALS_MEASUREMENT_RATE_2000 0x07
132  // End group als_measurement_rate_register // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef struct
144 {
145 
146  // Modules
147 
148  i2c_master_t i2c;
149 
150  // ctx variable
151 
152  uint8_t slave_address;
153 
154 } ambient8_t;
155 
159 typedef struct
160 {
161  // Communication gpio pins
162 
163  pin_name_t scl;
164  pin_name_t sda;
165 
166  // static variable
167 
168  uint32_t i2c_speed;
169  uint8_t i2c_address;
170 
172  // End types group
174 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
175 
181 #ifdef __cplusplus
182 extern "C"{
183 #endif
184 
195 
206 
216 void ambient8_set_register ( ambient8_t* ctx, uint8_t* write_buf, uint8_t n_bytes );
217 
228 void ambient8_get_register ( ambient8_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t n_bytes );
229 
239 
251 AMBIENT8_RETVAL ambient8_get_als_data ( ambient8_t* ctx, uint16_t* als_data_ch1,
252  uint16_t* als_data_ch0);
253 
271  float window_factor, float IR_factor );
272 
273 #ifdef __cplusplus
274 }
275 #endif
276 #endif // _AMBIENT8_H_
277  // End public_function group
280 
281 // ------------------------------------------------------------------------- END
ambient8_set_register
void ambient8_set_register(ambient8_t *ctx, uint8_t *write_buf, uint8_t n_bytes)
Writing to device registers.
ambient8_t::slave_address
uint8_t slave_address
Definition: ambient8.h:152
ambient8_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient8.h:169
ambient8_cfg_setup
void ambient8_cfg_setup(ambient8_cfg_t *cfg)
Config Object Initialization function.
ambient8_cfg_t
Click configuration structure definition.
Definition: ambient8.h:160
AMBIENT8_RETVAL
#define AMBIENT8_RETVAL
Definition: ambient8.h:72
ambient8_get_lux_level
AMBIENT8_RETVAL ambient8_get_lux_level(ambient8_t *ctx, float *lux_level, float window_factor, float IR_factor)
Calculating lux level.
ambient8_get_als_data
AMBIENT8_RETVAL ambient8_get_als_data(ambient8_t *ctx, uint16_t *als_data_ch1, uint16_t *als_data_ch0)
Reading ALS data.
ambient8_get_register
void ambient8_get_register(ambient8_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t n_bytes)
Reading register value(s).
ambient8_cfg_t::scl
pin_name_t scl
Definition: ambient8.h:163
ambient8_t
Click ctx object definition.
Definition: ambient8.h:144
ambient8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient8.h:168
ambient8_cfg_t::sda
pin_name_t sda
Definition: ambient8.h:164
ambient8_init
AMBIENT8_RETVAL ambient8_init(ambient8_t *ctx, ambient8_cfg_t *cfg)
Initialization function.
ambient8_set_constants
void ambient8_set_constants(ambient8_t *ctx)
Setting constants for lux level calculation.
ambient8_t::i2c
i2c_master_t i2c
Definition: ambient8.h:148