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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define AMBIENT3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define AMBIENT3_RETVAL uint8_t
78
79#define AMBIENT3_OK 0x00
80#define AMBIENT3_INIT_ERROR 0xFF
87#define AMBIENT3_DEVICE_SLAVE_ADDRESS 0x49
94#define AMBIENT3_REG_HW_VERSION_MSB 0x00
95#define AMBIENT3_REG_HW_VERSION_LSB 0x01
96#define AMBIENT3_REG_FW_VERSION_MSB 0x02
97#define AMBIENT3_REG_FW_VERSION_LSB 0x03
98#define AMBIENT3_REG_CONF_CONTROL 0x04
99#define AMBIENT3_REG_INTEGRATION_TIME 0x05
100#define AMBIENT3_REG_DEVICE_TEMP 0x06
101#define AMBIENT3_REG_LED_CONFIG 0x07
102#define AMBIENT3_REG_ESP 0x4F
103#define AMBIENT3_REG_DIR_CONFIG 0x60
104#define AMBIENT3_REG_DIR_CONTROL 0x61
105#define AMBIENT3_REG_DIR_CH_1_MSB 0x62
106#define AMBIENT3_REG_DIR_CH_1_LSB 0x63
107#define AMBIENT3_REG_DIR_CH_2_MSB 0x64
108#define AMBIENT3_REG_DIR_CH_2_LSB 0x65
109#define AMBIENT3_REG_DIR_CH_3_MSB 0x66
110#define AMBIENT3_REG_DIR_CH_3_LSB 0x67
111#define AMBIENT3_REG_DIR_LUXT_MSB 0x70
112#define AMBIENT3_REG_DIR_LUXT_LSB 0x71
113#define AMBIENT3_REG_DIR_CCTT_MSB 0x72
114#define AMBIENT3_REG_DIR_CCTT_LSB 0x73
121#define AMBIENT3_REG_RAW_VALUE_0_MSB 0x08
122#define AMBIENT3_REG_RAW_VALUE_0_LSB 0x09
123#define AMBIENT3_REG_RAW_VALUE_1_MSB 0x0A
124#define AMBIENT3_REG_RAW_VALUE_1_LSB 0x0B
125#define AMBIENT3_REG_RAW_VALUE_2_MSB 0x0C
126#define AMBIENT3_REG_RAW_VALUE_2_LSB 0x0D
127#define AMBIENT3_REG_RAW_VALUE_3_MSB 0x0E
128#define AMBIENT3_REG_RAW_VALUE_3_LSB 0x0F
129#define AMBIENT3_REG_RAW_VALUE_4_MSB 0x10
130#define AMBIENT3_REG_RAW_VALUE_4_LSB 0x11
131#define AMBIENT3_REG_RAW_VALUE_5_MSB 0x12
132#define AMBIENT3_REG_RAW_VALUE_5_LSB 0x13
139#define AMBIENT3_REG_COEF_DATA_0 0x50
140#define AMBIENT3_REG_COEF_DATA_1 0x51
141#define AMBIENT3_REG_COEF_DATA_2 0x52
142#define AMBIENT3_REG_COEF_DATA_3 0x53
143#define AMBIENT3_REG_COEF_READ 0x54
144#define AMBIENT3_REG_COEF_WRITE 0x55
151#define AMBIENT3_REG_X_CALIBRATED_B1 0x14
152#define AMBIENT3_REG_X_CALIBRATED_B2 0x15
153#define AMBIENT3_REG_X_CALIBRATED_B3 0x16
154#define AMBIENT3_REG_X_CALIBRATED_B4 0x17
155#define AMBIENT3_REG_Y_CALIBRATED_B1 0x18
156#define AMBIENT3_REG_Y_CALIBRATED_B2 0x19
157#define AMBIENT3_REG_Y_CALIBRATED_B3 0x1A
158#define AMBIENT3_REG_Y_CALIBRATED_B4 0x1B
159#define AMBIENT3_REG_Z_CALIBRATED_B1 0x1C
160#define AMBIENT3_REG_Z_CALIBRATED_B2 0x1D
161#define AMBIENT3_REG_Z_CALIBRATED_B3 0x1E
162#define AMBIENT3_REG_Z_CALIBRATED_B4 0x1F
169#define AMBIENT3_REG_CIE1931_X_CALIBRATED_B1 0x20
170#define AMBIENT3_REG_CIE1931_X_CALIBRATED_B2 0x21
171#define AMBIENT3_REG_CIE1931_X_CALIBRATED_B3 0x22
172#define AMBIENT3_REG_CIE1931_X_CALIBRATED_B4 0x23
173#define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B1 0x24
174#define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B2 0x25
175#define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B3 0x26
176#define AMBIENT3_REG_CIE1931_Y_CALIBRATED_B4 0x27
183#define AMBIENT3_REG_U_PRI_CALIBRATED_B1 0x28
184#define AMBIENT3_REG_U_PRI_CALIBRATED_B2 0x29
185#define AMBIENT3_REG_U_PRI_CALIBRATED_B3 0x2A
186#define AMBIENT3_REG_U_PRI_CALIBRATED_B4 0x2B
187#define AMBIENT3_REG_V_PRI_CALIBRATED_B1 0x2C
188#define AMBIENT3_REG_V_PRI_CALIBRATED_B2 0x2D
189#define AMBIENT3_REG_V_PRI_CALIBRATED_B3 0x2E
190#define AMBIENT3_REG_V_PRI_CALIBRATED_B4 0x2F
191#define AMBIENT3_REG_U_CALIBRATED_B1 0x30
192#define AMBIENT3_REG_U_CALIBRATED_B2 0x31
193#define AMBIENT3_REG_U_CALIBRATED_B3 0x32
194#define AMBIENT3_REG_U_CALIBRATED_B4 0x33
195#define AMBIENT3_REG_V_CALIBRATED_B1 0x34
196#define AMBIENT3_REG_V_CALIBRATED_B2 0x35
197#define AMBIENT3_REG_V_CALIBRATED_B3 0x36
198#define AMBIENT3_REG_V_CALIBRATED_B4 0x37
205#define AMBIENT3_REG_DUV_CALIBRATED_B1 0x38
206#define AMBIENT3_REG_DUV_CALIBRATED_B2 0x39
207#define AMBIENT3_REG_DUV_CALIBRATED_B3 0x3A
208#define AMBIENT3_REG_DUV_CALIBRATED_B4 0x3B
215#define AMBIENT3_REG_CAL_LUX_MSB 0x3C
216#define AMBIENT3_REG_CAL_LUX_LSB 0x3D
217#define AMBIENT3_REG_CAL_CCT_MSB 0x3E
218#define AMBIENT3_REG_CAL_CCT_LSB 0x3F
225#define AMBIENT3_CC_GAIN_x1 0x00
226#define AMBIENT3_CC_GAIN_x3_7 0x10
227#define AMBIENT3_CC_GAIN_x16 0x20
228#define AMBIENT3_CC_GAIN_x64 0x30
229#define AMBIENT3_CC_RDY_TO_INT 0x02
230#define AMBIENT3_CC_SOFTWARE_RESET 0x01
234 // End group macro
235// --------------------------------------------------------------- PUBLIC TYPES
244typedef struct
245{
246 // Output pins
247
248 digital_out_t rst;
249
250 // Input pins
251
252 digital_in_t int_pin;
253
254 // Modules
255
256 i2c_master_t i2c;
257
258 // ctx variable
259
261
262} ambient3_t;
263
267typedef struct
268{
269 // Communication gpio pins
270
271 pin_name_t scl;
272 pin_name_t sda;
273
274 // Additional gpio pins
275
276 pin_name_t rst;
277 pin_name_t int_pin;
278
279 // static variable
280
281 uint32_t i2c_speed;
282 uint8_t i2c_address;
283
285
286 // End types group
287// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
288
294#ifdef __cplusplus
295extern "C"{
296#endif
297
307
317
326
336void ambient3_write_byte ( ambient3_t *ctx, uint8_t virtual_reg, uint8_t data_buf);
337
347uint8_t ambient3_read_byte ( ambient3_t *ctx, uint8_t virtual_reg);
348
357
367
377
378
388
398
399#ifdef __cplusplus
400}
401#endif
402#endif // _AMBIENT3_H_
403
404 // End public_function group
406
407// ------------------------------------------------------------------------- END
#define AMBIENT3_RETVAL
Definition ambient3.h:77
void ambient3_hardware_reset(ambient3_t *ctx)
Hardware reset function.
void ambient3_default_cfg(ambient3_t *ctx)
Default Config Initialization function.
uint8_t ambient3_get_device_temperature(ambient3_t *ctx)
Getting temperature function.
uint16_t ambient3_get_data_in_lux(ambient3_t *ctx)
This function reads data in LUX.
void ambient3_cfg_setup(ambient3_cfg_t *cfg)
Config Object Initialization function.
uint8_t ambient3_get_interrupt(ambient3_t *ctx)
This function reads interrupt state.
uint8_t ambient3_read_byte(ambient3_t *ctx, uint8_t virtual_reg)
Read function.
void ambient3_write_byte(ambient3_t *ctx, uint8_t virtual_reg, uint8_t data_buf)
Write function.
uint16_t ambient3_get_cct_data(ambient3_t *ctx)
This function reads CCT data in K.
AMBIENT3_RETVAL ambient3_init(ambient3_t *ctx, ambient3_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition ambient3.h:268
uint32_t i2c_speed
Definition ambient3.h:281
pin_name_t scl
Definition ambient3.h:271
pin_name_t int_pin
Definition ambient3.h:277
pin_name_t sda
Definition ambient3.h:272
pin_name_t rst
Definition ambient3.h:276
uint8_t i2c_address
Definition ambient3.h:282
Click ctx object definition.
Definition ambient3.h:245
digital_in_t int_pin
Definition ambient3.h:252
i2c_master_t i2c
Definition ambient3.h:256
digital_out_t rst
Definition ambient3.h:248
uint8_t slave_address
Definition ambient3.h:260