color4  2.1.0.0
color4.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 COLOR4_H
29 #define COLOR4_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 COLOR4_CMD_CODE_CONF 0x00
74 #define COLOR4_CMD_CODE_RED 0x08
75 #define COLOR4_CMD_CODE_GREEN 0x09
76 #define COLOR4_CMD_CODE_BLUE 0x0A
77 #define COLOR4_CMD_CODE_WHITE 0x0B
78  // color4_reg
80 
95 #define COLOR4_INTEGRATION_TIME_40MS 0x00
96 #define COLOR4_INTEGRATION_TIME_80MS 0x10
97 #define COLOR4_INTEGRATION_TIME_160MS 0x20
98 #define COLOR4_INTEGRATION_TIME_320MS 0x30
99 #define COLOR4_INTEGRATION_TIME_640MS 0x40
100 #define COLOR4_INTEGRATION_TIME_1280MS 0x50
101 #define COLOR4_INTEGRATION_BIT_MASK 0x70
102 
103 #define COLOR4_TRIG_DISABLE 0x00
104 #define COLOR4_TRIG_ENABLE 0x04
105 #define COLOR4_TRIG_BIT_MASK 0x04
106 
107 #define COLOR4_AF_AUTO 0x00
108 #define COLOR4_AF_FORCE 0x02
109 #define COLOR4_AF_BIT_MASK 0x02
110 
111 #define COLOR4_SD_ENABLE 0x00
112 #define COLOR4_SD_DISABLE 0x01
113 #define COLOR4_SD_BIT_MASK 0x01
114 
115 
121 #define COLOR4_DEVICE_ADDRESS 0x10
122  // color4_set
124 
139 #define COLOR4_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
142  // color4_map // color4
145 
150 typedef struct
151 {
152  // Modules
153  i2c_master_t i2c;
155  // I2C slave address
156  uint8_t slave_address;
158  float offset;
160 } color4_t;
161 
166 typedef struct
167 {
168  pin_name_t scl;
169  pin_name_t sda;
171  uint32_t i2c_speed;
172  uint8_t i2c_address;
174 } color4_cfg_t;
175 
180 typedef enum
181 {
183  COLOR4_ERROR = -1
184 
186 
191 typedef enum
192 {
197 
199 
204 typedef struct
205 {
207  uint8_t trig;
208  uint8_t mode;
209  uint8_t chip_shutdown;
212 
229 
243 err_t color4_init ( color4_t *ctx, color4_cfg_t *cfg );
244 
259 
274 err_t color4_generic_write ( color4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
275 
290 err_t color4_generic_read ( color4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
291 
306 
321 
337 err_t color4_get_color_data ( color4_t *ctx, color4_ch_color_t ch_color, uint16_t *color_data );
338 
353 err_t color4_get_ambient_light ( color4_t *ctx, float *ambient_light );
354 
370 err_t color4_get_cct ( color4_t *ctx, float *cct );
371 
372 #ifdef __cplusplus
373 }
374 #endif
375 #endif // COLOR4_H
376  // color4
378 
379 // ------------------------------------------------------------------------ END
COLOR4_RED
@ COLOR4_RED
Definition: color4.h:193
color4_generic_write
err_t color4_generic_write(color4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 4 I2C writing function.
color4_cfg_t
Color 4 Click configuration object.
Definition: color4.h:167
color4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color4.h:171
color4_default_cfg
err_t color4_default_cfg(color4_t *ctx)
Color 4 default configuration function.
color4_init
err_t color4_init(color4_t *ctx, color4_cfg_t *cfg)
Color 4 initialization function.
color4_config_t::chip_shutdown
uint8_t chip_shutdown
Definition: color4.h:209
color4_config_t::integration_time
uint8_t integration_time
Definition: color4.h:206
color4_ch_color_t
color4_ch_color_t
Color 4 Click channel selection value data.
Definition: color4.h:192
color4_get_color_data
err_t color4_get_color_data(color4_t *ctx, color4_ch_color_t ch_color, uint16_t *color_data)
Color 4 get color data function.
COLOR4_WHITE
@ COLOR4_WHITE
Definition: color4.h:196
color4_cfg_setup
void color4_cfg_setup(color4_cfg_t *cfg)
Color 4 configuration object setup function.
COLOR4_ERROR
@ COLOR4_ERROR
Definition: color4.h:183
color4_t::offset
float offset
Definition: color4.h:158
color4_set_config
err_t color4_set_config(color4_t *ctx, color4_config_t config)
Color 4 set configuration function.
color4_generic_read
err_t color4_generic_read(color4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 4 I2C reading function.
color4_cfg_t::sda
pin_name_t sda
Definition: color4.h:169
COLOR4_GREEN
@ COLOR4_GREEN
Definition: color4.h:194
color4_t::slave_address
uint8_t slave_address
Definition: color4.h:156
color4_config_t
Color 4 Click sensor configuration object.
Definition: color4.h:205
color4_t
Color 4 Click context object.
Definition: color4.h:151
color4_config_t::trig
uint8_t trig
Definition: color4.h:207
color4_t::i2c
i2c_master_t i2c
Definition: color4.h:153
color4_cfg_t::i2c_address
uint8_t i2c_address
Definition: color4.h:172
color4_cfg_t::scl
pin_name_t scl
Definition: color4.h:168
COLOR4_BLUE
@ COLOR4_BLUE
Definition: color4.h:195
color4_return_value_t
color4_return_value_t
Color 4 Click return value data.
Definition: color4.h:181
color4_get_cct
err_t color4_get_cct(color4_t *ctx, float *cct)
Color 4 get CCT data function.
color4_get_ambient_light
err_t color4_get_ambient_light(color4_t *ctx, float *ambient_light)
Color 4 get ambient light level function.
color4_config_t::mode
uint8_t mode
Definition: color4.h:208
COLOR4_OK
@ COLOR4_OK
Definition: color4.h:182
color4_get_config
err_t color4_get_config(color4_t *ctx, color4_config_t *config)
Color 4 get configuration function.