color16  2.1.0.0
color16.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 COLOR16_H
29 #define COLOR16_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 COLOR16_REG_AUXID 0x58
60 #define COLOR16_REG_REVID 0x59
61 #define COLOR16_REG_ID 0x5A
62 #define COLOR16_REG_CFG_12 0x66
63 #define COLOR16_REG_ENABLE 0x80
64 #define COLOR16_REG_ATIME 0x81
65 #define COLOR16_REG_WTIME 0x83
66 #define COLOR16_REG_SP_TH_L_LSB 0x84
67 #define COLOR16_REG_SP_TH_L_MSB 0x85
68 #define COLOR16_REG_SP_TH_H_LSB 0x86
69 #define COLOR16_REG_SP_TH_H_MSB 0x87
70 #define COLOR16_REG_STATUS 0x93
71 #define COLOR16_REG_ASTATUS 0x94
72 #define COLOR16_REG_DATA_0_L 0x95
73 #define COLOR16_REG_DATA_0_H 0x96
74 #define COLOR16_REG_DATA_1_L 0x97
75 #define COLOR16_REG_DATA_1_H 0x98
76 #define COLOR16_REG_DATA_2_L 0x99
77 #define COLOR16_REG_DATA_2_H 0x9A
78 #define COLOR16_REG_DATA_3_L 0x9B
79 #define COLOR16_REG_DATA_3_H 0x9C
80 #define COLOR16_REG_DATA_4_L 0x9D
81 #define COLOR16_REG_DATA_4_H 0x9E
82 #define COLOR16_REG_DATA_5_L 0x9F
83 #define COLOR16_REG_DATA_5_H 0xA0
84 #define COLOR16_REG_DATA_6_L 0xA1
85 #define COLOR16_REG_DATA_6_H 0xA2
86 #define COLOR16_REG_DATA_7_L 0xA3
87 #define COLOR16_REG_DATA_7_H 0xA4
88 #define COLOR16_REG_DATA_8_L 0xA5
89 #define COLOR16_REG_DATA_8_H 0xA6
90 #define COLOR16_REG_DATA_9_L 0xA7
91 #define COLOR16_REG_DATA_9_H 0xA8
92 #define COLOR16_REG_DATA_10_L 0xA9
93 #define COLOR16_REG_DATA_10_H 0xAA
94 #define COLOR16_REG_DATA_11_L 0xAB
95 #define COLOR16_REG_DATA_11_H 0xAC
96 #define COLOR16_REG_DATA_12_L 0xAD
97 #define COLOR16_REG_DATA_12_H 0xAE
98 #define COLOR16_REG_DATA_13_L 0xAF
99 #define COLOR16_REG_DATA_13_H 0xB0
100 #define COLOR16_REG_DATA_14_L 0xB1
101 #define COLOR16_REG_DATA_14_H 0xB2
102 #define COLOR16_REG_DATA_15_L 0xB3
103 #define COLOR16_REG_DATA_15_H 0xB4
104 #define COLOR16_REG_DATA_16_L 0xB5
105 #define COLOR16_REG_DATA_16_H 0xB6
106 #define COLOR16_REG_DATA_17_L 0xB7
107 #define COLOR16_REG_DATA_17_H 0xB8
108 #define COLOR16_REG_STATUS_2 0x90
109 #define COLOR16_REG_STATUS_3 0x91
110 #define COLOR16_REG_STATUS_5 0xBB
111 #define COLOR16_REG_STATUS_4 0xBC
112 #define COLOR16_REG_CFG_0 0xBF
113 #define COLOR16_REG_CFG_1 0xC6
114 #define COLOR16_REG_CFG_3 0xC7
115 #define COLOR16_REG_CFG_6 0xF5
116 #define COLOR16_REG_CFG_8 0xC9
117 #define COLOR16_REG_CFG_9 0xCA
118 #define COLOR16_REG_CFG_10 0x65
119 #define COLOR16_REG_PERS 0xCF
120 #define COLOR16_REG_GPIO 0x6B
121 #define COLOR16_REG_ASTEP_LSB 0xD4
122 #define COLOR16_REG_ASTEP_MSB 0xD5
123 #define COLOR16_REG_CFG_20 0xD6
124 #define COLOR16_REG_LED 0xCD
125 #define COLOR16_REG_AGC_GAIN_MAX 0xD7
126 #define COLOR16_REG_AZ_CONFIG 0xDE
127 #define COLOR16_REG_FD_TIME_1 0xE0
128 #define COLOR16_REG_FD_TIME_2 0xE2
129 #define COLOR16_REG_FD_CFG_0 0xDF
130 #define COLOR16_REG_FD_STATUS 0xE3
131 #define COLOR16_REG_INTENAB 0xF9
132 #define COLOR16_REG_CONTROL 0xFA
133 #define COLOR16_REG_FIFO_MAP 0xFC
134 #define COLOR16_REG_FIFO_LVL 0xFD
135 #define COLOR16_REG_FDATA_L 0xFE
136 #define COLOR16_REG_FDATA_H 0xFF
137  // color16_reg
139 
154 #define COLOR16_ENABLE_FDEN 0x40
155 #define COLOR16_ENABLE_SMUXEN 0x10
156 #define COLOR16_ENABLE_WEN 0x08
157 #define COLOR16_ENABLE_SP_EN 0x02
158 #define COLOR16_ENABLE_PON 0x01
159 #define COLOR16_ENABLE_POFF 0x00
160 
165 #define COLOR16_CFG_0_LOW_POWER 0x20
166 #define COLOR16_CFG_0_REG_BANK 0x10
167 #define COLOR16_CFG_0_WLONG 0x04
168 
173 #define COLOR16_CFG_1_AGAIN_0p5 0x00
174 #define COLOR16_CFG_1_AGAIN_1 0x01
175 #define COLOR16_CFG_1_AGAIN_2 0x02
176 #define COLOR16_CFG_1_AGAIN_4 0x03
177 #define COLOR16_CFG_1_AGAIN_8 0x04
178 #define COLOR16_CFG_1_AGAIN_16 0x05
179 #define COLOR16_CFG_1_AGAIN_32 0x06
180 #define COLOR16_CFG_1_AGAIN_64 0x07
181 #define COLOR16_CFG_1_AGAIN_128 0x08
182 #define COLOR16_CFG_1_AGAIN_256 0x09
183 #define COLOR16_CFG_1_AGAIN_512 0x0A
184 #define COLOR16_CFG_1_AGAIN_1024 0x0B
185 #define COLOR16_CFG_1_AGAIN_2048 0x0C
186 #define COLOR16_CFG_1_AGAIN_MASK 0x1F
187 
192 #define COLOR16_CFG_20_FD_FIFO_8BIT 0x80
193 #define COLOR16_CFG_20_AUTO_SMUX_6CH 0x00
194 #define COLOR16_CFG_20_AUTO_SMUX_12CH 0x40
195 #define COLOR16_CFG_20_AUTO_SMUX_18CH 0x60
196 #define COLOR16_CFG_20_AUTO_SMUX_MASK 0x60
197 
202 #define COLOR16_CONTROL_SW_RESET 0x08
203 #define COLOR16_CONTROL_SP_MAN_AZ 0x04
204 #define COLOR16_CONTROL_FIFO_CLR 0x02
205 #define COLOR16_CONTROL_CLEAR_SAI_ACT 0x01
206 
211 #define COLOR16_LED_OFF 0x00
212 #define COLOR16_LED_ON 0x80
213 #define COLOR16_LED_DRIVE_CURR_MIN 4
214 #define COLOR16_LED_DRIVE_CURR_MAX 258
215 #define COLOR16_LED_DRIVE_CURR_STEP 2
216 #define COLOR16_LED_DRIVE_CURR_DEFAULT 8
217 
222 #define COLOR16_STATUS_ASAT 0x80
223 #define COLOR16_STATUS_AINT 0x08
224 #define COLOR16_STATUS_FINT 0x04
225 #define COLOR16_STATUS_SINT 0x01
226 
231 #define COLOR16_ASTATUS_ASAT 0x80
232 #define COLOR16_ASTATUS_AGAIN_MASK 0x0F
233 
238 #define COLOR16_STATUS_2_AVALID 0x40
239 #define COLOR16_STATUS_2_ASAT_DIG 0x10
240 #define COLOR16_STATUS_2_ASAT_ANA 0x08
241 #define COLOR16_STATUS_2_FDSAT_ANA 0x02
242 #define COLOR16_STATUS_2_FDSAT_DIG 0x01
243 
248 #define COLOR16_DEVICE_ID 0x81
249 
254 #define COLOR16_ACCESS_REG_BANK_ABOVE_80H 0
255 #define COLOR16_ACCESS_REG_BANK_20H_7FH 1
256 
261 #define COLOR16_SINGLE_STEP_MS 0.00278f
262 #define COLOR16_ATIME_MAX 255
263 #define COLOR16_ASTEP_MAX 65534
264 #define COLOR16_INTEGRATION_TIME_MAX ( ( float ) ( COLOR16_ATIME_MAX + 1 ) * ( COLOR16_ASTEP_MAX + 1 ) * COLOR16_SINGLE_STEP_MS )
265 #define COLOR16_INTEGRATION_TIME_MIN COLOR16_SINGLE_STEP_MS
266 #define COLOR16_INTEGRATION_TIME_DEFAULT 90.0f
267 #define COLOR16_WAIT_STEP_MS 2.78f
268 #define COLOR16_WTIME_MAX 255
269 #define COLOR16_WAIT_TIME_MAX ( ( float ) ( COLOR16_WTIME_MAX + 1 ) * COLOR16_WAIT_STEP_MS )
270 #define COLOR16_WAIT_TIME_MIN COLOR16_WAIT_STEP_MS
271 #define COLOR16_WAIT_TIME_DEFAULT 100.0f
272 
278 #define COLOR16_DEVICE_ADDRESS 0x39
279  // color16_set
281 
296 #define COLOR16_MAP_MIKROBUS( cfg, mikrobus ) \
297  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
298  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
299  cfg.ldr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
300  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
301  // color16_map // color16
304 
309 typedef struct
310 {
311  uint8_t status;
312  uint8_t astatus;
313  uint16_t ch_fz;
314  uint16_t ch_fy;
315  uint16_t ch_fxl;
316  uint16_t ch_nir;
317  uint16_t ch_2x_vis_1;
318  uint16_t ch_fd_1;
319  uint16_t ch_f2;
320  uint16_t ch_f3;
321  uint16_t ch_f4;
322  uint16_t ch_f6;
323  uint16_t ch_2x_vis_2;
324  uint16_t ch_fd_2;
325  uint16_t ch_f1;
326  uint16_t ch_f5;
327  uint16_t ch_f7;
328  uint16_t ch_f8;
329  uint16_t ch_2x_vis_3;
330  uint16_t ch_fd_3;
331 
333 
338 typedef struct
339 {
340  // Output pins
341  digital_out_t ldr;
343  // Input pins
344  digital_in_t int_pin;
346  // Modules
347  i2c_master_t i2c;
349  // I2C slave address
350  uint8_t slave_address;
352 } color16_t;
353 
358 typedef struct
359 {
360  pin_name_t scl;
361  pin_name_t sda;
363  pin_name_t ldr;
364  pin_name_t int_pin;
366  uint32_t i2c_speed;
367  uint8_t i2c_address;
369 } color16_cfg_t;
370 
375 typedef enum
376 {
378  COLOR16_ERROR = -1
379 
381 
398 
412 err_t color16_init ( color16_t *ctx, color16_cfg_t *cfg );
413 
427 
442 err_t color16_generic_write ( color16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
443 
458 err_t color16_generic_read ( color16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
459 
472 err_t color16_write_register ( color16_t *ctx, uint8_t reg, uint8_t data_in );
473 
486 err_t color16_read_register ( color16_t *ctx, uint8_t reg, uint8_t *data_out );
487 
501 err_t color16_write_register_word ( color16_t *ctx, uint8_t reg, uint16_t data_in );
502 
516 err_t color16_read_register_word ( color16_t *ctx, uint8_t reg, uint16_t *data_out );
517 
529 
539 void color16_set_ldr_pin ( color16_t *ctx, uint8_t state );
540 
550 
563 err_t color16_set_reg_bank_access ( color16_t *ctx, uint8_t reg_bank );
564 
576 
588 err_t color16_enable_ext_led ( color16_t *ctx, uint8_t led_curr );
589 
603 err_t color16_set_integration_time_ms ( color16_t *ctx, float int_time_ms );
604 
617 err_t color16_set_wait_time_ms ( color16_t *ctx, float wait_time_ms );
618 
632 err_t color16_read_data ( color16_t *ctx, color16_data_t *data_out );
633 
634 #ifdef __cplusplus
635 }
636 #endif
637 #endif // COLOR16_H
638  // color16
640 
641 // ------------------------------------------------------------------------ END
color16_data_t::ch_fd_3
uint16_t ch_fd_3
Definition: color16.h:330
color16_read_register
err_t color16_read_register(color16_t *ctx, uint8_t reg, uint8_t *data_out)
Color 16 read register function.
COLOR16_ERROR
@ COLOR16_ERROR
Definition: color16.h:378
color16_cfg_t::ldr
pin_name_t ldr
Definition: color16.h:363
color16_data_t::status
uint8_t status
Definition: color16.h:311
color16_t::ldr
digital_out_t ldr
Definition: color16.h:341
color16_cfg_t
Color 16 Click configuration object.
Definition: color16.h:359
color16_data_t::ch_f3
uint16_t ch_f3
Definition: color16.h:320
color16_t::i2c
i2c_master_t i2c
Definition: color16.h:347
color16_t::int_pin
digital_in_t int_pin
Definition: color16.h:344
color16_generic_read
err_t color16_generic_read(color16_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 16 I2C reading function.
color16_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color16.h:366
color16_read_data
err_t color16_read_data(color16_t *ctx, color16_data_t *data_out)
Color 16 read data function.
color16_cfg_t::scl
pin_name_t scl
Definition: color16.h:360
color16_data_t::ch_fxl
uint16_t ch_fxl
Definition: color16.h:315
color16_set_reg_bank_access
err_t color16_set_reg_bank_access(color16_t *ctx, uint8_t reg_bank)
Color 16 set reg bank access function.
color16_generic_write
err_t color16_generic_write(color16_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 16 I2C writing function.
color16_cfg_t::int_pin
pin_name_t int_pin
Definition: color16.h:364
color16_enable_ext_led
err_t color16_enable_ext_led(color16_t *ctx, uint8_t led_curr)
Color 16 enable ext led function.
color16_read_register_word
err_t color16_read_register_word(color16_t *ctx, uint8_t reg, uint16_t *data_out)
Color 16 read register word function.
color16_cfg_t::i2c_address
uint8_t i2c_address
Definition: color16.h:367
color16_data_t
Color 16 Click data object.
Definition: color16.h:310
color16_set_ldr_pin
void color16_set_ldr_pin(color16_t *ctx, uint8_t state)
Color 16 set ldr pin function.
color16_init
err_t color16_init(color16_t *ctx, color16_cfg_t *cfg)
Color 16 initialization function.
color16_data_t::ch_2x_vis_2
uint16_t ch_2x_vis_2
Definition: color16.h:323
color16_data_t::ch_f4
uint16_t ch_f4
Definition: color16.h:321
color16_set_integration_time_ms
err_t color16_set_integration_time_ms(color16_t *ctx, float int_time_ms)
Color 16 set integration time ms function.
color16_write_register
err_t color16_write_register(color16_t *ctx, uint8_t reg, uint8_t data_in)
Color 16 write register function.
color16_data_t::ch_f6
uint16_t ch_f6
Definition: color16.h:322
color16_data_t::ch_f2
uint16_t ch_f2
Definition: color16.h:319
color16_t::slave_address
uint8_t slave_address
Definition: color16.h:350
color16_t
Color 16 Click context object.
Definition: color16.h:339
color16_get_int_pin
uint8_t color16_get_int_pin(color16_t *ctx)
Color 16 get int pin function.
color16_return_value_t
color16_return_value_t
Color 16 Click return value data.
Definition: color16.h:376
color16_data_t::ch_fd_1
uint16_t ch_fd_1
Definition: color16.h:318
COLOR16_OK
@ COLOR16_OK
Definition: color16.h:377
color16_data_t::ch_f7
uint16_t ch_f7
Definition: color16.h:327
color16_disable_ext_led
err_t color16_disable_ext_led(color16_t *ctx)
Color 16 disable ext led function.
color16_data_t::ch_nir
uint16_t ch_nir
Definition: color16.h:316
color16_set_wait_time_ms
err_t color16_set_wait_time_ms(color16_t *ctx, float wait_time_ms)
Color 16 set wait time ms function.
color16_cfg_t::sda
pin_name_t sda
Definition: color16.h:361
color16_check_communication
err_t color16_check_communication(color16_t *ctx)
Color 16 check communication function.
color16_data_t::ch_f8
uint16_t ch_f8
Definition: color16.h:328
color16_write_register_word
err_t color16_write_register_word(color16_t *ctx, uint8_t reg, uint16_t data_in)
Color 16 write register word function.
color16_data_t::ch_f5
uint16_t ch_f5
Definition: color16.h:326
color16_data_t::ch_fz
uint16_t ch_fz
Definition: color16.h:313
color16_default_cfg
err_t color16_default_cfg(color16_t *ctx)
Color 16 default configuration function.
color16_data_t::ch_fy
uint16_t ch_fy
Definition: color16.h:314
color16_data_t::ch_2x_vis_1
uint16_t ch_2x_vis_1
Definition: color16.h:317
color16_data_t::ch_fd_2
uint16_t ch_fd_2
Definition: color16.h:324
color16_cfg_setup
void color16_cfg_setup(color16_cfg_t *cfg)
Color 16 configuration object setup function.
color16_data_t::ch_2x_vis_3
uint16_t ch_2x_vis_3
Definition: color16.h:329
color16_data_t::astatus
uint8_t astatus
Definition: color16.h:312
color16_data_t::ch_f1
uint16_t ch_f1
Definition: color16.h:325