color2  2.0.0.0
color2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef COLOR2_H
36 #define COLOR2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define COLOR2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define COLOR2_RETVAL uint8_t
64 
65 #define COLOR2_OK 0x00
66 #define COLOR2_INIT_ERROR 0xFF
67 
73 #define COLOR2_I2C_ADDR 0x44
74 #define COLOR2_DEVICE_ID 0x00
75 #define COLOR2_CONFIG_1 0x01
76 #define COLOR2_CONFIG_2 0x02
77 #define COLOR2_CONFIG_3 0x03
78 #define COLOR2_THRESHOLD_LL 0x04
79 #define COLOR2_THRESHOLD_LH 0x05
80 #define COLOR2_THRESHOLD_HL 0x06
81 #define COLOR2_THRESHOLD_HH 0x07
82 #define COLOR2_STATUS 0x08
83 #define COLOR2_GREEN_L 0x09
84 #define COLOR2_GREEN_H 0x0A
85 #define COLOR2_RED_L 0x0B
86 #define COLOR2_RED_H 0x0C
87 #define COLOR2_BLUE_L 0x0D
88 #define COLOR2_BLUE_H 0x0E
89 #define COLOR2_CFG_DEFAULT 0x00
90 #define COLOR2_CFG1_MODE_POWERDOWN 0x00
91 #define COLOR2_CFG1_MODE_G 0x01
92 #define COLOR2_CFG1_MODE_R 0x02
93 #define COLOR2_CFG1_MODE_B 0x03
94 #define COLOR2_CFG1_MODE_STANDBY 0x04
95 #define COLOR2_CFG1_MODE_RGB 0x05
96 #define COLOR2_CFG1_MODE_RG 0x06
97 #define COLOR2_CFG1_MODE_GB 0x07
98 #define COLOR2_CFG1_375LUX 0x00
99 #define COLOR2_CFG1_10KLUX 0x08
100 #define COLOR2_CFG1_16BIT 0x00
101 #define COLOR2_CFG1_12BIT 0x10
102 #define COLOR2_CFG1_ADC_SYNC_NORMAL 0x00
103 #define COLOR2_CFG1_ADC_SYNC_TO_INT 0x20
104 #define COLOR2_CFG2_IR_OFFSET_OFF 0x00
105 #define COLOR2_CFG2_IR_OFFSET_ON 0x80
106 #define COLOR2_CFG2_IR_ADJUST_LOW 0x00
107 #define COLOR2_CFG2_IR_ADJUST_MID 0x20
108 #define COLOR2_CFG2_IR_ADJUST_HIGH 0x3F
109 
115 #define COLOR2_CFG3_NO_INT 0x00
116 #define COLOR2_CFG3_G_INT 0x01
117 #define COLOR2_CFG3_R_INT 0x02
118 #define COLOR2_CFG3_B_INT 0x03
119 #define COLOR2_CFG3_INT_PRST1 0x00
120 #define COLOR2_CFG3_INT_PRST2 0x04
121 #define COLOR2_CFG3_INT_PRST4 0x08
122 #define COLOR2_CFG3_INT_PRST8 0x0C
123 #define COLOR2_CFG3_RGB_CONV_TO_INT_DISABLE 0x00
124 #define COLOR2_CFG3_RGB_CONV_TO_INT_ENABLE 0x10
125 
131 #define COLOR2_FLAG_INT 0x01
132 #define COLOR2_FLAG_CONV_DONE 0x02
133 #define COLOR2_FLAG_BROWNOUT 0x04
134 #define COLOR2_FLAG_CONV_G 0x10
135 #define COLOR2_FLAG_CONV_R 0x20
136 #define COLOR2_FLAG_CONV_B 0x30
137  // End group macro
140 // --------------------------------------------------------------- PUBLIC TYPES
149 typedef struct
150 {
151  // Input pins
152 
153  digital_in_t int_pin;
154 
155  // Modules
156 
157  i2c_master_t i2c;
158 
159  // ctx variable
160 
161  hal_i2c_address_t slave_address;
162 
163 } color2_t;
164 
168 typedef struct
169 {
170  // Communication gpio pins
171 
172  pin_name_t scl;
173  pin_name_t sda;
174 
175  // Additional gpio pins
176 
177  pin_name_t int_pin;
178 
179  // static variable
180 
181  hal_i2c_speed_t i2c_speed;
182  hal_i2c_address_t i2c_address;
183 
184 } color2_cfg_t;
185  // End types group
187 
188 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189 
195 #ifdef __cplusplus
196 extern "C"{
197 #endif
198 
207 void color2_cfg_setup ( color2_cfg_t *cfg );
208 
217 
225 void color2_default_cfg ( color2_t *ctx );
226 
237 void color2_write_data ( color2_t *ctx, uint8_t address, uint8_t write_command );
238 
249 uint8_t color2_read_data ( color2_t *ctx, uint8_t address );
250 
259 uint8_t color2_reset ( color2_t *ctx );
260 
275 uint8_t color2_init_advanced ( color2_t *ctx, uint8_t config1, uint8_t config2, uint8_t config3);
276 
285 void color2_set_upper_threshold ( color2_t *ctx, uint16_t upper_threshold );
286 
295 void color2_set_lower_hreshold ( color2_t *ctx, uint16_t lower_threshold );
296 
305 uint16_t color2_read_upper_threshold ( color2_t *ctx );
306 
315 uint16_t color2_read_lower_threshold ( color2_t *ctx );
316 
325 float color2_read_red ( color2_t *ctx );
326 
335 float color2_read_green ( color2_t *ctx );
336 
345 float color2_read_blue ( color2_t *ctx );
346 
355 uint8_t color2_read_status ( color2_t *ctx );
356 
366 float color2_get_color_value ( color2_t *ctx );
367 
386 uint8_t color2_get_color ( float color_value );
387 
388 #ifdef __cplusplus
389 }
390 #endif
391 #endif // _COLOR2_H_
392  // End public_function group
395 
396 // ------------------------------------------------------------------------- END
Click ctx object definition.
Definition: color2.h:149
i2c_master_t i2c
Definition: color2.h:157
Click configuration structure definition.
Definition: color2.h:168
float color2_get_color_value(color2_t *ctx)
Functions for read color value.
uint8_t color2_reset(color2_t *ctx)
Reset default register value function.
hal_i2c_address_t i2c_address
Definition: color2.h:182
hal_i2c_address_t slave_address
Definition: color2.h:161
void color2_set_lower_hreshold(color2_t *ctx, uint16_t lower_threshold)
Function set lower threshold register.
float color2_read_blue(color2_t *ctx)
Function read blue color data.
float color2_read_red(color2_t *ctx)
Function read red color data.
digital_in_t int_pin
Definition: color2.h:153
pin_name_t scl
Definition: color2.h:172
uint8_t color2_read_data(color2_t *ctx, uint8_t address)
Generic read data function.
uint16_t color2_read_lower_threshold(color2_t *ctx)
Function read lower threshold register.
float color2_read_green(color2_t *ctx)
Function read green color data.
void color2_cfg_setup(color2_cfg_t *cfg)
Config Object Initialization function.
void color2_set_upper_threshold(color2_t *ctx, uint16_t upper_threshold)
Function set upper threshold register.
uint8_t color2_init_advanced(color2_t *ctx, uint8_t config1, uint8_t config2, uint8_t config3)
Generic read data function.
uint8_t color2_get_color(float color_value)
Functions for detect colors.
hal_i2c_speed_t i2c_speed
Definition: color2.h:181
void color2_write_data(color2_t *ctx, uint8_t address, uint8_t write_command)
Generic write data function.
pin_name_t sda
Definition: color2.h:173
void color2_default_cfg(color2_t *ctx)
Click Default Configuration function.
COLOR2_RETVAL color2_init(color2_t *ctx, color2_cfg_t *cfg)
Initialization function.
uint8_t color2_read_status(color2_t *ctx)
Function read status registe value.
uint16_t color2_read_upper_threshold(color2_t *ctx)
Function read upper threshold register.
pin_name_t int_pin
Definition: color2.h:177
#define COLOR2_RETVAL
Definition: color2.h:63