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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define COLOR12_REG_SYSTEM_CONTROL 0x40
70 #define COLOR12_REG_MODE_CONTROL1 0x41
71 #define COLOR12_REG_MODE_CONTROL2 0x42
72 #define COLOR12_REG_MODE_CONTROL3 0x43
73 #define COLOR12_REG_RED_DATA_L 0x50
74 #define COLOR12_REG_RED_DATA_H 0x51
75 #define COLOR12_REG_GREEN_DATA_L 0x52
76 #define COLOR12_REG_GREEN_DATA_H 0x53
77 #define COLOR12_REG_BLUE_DATA_L 0x54
78 #define COLOR12_REG_BLUE_DATA_H 0x55
79 #define COLOR12_REG_IR_DATA_L 0x56
80 #define COLOR12_REG_IR_DATA_H 0x57
81 #define COLOR12_REG_FLICKER_DATA_L 0x58
82 #define COLOR12_REG_FLICKER_DATA_H 0x59
83 #define COLOR12_REG_FLICKER_COUNTER 0x5A
84 #define COLOR12_REG_FIFO_LEVEL 0x5B
85 #define COLOR12_REG_FIFO_DATA_L 0x5C
86 #define COLOR12_REG_FIFO_DATA_H 0x5D
87 #define COLOR12_REG_MANUFACTURER_ID 0x92
88  // color12_reg
90 
105 #define COLOR12_SET_SW_RESET 0x80
106 
111 #define COLOR12_RGB_GAIN_X1 0x00
112 #define COLOR12_RGB_GAIN_X2 0x01
113 #define COLOR12_RGB_GAIN_X4 0x02
114 #define COLOR12_RGB_GAIN_X8 0x03
115 #define COLOR12_RGB_GAIN_X16 0x04
116 #define COLOR12_RGB_GAIN_X32 0x05
117 
122 #define COLOR12_MEAS_MODE_55MS 0x01
123 #define COLOR12_MEAS_MODE_100MS 0x02
124 
129 #define COLOR12_FLC_GAIN_X1 0x00
130 #define COLOR12_FLC_GAIN_X2 0x01
131 #define COLOR12_FLC_GAIN_X4 0x02
132 #define COLOR12_FLC_GAIN_X8 0x03
133 #define COLOR12_FLC_GAIN_X16 0x04
134 #define COLOR12_FLC_GAIN_X32 0x05
135 
140 #define COLOR12_FLC_MODE_1KHZ 0x00
141 #define COLOR12_FLC_MODE_2KHZ 0x01
142 
147 #define COLOR12_INT_SEL_DISABLE 0x00
148 #define COLOR12_INT_SEL_RDY_RGB_IR 0x01
149 #define COLOR12_INT_SEL_RDY_FLICKER 0x02
150 #define COLOR12_INT_SEL_RDY_FIFO 0x03
151 
156 #define COLOR12_RGB_EN_DISABLE 0x00
157 #define COLOR12_RGB_EN_ENABLE 0x01
158 
163 #define COLOR12_FLC_EN_DISABLE 0x00
164 #define COLOR12_FLC_EN_ENABLE 0x01
165 
170 #define COLOR12_MANUFACTURER_ID 0xE0
171 
177 #define COLOR12_DEVICE_ADDRESS 0x38
178  // color12_set
180 
195 #define COLOR12_MAP_MIKROBUS( cfg, mikrobus ) \
196  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
197  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
198  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
199  // color12_map // color12
202 
207 typedef struct
208 {
209  // Input pins
210  digital_in_t int_pin;
212  // Modules
213  i2c_master_t i2c;
215  // I2C slave address
216  uint8_t slave_address;
218 } color12_t;
219 
224 typedef struct
225 {
226  pin_name_t scl;
227  pin_name_t sda;
229  pin_name_t int_pin;
231  uint32_t i2c_speed;
232  uint8_t i2c_address;
234 } color12_cfg_t;
235 
240 typedef enum
241 {
243  COLOR12_ERROR = -1
244 
246 
251 typedef enum
252 {
257 
259 
264 typedef struct
265 {
266  uint8_t rgb_gain;
267  uint8_t meas_mode;
268  uint8_t flc_gain;
269  uint8_t flc_mode;
270  uint8_t int_sel;
271  uint8_t rgb_en;
272  uint8_t flc_en;
275 
292 
306 err_t color12_init ( color12_t *ctx, color12_cfg_t *cfg );
307 
321 
336 err_t color12_generic_write ( color12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
337 
352 err_t color12_generic_read ( color12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
353 
367 
383 
399 
415 err_t color12_get_color_data ( color12_t *ctx, color12_color_sel_t color_sel, uint16_t *color_data );
416 
430 err_t color12_get_device_id ( color12_t *ctx, uint8_t *device_id );
431 
444 
445 #ifdef __cplusplus
446 }
447 #endif
448 #endif // COLOR12_H
449  // color12
451 
452 // ------------------------------------------------------------------------ END
color12_color_sel_t
color12_color_sel_t
Color 12 Click color selection value data.
Definition: color12.h:252
color12_t
Color 12 Click context object.
Definition: color12.h:208
color12_t::slave_address
uint8_t slave_address
Definition: color12.h:216
color12_get_int_pin
uint8_t color12_get_int_pin(color12_t *ctx)
Color 12 gets the interrupt function.
COLOR12_ERROR
@ COLOR12_ERROR
Definition: color12.h:243
color12_cfg_t::int_pin
pin_name_t int_pin
Definition: color12.h:229
color12_generic_write
err_t color12_generic_write(color12_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 12 I2C writing function.
color12_get_config
err_t color12_get_config(color12_t *ctx, color12_config_t *config)
Color 12 gets the configuration function.
COLOR12_DATA_BLUE
@ COLOR12_DATA_BLUE
Definition: color12.h:255
color12_config_t::flc_en
uint8_t flc_en
Definition: color12.h:272
color12_cfg_t::scl
pin_name_t scl
Definition: color12.h:226
color12_cfg_setup
void color12_cfg_setup(color12_cfg_t *cfg)
Color 12 configuration object setup function.
COLOR12_DATA_RED
@ COLOR12_DATA_RED
Definition: color12.h:253
color12_config_t::int_sel
uint8_t int_sel
Definition: color12.h:270
color12_config_t::meas_mode
uint8_t meas_mode
Definition: color12.h:267
color12_generic_read
err_t color12_generic_read(color12_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 12 I2C reading function.
color12_default_cfg
err_t color12_default_cfg(color12_t *ctx)
Color 12 default configuration function.
color12_config_t::rgb_gain
uint8_t rgb_gain
Definition: color12.h:266
color12_cfg_t::i2c_address
uint8_t i2c_address
Definition: color12.h:232
color12_init
err_t color12_init(color12_t *ctx, color12_cfg_t *cfg)
Color 12 initialization function.
color12_set_config
err_t color12_set_config(color12_t *ctx, color12_config_t config)
Color 12 sets the configuration function.
COLOR12_DATA_GREEN
@ COLOR12_DATA_GREEN
Definition: color12.h:254
color12_t::int_pin
digital_in_t int_pin
Definition: color12.h:210
color12_t::i2c
i2c_master_t i2c
Definition: color12.h:213
color12_config_t::flc_gain
uint8_t flc_gain
Definition: color12.h:268
color12_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color12.h:231
color12_get_device_id
err_t color12_get_device_id(color12_t *ctx, uint8_t *device_id)
Color 12 gets the device ID function.
color12_get_color_data
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.
COLOR12_OK
@ COLOR12_OK
Definition: color12.h:242
color12_config_t
Color 12 Click sensor configuration object.
Definition: color12.h:265
color12_return_value_t
color12_return_value_t
Color 12 Click return value data.
Definition: color12.h:241
color12_config_t::rgb_en
uint8_t rgb_en
Definition: color12.h:271
color12_sw_reset
err_t color12_sw_reset(color12_t *ctx)
Color 12 software reset function.
color12_config_t::flc_mode
uint8_t flc_mode
Definition: color12.h:269
color12_cfg_t
Color 12 Click configuration object.
Definition: color12.h:225
COLOR12_DATA_IR
@ COLOR12_DATA_IR
Definition: color12.h:256
color12_cfg_t::sda
pin_name_t sda
Definition: color12.h:227