ambient3  2.0.0.0
ambient3.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 AMBIENT3_H
36 #define AMBIENT3_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 // -------------------------------------------------------------- PUBLIC MACROS
62 #define AMBIENT3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define AMBIENT3_RETVAL uint8_t
74 
75 #define AMBIENT3_OK 0x00
76 #define AMBIENT3_INIT_ERROR 0xFF
77 
83 #define AMBIENT3_DEVICE_SLAVE_ADDRESS 0x49
84 
90 #define AMBIENT3_REG_HW_VERSION_MSB 0x00
91 #define AMBIENT3_REG_HW_VERSION_LSB 0x01
92 #define AMBIENT3_REG_FW_VERSION_MSB 0x02
93 #define AMBIENT3_REG_FW_VERSION_LSB 0x03
94 #define AMBIENT3_REG_CONF_CONTROL 0x04
95 #define AMBIENT3_REG_INTEGRATION_TIME 0x05
96 #define AMBIENT3_REG_DEVICE_TEMP 0x06
97 #define AMBIENT3_REG_LED_CONFIG 0x07
98 #define AMBIENT3_REG_ESP 0x4F
99 #define AMBIENT3_REG_DIR_CONFIG 0x60
100 #define AMBIENT3_REG_DIR_CONTROL 0x61
101 #define AMBIENT3_REG_DIR_CH_1_MSB 0x62
102 #define AMBIENT3_REG_DIR_CH_1_LSB 0x63
103 #define AMBIENT3_REG_DIR_CH_2_MSB 0x64
104 #define AMBIENT3_REG_DIR_CH_2_LSB 0x65
105 #define AMBIENT3_REG_DIR_CH_3_MSB 0x66
106 #define AMBIENT3_REG_DIR_CH_3_LSB 0x67
107 #define AMBIENT3_REG_DIR_LUXT_MSB 0x70
108 #define AMBIENT3_REG_DIR_LUXT_LSB 0x71
109 #define AMBIENT3_REG_DIR_CCTT_MSB 0x72
110 #define AMBIENT3_REG_DIR_CCTT_LSB 0x73
111 
117 #define AMBIENT3_REG_RAW_VALUE_0_MSB 0x08
118 #define AMBIENT3_REG_RAW_VALUE_0_LSB 0x09
119 #define AMBIENT3_REG_RAW_VALUE_1_MSB 0x0A
120 #define AMBIENT3_REG_RAW_VALUE_1_LSB 0x0B
121 #define AMBIENT3_REG_RAW_VALUE_2_MSB 0x0C
122 #define AMBIENT3_REG_RAW_VALUE_2_LSB 0x0D
123 #define AMBIENT3_REG_RAW_VALUE_3_MSB 0x0E
124 #define AMBIENT3_REG_RAW_VALUE_3_LSB 0x0F
125 #define AMBIENT3_REG_RAW_VALUE_4_MSB 0x10
126 #define AMBIENT3_REG_RAW_VALUE_4_LSB 0x11
127 #define AMBIENT3_REG_RAW_VALUE_5_MSB 0x12
128 #define AMBIENT3_REG_RAW_VALUE_5_LSB 0x13
129 
135 #define AMBIENT3_REG_COEF_DATA_0 0x50
136 #define AMBIENT3_REG_COEF_DATA_1 0x51
137 #define AMBIENT3_REG_COEF_DATA_2 0x52
138 #define AMBIENT3_REG_COEF_DATA_3 0x53
139 #define AMBIENT3_REG_COEF_READ 0x54
140 #define AMBIENT3_REG_COEF_WRITE 0x55
141 
147 #define AMBIENT3_REG_X_CALIBRATED_B1 0x14
148 #define AMBIENT3_REG_X_CALIBRATED_B2 0x15
149 #define AMBIENT3_REG_X_CALIBRATED_B3 0x16
150 #define AMBIENT3_REG_X_CALIBRATED_B4 0x17
151 #define AMBIENT3_REG_Y_CALIBRATED_B1 0x18
152 #define AMBIENT3_REG_Y_CALIBRATED_B2 0x19
153 #define AMBIENT3_REG_Y_CALIBRATED_B3 0x1A
154 #define AMBIENT3_REG_Y_CALIBRATED_B4 0x1B
155 #define AMBIENT3_REG_Z_CALIBRATED_B1 0x1C
156 #define AMBIENT3_REG_Z_CALIBRATED_B2 0x1D
157 #define AMBIENT3_REG_Z_CALIBRATED_B3 0x1E
158 #define AMBIENT3_REG_Z_CALIBRATED_B4 0x1F
159 
165 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B1 0x20
166 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B2 0x21
167 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B3 0x22
168 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B4 0x23
169 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B1 0x24
170 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B2 0x25
171 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B3 0x26
172 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B4 0x27
173 
179 #define AMBIENT3_REG_U_PRI_CALIBRATED_B1 0x28
180 #define AMBIENT3_REG_U_PRI_CALIBRATED_B2 0x29
181 #define AMBIENT3_REG_U_PRI_CALIBRATED_B3 0x2A
182 #define AMBIENT3_REG_U_PRI_CALIBRATED_B4 0x2B
183 #define AMBIENT3_REG_V_PRI_CALIBRATED_B1 0x2C
184 #define AMBIENT3_REG_V_PRI_CALIBRATED_B2 0x2D
185 #define AMBIENT3_REG_V_PRI_CALIBRATED_B3 0x2E
186 #define AMBIENT3_REG_V_PRI_CALIBRATED_B4 0x2F
187 #define AMBIENT3_REG_U_CALIBRATED_B1 0x30
188 #define AMBIENT3_REG_U_CALIBRATED_B2 0x31
189 #define AMBIENT3_REG_U_CALIBRATED_B3 0x32
190 #define AMBIENT3_REG_U_CALIBRATED_B4 0x33
191 #define AMBIENT3_REG_V_CALIBRATED_B1 0x34
192 #define AMBIENT3_REG_V_CALIBRATED_B2 0x35
193 #define AMBIENT3_REG_V_CALIBRATED_B3 0x36
194 #define AMBIENT3_REG_V_CALIBRATED_B4 0x37
195 
201 #define AMBIENT3_REG_DUV_CALIBRATED_B1 0x38
202 #define AMBIENT3_REG_DUV_CALIBRATED_B2 0x39
203 #define AMBIENT3_REG_DUV_CALIBRATED_B3 0x3A
204 #define AMBIENT3_REG_DUV_CALIBRATED_B4 0x3B
205 
211 #define AMBIENT3_REG_CAL_LUX_MSB 0x3C
212 #define AMBIENT3_REG_CAL_LUX_LSB 0x3D
213 #define AMBIENT3_REG_CAL_CCT_MSB 0x3E
214 #define AMBIENT3_REG_CAL_CCT_LSB 0x3F
215 
221 #define AMBIENT3_CC_GAIN_x1 0x00
222 #define AMBIENT3_CC_GAIN_x3_7 0x10
223 #define AMBIENT3_CC_GAIN_x16 0x20
224 #define AMBIENT3_CC_GAIN_x64 0x30
225 #define AMBIENT3_CC_RDY_TO_INT 0x02
226 #define AMBIENT3_CC_SOFTWARE_RESET 0x01
227  // End group macro
231 // --------------------------------------------------------------- PUBLIC TYPES
240 typedef struct
241 {
242  // Output pins
243 
244  digital_out_t rst;
245 
246  // Input pins
247 
248  digital_in_t int_pin;
249 
250  // Modules
251 
252  i2c_master_t i2c;
253 
254  // ctx variable
255 
256  uint8_t slave_address;
257 
258 } ambient3_t;
259 
263 typedef struct
264 {
265  // Communication gpio pins
266 
267  pin_name_t scl;
268  pin_name_t sda;
269 
270  // Additional gpio pins
271 
272  pin_name_t rst;
273  pin_name_t int_pin;
274 
275  // static variable
276 
277  uint32_t i2c_speed;
278  uint8_t i2c_address;
279 
281  // End types group
283 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
284 
290 #ifdef __cplusplus
291 extern "C"{
292 #endif
293 
303 
313 
322 
332 void ambient3_write_byte ( ambient3_t *ctx, uint8_t virtual_reg, uint8_t data_buf);
333 
343 uint8_t ambient3_read_byte ( ambient3_t *ctx, uint8_t virtual_reg);
344 
353 
363 
373 
374 
384 
394 
395 #ifdef __cplusplus
396 }
397 #endif
398 #endif // _AMBIENT3_H_
399  // End public_function group
402 
403 // ------------------------------------------------------------------------- END
ambient3_get_data_in_lux
uint16_t ambient3_get_data_in_lux(ambient3_t *ctx)
This function reads data in LUX.
ambient3_init
AMBIENT3_RETVAL ambient3_init(ambient3_t *ctx, ambient3_cfg_t *cfg)
Initialization function.
ambient3_get_interrupt
uint8_t ambient3_get_interrupt(ambient3_t *ctx)
This function reads interrupt state.
ambient3_t::int_pin
digital_in_t int_pin
Definition: ambient3.h:248
ambient3_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient3.h:273
ambient3_cfg_setup
void ambient3_cfg_setup(ambient3_cfg_t *cfg)
Config Object Initialization function.
ambient3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient3.h:277
ambient3_cfg_t
Click configuration structure definition.
Definition: ambient3.h:264
ambient3_t::i2c
i2c_master_t i2c
Definition: ambient3.h:252
ambient3_default_cfg
void ambient3_default_cfg(ambient3_t *ctx)
Default Config Initialization function.
ambient3_get_cct_data
uint16_t ambient3_get_cct_data(ambient3_t *ctx)
This function reads CCT data in K.
ambient3_cfg_t::sda
pin_name_t sda
Definition: ambient3.h:268
AMBIENT3_RETVAL
#define AMBIENT3_RETVAL
Definition: ambient3.h:73
ambient3_t
Click ctx object definition.
Definition: ambient3.h:241
ambient3_read_byte
uint8_t ambient3_read_byte(ambient3_t *ctx, uint8_t virtual_reg)
Read function.
ambient3_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient3.h:278
ambient3_cfg_t::rst
pin_name_t rst
Definition: ambient3.h:272
ambient3_t::slave_address
uint8_t slave_address
Definition: ambient3.h:256
ambient3_hardware_reset
void ambient3_hardware_reset(ambient3_t *ctx)
Hardware reset function.
ambient3_get_device_temperature
uint8_t ambient3_get_device_temperature(ambient3_t *ctx)
Getting temperature function.
ambient3_write_byte
void ambient3_write_byte(ambient3_t *ctx, uint8_t virtual_reg, uint8_t data_buf)
Write function.
ambient3_t::rst
digital_out_t rst
Definition: ambient3.h:244
ambient3_cfg_t::scl
pin_name_t scl
Definition: ambient3.h:267