color18  2.1.0.0
color18.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 COLOR18_H
29 #define COLOR18_H
30 
31 #ifdef __cplusplus
32 extern "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 COLOR18_REG_CONTROL_SCL 0x24
74 #define COLOR18_REG_MOD_OFFSET0_LSB 0x40
75 #define COLOR18_REG_MOD_OFFSET0_MSB 0x41
76 #define COLOR18_REG_MOD_OFFSET1_LSB 0x42
77 #define COLOR18_REG_MOD_OFFSET1_MSB 0x43
78 #define COLOR18_REG_MOD_OFFSET2_LSB 0x44
79 #define COLOR18_REG_MOD_OFFSET2_MSB 0x45
80 #define COLOR18_REG_MOD_OFFSET3_LSB 0x46
81 #define COLOR18_REG_MOD_OFFSET3_MSB 0x47
82 #define COLOR18_REG_MOD_OFFSET4_LSB 0x48
83 #define COLOR18_REG_MOD_OFFSET4_MSB 0x49
84 #define COLOR18_REG_MOD_OFFSET5_LSB 0x4A
85 #define COLOR18_REG_MOD_OFFSET5_MSB 0x4B
86 #define COLOR18_REG_MOD_OFFSET6_LSB 0x4C
87 #define COLOR18_REG_MOD_OFFSET6_MSB 0x4D
88 #define COLOR18_REG_MOD_OFFSET7_LSB 0x4E
89 #define COLOR18_REG_MOD_OFFSET7_MSB 0x4F
90 #define COLOR18_REG_OSCEN 0x7F
91 #define COLOR18_REG_ENABLE 0x80
92 #define COLOR18_REG_MEAS_MODE0 0x81
93 #define COLOR18_REG_MEAS_MODE1 0x82
94 #define COLOR18_REG_SAMPLE_TIME0 0x83
95 #define COLOR18_REG_SAMPLE_TIME1 0x84
96 #define COLOR18_REG_SAMPLE_TIME_ALTERNATIVE0 0x85
97 #define COLOR18_REG_SAMPLE_TIME_ALTERNATIVE1 0x86
98 #define COLOR18_REG_ALS_NR_SAMPLES0 0x87
99 #define COLOR18_REG_ALS_NR_SAMPLES1 0x88
100 #define COLOR18_REG_ALS_NR_SAMPLES_ALTERNATIVE0 0x89
101 #define COLOR18_REG_ALS_NR_SAMPLES_ALTERNATIVE1 0x8A
102 #define COLOR18_REG_FD_NR_SAMPLES0 0x8B
103 #define COLOR18_REG_FD_NR_SAMPLES1 0x8C
104 #define COLOR18_REG_FD_NR_SAMPLES_ALTERNATIVE0 0x8D
105 #define COLOR18_REG_FD_NR_SAMPLES_ALTERNATIVE1 0x8E
106 #define COLOR18_REG_WTIME 0x8F
107 #define COLOR18_REG_AUX_ID 0x90
108 #define COLOR18_REG_REV_ID 0x91
109 #define COLOR18_REG_ID 0x92
110 #define COLOR18_REG_AILT0 0x93
111 #define COLOR18_REG_AILT1 0x94
112 #define COLOR18_REG_AILT2 0x95
113 #define COLOR18_REG_AIHT0 0x96
114 #define COLOR18_REG_AIHT1 0x97
115 #define COLOR18_REG_AIHT2 0x98
116 #define COLOR18_REG_AGC_NR_SAMPLES0 0x99
117 #define COLOR18_REG_AGC_NR_SAMPLES1 0x9A
118 #define COLOR18_REG_STATUS 0x9B
119 #define COLOR18_REG_STATUS2 0x9C
120 #define COLOR18_REG_STATUS3 0x9D
121 #define COLOR18_REG_STATUS4 0x9E
122 #define COLOR18_REG_STATUS5 0x9F
123 #define COLOR18_REG_STATUS6 0xA0
124 #define COLOR18_REG_CFG0 0xA1
125 #define COLOR18_REG_CFG1 0xA2
126 #define COLOR18_REG_CFG2 0xA3
127 #define COLOR18_REG_CFG3 0xA4
128 #define COLOR18_REG_CFG4 0xA5
129 #define COLOR18_REG_CFG5 0xA6
130 #define COLOR18_REG_CFG6 0xA7
131 #define COLOR18_REG_CFG7 0xA8
132 #define COLOR18_REG_CFG8 0xA9
133 #define COLOR18_REG_CFG9 0xAA
134 #define COLOR18_REG_MOD_CHANNEL_CTRL 0xAB
135 #define COLOR18_REG_TRIGGER_MODE 0xAD
136 #define COLOR18_REG_OSC_TUNE 0xAE
137 #define COLOR18_REG_VSYNC_GPIO_INT 0xB0
138 #define COLOR18_REG_INTENAB 0xBA
139 #define COLOR18_REG_SIEN 0xBB
140 #define COLOR18_REG_CONTROL 0xBC
141 #define COLOR18_REG_ALS_DATA_STATUS 0xBD
142 #define COLOR18_REG_ALS_DATA_FIRST 0xBE
143 #define COLOR18_REG_ALS_DATA 0xBF
144 #define COLOR18_REG_MEAS_SEQR_STEP0_MOD_GAINX_0 0xC0
145 #define COLOR18_REG_MEAS_SEQR_STEP0_MOD_GAINX_1 0xC1
146 #define COLOR18_REG_MEAS_SEQR_STEP0_MOD_GAINX_2 0xC2
147 #define COLOR18_REG_MEAS_SEQR_STEP0_MOD_GAINX_3 0xC3
148 #define COLOR18_REG_MEAS_SEQR_STEP1_MOD_GAINX_0 0xC4
149 #define COLOR18_REG_MEAS_SEQR_STEP1_MOD_GAINX_1 0xC5
150 #define COLOR18_REG_MEAS_SEQR_STEP1_MOD_GAINX_2 0xC6
151 #define COLOR18_REG_MEAS_SEQR_STEP1_MOD_GAINX_3 0xC7
152 #define COLOR18_REG_MEAS_SEQR_STEP2_MOD_GAINX_0 0xC8
153 #define COLOR18_REG_MEAS_SEQR_STEP2_MOD_GAINX_1 0xC9
154 #define COLOR18_REG_MEAS_SEQR_STEP2_MOD_GAINX_2 0xCA
155 #define COLOR18_REG_MEAS_SEQR_STEP2_MOD_GAINX_3 0xCB
156 #define COLOR18_REG_MEAS_SEQR_STEP3_MOD_GAINX_0 0xCC
157 #define COLOR18_REG_MEAS_SEQR_STEP3_MOD_GAINX_1 0xCD
158 #define COLOR18_REG_MEAS_SEQR_STEP3_MOD_GAINX_2 0xCE
159 #define COLOR18_REG_MEAS_SEQR_STEP3_MOD_GAINX_3 0xCF
160 #define COLOR18_REG_MEAS_SEQR_STEP0_FD 0xD0
161 #define COLOR18_REG_MEAS_SEQR_STEP1_FD 0xD1
162 #define COLOR18_REG_MEAS_SEQR_STEP2_FD 0xD2
163 #define COLOR18_REG_MEAS_SEQR_STEP3_FD 0xD3
164 #define COLOR18_REG_MEAS_SEQR_STEP0_RESIDUAL 0xD4
165 #define COLOR18_REG_MEAS_SEQR_STEP1_RESIDUAL 0xD5
166 #define COLOR18_REG_MEAS_SEQR_STEP2_RESIDUAL 0xD6
167 #define COLOR18_REG_MEAS_SEQR_STEP3_RESIDUAL 0xD7
168 #define COLOR18_REG_MEAS_SEQR_STEP0_ALS 0xD8
169 #define COLOR18_REG_MEAS_SEQR_STEP1_ALS 0xD9
170 #define COLOR18_REG_MEAS_SEQR_STEP2_ALS 0xDA
171 #define COLOR18_REG_MEAS_SEQR_STEP3_ALS 0xDB
172 #define COLOR18_REG_MEAS_SEQR_APERS_AND_VSYNC_WAIT 0xDC
173 #define COLOR18_REG_MEAS_SEQR_AGC 0xDD
174 #define COLOR18_REG_MEAS_SEQR_SMUX_AND_SAMPLE_TIME 0xDE
175 #define COLOR18_REG_MEAS_SEQR_WAIT_AND_TS_ENABLE 0xDF
176 #define COLOR18_REG_MOD_CALIB_CFG0 0xE0
177 #define COLOR18_REG_MOD_CALIB_CFG2 0xE2
178 #define COLOR18_REG_MOD_CALIB_CFG3 0xE3
179 #define COLOR18_REG_MOD_COMP_CFG2 0xE7
180 #define COLOR18_REG_MOD_RESIDUAL_CFG0 0xE8
181 #define COLOR18_REG_MOD_RESIDUAL_CFG1 0xE9
182 #define COLOR18_REG_MOD_RESIDUAL_CFG2 0xEA
183 #define COLOR18_REG_VSYNC_DELAY_CFG0 0xEB
184 #define COLOR18_REG_VSYNC_DELAY_CFG1 0xEC
185 #define COLOR18_REG_VSYNC_PERIOD0 0xED
186 #define COLOR18_REG_VSYNC_PERIOD1 0xEE
187 #define COLOR18_REG_VSYNC_PERIOD_TARGET0 0xEF
188 #define COLOR18_REG_VSYNC_PERIOD_TARGET1 0xF0
189 #define COLOR18_REG_VSYNC_CONTROL 0xF1
190 #define COLOR18_REG_VSYNC_CFG 0xF2
191 #define COLOR18_REG_FIFO_THR 0xF3
192 #define COLOR18_REG_MOD_FIFO_DATA_CFG0 0xF4
193 #define COLOR18_REG_MOD_FIFO_DATA_CFG1 0xF5
194 #define COLOR18_REG_MOD_FIFO_DATA_CFG2 0xF6
195 #define COLOR18_REG_MOD_FIFO_DATA_CFG3 0xF7
196 #define COLOR18_REG_MOD_FIFO_DATA_CFG4 0xF8
197 #define COLOR18_REG_MOD_FIFO_DATA_CFG5 0xF9
198 #define COLOR18_REG_MOD_FIFO_DATA_CFG6 0xFA
199 #define COLOR18_REG_MOD_FIFO_DATA_CFG7 0xFB
200 #define COLOR18_REG_FIFO_STATUS0 0xFC
201 #define COLOR18_REG_FIFO_STATUS1 0xFD
202 #define COLOR18_REG_FIFO_DATA_PROTOCOL 0xFE
203 #define COLOR18_REG_FIFO_DATA 0xFF
204  // color18_reg
206 
221 #define COLOR18_CONTROL_SCL_SOFT_RESET 0x01
222 
227 #define COLOR18_OSCEN_PON_INIT 0x04
228 #define COLOR18_OSCEN_OSCEN_STATUS 0x02
229 #define COLOR18_OSCEN_OSCEN 0x01
230 
235 #define COLOR18_ENABLE_FDEN 0x40
236 #define COLOR18_ENABLE_AEN 0x02
237 #define COLOR18_ENABLE_PON 0x01
238 
243 #define COLOR18_WTIME_DEFAULT 0x46
244 
249 #define COLOR18_TRIGGER_MODE_OFF 0x00
250 #define COLOR18_TRIGGER_MODE_NORMAL 0x01
251 #define COLOR18_TRIGGER_MODE_LONG 0x02
252 #define COLOR18_TRIGGER_MODE_FAST 0x03
253 #define COLOR18_TRIGGER_MODE_FASTLONG 0x04
254 #define COLOR18_TRIGGER_MODE_VSYNC 0x05
255 #define COLOR18_TRIGGER_MODE_MASK 0x07
256 
261 #define COLOR18_INTENAB_MIEN 0x80
262 #define COLOR18_INTENAB_AIEN 0x08
263 #define COLOR18_INTENAB_FIEN 0x04
264 #define COLOR18_INTENAB_SIEN 0x01
265 
270 #define COLOR18_FIFO_THR_DEFAULT 15
271 
276 #define COLOR18_CONTROL_FIFO_CLR 0x02
277 #define COLOR18_CONTROL_CLEAR_SAI_ACTIVE 0x01
278 
283 #define COLOR18_DEVICE_ID 0x68
284 
290 #define COLOR18_DEVICE_ADDRESS 0x39
291  // color18_set
293 
308 #define COLOR18_MAP_MIKROBUS( cfg, mikrobus ) \
309  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
310  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
311  cfg.vsync = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
312  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
313  // color18_map // color18
316 
321 typedef struct
322 {
323  uint16_t x;
324  uint16_t y;
325  uint16_t z;
326  uint16_t ir;
327  uint16_t hgl;
328  uint16_t hgh;
329  uint16_t clear;
330  uint16_t flicker;
333 
338 typedef struct
339 {
340  // Output pins
341  digital_out_t vsync;
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 } color18_t;
353 
358 typedef struct
359 {
360  pin_name_t scl;
361  pin_name_t sda;
363  pin_name_t vsync;
364  pin_name_t int_pin;
366  uint32_t i2c_speed;
367  uint8_t i2c_address;
369 } color18_cfg_t;
370 
375 typedef enum
376 {
378  COLOR18_ERROR = -1
379 
381 
398 
412 err_t color18_init ( color18_t *ctx, color18_cfg_t *cfg );
413 
427 
442 err_t color18_write_regs ( color18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
443 
458 err_t color18_read_regs ( color18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
459 
472 err_t color18_write_reg ( color18_t *ctx, uint8_t reg, uint8_t data_in );
473 
486 err_t color18_read_reg ( color18_t *ctx, uint8_t reg, uint8_t *data_out );
487 
501 err_t color18_write_reg_word ( color18_t *ctx, uint8_t reg, uint16_t data_in );
502 
516 err_t color18_read_reg_word ( color18_t *ctx, uint8_t reg, uint16_t *data_out );
517 
529 
539 void color18_set_vsync_pin ( color18_t *ctx, uint8_t state );
540 
550 
562 
574 
586 err_t color18_read_fifo_size ( color18_t *ctx, uint16_t *fifo_size );
587 
600 err_t color18_read_data ( color18_t *ctx, color18_data_t *data_out );
601 
602 #ifdef __cplusplus
603 }
604 #endif
605 #endif // COLOR18_H
606  // color18
608 
609 // ------------------------------------------------------------------------ END
color18_t::slave_address
uint8_t slave_address
Definition: color18.h:350
color18_read_data
err_t color18_read_data(color18_t *ctx, color18_data_t *data_out)
Color 18 read data function.
color18_data_t::ir
uint16_t ir
Definition: color18.h:326
color18_return_value_t
color18_return_value_t
Color 18 Click return value data.
Definition: color18.h:376
color18_write_regs
err_t color18_write_regs(color18_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 18 write regs function.
color18_data_t::flicker
uint16_t flicker
Definition: color18.h:330
color18_check_communication
err_t color18_check_communication(color18_t *ctx)
Color 18 check communication function.
color18_soft_reset
err_t color18_soft_reset(color18_t *ctx)
Color 18 soft reset function.
color18_read_reg
err_t color18_read_reg(color18_t *ctx, uint8_t reg, uint8_t *data_out)
Color 18 read reg function.
color18_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color18.h:366
color18_default_cfg
err_t color18_default_cfg(color18_t *ctx)
Color 18 default configuration function.
color18_set_vsync_pin
void color18_set_vsync_pin(color18_t *ctx, uint8_t state)
Color 18 set vsync pin state function.
color18_write_reg_word
err_t color18_write_reg_word(color18_t *ctx, uint8_t reg, uint16_t data_in)
Color 18 write reg word function.
color18_read_regs
err_t color18_read_regs(color18_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 18 read regs function.
color18_write_reg
err_t color18_write_reg(color18_t *ctx, uint8_t reg, uint8_t data_in)
Color 18 write reg function.
color18_cfg_t::sda
pin_name_t sda
Definition: color18.h:361
color18_clear_fifo
err_t color18_clear_fifo(color18_t *ctx)
Color 18 clear fifo function.
COLOR18_ERROR
@ COLOR18_ERROR
Definition: color18.h:378
color18_cfg_t::i2c_address
uint8_t i2c_address
Definition: color18.h:367
color18_t::i2c
i2c_master_t i2c
Definition: color18.h:347
color18_data_t::clear
uint16_t clear
Definition: color18.h:329
color18_cfg_setup
void color18_cfg_setup(color18_cfg_t *cfg)
Color 18 configuration object setup function.
color18_init
err_t color18_init(color18_t *ctx, color18_cfg_t *cfg)
Color 18 initialization function.
color18_read_reg_word
err_t color18_read_reg_word(color18_t *ctx, uint8_t reg, uint16_t *data_out)
Color 18 read reg word function.
COLOR18_OK
@ COLOR18_OK
Definition: color18.h:377
color18_read_fifo_size
err_t color18_read_fifo_size(color18_t *ctx, uint16_t *fifo_size)
Color 18 read fifo size function.
color18_data_t::z
uint16_t z
Definition: color18.h:325
color18_data_t::x
uint16_t x
Definition: color18.h:323
color18_data_t
Color 18 Click data object.
Definition: color18.h:322
color18_t::int_pin
digital_in_t int_pin
Definition: color18.h:344
color18_t
Color 18 Click context object.
Definition: color18.h:339
color18_cfg_t::scl
pin_name_t scl
Definition: color18.h:360
color18_data_t::hgh
uint16_t hgh
Definition: color18.h:328
color18_get_int_pin
uint8_t color18_get_int_pin(color18_t *ctx)
Color 18 get int pin state function.
color18_cfg_t::vsync
pin_name_t vsync
Definition: color18.h:363
color18_cfg_t::int_pin
pin_name_t int_pin
Definition: color18.h:364
color18_t::vsync
digital_out_t vsync
Definition: color18.h:341
color18_data_t::hgl
uint16_t hgl
Definition: color18.h:327
color18_data_t::y
uint16_t y
Definition: color18.h:324
color18_cfg_t
Color 18 Click configuration object.
Definition: color18.h:359