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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define COLOR15_REG_SYSM_CTRL 0x00
70 #define COLOR15_REG_INT_CTRL 0x01
71 #define COLOR15_REG_INT_FLAG 0x02
72 #define COLOR15_REG_WAIT_TIME 0x03
73 #define COLOR15_REG_CLS_GAIN 0x04
74 #define COLOR15_REG_CLS_TIME 0x05
75 #define COLOR15_REG_PERSISTENCE 0x0B
76 #define COLOR15_REG_CLS_THRES_LL 0x0C
77 #define COLOR15_REG_CLS_THRES_LH 0x0D
78 #define COLOR15_REG_CLS_THRES_HL 0x0E
79 #define COLOR15_REG_CLS_THRES_HH 0x0F
80 #define COLOR15_REG_INT_SOURCE 0x16
81 #define COLOR15_REG_ERROR_FLAG 0x17
82 #define COLOR15_REG_RCH_DATA_L 0x1C
83 #define COLOR15_REG_RCH_DATA_H 0x1D
84 #define COLOR15_REG_GCH_DATA_L 0x1E
85 #define COLOR15_REG_GCH_DATA_H 0x1F
86 #define COLOR15_REG_BCH_DATA_L 0x20
87 #define COLOR15_REG_BCH_DATA_H 0x21
88 #define COLOR15_REG_WCH_DATA_L 0x22
89 #define COLOR15_REG_WCH_DATA_H 0x23
90 #define COLOR15_REG_IRCH_DATA_L 0x24
91 #define COLOR15_REG_IRCH_DATA_H 0x25
92 #define COLOR15_REG_PROD_ID_L 0xBC
93 #define COLOR15_REG_PROD_ID_H 0xBD
94  // color15_reg
96 
111 #define COLOR15_SYSM_CTRL_SWRST 0x80
112 #define COLOR15_SYSM_CTRL_EN_WAIT 0x40
113 #define COLOR15_SYSM_CTRL_EN_IR 0x02
114 #define COLOR15_SYSM_CTRL_EN_CLS 0x01
115 
120 #define COLOR15_INT_CTRL_CLS_SYNC 0x10
121 #define COLOR15_INT_CTRL_EN_CINT 0x01
122 
127 #define COLOR15_INT_FLAG_POR 0x80
128 #define COLOR15_INT_FLAG_DATA_FLAG 0x40
129 #define COLOR15_INT_FLAG_CLS 0x01
130 #define COLOR15_INT_FLAG_CLEAR_ALL 0x00
131 
136 #define COLOR15_WAIT_TIME_MS_MAX 2560
137 #define COLOR15_WAIT_TIME_MS_DEFAULT 100
138 #define COLOR15_WAIT_TIME_MS_MIN 10
139 #define COLOR15_WAIT_TIME_MS_LSB 10
140 #define COLOR15_WAIT_TIME_RES 0xFF
141 
146 #define COLOR15_CLSCONV_1 0x00
147 #define COLOR15_CLSCONV_2 0x01
148 #define COLOR15_CLSCONV_3 0x02
149 #define COLOR15_CLSCONV_4 0x03
150 #define COLOR15_CLSCONV_5 0x04
151 #define COLOR15_CLSCONV_6 0x05
152 #define COLOR15_CLSCONV_7 0x06
153 #define COLOR15_CLSCONV_8 0x07
154 #define COLOR15_CLSCONV_9 0x08
155 #define COLOR15_CLSCONV_10 0x09
156 #define COLOR15_CLSCONV_11 0x0A
157 #define COLOR15_CLSCONV_12 0x0B
158 #define COLOR15_CLSCONV_13 0x0C
159 #define COLOR15_CLSCONV_14 0x0D
160 #define COLOR15_CLSCONV_15 0x0E
161 #define COLOR15_INT_TIME_1 0x00
162 #define COLOR15_INT_TIME_4 0x01
163 #define COLOR15_INT_TIME_16 0x02
164 #define COLOR15_INT_TIME_64 0x03
165 #define COLOR15_MAX_COUNT_LSB 1024
166 #define COLOR15_MAX_COUNT_RES 0xFFFF
167 
172 #define COLOR15_CLS_GAIN_DIOD_SELT_X1 0x00
173 #define COLOR15_CLS_GAIN_DIOD_SELT_X2 0x80
174 #define COLOR15_CLS_GAIN_PGA_CLS_X1 0x01
175 #define COLOR15_CLS_GAIN_PGA_CLS_X4 0x02
176 #define COLOR15_CLS_GAIN_PGA_CLS_X8 0x04
177 #define COLOR15_CLS_GAIN_PGA_CLS_X32 0x08
178 #define COLOR15_CLS_GAIN_PGA_CLS_X96 0x10
179 
184 #define COLOR15_PRS_CLS_INDEPENDENT 0x00
185 #define COLOR15_PRS_CLS_1_CLS 0x01
186 #define COLOR15_PRS_CLS_2_CLS 0x02
187 #define COLOR15_PRS_CLS_3_CLS 0x03
188 #define COLOR15_PRS_CLS_4_CLS 0x04
189 #define COLOR15_PRS_CLS_5_CLS 0x05
190 #define COLOR15_PRS_CLS_6_CLS 0x06
191 #define COLOR15_PRS_CLS_7_CLS 0x07
192 #define COLOR15_PRS_CLS_8_CLS 0x08
193 #define COLOR15_PRS_CLS_9_CLS 0x09
194 #define COLOR15_PRS_CLS_10_CLS 0x0A
195 #define COLOR15_PRS_CLS_11_CLS 0x0B
196 #define COLOR15_PRS_CLS_12_CLS 0x0C
197 #define COLOR15_PRS_CLS_13_CLS 0x0D
198 #define COLOR15_PRS_CLS_14_CLS 0x0E
199 #define COLOR15_PRS_CLS_15_CLS 0x0F
200 
205 #define COLOR15_INT_SRC_RCH_DATA 0x01
206 #define COLOR15_INT_SRC_GCH_DATA 0x02
207 #define COLOR15_INT_SRC_BCH_DATA 0x04
208 #define COLOR15_INT_SRC_WCH_DATA 0x08
209 #define COLOR15_INT_SRC_IRCH_DATA 0x10
210 
215 #define COLOR15_UNKNOWN_COLOR 0
216 #define COLOR15_RED_COLOR 1
217 #define COLOR15_YELLOW_COLOR 2
218 #define COLOR15_GREEN_COLOR 3
219 #define COLOR15_CYAN_COLOR 4
220 #define COLOR15_BLUE_COLOR 5
221 #define COLOR15_MAGENTA_COLOR 6
222 #define COLOR15_WHITE_COLOR 7
223 #define COLOR15_BLACK_COLOR 8
224 
229 #define COLOR15_WHITE_COLOR_LIGHTNESS 97
230 #define COLOR15_BLACK_COLOR_LIGHTNESS 3
231 #define COLOR15_YELLOW_COLOR_HUE_ANGLE 30
232 #define COLOR15_GREEN_COLOR_HUE_ANGLE 90
233 #define COLOR15_CYAN_COLOR_HUE_ANGLE 150
234 #define COLOR15_BLUE_COLOR_HUE_ANGLE 210
235 #define COLOR15_MAGENTA_COLOR_HUE_ANGLE 270
236 #define COLOR15_RED_COLOR_HUE_ANGLE 330
237 
242 #define COLOR15_HSL_HUE_RESOLUTION 360
243 #define COLOR15_HSL_SATURATION_RESOLUTION 100
244 #define COLOR15_HSL_LIGHTNESS_RESOLUTION 100
245 
250 #define COLOR15_PRODUCT_ID_LSB 0x12
251 #define COLOR15_PRODUCT_ID_MSB 0x07
252 
258 #define COLOR15_DEVICE_ADDRESS 0x38
259  // color15_set
261 
276 #define COLOR15_MAP_MIKROBUS( cfg, mikrobus ) \
277  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
278  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
279  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
280  // color15_map // color15
283 
288 typedef struct
289 {
290  // Input pins
291  digital_in_t int_pin;
293  // Modules
294  i2c_master_t i2c;
296  // I2C slave address
297  uint8_t slave_address;
299  uint16_t resolution;
301 } color15_t;
302 
307 typedef struct
308 {
309  pin_name_t scl;
310  pin_name_t sda;
312  pin_name_t int_pin;
314  uint32_t i2c_speed;
315  uint8_t i2c_address;
317 } color15_cfg_t;
318 
323 typedef struct
324 {
325  uint16_t red;
326  uint16_t green;
327  uint16_t blue;
328  uint16_t white;
329  uint16_t ir;
330 
332 
337 typedef struct
338 {
339  float hue;
340  float saturation;
341  float lightness;
342 
343 } color15_hsl_t;
344 
349 typedef enum
350 {
352  COLOR15_ERROR = -1
353 
355 
372 
386 err_t color15_init ( color15_t *ctx, color15_cfg_t *cfg );
387 
401 
416 err_t color15_generic_write ( color15_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
417 
432 err_t color15_generic_read ( color15_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
433 
446 err_t color15_write_register ( color15_t *ctx, uint8_t reg, uint8_t data_in );
447 
460 err_t color15_read_register ( color15_t *ctx, uint8_t reg, uint8_t *data_out );
461 
473 
483 
495 
507 err_t color15_set_wait_time ( color15_t *ctx, uint16_t wait_time );
508 
521 err_t color15_set_cls_time ( color15_t *ctx, uint8_t clsconv, uint8_t int_time );
522 
536 
547 
561 
562 #ifdef __cplusplus
563 }
564 #endif
565 #endif // COLOR15_H
566  // color15
568 
569 // ------------------------------------------------------------------------ END
color15_channels_t::red
uint16_t red
Definition: color15.h:325
color15_t::resolution
uint16_t resolution
Definition: color15.h:299
color15_hsl_t::lightness
float lightness
Definition: color15.h:341
color15_cfg_t::scl
pin_name_t scl
Definition: color15.h:309
color15_t::i2c
i2c_master_t i2c
Definition: color15.h:294
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:350
color15_cfg_t::sda
pin_name_t sda
Definition: color15.h:310
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:297
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:291
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:315
COLOR15_OK
@ COLOR15_OK
Definition: color15.h:351
color15_cfg_t::int_pin
pin_name_t int_pin
Definition: color15.h:312
color15_channels_t::blue
uint16_t blue
Definition: color15.h:327
color15_channels_t
Color 15 RGBWIR channels data object.
Definition: color15.h:324
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:340
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:328
color15_channels_t::ir
uint16_t ir
Definition: color15.h:329
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:326
COLOR15_ERROR
@ COLOR15_ERROR
Definition: color15.h:352
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:314
color15_hsl_t::hue
float hue
Definition: color15.h:339
color15_t
Color 15 Click context object.
Definition: color15.h:289
color15_hsl_t
Color 15 HSL color data object.
Definition: color15.h:338
color15_cfg_t
Color 15 Click configuration object.
Definition: color15.h:308