color7  2.0.0.0
color7.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef COLOR7_H
36 #define COLOR7_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define COLOR7_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
65 
71 #define COLOR7_RETVAL uint8_t
72 
73 #define COLOR7_OK 0x00
74 #define COLOR7_INIT_ERROR 0xFF
75 
81 #define COLOR7_REG_ENABLE 0x00
82 #define COLOR7_REG_RGBC_TIME 0x01
83 #define COLOR7_REG_WAIT_TIME 0x02
84 #define COLOR7_REG_AILTL 0x03
85 #define COLOR7_REG_AILTH 0x04
86 #define COLOR7_REG_AIHTL 0x05
87 #define COLOR7_REG_AIHTH 0x06
88 #define COLOR7_REG_PERS 0x0C
89 #define COLOR7_REG_CONFIGURATION 0x0D
90 #define COLOR7_REG_CONTROL 0x0F
91 #define COLOR7_REG_DEVICE_ID 0x12
92 #define COLOR7_REG_DEVICE_STATUS 0x13
93 #define COLOR7_REG_CLEAR_DATA_LOW 0x14
94 #define COLOR7_REG_CLEAR_DATA_HIGH 0x15
95 #define COLOR7_REG_RED_DATA_LOW 0x16
96 #define COLOR7_REG_RED_DATA_HIGH 0x17
97 #define COLOR7_REG_GREEN_DATA_LOW 0x18
98 #define COLOR7_REG_GREEN_DATA_HIGH 0x19
99 #define COLOR7_REG_BLUE_DATA_LOW 0x1A
100 #define COLOR7_REG_BLUE_DATA_HIGH 0x1B
101 
107 #define COLOR7_CMD_SELECT 0x80
108 #define COLOR7_CMD_REPEATED_BYTE_PROTOCOL 0x00
109 #define COLOR7_CMD_AUTO_INCREMENT_PROTOCOL 0x20
110 
116 #define COLOR7_ENABLE_RGBC_INTERRUPT 0x10
117 #define COLOR7_ENABLE_WAIT 0x08
118 #define COLOR7_ENABLE_RGBC 0x02
119 #define COLOR7_POWER_ON 0x01
120 
126 #define COLOR7_RGBC_TIME_2_4ms 0xFF
127 #define COLOR7_RGBC_TIME_24ms 0xF6
128 #define COLOR7_RGBC_TIME_101ms 0xD5
129 #define COLOR7_RGBC_TIME_154ms 0xC0
130 #define COLOR7_RGBC_TIME_700ms 0x00
131 
137 #define COLOR7_WAIT_TIME_W0_2_4ms 0xFF
138 #define COLOR7_WAIT_TIME_W0_204ms 0xAB
139 #define COLOR7_WAIT_TIME_W0_614ms 0xFF
140 #define COLOR7_WAIT_TIME_W1_0_029sec 0xFF
141 #define COLOR7_WAIT_TIME_W1_2_45sec 0xAB
142 #define COLOR7_WAIT_TIME_W1_7_4sec 0xFF
143 
149 #define COLOR7_PERS_EVERY_RGBC 0x00
150 #define COLOR7_PERS_CLEAR_CH_1 0x01
151 #define COLOR7_PERS_CLEAR_CH_2 0x02
152 #define COLOR7_PERS_CLEAR_CH_3 0x03
153 #define COLOR7_PERS_CLEAR_CH_5 0x04
154 #define COLOR7_PERS_CLEAR_CH_10 0x05
155 #define COLOR7_PERS_CLEAR_CH_15 0x06
156 #define COLOR7_PERS_CLEAR_CH_20 0x07
157 #define COLOR7_PERS_CLEAR_CH_25 0x08
158 #define COLOR7_PERS_CLEAR_CH_30 0x09
159 #define COLOR7_PERS_CLEAR_CH_35 0x0A
160 #define COLOR7_PERS_CLEAR_CH_40 0x0B
161 #define COLOR7_PERS_CLEAR_CH_45 0x0C
162 #define COLOR7_PERS_CLEAR_CH_50 0x0D
163 #define COLOR7_PERS_CLEAR_CH_55 0x0E
164 #define COLOR7_PERS_CLEAR_CH_60 0x0F
165 
171 #define COLOR7_CFG_WAIT_LONG 0x01
172 
178 #define COLOR7_CTRL_GAIN_x1 0x00
179 #define COLOR7_CTRL_GAIN_x4 0x01
180 #define COLOR7_CTRL_GAIN_x16 0x02
181 #define COLOR7_CTRL_GAIN_x60 0x03
182 
188 #define COLOR7_COLOR_DATA_CLEAR 0x14
189 #define COLOR7_COLOR_DATA_RED 0x16
190 #define COLOR7_COLOR_DATA_GREEN 0x18
191 #define COLOR7_COLOR_DATA_BLUE 0x1A
192  // End group macro
195 // --------------------------------------------------------------- PUBLIC TYPES
204 typedef struct
205 {
206  // Input pins
207 
208  digital_in_t int_pin;
209 
210  // Modules
211 
212  i2c_master_t i2c;
213 
214  // ctx variable
215 
216  uint8_t slave_address;
217 
218 } color7_t;
219 
223 typedef struct
224 {
225  // Communication gpio pins
226 
227  pin_name_t scl;
228  pin_name_t sda;
229 
230  // Additional gpio pins
231 
232  pin_name_t int_pin;
233 
234  // static variable
235 
236  uint32_t i2c_speed;
237  uint8_t i2c_address;
238 
239 } color7_cfg_t;
240  // End types group
242 
243 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
244 
250 #ifdef __cplusplus
251 extern "C"{
252 #endif
253 
263 
272 
294 
305 void color7_generic_write ( color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
306 
318 void color7_generic_read ( color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
319 
329 float color7_read_color_ratio ( color7_t *ctx, uint8_t color );
330 
340 
358 uint8_t color7_get_color( color7_t *ctx );
359 
366 
367 
368 #ifdef __cplusplus
369 }
370 #endif
371 #endif // _COLOR7_H_
372  // End public_function group
375 
376 // ------------------------------------------------------------------------- END
color7_cfg_t
Click configuration structure definition.
Definition: color7.h:224
color7_cfg_t::sda
pin_name_t sda
Definition: color7.h:228
color7_get_color_value
float color7_get_color_value(color7_t *ctx)
Functions for read color value.
color7_init
COLOR7_RETVAL color7_init(color7_t *ctx, color7_cfg_t *cfg)
Initialization function.
color7_cfg_setup
void color7_cfg_setup(color7_cfg_t *cfg)
Config Object Initialization function.
color7_t::slave_address
uint8_t slave_address
Definition: color7.h:216
color7_cfg_t::i2c_address
uint8_t i2c_address
Definition: color7.h:237
color7_t::i2c
i2c_master_t i2c
Definition: color7.h:212
color7_get_color
uint8_t color7_get_color(color7_t *ctx)
Functions for detect colors.
color7_generic_write
void color7_generic_write(color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
color7_cfg_t::int_pin
pin_name_t int_pin
Definition: color7.h:232
color7_generic_read
void color7_generic_read(color7_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
color7_read_color_ratio
float color7_read_color_ratio(color7_t *ctx, uint8_t color)
Functions for read color ratio.
COLOR7_RETVAL
#define COLOR7_RETVAL
Definition: color7.h:71
color7_t::int_pin
digital_in_t int_pin
Definition: color7.h:208
color7_t
Click ctx object definition.
Definition: color7.h:205
color7_get_interrupt_state
uint8_t color7_get_interrupt_state(color7_t *ctx)
Get interrut pin state.
color7_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color7.h:236
color7_default_cfg
void color7_default_cfg(color7_t *ctx)
Click Default Configuration function.
color7_cfg_t::scl
pin_name_t scl
Definition: color7.h:227