color11  2.1.0.0
color11.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 COLOR11_H
29 #define COLOR11_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 COLOR11_REG_RAM_START 0x00
70 #define COLOR11_REG_ENABLE 0x80
71 #define COLOR11_REG_ATIME 0x81
72 #define COLOR11_REG_PTIME 0x82
73 #define COLOR11_REG_WTIME 0x83
74 #define COLOR11_REG_AILTL 0x84
75 #define COLOR11_REG_AILTH 0x85
76 #define COLOR11_REG_AIHTL 0x86
77 #define COLOR11_REG_AIHTH 0x87
78 #define COLOR11_REG_AUXID 0x90
79 #define COLOR11_REG_REVID 0x91
80 #define COLOR11_REG_ID 0x92
81 #define COLOR11_REG_STATUS 0x93
82 #define COLOR11_REG_ASTATUS 0x94
83 #define COLOR11_REG_ADATAL0 0x95
84 #define COLOR11_REG_ADATAH0 0x96
85 #define COLOR11_REG_ADATAL1 0x97
86 #define COLOR11_REG_ADATAH1 0x98
87 #define COLOR11_REG_ADATAL2 0x99
88 #define COLOR11_REG_ADATAH2 0x9A
89 #define COLOR11_REG_ADATAL3 0x9B
90 #define COLOR11_REG_ADATAH3 0x9C
91 #define COLOR11_REG_ADATAL4 0x9D
92 #define COLOR11_REG_ADATAH4 0x9E
93 #define COLOR11_REG_ADATAL5 0x9F
94 #define COLOR11_REG_ADATAH5 0xA0
95 #define COLOR11_REG_STATUS2 0xA3
96 #define COLOR11_REG_STATUS3 0xA4
97 #define COLOR11_REG_STATUS5 0xA6
98 #define COLOR11_REG_STATUS6 0xA7
99 #define COLOR11_REG_CFG0 0xA9
100 #define COLOR11_REG_CFG1 0xAA
101 #define COLOR11_REG_CFG3 0xAC
102 #define COLOR11_REG_CFG4 0xAD
103 #define COLOR11_REG_CFG6 0xAF
104 #define COLOR11_REG_CFG8 0xB1
105 #define COLOR11_REG_CFG9 0xB2
106 #define COLOR11_REG_CFG10 0xB3
107 #define COLOR11_REG_CFG11 0xB4
108 #define COLOR11_REG_CFG12 0xB5
109 #define COLOR11_REG_PERS 0xBD
110 #define COLOR11_REG_POFFSETH 0xC8
111 #define COLOR11_REG_ASTEPL 0xCA
112 #define COLOR11_REG_ASTEPH 0xCB
113 #define COLOR11_REG_AGC_GAIN_MAX 0xCF
114 #define COLOR11_REG_AZCONFIG 0xD6
115 #define COLOR11_REG_FD_STATUS 0xDB
116 #define COLOR11_REG_INTENAB 0xF9
117 #define COLOR11_REG_CONTROL 0xFA
118  // color11_reg
120 
135 #define COLOR11_ID_AUX 0x4A
136 #define COLOR11_ID_REV 0x53
137 #define COLOR11_ID_DEV 0x18
138 
143 #define COLOR11_ALS_INTEG_TIME_DEFAULT 19000
144 #define COLOR11_ALS_STEP_DEFAULT 2780
145 #define COLOR11_ALS_THOLD_LOW_DEFAULT 0x0000u
146 #define COLOR11_ALS_THOLD_HIGH_DEFAULT 0xFFFFu
147 
152 #define COLOR11_SET_INTENAB_ASI_DIS 0x00
153 #define COLOR11_SET_INTENAB_ASI_EN 0x80
154 #define COLOR11_SET_INTENAB_AI_DIS 0x00
155 #define COLOR11_SET_INTENAB_AI_EN 0x08
156 #define COLOR11_SET_INTENAB_SI_DIS 0x00
157 #define COLOR11_SET_INTENAB_SI_EN 0x01
158 
163 #define COLOR11_STATUS2_AVALID 0x40
164 #define COLOR11_STATUS2_ASAT_DIGITAL 0x10
165 #define COLOR11_STATUS2_ASAT_ANALOG 0x08
166 #define COLOR11_STATUS2_FDSAT_ANALOG 0x02
167 #define COLOR11_STATUS2_FDSAT_DIGITAL 0x01
168 
173 #define COLOR11_ALS_STEP_CONV_TO_US 100
174 #define COLOR11_ALS_STEP_MIN_ASTEP 278
175 #define COLOR11_ALS_STEP_COR_FACT 50
176 
181 #define COLOR11_COEF_SCALE_DEFAULT 1000.0f
182 #define COLOR11_COEF_DGF_DEFAULT 898.0f
183 #define COLOR11_COEF_CLR_DEFAULT 210.0f
184 #define COLOR11_COEF_RED_DEFAULT -60.0f
185 #define COLOR11_COEF_GREEN_DEFAULT 10.0f
186 #define COLOR11_COEF_BLUE_DEFAULT -290.0f
187 
193 #define COLOR11_DEVICE_ADDRESS 0x39
194  // color11_set
196 
211 #define COLOR11_MAP_MIKROBUS( cfg, mikrobus ) \
212  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
213  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
214  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
215  // color11_map // color11
218 
223 typedef struct
224 {
225  // Input pins
226  digital_in_t int_pin;
228  // Modules
229  i2c_master_t i2c;
231  // I2C slave address
232  uint8_t slave_address;
234 } color11_t;
235 
240 typedef struct
241 {
242  pin_name_t scl;
243  pin_name_t sda;
245  pin_name_t int_pin;
247  uint32_t i2c_speed;
248  uint8_t i2c_address;
250 } color11_cfg_t;
251 
256 typedef struct
257 {
258  uint16_t clear;
259  uint16_t red;
260  uint16_t green;
261  uint16_t blue;
262  uint16_t wideband;
263  uint16_t flicker;
264 
266 
271 typedef struct
272 {
273  uint8_t aux_id;
274  uint8_t rev_id;
275  uint8_t dev_id;
276 
278 
283 typedef enum
284 {
286  COLOR11_ERROR = -1
287 
289 
294 typedef enum
295 {
298 
300 
305 typedef enum
306 {
320 
322 
339 
353 err_t color11_init ( color11_t *ctx, color11_cfg_t *cfg );
354 
368 
383 err_t color11_generic_write ( color11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
384 
399 err_t color11_generic_read ( color11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
400 
416 
431 err_t color11_set_als_thold ( color11_t *ctx, uint16_t l_thold, uint16_t h_thold );
432 
454  color11_pwr_ctrl_t pwr,
455  color11_pwr_ctrl_t aen,
456  color11_pwr_ctrl_t wen,
457  color11_pwr_ctrl_t fden );
458 
472 err_t color11_set_als_step ( color11_t *ctx, uint32_t als_step );
473 
487 err_t color11_get_als_step ( color11_t *ctx, uint32_t *als_step );
488 
502 err_t color11_set_als_wait ( color11_t *ctx, uint8_t wait_time );
503 
517 err_t color11_set_als_time ( color11_t *ctx, uint32_t als_time );
518 
532 err_t color11_get_als_time ( color11_t *ctx, float *als_time );
533 
549 
564 err_t color11_get_gain ( color11_t *ctx, uint8_t *gain );
565 
580 err_t color11_set_interrupt ( color11_t *ctx, uint8_t intenab );
581 
595 err_t color11_get_data_valid_status ( color11_t *ctx, uint8_t *status );
596 
612 
627 err_t color11_get_ir ( color11_t *ctx, float *ir );
628 
643 err_t color11_get_illuminance ( color11_t *ctx, float *lux );
644 
658 
659 #ifdef __cplusplus
660 }
661 #endif
662 #endif // COLOR11_H
663  // color11
665 
666 // ------------------------------------------------------------------------ END
color11_set_als_step
err_t color11_set_als_step(color11_t *ctx, uint32_t als_step)
Color 11 set ALS step function.
color11_get_als_step
err_t color11_get_als_step(color11_t *ctx, uint32_t *als_step)
Color 11 get ALS step function.
color11_als_data_t::green
uint16_t green
Definition: color11.h:260
color11_init
err_t color11_init(color11_t *ctx, color11_cfg_t *cfg)
Color 11 initialization function.
color11_cfg_t::int_pin
pin_name_t int_pin
Definition: color11.h:245
color11_t::slave_address
uint8_t slave_address
Definition: color11.h:232
COLOR11_ERROR
@ COLOR11_ERROR
Definition: color11.h:286
color11_als_data_t::clear
uint16_t clear
Definition: color11.h:258
color11_set_power_ctrl
err_t color11_set_power_ctrl(color11_t *ctx, color11_pwr_ctrl_t pwr, color11_pwr_ctrl_t aen, color11_pwr_ctrl_t wen, color11_pwr_ctrl_t fden)
Color 11 set power control function.
COLOR11_AGAIN_X512
@ COLOR11_AGAIN_X512
Definition: color11.h:317
color11_again_t
color11_again_t
Color 11 Click ALS Gain value data.
Definition: color11.h:306
color11_als_data_t::red
uint16_t red
Definition: color11.h:259
color11_get_interrupt
uint8_t color11_get_interrupt(color11_t *ctx)
Color 11 get interrupt function.
color11_get_gain
err_t color11_get_gain(color11_t *ctx, uint8_t *gain)
Color 11 get gain function.
COLOR11_AGAIN_X128
@ COLOR11_AGAIN_X128
Definition: color11.h:315
color11_cfg_t::i2c_address
uint8_t i2c_address
Definition: color11.h:248
color11_t::i2c
i2c_master_t i2c
Definition: color11.h:229
color11_set_als_wait
err_t color11_set_als_wait(color11_t *ctx, uint8_t wait_time)
Color 11 set ALS wait time function.
color11_als_data_t
Color 11 Click ALS data object.
Definition: color11.h:257
COLOR11_AGAIN_X1
@ COLOR11_AGAIN_X1
Definition: color11.h:308
COLOR11_OK
@ COLOR11_OK
Definition: color11.h:285
color11_generic_read
err_t color11_generic_read(color11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 11 I2C reading function.
color11_identification_t::rev_id
uint8_t rev_id
Definition: color11.h:274
color11_identification_t
Color 11 Click device identification object.
Definition: color11.h:272
color11_generic_write
err_t color11_generic_write(color11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 11 I2C writing function.
COLOR11_AGAIN_X16
@ COLOR11_AGAIN_X16
Definition: color11.h:312
color11_set_interrupt
err_t color11_set_interrupt(color11_t *ctx, uint8_t intenab)
Color 11 set interrupt function.
COLOR11_AGAIN_X8
@ COLOR11_AGAIN_X8
Definition: color11.h:311
COLOR11_ENABLE
@ COLOR11_ENABLE
Definition: color11.h:297
COLOR11_DISABLE
@ COLOR11_DISABLE
Definition: color11.h:296
color11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color11.h:247
color11_get_identification
err_t color11_get_identification(color11_t *ctx, color11_identification_t *id)
Color 11 get identification function.
color11_set_als_time
err_t color11_set_als_time(color11_t *ctx, uint32_t als_time)
Color 11 set ALS integration time function.
color11_t::int_pin
digital_in_t int_pin
Definition: color11.h:226
color11_cfg_t::scl
pin_name_t scl
Definition: color11.h:242
color11_identification_t::aux_id
uint8_t aux_id
Definition: color11.h:273
COLOR11_AGAIN_X0_5
@ COLOR11_AGAIN_X0_5
Definition: color11.h:307
COLOR11_AGAIN_X32
@ COLOR11_AGAIN_X32
Definition: color11.h:313
color11_identification_t::dev_id
uint8_t dev_id
Definition: color11.h:275
COLOR11_AGAIN_X2048
@ COLOR11_AGAIN_X2048
Definition: color11.h:319
color11_set_als_thold
err_t color11_set_als_thold(color11_t *ctx, uint16_t l_thold, uint16_t h_thold)
Color 11 set ALS interrupt threshold function.
color11_cfg_t::sda
pin_name_t sda
Definition: color11.h:243
color11_set_gain
err_t color11_set_gain(color11_t *ctx, color11_again_t gain)
Color 11 set gain function.
color11_return_value_t
color11_return_value_t
Color 11 Click return value data.
Definition: color11.h:284
color11_als_data_t::blue
uint16_t blue
Definition: color11.h:261
color11_get_ir
err_t color11_get_ir(color11_t *ctx, float *ir)
Color 11 get IR data function.
color11_cfg_setup
void color11_cfg_setup(color11_cfg_t *cfg)
Color 11 configuration object setup function.
color11_get_data_valid_status
err_t color11_get_data_valid_status(color11_t *ctx, uint8_t *status)
Color 11 get data valid status function.
color11_als_data_t::flicker
uint16_t flicker
Definition: color11.h:263
COLOR11_AGAIN_X1024
@ COLOR11_AGAIN_X1024
Definition: color11.h:318
color11_default_cfg
err_t color11_default_cfg(color11_t *ctx)
Color 11 default configuration function.
COLOR11_AGAIN_X64
@ COLOR11_AGAIN_X64
Definition: color11.h:314
color11_get_als_time
err_t color11_get_als_time(color11_t *ctx, float *als_time)
Color 11 get ALS integration time function.
COLOR11_AGAIN_X2
@ COLOR11_AGAIN_X2
Definition: color11.h:309
color11_pwr_ctrl_t
color11_pwr_ctrl_t
Color 11 Click power, enable, and operation value data.
Definition: color11.h:295
color11_get_illuminance
err_t color11_get_illuminance(color11_t *ctx, float *lux)
Color 11 get illuminance function.
COLOR11_AGAIN_X256
@ COLOR11_AGAIN_X256
Definition: color11.h:316
color11_t
Color 11 Click context object.
Definition: color11.h:224
COLOR11_AGAIN_X4
@ COLOR11_AGAIN_X4
Definition: color11.h:310
color11_als_data_t::wideband
uint16_t wideband
Definition: color11.h:262
color11_cfg_t
Color 11 Click configuration object.
Definition: color11.h:241
color11_get_als_data
err_t color11_get_als_data(color11_t *ctx, color11_als_data_t *als_data)
Color 11 get ALS data function.