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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AMBIENT3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define AMBIENT3_RETVAL uint8_t
64 
65 #define AMBIENT3_OK 0x00
66 #define AMBIENT3_INIT_ERROR 0xFF
67 
73 #define AMBIENT3_DEVICE_SLAVE_ADDRESS 0x49
74 
80 #define AMBIENT3_REG_HW_VERSION_MSB 0x00
81 #define AMBIENT3_REG_HW_VERSION_LSB 0x01
82 #define AMBIENT3_REG_FW_VERSION_MSB 0x02
83 #define AMBIENT3_REG_FW_VERSION_LSB 0x03
84 #define AMBIENT3_REG_CONF_CONTROL 0x04
85 #define AMBIENT3_REG_INTEGRATION_TIME 0x05
86 #define AMBIENT3_REG_DEVICE_TEMP 0x06
87 #define AMBIENT3_REG_LED_CONFIG 0x07
88 #define AMBIENT3_REG_ESP 0x4F
89 #define AMBIENT3_REG_DIR_CONFIG 0x60
90 #define AMBIENT3_REG_DIR_CONTROL 0x61
91 #define AMBIENT3_REG_DIR_CH_1_MSB 0x62
92 #define AMBIENT3_REG_DIR_CH_1_LSB 0x63
93 #define AMBIENT3_REG_DIR_CH_2_MSB 0x64
94 #define AMBIENT3_REG_DIR_CH_2_LSB 0x65
95 #define AMBIENT3_REG_DIR_CH_3_MSB 0x66
96 #define AMBIENT3_REG_DIR_CH_3_LSB 0x67
97 #define AMBIENT3_REG_DIR_LUXT_MSB 0x70
98 #define AMBIENT3_REG_DIR_LUXT_LSB 0x71
99 #define AMBIENT3_REG_DIR_CCTT_MSB 0x72
100 #define AMBIENT3_REG_DIR_CCTT_LSB 0x73
101 
107 #define AMBIENT3_REG_RAW_VALUE_0_MSB 0x08
108 #define AMBIENT3_REG_RAW_VALUE_0_LSB 0x09
109 #define AMBIENT3_REG_RAW_VALUE_1_MSB 0x0A
110 #define AMBIENT3_REG_RAW_VALUE_1_LSB 0x0B
111 #define AMBIENT3_REG_RAW_VALUE_2_MSB 0x0C
112 #define AMBIENT3_REG_RAW_VALUE_2_LSB 0x0D
113 #define AMBIENT3_REG_RAW_VALUE_3_MSB 0x0E
114 #define AMBIENT3_REG_RAW_VALUE_3_LSB 0x0F
115 #define AMBIENT3_REG_RAW_VALUE_4_MSB 0x10
116 #define AMBIENT3_REG_RAW_VALUE_4_LSB 0x11
117 #define AMBIENT3_REG_RAW_VALUE_5_MSB 0x12
118 #define AMBIENT3_REG_RAW_VALUE_5_LSB 0x13
119 
125 #define AMBIENT3_REG_COEF_DATA_0 0x50
126 #define AMBIENT3_REG_COEF_DATA_1 0x51
127 #define AMBIENT3_REG_COEF_DATA_2 0x52
128 #define AMBIENT3_REG_COEF_DATA_3 0x53
129 #define AMBIENT3_REG_COEF_READ 0x54
130 #define AMBIENT3_REG_COEF_WRITE 0x55
131 
137 #define AMBIENT3_REG_X_CALIBRATED_B1 0x14
138 #define AMBIENT3_REG_X_CALIBRATED_B2 0x15
139 #define AMBIENT3_REG_X_CALIBRATED_B3 0x16
140 #define AMBIENT3_REG_X_CALIBRATED_B4 0x17
141 #define AMBIENT3_REG_Y_CALIBRATED_B1 0x18
142 #define AMBIENT3_REG_Y_CALIBRATED_B2 0x19
143 #define AMBIENT3_REG_Y_CALIBRATED_B3 0x1A
144 #define AMBIENT3_REG_Y_CALIBRATED_B4 0x1B
145 #define AMBIENT3_REG_Z_CALIBRATED_B1 0x1C
146 #define AMBIENT3_REG_Z_CALIBRATED_B2 0x1D
147 #define AMBIENT3_REG_Z_CALIBRATED_B3 0x1E
148 #define AMBIENT3_REG_Z_CALIBRATED_B4 0x1F
149 
155 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B1 0x20
156 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B2 0x21
157 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B3 0x22
158 #define AMBIENT3_REG_CIE1931_X_CALIBRATED_B4 0x23
159 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B1 0x24
160 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B2 0x25
161 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B3 0x26
162 #define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B4 0x27
163 
169 #define AMBIENT3_REG_U_PRI_CALIBRATED_B1 0x28
170 #define AMBIENT3_REG_U_PRI_CALIBRATED_B2 0x29
171 #define AMBIENT3_REG_U_PRI_CALIBRATED_B3 0x2A
172 #define AMBIENT3_REG_U_PRI_CALIBRATED_B4 0x2B
173 #define AMBIENT3_REG_V_PRI_CALIBRATED_B1 0x2C
174 #define AMBIENT3_REG_V_PRI_CALIBRATED_B2 0x2D
175 #define AMBIENT3_REG_V_PRI_CALIBRATED_B3 0x2E
176 #define AMBIENT3_REG_V_PRI_CALIBRATED_B4 0x2F
177 #define AMBIENT3_REG_U_CALIBRATED_B1 0x30
178 #define AMBIENT3_REG_U_CALIBRATED_B2 0x31
179 #define AMBIENT3_REG_U_CALIBRATED_B3 0x32
180 #define AMBIENT3_REG_U_CALIBRATED_B4 0x33
181 #define AMBIENT3_REG_V_CALIBRATED_B1 0x34
182 #define AMBIENT3_REG_V_CALIBRATED_B2 0x35
183 #define AMBIENT3_REG_V_CALIBRATED_B3 0x36
184 #define AMBIENT3_REG_V_CALIBRATED_B4 0x37
185 
191 #define AMBIENT3_REG_DUV_CALIBRATED_B1 0x38
192 #define AMBIENT3_REG_DUV_CALIBRATED_B2 0x39
193 #define AMBIENT3_REG_DUV_CALIBRATED_B3 0x3A
194 #define AMBIENT3_REG_DUV_CALIBRATED_B4 0x3B
195 
201 #define AMBIENT3_REG_CAL_LUX_MSB 0x3C
202 #define AMBIENT3_REG_CAL_LUX_LSB 0x3D
203 #define AMBIENT3_REG_CAL_CCT_MSB 0x3E
204 #define AMBIENT3_REG_CAL_CCT_LSB 0x3F
205 
211 #define AMBIENT3_CC_GAIN_x1 0x00
212 #define AMBIENT3_CC_GAIN_x3_7 0x10
213 #define AMBIENT3_CC_GAIN_x16 0x20
214 #define AMBIENT3_CC_GAIN_x64 0x30
215 #define AMBIENT3_CC_RDY_TO_INT 0x02
216 #define AMBIENT3_CC_SOFTWARE_RESET 0x01
217  // End group macro
221 // --------------------------------------------------------------- PUBLIC TYPES
230 typedef struct
231 {
232  // Output pins
233 
234  digital_out_t rst;
235 
236  // Input pins
237 
238  digital_in_t int_pin;
239 
240  // Modules
241 
242  i2c_master_t i2c;
243 
244  // ctx variable
245 
246  uint8_t slave_address;
247 
248 } ambient3_t;
249 
253 typedef struct
254 {
255  // Communication gpio pins
256 
257  pin_name_t scl;
258  pin_name_t sda;
259 
260  // Additional gpio pins
261 
262  pin_name_t rst;
263  pin_name_t int_pin;
264 
265  // static variable
266 
267  uint32_t i2c_speed;
268  uint8_t i2c_address;
269 
271  // End types group
273 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
274 
280 #ifdef __cplusplus
281 extern "C"{
282 #endif
283 
292 void ambient3_cfg_setup ( ambient3_cfg_t *cfg );
293 
303 
311 void ambient3_default_cfg ( ambient3_t *ctx );
312 
322 void ambient3_write_byte ( ambient3_t *ctx, uint8_t virtual_reg, uint8_t data_buf);
323 
333 uint8_t ambient3_read_byte ( ambient3_t *ctx, uint8_t virtual_reg);
334 
342 void ambient3_hardware_reset ( ambient3_t *ctx );
343 
353 
362 uint16_t ambient3_get_data_in_lux ( ambient3_t *ctx );
363 
364 
373 uint16_t ambient3_get_cct_data ( ambient3_t *ctx );
374 
383 uint8_t ambient3_get_interrupt ( ambient3_t *ctx );
384 
385 #ifdef __cplusplus
386 }
387 #endif
388 #endif // _AMBIENT3_H_
389  // End public_function group
392 
393 // ------------------------------------------------------------------------- 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:238
ambient3_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient3.h:263
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:267
ambient3_cfg_t
Click configuration structure definition.
Definition: ambient3.h:253
ambient3_t::i2c
i2c_master_t i2c
Definition: ambient3.h:242
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:258
AMBIENT3_RETVAL
#define AMBIENT3_RETVAL
Definition: ambient3.h:63
ambient3_t
Click ctx object definition.
Definition: ambient3.h:230
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:268
ambient3_cfg_t::rst
pin_name_t rst
Definition: ambient3.h:262
ambient3_t::slave_address
uint8_t slave_address
Definition: ambient3.h:246
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:234
ambient3_cfg_t::scl
pin_name_t scl
Definition: ambient3.h:257