color  2.0.0.0
color.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 COLOR_H
36 #define COLOR_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_i2c_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define COLOR_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.rd = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71  cfg.gr = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.bl = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
74 
80 #define COLOR_RETVAL uint8_t
81 
82 #define COLOR_OK 0x00
83 #define COLOR_INIT_ERROR 0xFF
84 
90 #define COLOR_SLAVE_ADDRESS 0x29
91 
98 #define COLOR_REG_ENABLE 0x00
99 #define COLOR_REG_RGBC_TIME 0x01
100 #define COLOR_REG_WAIT_TIME 0x02
101 #define COLOR_REG_AILTL 0x03
102 #define COLOR_REG_AILTH 0x04
103 #define COLOR_REG_AIHTL 0x05
104 #define COLOR_REG_AIHTH 0x06
105 #define COLOR_REG_PERS 0x0C
106 #define COLOR_REG_CONFIGURATION 0x0D
107 #define COLOR_REG_CONTROL 0x0F
108 #define COLOR_REG_DEVICE_ID 0x12
109 #define COLOR_REG_DEVICE_STATUS 0x13
110 #define COLOR_REG_CLEAR_DATA_LOW 0x14
111 #define COLOR_REG_CLEAR_DATA_HIGH 0x15
112 #define COLOR_REG_RED_DATA_LOW 0x16
113 #define COLOR_REG_RED_DATA_HIGH 0x17
114 #define COLOR_REG_GREEN_DATA_LOW 0x18
115 #define COLOR_REG_GREEN_DATA_HIGH 0x19
116 #define COLOR_REG_BLUE_DATA_LOW 0x1A
117 #define COLOR_REG_BLUE_DATA_HIGH 0x1B
118 
124 #define COLOR_CMD_SELECT 0x80
125 #define COLOR_CMD_REPEATED_BYTE_PROTOCOL 0x00
126 #define COLOR_CMD_AUTO_INCREMENT_PROTOCOL 0x20
127 
133 #define COLOR_ENABLE_RGBC_INTERRUPT 0x10
134 #define COLOR_ENABLE_WAIT 0x08
135 #define COLOR_ENABLE_RGBC 0x02
136 #define COLOR_POWER_ON 0x01
137 
143 #define COLOR_RGBC_TIME_2_4ms 0xFF
144 #define COLOR_RGBC_TIME_24ms 0xF6
145 #define COLOR_RGBC_TIME_101ms 0xD5
146 #define COLOR_RGBC_TIME_154ms 0xC0
147 #define COLOR_RGBC_TIME_700ms 0x00
148 
154 #define COLOR_WAIT_TIME_W0_2_4ms 0xFF
155 #define COLOR_WAIT_TIME_W0_204ms 0xAB
156 #define COLOR_WAIT_TIME_W0_614ms 0xFF
157 #define COLOR_WAIT_TIME_W1_0_029sec 0xFF
158 #define COLOR_WAIT_TIME_W1_2_45sec 0xAB
159 #define COLOR_WAIT_TIME_W1_7_4sec 0xFF
160 
166 #define COLOR_PERS_EVERY_RGBC 0x00
167 #define COLOR_PERS_CLEAR_CH_1 0x01
168 #define COLOR_PERS_CLEAR_CH_2 0x02
169 #define COLOR_PERS_CLEAR_CH_3 0x03
170 #define COLOR_PERS_CLEAR_CH_5 0x04
171 #define COLOR_PERS_CLEAR_CH_10 0x05
172 #define COLOR_PERS_CLEAR_CH_15 0x06
173 #define COLOR_PERS_CLEAR_CH_20 0x07
174 #define COLOR_PERS_CLEAR_CH_25 0x08
175 #define COLOR_PERS_CLEAR_CH_30 0x09
176 #define COLOR_PERS_CLEAR_CH_35 0x0A
177 #define COLOR_PERS_CLEAR_CH_40 0x0B
178 #define COLOR_PERS_CLEAR_CH_45 0x0C
179 #define COLOR_PERS_CLEAR_CH_50 0x0D
180 #define COLOR_PERS_CLEAR_CH_55 0x0E
181 #define COLOR_PERS_CLEAR_CH_60 0x0F
182 
188 #define COLOR_CFG_WAIT_LONG 0x01
189 
195 #define COLOR_CTRL_GAIN_x1 0x00
196 #define COLOR_CTRL_GAIN_x4 0x01
197 #define COLOR_CTRL_GAIN_x16 0x02
198 #define COLOR_CTRL_GAIN_x60 0x03
199 
205 #define COLOR_COLOR_DATA_CLEAR 0x14
206 #define COLOR_COLOR_DATA_RED 0x16
207 #define COLOR_COLOR_DATA_GREEN 0x18
208 #define COLOR_COLOR_DATA_BLUE 0x1A
209 
215 #define COLOR_LED_RED_ENABLE 0x01
216 #define COLOR_LED_GREEN_ENABLE 0x01
217 #define COLOR_LED_BLUE_ENABLE 0x01
218 #define COLOR_LED_RED_DISABLE 0x00
219 #define COLOR_LED_GREEN_DISABLE 0x00
220 #define COLOR_LED_BLUE_DISABLE 0x00
221 
227 #define ORANGE_COLOR_FLAG 1
228 #define RED_COLOR_FLAG 2
229 #define PINK_COLOR_FLAG 3
230 #define PURPLE_COLOR_FLAG 4
231 #define BLUE_COLOR_FLAG 5
232 #define CYAN_COLOR_FLAG 6
233 #define GREEN_COLOR_FLAG 7
234 #define YELLOW_COLOR_FLAG 8
235 #define NON_COLOR_FLAG 0
236  // End group macro
240 // --------------------------------------------------------------- PUBLIC TYPES
249 typedef struct
250 {
251  // Output pins
252 
253  digital_out_t rd;
254  digital_out_t gr;
255  digital_out_t bl;
256 
257  // Input pins
258 
259  digital_in_t int_pin;
260 
261  // Modules
262 
263  i2c_master_t i2c;
264 
265  // ctx variable
266 
267  uint8_t slave_address;
268 
269 } color_t;
270 
274 typedef struct
275 {
276  // Communication gpio pins
277 
278  pin_name_t scl;
279  pin_name_t sda;
280 
281  // Additional gpio pins
282 
283  pin_name_t rd;
284  pin_name_t gr;
285  pin_name_t bl;
286  pin_name_t int_pin;
287 
288  // static variable
289 
290  uint32_t i2c_speed;
291  uint8_t i2c_address;
292 
293 } color_cfg_t;
294  // End types group
296 
297 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
298 
304 #ifdef __cplusplus
305 extern "C"{
306 #endif
307 
317 
327 
336 
347 void color_generic_write ( color_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
348 
360 void color_generic_read ( color_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
361 
371 void color_write_byte ( color_t *ctx, uint8_t reg, uint8_t data_to_write );
372 
383 uint16_t color_read_data ( color_t *ctx, uint8_t reg );
384 
395 float color_read_color_ratio ( color_t *ctx, uint8_t color );
396 
409 
434 uint8_t color_get_color ( float color_value );
435 
445 uint8_t color_get_interrupt ( color_t *ctx );
446 
457 void color_set_led ( color_t *ctx, uint8_t red, uint8_t green, uint8_t blue );
458 
459 
460 #ifdef __cplusplus
461 }
462 #endif
463 #endif // _COLOR_H_
464  // End public_function group
467 
468 // ------------------------------------------------------------------------- END
color_cfg_t::rd
pin_name_t rd
Definition: color.h:283
color_cfg_t::int_pin
pin_name_t int_pin
Definition: color.h:286
color_cfg_t::sda
pin_name_t sda
Definition: color.h:279
color_get_color
uint8_t color_get_color(float color_value)
Detect color.
color_cfg_t::i2c_address
uint8_t i2c_address
Definition: color.h:291
color_t::rd
digital_out_t rd
Definition: color.h:253
color_read_color_ratio
float color_read_color_ratio(color_t *ctx, uint8_t color)
Read color ratio from register.
color_read_data
uint16_t color_read_data(color_t *ctx, uint8_t reg)
Read 16-bit data from register.
color_generic_read
void color_generic_read(color_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
color_default_cfg
void color_default_cfg(color_t *ctx)
Click Default Configuration function.
color_generic_write
void color_generic_write(color_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
color_cfg_t::gr
pin_name_t gr
Definition: color.h:284
color_t::i2c
i2c_master_t i2c
Definition: color.h:263
color_t
Click ctx object definition.
Definition: color.h:250
color_t::gr
digital_out_t gr
Definition: color.h:254
color_t::slave_address
uint8_t slave_address
Definition: color.h:267
color_cfg_t
Click configuration structure definition.
Definition: color.h:275
color_t::bl
digital_out_t bl
Definition: color.h:255
color_write_byte
void color_write_byte(color_t *ctx, uint8_t reg, uint8_t data_to_write)
Write one byte to register.
color_init
COLOR_RETVAL color_init(color_t *ctx, color_cfg_t *cfg)
Initialization function.
color_t::int_pin
digital_in_t int_pin
Definition: color.h:259
color_cfg_setup
void color_cfg_setup(color_cfg_t *cfg)
Config Object Initialization function.
color_get_interrupt
uint8_t color_get_interrupt(color_t *ctx)
Get interrupt pin state.
color_get_color_value
float color_get_color_value(color_t *ctx)
Functions for read color value.
COLOR_RETVAL
#define COLOR_RETVAL
Definition: color.h:80
color_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color.h:290
color_cfg_t::bl
pin_name_t bl
Definition: color.h:285
color_set_led
void color_set_led(color_t *ctx, uint8_t red, uint8_t green, uint8_t blue)
Functions for set Led lights.
color_cfg_t::scl
pin_name_t scl
Definition: color.h:278