color9 2.0.0.0
color9.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 COLOR9_H
36#define COLOR9_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
63#define COLOR9_SLAVE_ADDR 0x52
64#define COLOR9_MAIN_CTRL 0x00
65#define COLOR9_LS_MEAS_RATE 0x04
66#define COLOR9_LS_GAIN 0x05
67#define COLOR9_PART_ID 0x06
68#define COLOR9_MAIN_STATUS 0x07
69#define COLOR9_LS_DATA_IR_0 0x0A
70#define COLOR9_LS_DATA_IR_1 0x0B
71#define COLOR9_LS_DATA_IR_2 0x0C
72#define COLOR9_LS_DATA_GREEN_0 0x0D
73#define COLOR9_LS_DATA_GREEN_1 0x0E
74#define COLOR9_LS_DATA_GREEN_2 0x0F
75#define COLOR9_LS_DATA_BLUE_0 0x10
76#define COLOR9_LS_DATA_BLUE_1 0x11
77#define COLOR9_LS_DATA_BLUE_2 0x12
78#define COLOR9_LS_DATA_RED_0 0x13
79#define COLOR9_LS_DATA_RED_1 0x14
80#define COLOR9_LS_DATA_RED_2 0x15
81#define COLOR9_INT_CFG 0x19
82#define COLOR9_INT_PERSISTENCE 0x1A
83#define COLOR9_LS_THRES_UP_0 0x21
84#define COLOR9_LS_THRES_UP_1 0x22
85#define COLOR9_LS_THRES_UP_2 0x23
86#define COLOR9_LS_THRES_LOW_0 0x24
87#define COLOR9_LS_THRES_LOW_1 0x25
88#define COLOR9_LS_THRES_LOW_2 0x26
89#define COLOR9_LS_THRES_VAR 0x27
90
91
96#define COLOR9_MAIN_CTRL_SW_RESET 0x10
97#define COLOR9_MAIN_CTRL_CS_MODE 0x04
98#define COLOR9_MAIN_CTRL_LS_EN 0x02
99 // End group main_ctrl
100
101
106#define COLOR9_LS_MEAS_BITWIDTH_20 0x00
107#define COLOR9_LS_MEAS_BITWIDTH_19 0x01
108#define COLOR9_LS_MEAS_BITWIDTH_18 0x02
109#define COLOR9_LS_MEAS_BITWIDTH_17 0x03
110#define COLOR9_LS_MEAS_BITWIDTH_16 0x04
111#define COLOR9_LS_MEAS_BITWIDTH_13 0x05
112
113#define COLOR9_LS_MEAS_RATE_25ms 0x00
114#define COLOR9_LS_MEAS_RATE_50ms 0x01
115#define COLOR9_LS_MEAS_RATE_100ms 0x02
116#define COLOR9_LS_MEAS_RATE_200ms 0x03
117#define COLOR9_LS_MEAS_RATE_500ms 0x04
118#define COLOR9_LS_MEAS_RATE_1000ms 0x05
119#define COLOR9_LS_MEAS_RATE_2000ms 0x06
120 // End group ls_meas_rate
121
126#define COLOR9_LS_GAIN_1 0x00
127#define COLOR9_LS_GAIN_3 0x01
128#define COLOR9_LS_GAIN_6 0x02
129#define COLOR9_LS_GAIN_9 0x03
130#define COLOR9_LS_GAIN_18 0x04
131 // End group ls_gain
132
137#define COLOR9_INT_CFG_IR_CH 0x00
138#define COLOR9_INT_CFG_ALS_GREEN_CH 0x01
139#define COLOR9_INT_CFG_RED_CH 0x02
140#define COLOR9_INT_CFG_BLUE_CH 0x03
141#define COLOR9_INT_CFG_LS_THRESHOLD_INT_MODE 0x00
142#define COLOR9_INT_CFG_LS_VARIATION_INT_MODE 0x01
143#define COLOR9_INT_CFG_LS_INT_ENABLE 0x01
144#define COLOR9_INT_CFG_LS_INT_DISABLE 0x00
145 // End group int_cfg
146
151#define COLOR9_INT_PERSISTENCE_ANYVAL_TRIGGER 0x00
152#define COLOR9_INT_PERSISTENCE_SECOND_COUNT_TRIGGER 0x01
153#define COLOR9_INT_PERSISTENCE_SIXTEEN_COUNT_TRIGGER 0x0F
154 // End group int_persistence
155
160#define COLOR9_LS_THRES_VAR_COUNT_8 0x00
161#define COLOR9_LS_THRES_VAR_COUNT_16 0x01
162#define COLOR9_LS_THRES_VAR_COUNT_32 0x02
163#define COLOR9_LS_THRES_VAR_COUNT_64 0x03
164#define COLOR9_LS_THRES_VAR_COUNT_1024 0x07
165 // End group ls_thres_var
166
171#define COLOR9_MAP_MIKROBUS( cfg, mikrobus ) \
172 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
174 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
181#define COLOR9_RETVAL uint8_t
182
183#define COLOR9_OK 0x00
184#define COLOR9_INIT_ERROR 0xFF
187 // End group macro
188// --------------------------------------------------------------- PUBLIC TYPES
197typedef struct
198{
199 digital_in_t int_pin;
200
201 // Modules
202
203 i2c_master_t i2c;
204
205 // ctx variable
206
208
209} color9_t;
210
214typedef struct
215{
216 // Communication gpio pins
217
218 pin_name_t scl;
219 pin_name_t sda;
220
221 // Additional gpio pins
222
223 pin_name_t int_pin;
224
225 // static variable
226
227 uint32_t i2c_speed;
228 uint8_t i2c_address;
229
231
232 // End types group
233// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
234
240#ifdef __cplusplus
241extern "C"{
242#endif
243
253
263
264
265
275void color9_write ( color9_t* ctx, uint8_t reg_addr, uint8_t r_data );
276
285uint8_t color9_read ( color9_t* ctx, uint8_t reg_addr );
286
294
304uint32_t color9_get_Ir ( color9_t* ctx );
305
315uint32_t color9_get_green ( color9_t* ctx );
316
326uint32_t color9_get_blue ( color9_t* ctx );
327
337uint32_t color9_get_red ( color9_t* ctx );
338
349
359void color9_meas_rate ( color9_t* ctx, uint8_t resolution, uint8_t meas_rate );
360
369void color9_reg_ctrl ( color9_t* ctx, uint8_t cfg );
370
379void color9_set_gain ( color9_t* ctx, uint8_t g_setting );
380
391void color9_int_config ( color9_t* ctx, uint8_t int_select, uint8_t int_mode,
392 uint8_t cfg_setting );
393
402void color9_sample_compare ( color9_t* ctx, uint8_t num_of_compares );
403
412uint32_t color9_read_32 ( color9_t* ctx, uint8_t reg_addr );
413
423void color9_write_32 ( color9_t* ctx, uint8_t reg_addr, uint32_t treas_val );
424
433void color9_similarity_count ( color9_t* ctx, uint8_t sim_set );
434
443void color9_upper_tresset ( color9_t* ctx, uint32_t set_val );
444
453void color9_lower_tresset ( color9_t* ctx, uint32_t set_val );
454
455#ifdef __cplusplus
456}
457#endif
458#endif // _COLOR9_H_
459
460 // End public_function group
462
463// ------------------------------------------------------------------------- END
#define COLOR9_RETVAL
Definition color9.h:181
void color9_cfg_setup(color9_cfg_t *cfg)
Config Object Initialization function.
void color9_reg_ctrl(color9_t *ctx, uint8_t cfg)
Function for setting the main configuration register.
uint32_t color9_get_red(color9_t *ctx)
Gets value of Red measurement reading.
uint32_t color9_read_32(color9_t *ctx, uint8_t reg_addr)
Generic read function for 32 bits.
void color9_similarity_count(color9_t *ctx, uint8_t sim_set)
Similarity count.
COLOR9_RETVAL color9_init(color9_t *ctx, color9_cfg_t *cfg)
Initialization function.
void color9_sample_compare(color9_t *ctx, uint8_t num_of_compares)
Configre number of compares between samples.
uint8_t color9_read(color9_t *ctx, uint8_t reg_addr)
Generic read function.
void color9_lower_tresset(color9_t *ctx, uint32_t set_val)
Lower Tresset.
uint32_t color9_get_green(color9_t *ctx)
Gets value of Green measurement reading.
void color9_write_32(color9_t *ctx, uint8_t reg_addr, uint32_t treas_val)
Generic write function for 32 bits.
void color9_sw_reset(color9_t *ctx)
Software reset function.
void color9_upper_tresset(color9_t *ctx, uint32_t set_val)
Upper Tresset.
void color9_write(color9_t *ctx, uint8_t reg_addr, uint8_t r_data)
Generic write function.
uint32_t color9_get_blue(color9_t *ctx)
Gets value of Blue measurement reading.
void color9_set_gain(color9_t *ctx, uint8_t g_setting)
Function for gain setting.
void color9_meas_rate(color9_t *ctx, uint8_t resolution, uint8_t meas_rate)
Configure measurement rates.
uint8_t color9_get_status_reg(color9_t *ctx)
Status register value.
uint32_t color9_get_Ir(color9_t *ctx)
Get value of IR measurement reading.
void color9_int_config(color9_t *ctx, uint8_t int_select, uint8_t int_mode, uint8_t cfg_setting)
Interrupt configuration.
Click configuration structure definition.
Definition color9.h:215
uint32_t i2c_speed
Definition color9.h:227
pin_name_t scl
Definition color9.h:218
pin_name_t int_pin
Definition color9.h:223
pin_name_t sda
Definition color9.h:219
uint8_t i2c_address
Definition color9.h:228
Click ctx object definition.
Definition color9.h:198
digital_in_t int_pin
Definition color9.h:199
i2c_master_t i2c
Definition color9.h:203
uint8_t slave_address
Definition color9.h:207