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
32extern "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
79 // 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
123 // 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
143 // color4_map
144 // color4
145
150typedef struct
151{
152 // Modules
153 i2c_master_t i2c;
155 // I2C slave address
158 float offset;
160} color4_t;
161
166typedef struct
167{
168 pin_name_t scl;
169 pin_name_t sda;
171 uint32_t i2c_speed;
172 uint8_t i2c_address;
175
180typedef enum
181{
183 COLOR4_ERROR = -1
184
186
199
204typedef struct
205{
207 uint8_t trig;
208 uint8_t mode;
212
229
243err_t color4_init ( color4_t *ctx, color4_cfg_t *cfg );
244
259
274err_t color4_generic_write ( color4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
275
290err_t color4_generic_read ( color4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
291
306
321
337err_t color4_get_color_data ( color4_t *ctx, color4_ch_color_t ch_color, uint16_t *color_data );
338
353err_t color4_get_ambient_light ( color4_t *ctx, float *ambient_light );
354
370err_t color4_get_cct ( color4_t *ctx, float *cct );
371
372#ifdef __cplusplus
373}
374#endif
375#endif // COLOR4_H
376
377 // color4
378
379// ------------------------------------------------------------------------ END
color4_ch_color_t
Color 4 Click channel selection value data.
Definition color4.h:192
@ COLOR4_RED
Definition color4.h:193
@ COLOR4_GREEN
Definition color4.h:194
@ COLOR4_WHITE
Definition color4.h:196
@ COLOR4_BLUE
Definition color4.h:195
color4_return_value_t
Color 4 Click return value data.
Definition color4.h:181
@ COLOR4_OK
Definition color4.h:182
@ COLOR4_ERROR
Definition color4.h:183
err_t color4_init(color4_t *ctx, color4_cfg_t *cfg)
Color 4 initialization function.
err_t color4_generic_read(color4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 4 I2C reading function.
err_t color4_default_cfg(color4_t *ctx)
Color 4 default configuration function.
err_t color4_get_ambient_light(color4_t *ctx, float *ambient_light)
Color 4 get ambient light level function.
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.
err_t color4_generic_write(color4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 4 I2C writing function.
void color4_cfg_setup(color4_cfg_t *cfg)
Color 4 configuration object setup function.
err_t color4_get_config(color4_t *ctx, color4_config_t *config)
Color 4 get configuration function.
err_t color4_get_cct(color4_t *ctx, float *cct)
Color 4 get CCT data function.
err_t color4_set_config(color4_t *ctx, color4_config_t config)
Color 4 set configuration function.
Color 4 Click configuration object.
Definition color4.h:167
uint32_t i2c_speed
Definition color4.h:171
pin_name_t scl
Definition color4.h:168
pin_name_t sda
Definition color4.h:169
uint8_t i2c_address
Definition color4.h:172
Color 4 Click sensor configuration object.
Definition color4.h:205
uint8_t mode
Definition color4.h:208
uint8_t trig
Definition color4.h:207
uint8_t integration_time
Definition color4.h:206
uint8_t chip_shutdown
Definition color4.h:209
Color 4 Click context object.
Definition color4.h:151
float offset
Definition color4.h:158
i2c_master_t i2c
Definition color4.h:153
uint8_t slave_address
Definition color4.h:156