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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define COLOR15_REG_SYSM_CTRL 0x00
60 #define COLOR15_REG_INT_CTRL 0x01
61 #define COLOR15_REG_INT_FLAG 0x02
62 #define COLOR15_REG_WAIT_TIME 0x03
63 #define COLOR15_REG_CLS_GAIN 0x04
64 #define COLOR15_REG_CLS_TIME 0x05
65 #define COLOR15_REG_PERSISTENCE 0x0B
66 #define COLOR15_REG_CLS_THRES_LL 0x0C
67 #define COLOR15_REG_CLS_THRES_LH 0x0D
68 #define COLOR15_REG_CLS_THRES_HL 0x0E
69 #define COLOR15_REG_CLS_THRES_HH 0x0F
70 #define COLOR15_REG_INT_SOURCE 0x16
71 #define COLOR15_REG_ERROR_FLAG 0x17
72 #define COLOR15_REG_RCH_DATA_L 0x1C
73 #define COLOR15_REG_RCH_DATA_H 0x1D
74 #define COLOR15_REG_GCH_DATA_L 0x1E
75 #define COLOR15_REG_GCH_DATA_H 0x1F
76 #define COLOR15_REG_BCH_DATA_L 0x20
77 #define COLOR15_REG_BCH_DATA_H 0x21
78 #define COLOR15_REG_WCH_DATA_L 0x22
79 #define COLOR15_REG_WCH_DATA_H 0x23
80 #define COLOR15_REG_IRCH_DATA_L 0x24
81 #define COLOR15_REG_IRCH_DATA_H 0x25
82 #define COLOR15_REG_PROD_ID_L 0xBC
83 #define COLOR15_REG_PROD_ID_H 0xBD
84  // color15_reg
86 
101 #define COLOR15_SYSM_CTRL_SWRST 0x80
102 #define COLOR15_SYSM_CTRL_EN_WAIT 0x40
103 #define COLOR15_SYSM_CTRL_EN_IR 0x02
104 #define COLOR15_SYSM_CTRL_EN_CLS 0x01
105 
110 #define COLOR15_INT_CTRL_CLS_SYNC 0x10
111 #define COLOR15_INT_CTRL_EN_CINT 0x01
112 
117 #define COLOR15_INT_FLAG_POR 0x80
118 #define COLOR15_INT_FLAG_DATA_FLAG 0x40
119 #define COLOR15_INT_FLAG_CLS 0x01
120 #define COLOR15_INT_FLAG_CLEAR_ALL 0x00
121 
126 #define COLOR15_WAIT_TIME_MS_MAX 2560
127 #define COLOR15_WAIT_TIME_MS_DEFAULT 100
128 #define COLOR15_WAIT_TIME_MS_MIN 10
129 #define COLOR15_WAIT_TIME_MS_LSB 10
130 #define COLOR15_WAIT_TIME_RES 0xFF
131 
136 #define COLOR15_CLSCONV_1 0x00
137 #define COLOR15_CLSCONV_2 0x01
138 #define COLOR15_CLSCONV_3 0x02
139 #define COLOR15_CLSCONV_4 0x03
140 #define COLOR15_CLSCONV_5 0x04
141 #define COLOR15_CLSCONV_6 0x05
142 #define COLOR15_CLSCONV_7 0x06
143 #define COLOR15_CLSCONV_8 0x07
144 #define COLOR15_CLSCONV_9 0x08
145 #define COLOR15_CLSCONV_10 0x09
146 #define COLOR15_CLSCONV_11 0x0A
147 #define COLOR15_CLSCONV_12 0x0B
148 #define COLOR15_CLSCONV_13 0x0C
149 #define COLOR15_CLSCONV_14 0x0D
150 #define COLOR15_CLSCONV_15 0x0E
151 #define COLOR15_INT_TIME_1 0x00
152 #define COLOR15_INT_TIME_4 0x01
153 #define COLOR15_INT_TIME_16 0x02
154 #define COLOR15_INT_TIME_64 0x03
155 #define COLOR15_MAX_COUNT_LSB 1024
156 #define COLOR15_MAX_COUNT_RES 0xFFFF
157 
162 #define COLOR15_CLS_GAIN_DIOD_SELT_X1 0x00
163 #define COLOR15_CLS_GAIN_DIOD_SELT_X2 0x80
164 #define COLOR15_CLS_GAIN_PGA_CLS_X1 0x01
165 #define COLOR15_CLS_GAIN_PGA_CLS_X4 0x02
166 #define COLOR15_CLS_GAIN_PGA_CLS_X8 0x04
167 #define COLOR15_CLS_GAIN_PGA_CLS_X32 0x08
168 #define COLOR15_CLS_GAIN_PGA_CLS_X96 0x10
169 
174 #define COLOR15_PRS_CLS_INDEPENDENT 0x00
175 #define COLOR15_PRS_CLS_1_CLS 0x01
176 #define COLOR15_PRS_CLS_2_CLS 0x02
177 #define COLOR15_PRS_CLS_3_CLS 0x03
178 #define COLOR15_PRS_CLS_4_CLS 0x04
179 #define COLOR15_PRS_CLS_5_CLS 0x05
180 #define COLOR15_PRS_CLS_6_CLS 0x06
181 #define COLOR15_PRS_CLS_7_CLS 0x07
182 #define COLOR15_PRS_CLS_8_CLS 0x08
183 #define COLOR15_PRS_CLS_9_CLS 0x09
184 #define COLOR15_PRS_CLS_10_CLS 0x0A
185 #define COLOR15_PRS_CLS_11_CLS 0x0B
186 #define COLOR15_PRS_CLS_12_CLS 0x0C
187 #define COLOR15_PRS_CLS_13_CLS 0x0D
188 #define COLOR15_PRS_CLS_14_CLS 0x0E
189 #define COLOR15_PRS_CLS_15_CLS 0x0F
190 
195 #define COLOR15_INT_SRC_RCH_DATA 0x01
196 #define COLOR15_INT_SRC_GCH_DATA 0x02
197 #define COLOR15_INT_SRC_BCH_DATA 0x04
198 #define COLOR15_INT_SRC_WCH_DATA 0x08
199 #define COLOR15_INT_SRC_IRCH_DATA 0x10
200 
205 #define COLOR15_UNKNOWN_COLOR 0
206 #define COLOR15_RED_COLOR 1
207 #define COLOR15_YELLOW_COLOR 2
208 #define COLOR15_GREEN_COLOR 3
209 #define COLOR15_CYAN_COLOR 4
210 #define COLOR15_BLUE_COLOR 5
211 #define COLOR15_MAGENTA_COLOR 6
212 #define COLOR15_WHITE_COLOR 7
213 #define COLOR15_BLACK_COLOR 8
214 
219 #define COLOR15_WHITE_COLOR_LIGHTNESS 97
220 #define COLOR15_BLACK_COLOR_LIGHTNESS 3
221 #define COLOR15_YELLOW_COLOR_HUE_ANGLE 30
222 #define COLOR15_GREEN_COLOR_HUE_ANGLE 90
223 #define COLOR15_CYAN_COLOR_HUE_ANGLE 150
224 #define COLOR15_BLUE_COLOR_HUE_ANGLE 210
225 #define COLOR15_MAGENTA_COLOR_HUE_ANGLE 270
226 #define COLOR15_RED_COLOR_HUE_ANGLE 330
227 
232 #define COLOR15_HSL_HUE_RESOLUTION 360
233 #define COLOR15_HSL_SATURATION_RESOLUTION 100
234 #define COLOR15_HSL_LIGHTNESS_RESOLUTION 100
235 
240 #define COLOR15_PRODUCT_ID_LSB 0x12
241 #define COLOR15_PRODUCT_ID_MSB 0x07
242 
248 #define COLOR15_DEVICE_ADDRESS 0x38
249  // color15_set
251 
266 #define COLOR15_MAP_MIKROBUS( cfg, mikrobus ) \
267  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
268  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
269  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
270  // color15_map // color15
273 
278 typedef struct
279 {
280  // Input pins
281  digital_in_t int_pin;
283  // Modules
284  i2c_master_t i2c;
286  // I2C slave address
287  uint8_t slave_address;
289  uint16_t resolution;
291 } color15_t;
292 
297 typedef struct
298 {
299  pin_name_t scl;
300  pin_name_t sda;
302  pin_name_t int_pin;
304  uint32_t i2c_speed;
305  uint8_t i2c_address;
307 } color15_cfg_t;
308 
313 typedef struct
314 {
315  uint16_t red;
316  uint16_t green;
317  uint16_t blue;
318  uint16_t white;
319  uint16_t ir;
320 
322 
327 typedef struct
328 {
329  float hue;
330  float saturation;
331  float lightness;
332 
333 } color15_hsl_t;
334 
339 typedef enum
340 {
342  COLOR15_ERROR = -1
343 
345 
362 
376 err_t color15_init ( color15_t *ctx, color15_cfg_t *cfg );
377 
391 
406 err_t color15_generic_write ( color15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
407 
422 err_t color15_generic_read ( color15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
423 
436 err_t color15_write_register ( color15_t *ctx, uint8_t reg, uint8_t data_in );
437 
450 err_t color15_read_register ( color15_t *ctx, uint8_t reg, uint8_t *data_out );
451 
463 
473 
485 
497 err_t color15_set_wait_time ( color15_t *ctx, uint16_t wait_time );
498 
511 err_t color15_set_cls_time ( color15_t *ctx, uint8_t clsconv, uint8_t int_time );
512 
526 
537 
551 
552 #ifdef __cplusplus
553 }
554 #endif
555 #endif // COLOR15_H
556  // color15
558 
559 // ------------------------------------------------------------------------ END
color15_channels_t::red
uint16_t red
Definition: color15.h:315
color15_t::resolution
uint16_t resolution
Definition: color15.h:289
color15_hsl_t::lightness
float lightness
Definition: color15.h:331
color15_cfg_t::scl
pin_name_t scl
Definition: color15.h:299
color15_t::i2c
i2c_master_t i2c
Definition: color15.h:284
color15_get_int_pin
uint8_t color15_get_int_pin(color15_t *ctx)
Color 15 get int pin function.
color15_return_value_t
color15_return_value_t
Color 15 Click return value data.
Definition: color15.h:340
color15_cfg_t::sda
pin_name_t sda
Definition: color15.h:300
color15_set_cls_time
err_t color15_set_cls_time(color15_t *ctx, uint8_t clsconv, uint8_t int_time)
Color 15 set cls time function.
color15_generic_read
err_t color15_generic_read(color15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 15 I2C reading function.
color15_t::slave_address
uint8_t slave_address
Definition: color15.h:287
color15_init
err_t color15_init(color15_t *ctx, color15_cfg_t *cfg)
Color 15 initialization function.
color15_get_data
err_t color15_get_data(color15_t *ctx, color15_channels_t *channels)
Color 15 get data function.
color15_t::int_pin
digital_in_t int_pin
Definition: color15.h:281
color15_default_cfg
err_t color15_default_cfg(color15_t *ctx)
Color 15 default configuration function.
color15_cfg_setup
void color15_cfg_setup(color15_cfg_t *cfg)
Color 15 configuration object setup function.
color15_rgbw_to_hsl
void color15_rgbw_to_hsl(color15_t *ctx, color15_channels_t *rgbw, color15_hsl_t *hsl)
Color 15 rgbw to hsl function.
color15_cfg_t::i2c_address
uint8_t i2c_address
Definition: color15.h:305
COLOR15_OK
@ COLOR15_OK
Definition: color15.h:341
color15_cfg_t::int_pin
pin_name_t int_pin
Definition: color15.h:302
color15_channels_t::blue
uint16_t blue
Definition: color15.h:317
color15_channels_t
Color 15 RGBWIR channels data object.
Definition: color15.h:314
color15_generic_write
err_t color15_generic_write(color15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 15 I2C writing function.
color15_hsl_t::saturation
float saturation
Definition: color15.h:330
color15_read_register
err_t color15_read_register(color15_t *ctx, uint8_t reg, uint8_t *data_out)
Color 15 read register function.
color15_set_wait_time
err_t color15_set_wait_time(color15_t *ctx, uint16_t wait_time)
Color 15 set wait time function.
color15_clear_interrupt
err_t color15_clear_interrupt(color15_t *ctx)
Color 15 clear interrupt function.
color15_channels_t::white
uint16_t white
Definition: color15.h:318
color15_channels_t::ir
uint16_t ir
Definition: color15.h:319
color15_write_register
err_t color15_write_register(color15_t *ctx, uint8_t reg, uint8_t data_in)
Color 15 write register function.
color15_channels_t::green
uint16_t green
Definition: color15.h:316
COLOR15_ERROR
@ COLOR15_ERROR
Definition: color15.h:342
color15_check_communication
err_t color15_check_communication(color15_t *ctx)
Color 15 check communication function.
color15_get_color
uint8_t color15_get_color(color15_hsl_t *hsl)
Color 15 get color function.
color15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color15.h:304
color15_hsl_t::hue
float hue
Definition: color15.h:329
color15_t
Color 15 Click context object.
Definition: color15.h:279
color15_hsl_t
Color 15 HSL color data object.
Definition: color15.h:328
color15_cfg_t
Color 15 Click configuration object.
Definition: color15.h:298