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 
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 // -------------------------------------------------------------- PUBLIC MACROS
66 #define COLOR8_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define COLOR8_RETVAL uint8_t
77 
78 #define COLOR8_OK 0x00
79 #define COLOR8_INIT_ERROR 0xFF
80 
86 #define COLOR8_REG_SYSTEM_CONTROL 0x40
87 #define COLOR8_REG_MODE_CONTROL_1 0x41
88 #define COLOR8_REG_MODE_CONTROL_2 0x42
89 #define COLOR8_REG_RED_DATA 0x50
90 #define COLOR8_REG_RED_DATA_LSB 0x50
91 #define COLOR8_REG_RED_DATA_MSB 0x51
92 #define COLOR8_REG_GREEN_DATA 0x52
93 #define COLOR8_REG_GREEN_DATA_LSB 0x52
94 #define COLOR8_REG_GREEN_DATA_MSB 0x53
95 #define COLOR8_REG_BLUE_DATA 0x54
96 #define COLOR8_REG_BLUE_DATA_LSB 0x54
97 #define COLOR8_REG_BLUE_DATA_MSB 0x55
98 #define COLOR8_REG_IR_DATA 0x58
99 #define COLOR8_REG_IR_DATA_LSB 0x58
100 #define COLOR8_REG_IR_DATA_MSB 0x59
101 #define COLOR8_REG_GREEN_DATA_2 0x5A
102 #define COLOR8_REG_GREEN_DATA_2_LSB 0x5A
103 #define COLOR8_REG_GREEN_DATA_2_MSB 0x5B
104 #define COLOR8_REG_INTERRUPT 0x60
105 #define COLOR8_REG_PERSISTENCE 0x61
106 #define COLOR8_REG_THRESHOLD_HIGH_LSB 0x62
107 #define COLOR8_REG_THRESHOLD_HIGH_MSB 0x63
108 #define COLOR8_REG_THRESHOLD_LOW_LSB 0x64
109 #define COLOR8_REG_THRESHOLD_LOW_MSB 0x65
110 #define COLOR8_REG_MANUFACTURER_ID 0x92
111 
117 #define COLOR8_SS_SW_RESET_IS_NOT_DONE 0x00
118 #define COLOR8_SS_SW_RESET_IS_DONE 0x80
119 #define COLOR8_SS_INT_PIN_IS_NOT_ACTIVE 0x00
120 #define COLOR8_SS_INT_PIN_IS_ACTIVE 0x40
121 
127 #define COLOR8_MC1_IR_DATA_GAIN_X1 0x20
128 #define COLOR8_MC1_IR_DATA_GAIN_X32 0x60
129 #define COLOR8_MC1_RGB_DATA_GAIN_X1 0x08
130 #define COLOR8_MC1_RGB_DATA_GAIN_X32 0x18
131 #define COLOR8_MC1_MEASURE_MODE_120ms 0x02
132 #define COLOR8_MC1_MEASURE_MODE_240ms 0x03
133 #define COLOR8_MC1_MEASURE_MODE_35ms 0x05
134 
140 #define COLOR8_MC2_MEASUREMENT_IS_ACTIVE 0x10
141 #define COLOR8_MC2_MEASUREMENT_IS_INACTIVE 0x00
142 
148 #define COLOR8_INT_INTERRUPT_SIGNAL_IS_ACTIVE 0x80
149 #define COLOR8_INT_RED_CHANNEL 0x00
150 #define COLOR8_INT_GREEN_CHANNEL 0x02
151 #define COLOR8_INT_BLUE_CHANNEL 0x04
152 #define COLOR8_INT_PIN_DISABLE 0x00
153 #define COLOR8_INT_PIN_ENABLE 0x01
154 
160 #define COLOR8_PERSISTENCE_INT_SETTINGS_0 0x00
161 #define COLOR8_PERSISTENCE_INT_SETTINGS_1 0x01
162 #define COLOR8_PERSISTENCE_INT_SETTINGS_2 0x02
163 #define COLOR8_PERSISTENCE_INT_SETTINGS_3 0x03
164 
170 #define COLOR8_DEF_MANUFACTURER_ID 0xE0
171 #define COLOR8_DEF_PART_ID 0x0D
172 #define COLOR8_DEF_SLAVE_ADDRESS_0 0x38
173 #define COLOR8_DEF_SLAVE_ADDRESS_1 0x39
174 
180 #define ORANGE_COLOR_FLAG 1
181 #define RED_COLOR_FLAG 2
182 #define PINK_COLOR_FLAG 3
183 #define PURPLE_COLOR_FLAG 4
184 #define BLUE_COLOR_FLAG 5
185 #define CYAN_COLOR_FLAG 6
186 #define GREEN_COLOR_FLAG 7
187 #define YELLOW_COLOR_FLAG 8
188 #define NON_COLOR_FLAG 0
189  // End group macro
192 // --------------------------------------------------------------- PUBLIC TYPES
201 typedef struct
202 {
203  // Input pins
204 
205  digital_in_t int_pin;
206 
207  // Modules
208 
209  i2c_master_t i2c;
210 
211  // ctx variable
212 
213  uint8_t slave_address;
214 
215 } color8_t;
216 
220 typedef struct
221 {
222  // Communication gpio pins
223 
224  pin_name_t scl;
225  pin_name_t sda;
226 
227  // Additional gpio pins
228 
229  pin_name_t int_pin;
230 
231  // static variable
232 
233  uint32_t i2c_speed;
234  uint8_t i2c_address;
235 
236 } color8_cfg_t;
237  // End types group
239 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
240 
246 #ifdef __cplusplus
247 extern "C"{
248 #endif
249 
259 
268 
279 void color8_generic_write ( color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
280 
291 void color8_generic_read ( color8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
292 
302 void color8_write_byte ( color8_t *ctx, uint8_t reg, uint8_t w_data );
303 
312 uint8_t color8_read_byte ( color8_t *ctx, uint8_t reg );
313 
322 
331 uint16_t color8_read_data ( color8_t *ctx, uint8_t reg_data );
332 
342 
358 uint8_t color8_get_color ( color8_t *ctx, float color_value );
359 
360 
361 #ifdef __cplusplus
362 }
363 #endif
364 #endif // _COLOR8_H_
365  // End public_function group
368 
369 // ------------------------------------------------------------------------- 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:221
color8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color8.h:233
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:205
color8_t
Click ctx object definition.
Definition: color8.h:202
color8_cfg_t::sda
pin_name_t sda
Definition: color8.h:225
color8_t::slave_address
uint8_t slave_address
Definition: color8.h:213
COLOR8_RETVAL
#define COLOR8_RETVAL
Definition: color8.h:76
color8_cfg_t::int_pin
pin_name_t int_pin
Definition: color8.h:229
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:224
color8_t::i2c
i2c_master_t i2c
Definition: color8.h:209
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:234