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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define COLOR11_REG_RAM_START 0x00
60 #define COLOR11_REG_ENABLE 0x80
61 #define COLOR11_REG_ATIME 0x81
62 #define COLOR11_REG_PTIME 0x82
63 #define COLOR11_REG_WTIME 0x83
64 #define COLOR11_REG_AILTL 0x84
65 #define COLOR11_REG_AILTH 0x85
66 #define COLOR11_REG_AIHTL 0x86
67 #define COLOR11_REG_AIHTH 0x87
68 #define COLOR11_REG_AUXID 0x90
69 #define COLOR11_REG_REVID 0x91
70 #define COLOR11_REG_ID 0x92
71 #define COLOR11_REG_STATUS 0x93
72 #define COLOR11_REG_ASTATUS 0x94
73 #define COLOR11_REG_ADATAL0 0x95
74 #define COLOR11_REG_ADATAH0 0x96
75 #define COLOR11_REG_ADATAL1 0x97
76 #define COLOR11_REG_ADATAH1 0x98
77 #define COLOR11_REG_ADATAL2 0x99
78 #define COLOR11_REG_ADATAH2 0x9A
79 #define COLOR11_REG_ADATAL3 0x9B
80 #define COLOR11_REG_ADATAH3 0x9C
81 #define COLOR11_REG_ADATAL4 0x9D
82 #define COLOR11_REG_ADATAH4 0x9E
83 #define COLOR11_REG_ADATAL5 0x9F
84 #define COLOR11_REG_ADATAH5 0xA0
85 #define COLOR11_REG_STATUS2 0xA3
86 #define COLOR11_REG_STATUS3 0xA4
87 #define COLOR11_REG_STATUS5 0xA6
88 #define COLOR11_REG_STATUS6 0xA7
89 #define COLOR11_REG_CFG0 0xA9
90 #define COLOR11_REG_CFG1 0xAA
91 #define COLOR11_REG_CFG3 0xAC
92 #define COLOR11_REG_CFG4 0xAD
93 #define COLOR11_REG_CFG6 0xAF
94 #define COLOR11_REG_CFG8 0xB1
95 #define COLOR11_REG_CFG9 0xB2
96 #define COLOR11_REG_CFG10 0xB3
97 #define COLOR11_REG_CFG11 0xB4
98 #define COLOR11_REG_CFG12 0xB5
99 #define COLOR11_REG_PERS 0xBD
100 #define COLOR11_REG_POFFSETH 0xC8
101 #define COLOR11_REG_ASTEPL 0xCA
102 #define COLOR11_REG_ASTEPH 0xCB
103 #define COLOR11_REG_AGC_GAIN_MAX 0xCF
104 #define COLOR11_REG_AZCONFIG 0xD6
105 #define COLOR11_REG_FD_STATUS 0xDB
106 #define COLOR11_REG_INTENAB 0xF9
107 #define COLOR11_REG_CONTROL 0xFA
108  // color11_reg
110 
125 #define COLOR11_ID_AUX 0x4A
126 #define COLOR11_ID_REV 0x53
127 #define COLOR11_ID_DEV 0x18
128 
133 #define COLOR11_ALS_INTEG_TIME_DEFAULT 19000
134 #define COLOR11_ALS_STEP_DEFAULT 2780
135 #define COLOR11_ALS_THOLD_LOW_DEFAULT 0x0000u
136 #define COLOR11_ALS_THOLD_HIGH_DEFAULT 0xFFFFu
137 
142 #define COLOR11_SET_INTENAB_ASI_DIS 0x00
143 #define COLOR11_SET_INTENAB_ASI_EN 0x80
144 #define COLOR11_SET_INTENAB_AI_DIS 0x00
145 #define COLOR11_SET_INTENAB_AI_EN 0x08
146 #define COLOR11_SET_INTENAB_SI_DIS 0x00
147 #define COLOR11_SET_INTENAB_SI_EN 0x01
148 
153 #define COLOR11_STATUS2_AVALID 0x40
154 #define COLOR11_STATUS2_ASAT_DIGITAL 0x10
155 #define COLOR11_STATUS2_ASAT_ANALOG 0x08
156 #define COLOR11_STATUS2_FDSAT_ANALOG 0x02
157 #define COLOR11_STATUS2_FDSAT_DIGITAL 0x01
158 
163 #define COLOR11_ALS_STEP_CONV_TO_US 100
164 #define COLOR11_ALS_STEP_MIN_ASTEP 278
165 #define COLOR11_ALS_STEP_COR_FACT 50
166 
171 #define COLOR11_COEF_SCALE_DEFAULT 1000.0f
172 #define COLOR11_COEF_DGF_DEFAULT 898.0f
173 #define COLOR11_COEF_CLR_DEFAULT 210.0f
174 #define COLOR11_COEF_RED_DEFAULT -60.0f
175 #define COLOR11_COEF_GREEN_DEFAULT 10.0f
176 #define COLOR11_COEF_BLUE_DEFAULT -290.0f
177 
183 #define COLOR11_DEVICE_ADDRESS 0x39
184  // color11_set
186 
201 #define COLOR11_MAP_MIKROBUS( cfg, mikrobus ) \
202  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
203  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
204  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
205  // color11_map // color11
208 
213 typedef struct
214 {
215  // Input pins
216  digital_in_t int_pin;
218  // Modules
219  i2c_master_t i2c;
221  // I2C slave address
222  uint8_t slave_address;
224 } color11_t;
225 
230 typedef struct
231 {
232  pin_name_t scl;
233  pin_name_t sda;
235  pin_name_t int_pin;
237  uint32_t i2c_speed;
238  uint8_t i2c_address;
240 } color11_cfg_t;
241 
246 typedef struct
247 {
248  uint16_t clear;
249  uint16_t red;
250  uint16_t green;
251  uint16_t blue;
252  uint16_t wideband;
253  uint16_t flicker;
254 
256 
261 typedef struct
262 {
263  uint8_t aux_id;
264  uint8_t rev_id;
265  uint8_t dev_id;
266 
268 
273 typedef enum
274 {
276  COLOR11_ERROR = -1
277 
279 
284 typedef enum
285 {
288 
290 
295 typedef enum
296 {
310 
312 
329 
343 err_t color11_init ( color11_t *ctx, color11_cfg_t *cfg );
344 
358 
373 err_t color11_generic_write ( color11_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
374 
389 err_t color11_generic_read ( color11_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
390 
406 
421 err_t color11_set_als_thold ( color11_t *ctx, uint16_t l_thold, uint16_t h_thold );
422 
444  color11_pwr_ctrl_t pwr,
445  color11_pwr_ctrl_t aen,
446  color11_pwr_ctrl_t wen,
447  color11_pwr_ctrl_t fden );
448 
462 err_t color11_set_als_step ( color11_t *ctx, uint32_t als_step );
463 
477 err_t color11_get_als_step ( color11_t *ctx, uint32_t *als_step );
478 
492 err_t color11_set_als_wait ( color11_t *ctx, uint8_t wait_time );
493 
507 err_t color11_set_als_time ( color11_t *ctx, uint32_t als_time );
508 
522 err_t color11_get_als_time ( color11_t *ctx, float *als_time );
523 
539 
554 err_t color11_get_gain ( color11_t *ctx, uint8_t *gain );
555 
570 err_t color11_set_interrupt ( color11_t *ctx, uint8_t intenab );
571 
585 err_t color11_get_data_valid_status ( color11_t *ctx, uint8_t *status );
586 
602 
617 err_t color11_get_ir ( color11_t *ctx, float *ir );
618 
633 err_t color11_get_illuminance ( color11_t *ctx, float *lux );
634 
648 
649 #ifdef __cplusplus
650 }
651 #endif
652 #endif // COLOR11_H
653  // color11
655 
656 // ------------------------------------------------------------------------ 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:250
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:235
color11_t::slave_address
uint8_t slave_address
Definition: color11.h:222
COLOR11_ERROR
@ COLOR11_ERROR
Definition: color11.h:276
color11_als_data_t::clear
uint16_t clear
Definition: color11.h:248
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:307
color11_again_t
color11_again_t
Color 11 Click ALS Gain value data.
Definition: color11.h:296
color11_als_data_t::red
uint16_t red
Definition: color11.h:249
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:305
color11_cfg_t::i2c_address
uint8_t i2c_address
Definition: color11.h:238
color11_t::i2c
i2c_master_t i2c
Definition: color11.h:219
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:247
COLOR11_AGAIN_X1
@ COLOR11_AGAIN_X1
Definition: color11.h:298
COLOR11_OK
@ COLOR11_OK
Definition: color11.h:275
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:264
color11_identification_t
Color 11 Click device identification object.
Definition: color11.h:262
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:302
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:301
COLOR11_ENABLE
@ COLOR11_ENABLE
Definition: color11.h:287
COLOR11_DISABLE
@ COLOR11_DISABLE
Definition: color11.h:286
color11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color11.h:237
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:216
color11_cfg_t::scl
pin_name_t scl
Definition: color11.h:232
color11_identification_t::aux_id
uint8_t aux_id
Definition: color11.h:263
COLOR11_AGAIN_X0_5
@ COLOR11_AGAIN_X0_5
Definition: color11.h:297
COLOR11_AGAIN_X32
@ COLOR11_AGAIN_X32
Definition: color11.h:303
color11_identification_t::dev_id
uint8_t dev_id
Definition: color11.h:265
COLOR11_AGAIN_X2048
@ COLOR11_AGAIN_X2048
Definition: color11.h:309
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:233
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:274
color11_als_data_t::blue
uint16_t blue
Definition: color11.h:251
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:253
COLOR11_AGAIN_X1024
@ COLOR11_AGAIN_X1024
Definition: color11.h:308
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:304
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:299
color11_pwr_ctrl_t
color11_pwr_ctrl_t
Color 11 Click power, enable, and operation value data.
Definition: color11.h:285
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:306
color11_t
Color 11 Click context object.
Definition: color11.h:214
COLOR11_AGAIN_X4
@ COLOR11_AGAIN_X4
Definition: color11.h:300
color11_als_data_t::wideband
uint16_t wideband
Definition: color11.h:252
color11_cfg_t
Color 11 Click configuration object.
Definition: color11.h:231
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.