color8  2.0.0.0
color8.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 COLOR8_H
36 #define COLOR8_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define COLOR8_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
56 
62 #define COLOR8_RETVAL uint8_t
63 
64 #define COLOR8_OK 0x00
65 #define COLOR8_INIT_ERROR 0xFF
66 
72 #define COLOR8_REG_SYSTEM_CONTROL 0x40
73 #define COLOR8_REG_MODE_CONTROL_1 0x41
74 #define COLOR8_REG_MODE_CONTROL_2 0x42
75 #define COLOR8_REG_RED_DATA 0x50
76 #define COLOR8_REG_RED_DATA_LSB 0x50
77 #define COLOR8_REG_RED_DATA_MSB 0x51
78 #define COLOR8_REG_GREEN_DATA 0x52
79 #define COLOR8_REG_GREEN_DATA_LSB 0x52
80 #define COLOR8_REG_GREEN_DATA_MSB 0x53
81 #define COLOR8_REG_BLUE_DATA 0x54
82 #define COLOR8_REG_BLUE_DATA_LSB 0x54
83 #define COLOR8_REG_BLUE_DATA_MSB 0x55
84 #define COLOR8_REG_IR_DATA 0x58
85 #define COLOR8_REG_IR_DATA_LSB 0x58
86 #define COLOR8_REG_IR_DATA_MSB 0x59
87 #define COLOR8_REG_GREEN_DATA_2 0x5A
88 #define COLOR8_REG_GREEN_DATA_2_LSB 0x5A
89 #define COLOR8_REG_GREEN_DATA_2_MSB 0x5B
90 #define COLOR8_REG_INTERRUPT 0x60
91 #define COLOR8_REG_PERSISTENCE 0x61
92 #define COLOR8_REG_THRESHOLD_HIGH_LSB 0x62
93 #define COLOR8_REG_THRESHOLD_HIGH_MSB 0x63
94 #define COLOR8_REG_THRESHOLD_LOW_LSB 0x64
95 #define COLOR8_REG_THRESHOLD_LOW_MSB 0x65
96 #define COLOR8_REG_MANUFACTURER_ID 0x92
97 
103 #define COLOR8_SS_SW_RESET_IS_NOT_DONE 0x00
104 #define COLOR8_SS_SW_RESET_IS_DONE 0x80
105 #define COLOR8_SS_INT_PIN_IS_NOT_ACTIVE 0x00
106 #define COLOR8_SS_INT_PIN_IS_ACTIVE 0x40
107 
113 #define COLOR8_MC1_IR_DATA_GAIN_X1 0x20
114 #define COLOR8_MC1_IR_DATA_GAIN_X32 0x60
115 #define COLOR8_MC1_RGB_DATA_GAIN_X1 0x08
116 #define COLOR8_MC1_RGB_DATA_GAIN_X32 0x18
117 #define COLOR8_MC1_MEASURE_MODE_120ms 0x02
118 #define COLOR8_MC1_MEASURE_MODE_240ms 0x03
119 #define COLOR8_MC1_MEASURE_MODE_35ms 0x05
120 
126 #define COLOR8_MC2_MEASUREMENT_IS_ACTIVE 0x10
127 #define COLOR8_MC2_MEASUREMENT_IS_INACTIVE 0x00
128 
134 #define COLOR8_INT_INTERRUPT_SIGNAL_IS_ACTIVE 0x80
135 #define COLOR8_INT_RED_CHANNEL 0x00
136 #define COLOR8_INT_GREEN_CHANNEL 0x02
137 #define COLOR8_INT_BLUE_CHANNEL 0x04
138 #define COLOR8_INT_PIN_DISABLE 0x00
139 #define COLOR8_INT_PIN_ENABLE 0x01
140 
146 #define COLOR8_PERSISTENCE_INT_SETTINGS_0 0x00
147 #define COLOR8_PERSISTENCE_INT_SETTINGS_1 0x01
148 #define COLOR8_PERSISTENCE_INT_SETTINGS_2 0x02
149 #define COLOR8_PERSISTENCE_INT_SETTINGS_3 0x03
150 
156 #define COLOR8_DEF_MANUFACTURER_ID 0xE0
157 #define COLOR8_DEF_PART_ID 0x0D
158 #define COLOR8_DEF_SLAVE_ADDRESS_0 0x38
159 #define COLOR8_DEF_SLAVE_ADDRESS_1 0x39
160 
166 #define ORANGE_COLOR_FLAG 1
167 #define RED_COLOR_FLAG 2
168 #define PINK_COLOR_FLAG 3
169 #define PURPLE_COLOR_FLAG 4
170 #define BLUE_COLOR_FLAG 5
171 #define CYAN_COLOR_FLAG 6
172 #define GREEN_COLOR_FLAG 7
173 #define YELLOW_COLOR_FLAG 8
174 #define NON_COLOR_FLAG 0
175  // End group macro
178 // --------------------------------------------------------------- PUBLIC TYPES
187 typedef struct
188 {
189  // Input pins
190 
191  digital_in_t int_pin;
192 
193  // Modules
194 
195  i2c_master_t i2c;
196 
197  // ctx variable
198 
199  uint8_t slave_address;
200 
201 } color8_t;
202 
206 typedef struct
207 {
208  // Communication gpio pins
209 
210  pin_name_t scl;
211  pin_name_t sda;
212 
213  // Additional gpio pins
214 
215  pin_name_t int_pin;
216 
217  // static variable
218 
219  uint32_t i2c_speed;
220  uint8_t i2c_address;
221 
222 } color8_cfg_t;
223  // End types group
225 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
226 
232 #ifdef __cplusplus
233 extern "C"{
234 #endif
235 
244 void color8_cfg_setup ( color8_cfg_t *cfg );
245 
254 
265 void color8_generic_write ( color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
266 
277 void color8_generic_read ( color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
278 
288 void color8_write_byte ( color8_t *ctx, uint8_t reg, uint8_t w_data );
289 
298 uint8_t color8_read_byte ( color8_t *ctx, uint8_t reg );
299 
307 uint8_t color8_get_interrupt ( color8_t *ctx );
308 
317 uint16_t color8_read_data ( color8_t *ctx, uint8_t reg_data );
318 
327 float color8_get_color_value ( color8_t *ctx );
328 
344 uint8_t color8_get_color ( color8_t *ctx, float color_value );
345 
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 #endif // _COLOR8_H_
351  // End public_function group
354 
355 // ------------------------------------------------------------------------- END
color8_get_interrupt
uint8_t color8_get_interrupt(color8_t *ctx)
Functions get interrupt.
color8_cfg_setup
void color8_cfg_setup(color8_cfg_t *cfg)
Config Object Initialization function.
color8_get_color
uint8_t color8_get_color(color8_t *ctx, float color_value)
Functions for detect colors.
color8_cfg_t
Click configuration structure definition.
Definition: color8.h:206
color8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color8.h:219
color8_init
COLOR8_RETVAL color8_init(color8_t *ctx, color8_cfg_t *cfg)
Initialization function.
color8_write_byte
void color8_write_byte(color8_t *ctx, uint8_t reg, uint8_t w_data)
Functions for write one byte in register.
color8_get_color_value
float color8_get_color_value(color8_t *ctx)
Functions for read color value.
color8_t::int_pin
digital_in_t int_pin
Definition: color8.h:191
color8_t
Click ctx object definition.
Definition: color8.h:187
color8_cfg_t::sda
pin_name_t sda
Definition: color8.h:211
color8_t::slave_address
uint8_t slave_address
Definition: color8.h:199
COLOR8_RETVAL
#define COLOR8_RETVAL
Definition: color8.h:62
color8_cfg_t::int_pin
pin_name_t int_pin
Definition: color8.h:215
color8_read_byte
uint8_t color8_read_byte(color8_t *ctx, uint8_t reg)
Functions for read one byte data from register.
color8_generic_write
void color8_generic_write(color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
color8_cfg_t::scl
pin_name_t scl
Definition: color8.h:210
color8_t::i2c
i2c_master_t i2c
Definition: color8.h:195
color8_generic_read
void color8_generic_read(color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
color8_read_data
uint16_t color8_read_data(color8_t *ctx, uint8_t reg_data)
Functions for read data from register.
color8_cfg_t::i2c_address
uint8_t i2c_address
Definition: color8.h:220