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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define COLOR4_CMD_CODE_CONF 0x00
60 #define COLOR4_CMD_CODE_RED 0x08
61 #define COLOR4_CMD_CODE_GREEN 0x09
62 #define COLOR4_CMD_CODE_BLUE 0x0A
63 #define COLOR4_CMD_CODE_WHITE 0x0B
64  // color4_reg
66 
81 #define COLOR4_INTEGRATION_TIME_40MS 0x00
82 #define COLOR4_INTEGRATION_TIME_80MS 0x10
83 #define COLOR4_INTEGRATION_TIME_160MS 0x20
84 #define COLOR4_INTEGRATION_TIME_320MS 0x30
85 #define COLOR4_INTEGRATION_TIME_640MS 0x40
86 #define COLOR4_INTEGRATION_TIME_1280MS 0x50
87 #define COLOR4_INTEGRATION_BIT_MASK 0x70
88 
89 #define COLOR4_TRIG_DISABLE 0x00
90 #define COLOR4_TRIG_ENABLE 0x04
91 #define COLOR4_TRIG_BIT_MASK 0x04
92 
93 #define COLOR4_AF_AUTO 0x00
94 #define COLOR4_AF_FORCE 0x02
95 #define COLOR4_AF_BIT_MASK 0x02
96 
97 #define COLOR4_SD_ENABLE 0x00
98 #define COLOR4_SD_DISABLE 0x01
99 #define COLOR4_SD_BIT_MASK 0x01
100 
101 
107 #define COLOR4_DEVICE_ADDRESS 0x10
108  // color4_set
110 
125 #define COLOR4_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
127  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
128  // color4_map // color4
131 
136 typedef struct
137 {
138  // Modules
139  i2c_master_t i2c;
141  // I2C slave address
142  uint8_t slave_address;
144  float offset;
146 } color4_t;
147 
152 typedef struct
153 {
154  pin_name_t scl;
155  pin_name_t sda;
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
160 } color4_cfg_t;
161 
166 typedef enum
167 {
169  COLOR4_ERROR = -1
170 
172 
177 typedef enum
178 {
183 
185 
190 typedef struct
191 {
193  uint8_t trig;
194  uint8_t mode;
195  uint8_t chip_shutdown;
198 
215 
229 err_t color4_init ( color4_t *ctx, color4_cfg_t *cfg );
230 
245 
260 err_t color4_generic_write ( color4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
261 
276 err_t color4_generic_read ( color4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
277 
292 
307 
323 err_t color4_get_color_data ( color4_t *ctx, color4_ch_color_t ch_color, uint16_t *color_data );
324 
339 err_t color4_get_ambient_light ( color4_t *ctx, float *ambient_light );
340 
356 err_t color4_get_cct ( color4_t *ctx, float *cct );
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 #endif // COLOR4_H
362  // color4
364 
365 // ------------------------------------------------------------------------ END
COLOR4_RED
@ COLOR4_RED
Definition: color4.h:179
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:153
color4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color4.h:157
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:195
color4_config_t::integration_time
uint8_t integration_time
Definition: color4.h:192
color4_ch_color_t
color4_ch_color_t
Color 4 Click channel selection value data.
Definition: color4.h:178
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:182
color4_cfg_setup
void color4_cfg_setup(color4_cfg_t *cfg)
Color 4 configuration object setup function.
COLOR4_ERROR
@ COLOR4_ERROR
Definition: color4.h:169
color4_t::offset
float offset
Definition: color4.h:144
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:155
COLOR4_GREEN
@ COLOR4_GREEN
Definition: color4.h:180
color4_t::slave_address
uint8_t slave_address
Definition: color4.h:142
color4_config_t
Color 4 Click sensor configuration object.
Definition: color4.h:191
color4_t
Color 4 Click context object.
Definition: color4.h:137
color4_config_t::trig
uint8_t trig
Definition: color4.h:193
color4_t::i2c
i2c_master_t i2c
Definition: color4.h:139
color4_cfg_t::i2c_address
uint8_t i2c_address
Definition: color4.h:158
color4_cfg_t::scl
pin_name_t scl
Definition: color4.h:154
COLOR4_BLUE
@ COLOR4_BLUE
Definition: color4.h:181
color4_return_value_t
color4_return_value_t
Color 4 Click return value data.
Definition: color4.h:167
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:194
COLOR4_OK
@ COLOR4_OK
Definition: color4.h:168
color4_get_config
err_t color4_get_config(color4_t *ctx, color4_config_t *config)
Color 4 get configuration function.