color14 2.0.0.0
color14.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 COLOR14_H
29#define COLOR14_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 COLOR14_REG_MAIN_CTRL 0x00
74#define COLOR14_REG_PS_VCSEL 0x01
75#define COLOR14_REG_PS_PULSES 0x02
76#define COLOR14_REG_PS_MEASRATE 0x03
77#define COLOR14_REG_LS_MEAS_RATE 0x04
78#define COLOR14_REG_LS_GAIN 0x05
79#define COLOR14_REG_PART_ID 0x06
80#define COLOR14_REG_MAIN_STATUS 0x07
81#define COLOR14_REG_PS_DATA_0 0x08
82#define COLOR14_REG_PS_DATA_1 0x09
83#define COLOR14_REG_LS_DATA_IR_0 0x0A
84#define COLOR14_REG_LS_DATA_IR_1 0x0B
85#define COLOR14_REG_LS_DATA_IR_2 0x0C
86#define COLOR14_REG_LS_DATA_GREEN_0 0x0D
87#define COLOR14_REG_LS_DATA_GREEN_1 0x0E
88#define COLOR14_REG_LS_DATA_GREEN_2 0x0F
89#define COLOR14_REG_LS_DATA_BLUE_0 0x10
90#define COLOR14_REG_LS_DATA_BLUE_1 0x11
91#define COLOR14_REG_LS_DATA_BLUE_2 0x12
92#define COLOR14_REG_LS_DATA_RED_0 0x13
93#define COLOR14_REG_LS_DATA_RED_1 0x14
94#define COLOR14_REG_LS_DATA_RED_2 0x15
95#define COLOR14_REG_INT_CFG 0x19
96#define COLOR14_REG_INT_PST 0x1A
97#define COLOR14_REG_PS_THRES_UP_0 0x1B
98#define COLOR14_REG_PS_THRES_UP_1 0x1C
99#define COLOR14_REG_PS_THRES_LOW_0 0x1D
100#define COLOR14_REG_PS_THRES_LOW_1 0x1E
101#define COLOR14_REG_PS_CAN_0 0x1F
102#define COLOR14_REG_PS_CAN_1_ANA 0x20
103#define COLOR14_REG_LS_THRES_UP_0 0x21
104#define COLOR14_REG_LS_THRES_UP_1 0x22
105#define COLOR14_REG_LS_THRES_UP_2 0x23
106#define COLOR14_REG_LS_THRES_LOW_0 0x24
107#define COLOR14_REG_LS_THRES_LOW_1 0x25
108#define COLOR14_REG_LS_THRES_LOW_2 0x26
109#define COLOR14_REG_LS_THRES_VAR 0x27
110
111 // color14_reg
112
127#define COLOR14_ID 0xC2
128
134#define COLOR14_SET_DEV_ADDR 0x52
135
136 // color14_set
137
152#define COLOR14_MAP_MIKROBUS( cfg, mikrobus ) \
153 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
154 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
155 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
156
157 // color14_map
158 // color14
159
164typedef struct
165{
166 // Input pins
167 digital_in_t int_pin;
169 // Modules
170 i2c_master_t i2c;
172 // I2C slave address
175 // ALS resolution
177
178} color14_t;
179
184typedef struct
185{
186 pin_name_t scl;
187 pin_name_t sda;
189 pin_name_t int_pin;
191 uint32_t i2c_speed;
192 uint8_t i2c_address;
195
200typedef struct
201{
202 uint32_t red;
203 uint32_t green;
204 uint32_t blue;
205 uint32_t ir;
206
208
222
239
255
270err_t color14_generic_write ( color14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
271
286err_t color14_generic_read ( color14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
287
295uint8_t color14_get_int ( color14_t *ctx );
296
313err_t color14_get_proximity ( color14_t *ctx, uint16_t *ps_data );
314
334err_t color14_get_als ( color14_t *ctx, float *als_data );
335
355err_t color14_ls_color ( color14_t *ctx, uint8_t ls_reg, uint32_t *ls_data );
356
373err_t color14_get_rgb_ir ( color14_t *ctx, color14_color_t *color_data );
374
385
386#ifdef __cplusplus
387}
388#endif
389#endif // COLOR14_H
390
391 // color14
392
393// ------------------------------------------------------------------------ END
color14_return_value_t
Color 14 Click return value data.
Definition color14.h:214
@ COLOR14_ERROR_PARAM
Definition color14.h:218
@ COLOR14_ERROR_OVF
Definition color14.h:217
@ COLOR14_ERROR_CFG
Definition color14.h:219
@ COLOR14_OK
Definition color14.h:215
@ COLOR14_ERROR
Definition color14.h:216
uint8_t color14_get_int(color14_t *ctx)
Get interrupt pin state.
err_t color14_generic_read(color14_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Color 14 I2C reading function.
void color14_cfg_setup(color14_cfg_t *cfg)
Color 14 configuration object setup function.
err_t color14_get_rgb_ir(color14_t *ctx, color14_color_t *color_data)
Read color data from device.
err_t color14_get_als(color14_t *ctx, float *als_data)
Read lux data from device.
err_t color14_generic_write(color14_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Color 14 I2C writing function.
float color14_get_als_resolution(color14_t *ctx)
Get resolution for the lux calculation.
err_t color14_init(color14_t *ctx, color14_cfg_t *cfg)
Color 14 initialization function.
err_t color14_ls_color(color14_t *ctx, uint8_t ls_reg, uint32_t *ls_data)
Read ls data from color registers.
err_t color14_get_proximity(color14_t *ctx, uint16_t *ps_data)
Read proximity data from device.
Color 14 Click configuration object.
Definition color14.h:185
uint32_t i2c_speed
Definition color14.h:191
pin_name_t scl
Definition color14.h:186
pin_name_t int_pin
Definition color14.h:189
pin_name_t sda
Definition color14.h:187
uint8_t i2c_address
Definition color14.h:192
Color 14 color data object.
Definition color14.h:201
uint32_t red
Definition color14.h:202
uint32_t blue
Definition color14.h:204
uint32_t ir
Definition color14.h:205
uint32_t green
Definition color14.h:203
Color 14 Click context object.
Definition color14.h:165
digital_in_t int_pin
Definition color14.h:167
i2c_master_t i2c
Definition color14.h:170
float lux_resolution
Definition color14.h:176
uint8_t slave_address
Definition color14.h:173