color15 2.0.0.0
color15.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 COLOR15_H
29#define COLOR15_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 COLOR15_REG_SYSM_CTRL 0x00
74#define COLOR15_REG_INT_CTRL 0x01
75#define COLOR15_REG_INT_FLAG 0x02
76#define COLOR15_REG_WAIT_TIME 0x03
77#define COLOR15_REG_CLS_GAIN 0x04
78#define COLOR15_REG_CLS_TIME 0x05
79#define COLOR15_REG_PERSISTENCE 0x0B
80#define COLOR15_REG_CLS_THRES_LL 0x0C
81#define COLOR15_REG_CLS_THRES_LH 0x0D
82#define COLOR15_REG_CLS_THRES_HL 0x0E
83#define COLOR15_REG_CLS_THRES_HH 0x0F
84#define COLOR15_REG_INT_SOURCE 0x16
85#define COLOR15_REG_ERROR_FLAG 0x17
86#define COLOR15_REG_RCH_DATA_L 0x1C
87#define COLOR15_REG_RCH_DATA_H 0x1D
88#define COLOR15_REG_GCH_DATA_L 0x1E
89#define COLOR15_REG_GCH_DATA_H 0x1F
90#define COLOR15_REG_BCH_DATA_L 0x20
91#define COLOR15_REG_BCH_DATA_H 0x21
92#define COLOR15_REG_WCH_DATA_L 0x22
93#define COLOR15_REG_WCH_DATA_H 0x23
94#define COLOR15_REG_IRCH_DATA_L 0x24
95#define COLOR15_REG_IRCH_DATA_H 0x25
96#define COLOR15_REG_PROD_ID_L 0xBC
97#define COLOR15_REG_PROD_ID_H 0xBD
98
99 // color15_reg
100
115#define COLOR15_SYSM_CTRL_SWRST 0x80
116#define COLOR15_SYSM_CTRL_EN_WAIT 0x40
117#define COLOR15_SYSM_CTRL_EN_IR 0x02
118#define COLOR15_SYSM_CTRL_EN_CLS 0x01
119
124#define COLOR15_INT_CTRL_CLS_SYNC 0x10
125#define COLOR15_INT_CTRL_EN_CINT 0x01
126
131#define COLOR15_INT_FLAG_POR 0x80
132#define COLOR15_INT_FLAG_DATA_FLAG 0x40
133#define COLOR15_INT_FLAG_CLS 0x01
134#define COLOR15_INT_FLAG_CLEAR_ALL 0x00
135
140#define COLOR15_WAIT_TIME_MS_MAX 2560
141#define COLOR15_WAIT_TIME_MS_DEFAULT 100
142#define COLOR15_WAIT_TIME_MS_MIN 10
143#define COLOR15_WAIT_TIME_MS_LSB 10
144#define COLOR15_WAIT_TIME_RES 0xFF
145
150#define COLOR15_CLSCONV_1 0x00
151#define COLOR15_CLSCONV_2 0x01
152#define COLOR15_CLSCONV_3 0x02
153#define COLOR15_CLSCONV_4 0x03
154#define COLOR15_CLSCONV_5 0x04
155#define COLOR15_CLSCONV_6 0x05
156#define COLOR15_CLSCONV_7 0x06
157#define COLOR15_CLSCONV_8 0x07
158#define COLOR15_CLSCONV_9 0x08
159#define COLOR15_CLSCONV_10 0x09
160#define COLOR15_CLSCONV_11 0x0A
161#define COLOR15_CLSCONV_12 0x0B
162#define COLOR15_CLSCONV_13 0x0C
163#define COLOR15_CLSCONV_14 0x0D
164#define COLOR15_CLSCONV_15 0x0E
165#define COLOR15_INT_TIME_1 0x00
166#define COLOR15_INT_TIME_4 0x01
167#define COLOR15_INT_TIME_16 0x02
168#define COLOR15_INT_TIME_64 0x03
169#define COLOR15_MAX_COUNT_LSB 1024
170#define COLOR15_MAX_COUNT_RES 0xFFFF
171
176#define COLOR15_CLS_GAIN_DIOD_SELT_X1 0x00
177#define COLOR15_CLS_GAIN_DIOD_SELT_X2 0x80
178#define COLOR15_CLS_GAIN_PGA_CLS_X1 0x01
179#define COLOR15_CLS_GAIN_PGA_CLS_X4 0x02
180#define COLOR15_CLS_GAIN_PGA_CLS_X8 0x04
181#define COLOR15_CLS_GAIN_PGA_CLS_X32 0x08
182#define COLOR15_CLS_GAIN_PGA_CLS_X96 0x10
183
188#define COLOR15_PRS_CLS_INDEPENDENT 0x00
189#define COLOR15_PRS_CLS_1_CLS 0x01
190#define COLOR15_PRS_CLS_2_CLS 0x02
191#define COLOR15_PRS_CLS_3_CLS 0x03
192#define COLOR15_PRS_CLS_4_CLS 0x04
193#define COLOR15_PRS_CLS_5_CLS 0x05
194#define COLOR15_PRS_CLS_6_CLS 0x06
195#define COLOR15_PRS_CLS_7_CLS 0x07
196#define COLOR15_PRS_CLS_8_CLS 0x08
197#define COLOR15_PRS_CLS_9_CLS 0x09
198#define COLOR15_PRS_CLS_10_CLS 0x0A
199#define COLOR15_PRS_CLS_11_CLS 0x0B
200#define COLOR15_PRS_CLS_12_CLS 0x0C
201#define COLOR15_PRS_CLS_13_CLS 0x0D
202#define COLOR15_PRS_CLS_14_CLS 0x0E
203#define COLOR15_PRS_CLS_15_CLS 0x0F
204
209#define COLOR15_INT_SRC_RCH_DATA 0x01
210#define COLOR15_INT_SRC_GCH_DATA 0x02
211#define COLOR15_INT_SRC_BCH_DATA 0x04
212#define COLOR15_INT_SRC_WCH_DATA 0x08
213#define COLOR15_INT_SRC_IRCH_DATA 0x10
214
219#define COLOR15_UNKNOWN_COLOR 0
220#define COLOR15_RED_COLOR 1
221#define COLOR15_YELLOW_COLOR 2
222#define COLOR15_GREEN_COLOR 3
223#define COLOR15_CYAN_COLOR 4
224#define COLOR15_BLUE_COLOR 5
225#define COLOR15_MAGENTA_COLOR 6
226#define COLOR15_WHITE_COLOR 7
227#define COLOR15_BLACK_COLOR 8
228
233#define COLOR15_WHITE_COLOR_LIGHTNESS 97
234#define COLOR15_BLACK_COLOR_LIGHTNESS 3
235#define COLOR15_YELLOW_COLOR_HUE_ANGLE 30
236#define COLOR15_GREEN_COLOR_HUE_ANGLE 90
237#define COLOR15_CYAN_COLOR_HUE_ANGLE 150
238#define COLOR15_BLUE_COLOR_HUE_ANGLE 210
239#define COLOR15_MAGENTA_COLOR_HUE_ANGLE 270
240#define COLOR15_RED_COLOR_HUE_ANGLE 330
241
246#define COLOR15_HSL_HUE_RESOLUTION 360
247#define COLOR15_HSL_SATURATION_RESOLUTION 100
248#define COLOR15_HSL_LIGHTNESS_RESOLUTION 100
249
254#define COLOR15_PRODUCT_ID_LSB 0x12
255#define COLOR15_PRODUCT_ID_MSB 0x07
256
262#define COLOR15_DEVICE_ADDRESS 0x38
263
264 // color15_set
265
280#define COLOR15_MAP_MIKROBUS( cfg, mikrobus ) \
281 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
282 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
283 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
284
285 // color15_map
286 // color15
287
292typedef struct
293{
294 // Input pins
295 digital_in_t int_pin;
297 // Modules
298 i2c_master_t i2c;
300 // I2C slave address
303 uint16_t resolution;
305} color15_t;
306
311typedef struct
312{
313 pin_name_t scl;
314 pin_name_t sda;
316 pin_name_t int_pin;
318 uint32_t i2c_speed;
319 uint8_t i2c_address;
322
327typedef struct
328{
329 uint16_t red;
330 uint16_t green;
331 uint16_t blue;
332 uint16_t white;
333 uint16_t ir;
334
336
341typedef struct
342{
343 float hue;
346
348
353typedef enum
354{
356 COLOR15_ERROR = -1
357
359
376
391
405
420err_t color15_generic_write ( color15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
421
436err_t color15_generic_read ( color15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
437
450err_t color15_write_register ( color15_t *ctx, uint8_t reg, uint8_t data_in );
451
464err_t color15_read_register ( color15_t *ctx, uint8_t reg, uint8_t *data_out );
465
477
487
499
511err_t color15_set_wait_time ( color15_t *ctx, uint16_t wait_time );
512
525err_t color15_set_cls_time ( color15_t *ctx, uint8_t clsconv, uint8_t int_time );
526
540
551
565
566#ifdef __cplusplus
567}
568#endif
569#endif // COLOR15_H
570
571 // color15
572
573// ------------------------------------------------------------------------ END
color15_return_value_t
Color 15 Click return value data.
Definition color15.h:354
@ COLOR15_ERROR
Definition color15.h:356
@ COLOR15_OK
Definition color15.h:355
err_t color15_generic_read(color15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 15 I2C reading function.
err_t color15_set_cls_time(color15_t *ctx, uint8_t clsconv, uint8_t int_time)
Color 15 set cls time function.
err_t color15_generic_write(color15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 15 I2C writing function.
err_t color15_write_register(color15_t *ctx, uint8_t reg, uint8_t data_in)
Color 15 write register function.
err_t color15_set_wait_time(color15_t *ctx, uint16_t wait_time)
Color 15 set wait time function.
err_t color15_read_register(color15_t *ctx, uint8_t reg, uint8_t *data_out)
Color 15 read register function.
err_t color15_init(color15_t *ctx, color15_cfg_t *cfg)
Color 15 initialization function.
void color15_rgbw_to_hsl(color15_t *ctx, color15_channels_t *rgbw, color15_hsl_t *hsl)
Color 15 rgbw to hsl function.
err_t color15_clear_interrupt(color15_t *ctx)
Color 15 clear interrupt function.
err_t color15_check_communication(color15_t *ctx)
Color 15 check communication function.
uint8_t color15_get_color(color15_hsl_t *hsl)
Color 15 get color function.
void color15_cfg_setup(color15_cfg_t *cfg)
Color 15 configuration object setup function.
err_t color15_default_cfg(color15_t *ctx)
Color 15 default configuration function.
err_t color15_get_data(color15_t *ctx, color15_channels_t *channels)
Color 15 get data function.
uint8_t color15_get_int_pin(color15_t *ctx)
Color 15 get int pin function.
Color 15 Click configuration object.
Definition color15.h:312
uint32_t i2c_speed
Definition color15.h:318
pin_name_t scl
Definition color15.h:313
pin_name_t int_pin
Definition color15.h:316
pin_name_t sda
Definition color15.h:314
uint8_t i2c_address
Definition color15.h:319
Color 15 RGBWIR channels data object.
Definition color15.h:328
uint16_t blue
Definition color15.h:331
uint16_t green
Definition color15.h:330
uint16_t white
Definition color15.h:332
uint16_t red
Definition color15.h:329
uint16_t ir
Definition color15.h:333
Color 15 HSL color data object.
Definition color15.h:342
float hue
Definition color15.h:343
float saturation
Definition color15.h:344
float lightness
Definition color15.h:345
Color 15 Click context object.
Definition color15.h:293
uint16_t resolution
Definition color15.h:303
digital_in_t int_pin
Definition color15.h:295
i2c_master_t i2c
Definition color15.h:298
uint8_t slave_address
Definition color15.h:301