color12 2.1.0.0
color12.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 COLOR12_H
29#define COLOR12_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 COLOR12_REG_SYSTEM_CONTROL 0x40
74#define COLOR12_REG_MODE_CONTROL1 0x41
75#define COLOR12_REG_MODE_CONTROL2 0x42
76#define COLOR12_REG_MODE_CONTROL3 0x43
77#define COLOR12_REG_RED_DATA_L 0x50
78#define COLOR12_REG_RED_DATA_H 0x51
79#define COLOR12_REG_GREEN_DATA_L 0x52
80#define COLOR12_REG_GREEN_DATA_H 0x53
81#define COLOR12_REG_BLUE_DATA_L 0x54
82#define COLOR12_REG_BLUE_DATA_H 0x55
83#define COLOR12_REG_IR_DATA_L 0x56
84#define COLOR12_REG_IR_DATA_H 0x57
85#define COLOR12_REG_FLICKER_DATA_L 0x58
86#define COLOR12_REG_FLICKER_DATA_H 0x59
87#define COLOR12_REG_FLICKER_COUNTER 0x5A
88#define COLOR12_REG_FIFO_LEVEL 0x5B
89#define COLOR12_REG_FIFO_DATA_L 0x5C
90#define COLOR12_REG_FIFO_DATA_H 0x5D
91#define COLOR12_REG_MANUFACTURER_ID 0x92
92
93 // color12_reg
94
109#define COLOR12_SET_SW_RESET 0x80
110
115#define COLOR12_RGB_GAIN_X1 0x00
116#define COLOR12_RGB_GAIN_X2 0x01
117#define COLOR12_RGB_GAIN_X4 0x02
118#define COLOR12_RGB_GAIN_X8 0x03
119#define COLOR12_RGB_GAIN_X16 0x04
120#define COLOR12_RGB_GAIN_X32 0x05
121
126#define COLOR12_MEAS_MODE_55MS 0x01
127#define COLOR12_MEAS_MODE_100MS 0x02
128
133#define COLOR12_FLC_GAIN_X1 0x00
134#define COLOR12_FLC_GAIN_X2 0x01
135#define COLOR12_FLC_GAIN_X4 0x02
136#define COLOR12_FLC_GAIN_X8 0x03
137#define COLOR12_FLC_GAIN_X16 0x04
138#define COLOR12_FLC_GAIN_X32 0x05
139
144#define COLOR12_FLC_MODE_1KHZ 0x00
145#define COLOR12_FLC_MODE_2KHZ 0x01
146
151#define COLOR12_INT_SEL_DISABLE 0x00
152#define COLOR12_INT_SEL_RDY_RGB_IR 0x01
153#define COLOR12_INT_SEL_RDY_FLICKER 0x02
154#define COLOR12_INT_SEL_RDY_FIFO 0x03
155
160#define COLOR12_RGB_EN_DISABLE 0x00
161#define COLOR12_RGB_EN_ENABLE 0x01
162
167#define COLOR12_FLC_EN_DISABLE 0x00
168#define COLOR12_FLC_EN_ENABLE 0x01
169
174#define COLOR12_MANUFACTURER_ID 0xE0
175
181#define COLOR12_DEVICE_ADDRESS 0x38
182
183 // color12_set
184
199#define COLOR12_MAP_MIKROBUS( cfg, mikrobus ) \
200 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
201 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
202 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
203
204 // color12_map
205 // color12
206
211typedef struct
212{
213 // Input pins
214 digital_in_t int_pin;
216 // Modules
217 i2c_master_t i2c;
219 // I2C slave address
222} color12_t;
223
228typedef struct
229{
230 pin_name_t scl;
231 pin_name_t sda;
233 pin_name_t int_pin;
235 uint32_t i2c_speed;
236 uint8_t i2c_address;
239
244typedef enum
245{
247 COLOR12_ERROR = -1
248
250
263
268typedef struct
269{
270 uint8_t rgb_gain;
271 uint8_t meas_mode;
272 uint8_t flc_gain;
273 uint8_t flc_mode;
274 uint8_t int_sel;
275 uint8_t rgb_en;
276 uint8_t flc_en;
279
296
311
325
340err_t color12_generic_write ( color12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
341
356err_t color12_generic_read ( color12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
357
371
387
403
419err_t color12_get_color_data ( color12_t *ctx, color12_color_sel_t color_sel, uint16_t *color_data );
420
434err_t color12_get_device_id ( color12_t *ctx, uint8_t *device_id );
435
448
449#ifdef __cplusplus
450}
451#endif
452#endif // COLOR12_H
453
454 // color12
455
456// ------------------------------------------------------------------------ END
color12_return_value_t
Color 12 Click return value data.
Definition color12.h:245
@ COLOR12_ERROR
Definition color12.h:247
@ COLOR12_OK
Definition color12.h:246
color12_color_sel_t
Color 12 Click color selection value data.
Definition color12.h:256
@ COLOR12_DATA_GREEN
Definition color12.h:258
@ COLOR12_DATA_BLUE
Definition color12.h:259
@ COLOR12_DATA_IR
Definition color12.h:260
@ COLOR12_DATA_RED
Definition color12.h:257
void color12_cfg_setup(color12_cfg_t *cfg)
Color 12 configuration object setup function.
err_t color12_get_device_id(color12_t *ctx, uint8_t *device_id)
Color 12 gets the device ID function.
uint8_t color12_get_int_pin(color12_t *ctx)
Color 12 gets the interrupt function.
err_t color12_get_color_data(color12_t *ctx, color12_color_sel_t color_sel, uint16_t *color_data)
Color 12 gets the color measurement result function.
err_t color12_generic_read(color12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 12 I2C reading function.
err_t color12_default_cfg(color12_t *ctx)
Color 12 default configuration function.
err_t color12_init(color12_t *ctx, color12_cfg_t *cfg)
Color 12 initialization function.
err_t color12_generic_write(color12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 12 I2C writing function.
err_t color12_get_config(color12_t *ctx, color12_config_t *config)
Color 12 gets the configuration function.
err_t color12_sw_reset(color12_t *ctx)
Color 12 software reset function.
err_t color12_set_config(color12_t *ctx, color12_config_t config)
Color 12 sets the configuration function.
Color 12 Click configuration object.
Definition color12.h:229
uint32_t i2c_speed
Definition color12.h:235
pin_name_t scl
Definition color12.h:230
pin_name_t int_pin
Definition color12.h:233
pin_name_t sda
Definition color12.h:231
uint8_t i2c_address
Definition color12.h:236
Color 12 Click sensor configuration object.
Definition color12.h:269
uint8_t rgb_en
Definition color12.h:275
uint8_t flc_gain
Definition color12.h:272
uint8_t meas_mode
Definition color12.h:271
uint8_t rgb_gain
Definition color12.h:270
uint8_t flc_mode
Definition color12.h:273
uint8_t flc_en
Definition color12.h:276
uint8_t int_sel
Definition color12.h:274
Color 12 Click context object.
Definition color12.h:212
digital_in_t int_pin
Definition color12.h:214
i2c_master_t i2c
Definition color12.h:217
uint8_t slave_address
Definition color12.h:220