color11 2.1.0.0
color11.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 COLOR11_H
29#define COLOR11_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define COLOR11_REG_RAM_START 0x00
74#define COLOR11_REG_ENABLE 0x80
75#define COLOR11_REG_ATIME 0x81
76#define COLOR11_REG_PTIME 0x82
77#define COLOR11_REG_WTIME 0x83
78#define COLOR11_REG_AILTL 0x84
79#define COLOR11_REG_AILTH 0x85
80#define COLOR11_REG_AIHTL 0x86
81#define COLOR11_REG_AIHTH 0x87
82#define COLOR11_REG_AUXID 0x90
83#define COLOR11_REG_REVID 0x91
84#define COLOR11_REG_ID 0x92
85#define COLOR11_REG_STATUS 0x93
86#define COLOR11_REG_ASTATUS 0x94
87#define COLOR11_REG_ADATAL0 0x95
88#define COLOR11_REG_ADATAH0 0x96
89#define COLOR11_REG_ADATAL1 0x97
90#define COLOR11_REG_ADATAH1 0x98
91#define COLOR11_REG_ADATAL2 0x99
92#define COLOR11_REG_ADATAH2 0x9A
93#define COLOR11_REG_ADATAL3 0x9B
94#define COLOR11_REG_ADATAH3 0x9C
95#define COLOR11_REG_ADATAL4 0x9D
96#define COLOR11_REG_ADATAH4 0x9E
97#define COLOR11_REG_ADATAL5 0x9F
98#define COLOR11_REG_ADATAH5 0xA0
99#define COLOR11_REG_STATUS2 0xA3
100#define COLOR11_REG_STATUS3 0xA4
101#define COLOR11_REG_STATUS5 0xA6
102#define COLOR11_REG_STATUS6 0xA7
103#define COLOR11_REG_CFG0 0xA9
104#define COLOR11_REG_CFG1 0xAA
105#define COLOR11_REG_CFG3 0xAC
106#define COLOR11_REG_CFG4 0xAD
107#define COLOR11_REG_CFG6 0xAF
108#define COLOR11_REG_CFG8 0xB1
109#define COLOR11_REG_CFG9 0xB2
110#define COLOR11_REG_CFG10 0xB3
111#define COLOR11_REG_CFG11 0xB4
112#define COLOR11_REG_CFG12 0xB5
113#define COLOR11_REG_PERS 0xBD
114#define COLOR11_REG_POFFSETH 0xC8
115#define COLOR11_REG_ASTEPL 0xCA
116#define COLOR11_REG_ASTEPH 0xCB
117#define COLOR11_REG_AGC_GAIN_MAX 0xCF
118#define COLOR11_REG_AZCONFIG 0xD6
119#define COLOR11_REG_FD_STATUS 0xDB
120#define COLOR11_REG_INTENAB 0xF9
121#define COLOR11_REG_CONTROL 0xFA
122
123 // color11_reg
124
139#define COLOR11_ID_AUX 0x4A
140#define COLOR11_ID_REV 0x53
141#define COLOR11_ID_DEV 0x18
142
147#define COLOR11_ALS_INTEG_TIME_DEFAULT 19000
148#define COLOR11_ALS_STEP_DEFAULT 2780
149#define COLOR11_ALS_THOLD_LOW_DEFAULT 0x0000u
150#define COLOR11_ALS_THOLD_HIGH_DEFAULT 0xFFFFu
151
156#define COLOR11_SET_INTENAB_ASI_DIS 0x00
157#define COLOR11_SET_INTENAB_ASI_EN 0x80
158#define COLOR11_SET_INTENAB_AI_DIS 0x00
159#define COLOR11_SET_INTENAB_AI_EN 0x08
160#define COLOR11_SET_INTENAB_SI_DIS 0x00
161#define COLOR11_SET_INTENAB_SI_EN 0x01
162
167#define COLOR11_STATUS2_AVALID 0x40
168#define COLOR11_STATUS2_ASAT_DIGITAL 0x10
169#define COLOR11_STATUS2_ASAT_ANALOG 0x08
170#define COLOR11_STATUS2_FDSAT_ANALOG 0x02
171#define COLOR11_STATUS2_FDSAT_DIGITAL 0x01
172
177#define COLOR11_ALS_STEP_CONV_TO_US 100
178#define COLOR11_ALS_STEP_MIN_ASTEP 278
179#define COLOR11_ALS_STEP_COR_FACT 50
180
185#define COLOR11_COEF_SCALE_DEFAULT 1000.0f
186#define COLOR11_COEF_DGF_DEFAULT 898.0f
187#define COLOR11_COEF_CLR_DEFAULT 210.0f
188#define COLOR11_COEF_RED_DEFAULT -60.0f
189#define COLOR11_COEF_GREEN_DEFAULT 10.0f
190#define COLOR11_COEF_BLUE_DEFAULT -290.0f
191
197#define COLOR11_DEVICE_ADDRESS 0x39
198
199 // color11_set
200
215#define COLOR11_MAP_MIKROBUS( cfg, mikrobus ) \
216 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
217 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
218 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
219
220 // color11_map
221 // color11
222
227typedef struct
228{
229 // Input pins
230 digital_in_t int_pin;
232 // Modules
233 i2c_master_t i2c;
235 // I2C slave address
238} color11_t;
239
244typedef struct
245{
246 pin_name_t scl;
247 pin_name_t sda;
249 pin_name_t int_pin;
251 uint32_t i2c_speed;
252 uint8_t i2c_address;
255
260typedef struct
261{
262 uint16_t clear;
263 uint16_t red;
264 uint16_t green;
265 uint16_t blue;
266 uint16_t wideband;
267 uint16_t flicker;
268
270
275typedef struct
276{
277 uint8_t aux_id;
278 uint8_t rev_id;
279 uint8_t dev_id;
280
282
287typedef enum
288{
290 COLOR11_ERROR = -1
291
293
304
326
343
358
372
387err_t color11_generic_write ( color11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
388
403err_t color11_generic_read ( color11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
404
420
435err_t color11_set_als_thold ( color11_t *ctx, uint16_t l_thold, uint16_t h_thold );
436
461 color11_pwr_ctrl_t fden );
462
476err_t color11_set_als_step ( color11_t *ctx, uint32_t als_step );
477
491err_t color11_get_als_step ( color11_t *ctx, uint32_t *als_step );
492
506err_t color11_set_als_wait ( color11_t *ctx, uint8_t wait_time );
507
521err_t color11_set_als_time ( color11_t *ctx, uint32_t als_time );
522
536err_t color11_get_als_time ( color11_t *ctx, float *als_time );
537
553
568err_t color11_get_gain ( color11_t *ctx, uint8_t *gain );
569
584err_t color11_set_interrupt ( color11_t *ctx, uint8_t intenab );
585
599err_t color11_get_data_valid_status ( color11_t *ctx, uint8_t *status );
600
616
631err_t color11_get_ir ( color11_t *ctx, float *ir );
632
647err_t color11_get_illuminance ( color11_t *ctx, float *lux );
648
662
663#ifdef __cplusplus
664}
665#endif
666#endif // COLOR11_H
667
668 // color11
669
670// ------------------------------------------------------------------------ END
color11_pwr_ctrl_t
Color 11 Click power, enable, and operation value data.
Definition color11.h:299
@ COLOR11_DISABLE
Definition color11.h:300
@ COLOR11_ENABLE
Definition color11.h:301
color11_return_value_t
Color 11 Click return value data.
Definition color11.h:288
@ COLOR11_ERROR
Definition color11.h:290
@ COLOR11_OK
Definition color11.h:289
color11_again_t
Color 11 Click ALS Gain value data.
Definition color11.h:310
@ COLOR11_AGAIN_X2
Definition color11.h:313
@ COLOR11_AGAIN_X64
Definition color11.h:318
@ COLOR11_AGAIN_X32
Definition color11.h:317
@ COLOR11_AGAIN_X4
Definition color11.h:314
@ COLOR11_AGAIN_X16
Definition color11.h:316
@ COLOR11_AGAIN_X1
Definition color11.h:312
@ COLOR11_AGAIN_X0_5
Definition color11.h:311
@ COLOR11_AGAIN_X2048
Definition color11.h:323
@ COLOR11_AGAIN_X8
Definition color11.h:315
@ COLOR11_AGAIN_X128
Definition color11.h:319
@ COLOR11_AGAIN_X256
Definition color11.h:320
@ COLOR11_AGAIN_X512
Definition color11.h:321
@ COLOR11_AGAIN_X1024
Definition color11.h:322
err_t color11_set_als_thold(color11_t *ctx, uint16_t l_thold, uint16_t h_thold)
Color 11 set ALS interrupt threshold function.
void color11_cfg_setup(color11_cfg_t *cfg)
Color 11 configuration object setup function.
err_t color11_get_illuminance(color11_t *ctx, float *lux)
Color 11 get illuminance function.
err_t color11_get_als_time(color11_t *ctx, float *als_time)
Color 11 get ALS integration time function.
err_t color11_set_power_ctrl(color11_t *ctx, color11_pwr_ctrl_t pwr, color11_pwr_ctrl_t aen, color11_pwr_ctrl_t wen, color11_pwr_ctrl_t fden)
Color 11 set power control function.
err_t color11_get_ir(color11_t *ctx, float *ir)
Color 11 get IR data function.
err_t color11_init(color11_t *ctx, color11_cfg_t *cfg)
Color 11 initialization function.
err_t color11_set_als_step(color11_t *ctx, uint32_t als_step)
Color 11 set ALS step function.
err_t color11_generic_write(color11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 11 I2C writing function.
err_t color11_generic_read(color11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 11 I2C reading function.
err_t color11_set_als_wait(color11_t *ctx, uint8_t wait_time)
Color 11 set ALS wait time function.
err_t color11_set_als_time(color11_t *ctx, uint32_t als_time)
Color 11 set ALS integration time function.
err_t color11_default_cfg(color11_t *ctx)
Color 11 default configuration function.
err_t color11_set_gain(color11_t *ctx, color11_again_t gain)
Color 11 set gain function.
err_t color11_get_identification(color11_t *ctx, color11_identification_t *id)
Color 11 get identification function.
uint8_t color11_get_interrupt(color11_t *ctx)
Color 11 get interrupt function.
err_t color11_get_gain(color11_t *ctx, uint8_t *gain)
Color 11 get gain function.
err_t color11_get_data_valid_status(color11_t *ctx, uint8_t *status)
Color 11 get data valid status function.
err_t color11_get_als_data(color11_t *ctx, color11_als_data_t *als_data)
Color 11 get ALS data function.
err_t color11_set_interrupt(color11_t *ctx, uint8_t intenab)
Color 11 set interrupt function.
err_t color11_get_als_step(color11_t *ctx, uint32_t *als_step)
Color 11 get ALS step function.
Color 11 Click ALS data object.
Definition color11.h:261
uint16_t clear
Definition color11.h:262
uint16_t wideband
Definition color11.h:266
uint16_t blue
Definition color11.h:265
uint16_t green
Definition color11.h:264
uint16_t flicker
Definition color11.h:267
uint16_t red
Definition color11.h:263
Color 11 Click configuration object.
Definition color11.h:245
uint32_t i2c_speed
Definition color11.h:251
pin_name_t scl
Definition color11.h:246
pin_name_t int_pin
Definition color11.h:249
pin_name_t sda
Definition color11.h:247
uint8_t i2c_address
Definition color11.h:252
Color 11 Click device identification object.
Definition color11.h:276
uint8_t dev_id
Definition color11.h:279
uint8_t aux_id
Definition color11.h:277
uint8_t rev_id
Definition color11.h:278
Color 11 Click context object.
Definition color11.h:228
digital_in_t int_pin
Definition color11.h:230
i2c_master_t i2c
Definition color11.h:233
uint8_t slave_address
Definition color11.h:236