color7  2.0.0.0
color7.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 COLOR7_H
36 #define COLOR7_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define COLOR7_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define COLOR7_RETVAL uint8_t
62 
63 #define COLOR7_OK 0x00
64 #define COLOR7_INIT_ERROR 0xFF
65 
71 #define COLOR7_REG_ENABLE 0x00
72 #define COLOR7_REG_RGBC_TIME 0x01
73 #define COLOR7_REG_WAIT_TIME 0x02
74 #define COLOR7_REG_AILTL 0x03
75 #define COLOR7_REG_AILTH 0x04
76 #define COLOR7_REG_AIHTL 0x05
77 #define COLOR7_REG_AIHTH 0x06
78 #define COLOR7_REG_PERS 0x0C
79 #define COLOR7_REG_CONFIGURATION 0x0D
80 #define COLOR7_REG_CONTROL 0x0F
81 #define COLOR7_REG_DEVICE_ID 0x12
82 #define COLOR7_REG_DEVICE_STATUS 0x13
83 #define COLOR7_REG_CLEAR_DATA_LOW 0x14
84 #define COLOR7_REG_CLEAR_DATA_HIGH 0x15
85 #define COLOR7_REG_RED_DATA_LOW 0x16
86 #define COLOR7_REG_RED_DATA_HIGH 0x17
87 #define COLOR7_REG_GREEN_DATA_LOW 0x18
88 #define COLOR7_REG_GREEN_DATA_HIGH 0x19
89 #define COLOR7_REG_BLUE_DATA_LOW 0x1A
90 #define COLOR7_REG_BLUE_DATA_HIGH 0x1B
91 
97 #define COLOR7_CMD_SELECT 0x80
98 #define COLOR7_CMD_REPEATED_BYTE_PROTOCOL 0x00
99 #define COLOR7_CMD_AUTO_INCREMENT_PROTOCOL 0x20
100 
106 #define COLOR7_ENABLE_RGBC_INTERRUPT 0x10
107 #define COLOR7_ENABLE_WAIT 0x08
108 #define COLOR7_ENABLE_RGBC 0x02
109 #define COLOR7_POWER_ON 0x01
110 
116 #define COLOR7_RGBC_TIME_2_4ms 0xFF
117 #define COLOR7_RGBC_TIME_24ms 0xF6
118 #define COLOR7_RGBC_TIME_101ms 0xD5
119 #define COLOR7_RGBC_TIME_154ms 0xC0
120 #define COLOR7_RGBC_TIME_700ms 0x00
121 
127 #define COLOR7_WAIT_TIME_W0_2_4ms 0xFF
128 #define COLOR7_WAIT_TIME_W0_204ms 0xAB
129 #define COLOR7_WAIT_TIME_W0_614ms 0xFF
130 #define COLOR7_WAIT_TIME_W1_0_029sec 0xFF
131 #define COLOR7_WAIT_TIME_W1_2_45sec 0xAB
132 #define COLOR7_WAIT_TIME_W1_7_4sec 0xFF
133 
139 #define COLOR7_PERS_EVERY_RGBC 0x00
140 #define COLOR7_PERS_CLEAR_CH_1 0x01
141 #define COLOR7_PERS_CLEAR_CH_2 0x02
142 #define COLOR7_PERS_CLEAR_CH_3 0x03
143 #define COLOR7_PERS_CLEAR_CH_5 0x04
144 #define COLOR7_PERS_CLEAR_CH_10 0x05
145 #define COLOR7_PERS_CLEAR_CH_15 0x06
146 #define COLOR7_PERS_CLEAR_CH_20 0x07
147 #define COLOR7_PERS_CLEAR_CH_25 0x08
148 #define COLOR7_PERS_CLEAR_CH_30 0x09
149 #define COLOR7_PERS_CLEAR_CH_35 0x0A
150 #define COLOR7_PERS_CLEAR_CH_40 0x0B
151 #define COLOR7_PERS_CLEAR_CH_45 0x0C
152 #define COLOR7_PERS_CLEAR_CH_50 0x0D
153 #define COLOR7_PERS_CLEAR_CH_55 0x0E
154 #define COLOR7_PERS_CLEAR_CH_60 0x0F
155 
161 #define COLOR7_CFG_WAIT_LONG 0x01
162 
168 #define COLOR7_CTRL_GAIN_x1 0x00
169 #define COLOR7_CTRL_GAIN_x4 0x01
170 #define COLOR7_CTRL_GAIN_x16 0x02
171 #define COLOR7_CTRL_GAIN_x60 0x03
172 
178 #define COLOR7_COLOR_DATA_CLEAR 0x14
179 #define COLOR7_COLOR_DATA_RED 0x16
180 #define COLOR7_COLOR_DATA_GREEN 0x18
181 #define COLOR7_COLOR_DATA_BLUE 0x1A
182  // End group macro
185 // --------------------------------------------------------------- PUBLIC TYPES
194 typedef struct
195 {
196  // Input pins
197 
198  digital_in_t int_pin;
199 
200  // Modules
201 
202  i2c_master_t i2c;
203 
204  // ctx variable
205 
206  hal_i2c_address_t slave_address;
207 
208 } color7_t;
209 
213 typedef struct
214 {
215  // Communication gpio pins
216 
217  pin_name_t scl;
218  pin_name_t sda;
219 
220  // Additional gpio pins
221 
222  pin_name_t int_pin;
223 
224  // static variable
225 
226  hal_i2c_speed_t i2c_speed;
227  hal_i2c_address_t i2c_address;
228 
229 } color7_cfg_t;
230  // End types group
232 
233 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
234 
240 #ifdef __cplusplus
241 extern "C"{
242 #endif
243 
252 void color7_cfg_setup ( color7_cfg_t *cfg );
253 
262 
283 void color7_default_cfg ( color7_t *ctx );
284 
295 void color7_generic_write ( color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
296 
308 void color7_generic_read ( color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
309 
319 float color7_read_color_ratio ( color7_t *ctx, uint8_t color );
320 
329 float color7_get_color_value ( color7_t *ctx );
330 
348 uint8_t color7_get_color( color7_t *ctx );
349 
355 uint8_t color7_get_interrupt_state ( color7_t *ctx );
356 
357 
358 #ifdef __cplusplus
359 }
360 #endif
361 #endif // _COLOR7_H_
362  // End public_function group
365 
366 // ------------------------------------------------------------------------- END
i2c_master_t i2c
Definition: color7.h:202
float color7_get_color_value(color7_t *ctx)
Functions for read color value.
Click configuration structure definition.
Definition: color7.h:213
void color7_cfg_setup(color7_cfg_t *cfg)
Config Object Initialization function.
digital_in_t int_pin
Definition: color7.h:198
hal_i2c_speed_t i2c_speed
Definition: color7.h:226
Click ctx object definition.
Definition: color7.h:194
hal_i2c_address_t slave_address
Definition: color7.h:206
hal_i2c_address_t i2c_address
Definition: color7.h:227
uint8_t color7_get_interrupt_state(color7_t *ctx)
Get interrut pin state.
void color7_generic_read(color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pin_name_t sda
Definition: color7.h:218
pin_name_t int_pin
Definition: color7.h:222
uint8_t color7_get_color(color7_t *ctx)
Functions for detect colors.
void color7_generic_write(color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t scl
Definition: color7.h:217
COLOR7_RETVAL color7_init(color7_t *ctx, color7_cfg_t *cfg)
Initialization function.
float color7_read_color_ratio(color7_t *ctx, uint8_t color)
Functions for read color ratio.
#define COLOR7_RETVAL
Definition: color7.h:61
void color7_default_cfg(color7_t *ctx)
Click Default Configuration function.