color13  2.0.0.0
color13.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef COLOR13_H
29 #define COLOR13_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define COLOR13_REG_MAIN_CTRL 0x00
60 #define COLOR13_REG_PS_VCSEL 0x01
61 #define COLOR13_REG_PS_PULSES 0x02
62 #define COLOR13_REG_PS_MEASRATE 0x03
63 #define COLOR13_REG_LS_MEAS_RATE 0x04
64 #define COLOR13_REG_LS_GAIN 0x05
65 #define COLOR13_REG_PART_ID 0x06
66 #define COLOR13_REG_MAIN_STATUS 0x07
67 #define COLOR13_REG_PS_DATA_0 0x08
68 #define COLOR13_REG_PS_DATA_1 0x09
69 #define COLOR13_REG_LS_DATA_IR_0 0x0A
70 #define COLOR13_REG_LS_DATA_IR_1 0x0B
71 #define COLOR13_REG_LS_DATA_IR_2 0x0C
72 #define COLOR13_REG_LS_DATA_GREEN_0 0x0D
73 #define COLOR13_REG_LS_DATA_GREEN_1 0x0E
74 #define COLOR13_REG_LS_DATA_GREEN_2 0x0F
75 #define COLOR13_REG_LS_DATA_BLUE_0 0x10
76 #define COLOR13_REG_LS_DATA_BLUE_1 0x11
77 #define COLOR13_REG_LS_DATA_BLUE_2 0x12
78 #define COLOR13_REG_LS_DATA_RED_0 0x13
79 #define COLOR13_REG_LS_DATA_RED_1 0x14
80 #define COLOR13_REG_LS_DATA_RED_2 0x15
81 #define COLOR13_REG_INT_CFG 0x19
82 #define COLOR13_REG_INT_PST 0x1A
83 #define COLOR13_REG_PS_THRES_UP_0 0x1B
84 #define COLOR13_REG_PS_THRES_UP_1 0x1C
85 #define COLOR13_REG_PS_THRES_LOW_0 0x1D
86 #define COLOR13_REG_PS_THRES_LOW_1 0x1E
87 #define COLOR13_REG_PS_CAN_0 0x1F
88 #define COLOR13_REG_PS_CAN_1_ANA 0x20
89 #define COLOR13_REG_LS_THRES_UP_0 0x21
90 #define COLOR13_REG_LS_THRES_UP_1 0x22
91 #define COLOR13_REG_LS_THRES_UP_2 0x23
92 #define COLOR13_REG_LS_THRES_LOW_0 0x24
93 #define COLOR13_REG_LS_THRES_LOW_1 0x25
94 #define COLOR13_REG_LS_THRES_LOW_2 0x26
95 #define COLOR13_REG_LS_THRES_VAR 0x27
96  // color13_reg
98 
113 #define COLOR13_ID 0xC2
114 
115 
121 #define COLOR13_SET_DEV_ADDR 0x52
122  // color13_set
124 
139 #define COLOR13_MAP_MIKROBUS( cfg, mikrobus ) \
140  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
141  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
142  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
143  // color13_map // color13
146 
151 typedef struct
152 {
153  // Input pins
154  digital_in_t int_pin;
156  // Modules
157  i2c_master_t i2c;
159  // I2C slave address
160  uint8_t slave_address;
162  // ALS resolution
164 
165 } color13_t;
166 
171 typedef struct
172 {
173  pin_name_t scl;
174  pin_name_t sda;
176  pin_name_t int_pin;
178  uint32_t i2c_speed;
179  uint8_t i2c_address;
181 } color13_cfg_t;
182 
187 typedef struct
188 {
189  uint32_t red;
190  uint32_t green;
191  uint32_t blue;
192  uint32_t ir;
193 
195 
200 typedef enum
201 {
206  COLOR13_ERROR_CFG = -4
207 
209 
226 
240 err_t color13_init ( color13_t *ctx, color13_cfg_t *cfg );
241 
256 err_t color13_generic_write ( color13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
257 
272 err_t color13_generic_read ( color13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
273 
281 uint8_t color13_get_int ( color13_t *ctx );
282 
299 err_t color13_get_proximity ( color13_t *ctx, uint16_t *ps_data );
300 
320 err_t color13_get_als ( color13_t *ctx, float *als_data );
321 
341 err_t color13_ls_color ( color13_t *ctx, uint8_t ls_reg, uint32_t *ls_data );
342 
359 err_t color13_get_rgb_ir ( color13_t *ctx, color13_color_t *color_data );
360 
371 
372 #ifdef __cplusplus
373 }
374 #endif
375 #endif // COLOR13_H
376  // color13
378 
379 // ------------------------------------------------------------------------ END
color13_cfg_setup
void color13_cfg_setup(color13_cfg_t *cfg)
Color 13 configuration object setup function.
color13_ls_color
err_t color13_ls_color(color13_t *ctx, uint8_t ls_reg, uint32_t *ls_data)
Read ls data from color registers.
COLOR13_ERROR_PARAM
@ COLOR13_ERROR_PARAM
Definition: color13.h:205
color13_get_proximity
err_t color13_get_proximity(color13_t *ctx, uint16_t *ps_data)
Read proximity data from device.
color13_generic_read
err_t color13_generic_read(color13_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Color 13 I2C reading function.
color13_get_rgb_ir
err_t color13_get_rgb_ir(color13_t *ctx, color13_color_t *color_data)
Read color data from device.
COLOR13_ERROR_OVF
@ COLOR13_ERROR_OVF
Definition: color13.h:204
color13_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color13.h:178
color13_t::slave_address
uint8_t slave_address
Definition: color13.h:160
color13_color_t::red
uint32_t red
Definition: color13.h:189
color13_get_int
uint8_t color13_get_int(color13_t *ctx)
Get interrupt pin state.
color13_color_t::blue
uint32_t blue
Definition: color13.h:191
color13_t::lux_resolution
float lux_resolution
Definition: color13.h:163
COLOR13_OK
@ COLOR13_OK
Definition: color13.h:202
color13_color_t
Color 13 color data object.
Definition: color13.h:188
color13_t::i2c
i2c_master_t i2c
Definition: color13.h:157
color13_t::int_pin
digital_in_t int_pin
Definition: color13.h:154
color13_init
err_t color13_init(color13_t *ctx, color13_cfg_t *cfg)
Color 13 initialization function.
color13_return_value_t
color13_return_value_t
Color 13 Click return value data.
Definition: color13.h:201
color13_get_als_resolution
float color13_get_als_resolution(color13_t *ctx)
Get resolution for the lux calculation.
color13_generic_write
err_t color13_generic_write(color13_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Color 13 I2C writing function.
color13_cfg_t::i2c_address
uint8_t i2c_address
Definition: color13.h:179
color13_get_als
err_t color13_get_als(color13_t *ctx, float *als_data)
Read lux data from device.
color13_cfg_t::int_pin
pin_name_t int_pin
Definition: color13.h:176
COLOR13_ERROR_CFG
@ COLOR13_ERROR_CFG
Definition: color13.h:206
color13_color_t::ir
uint32_t ir
Definition: color13.h:192
color13_color_t::green
uint32_t green
Definition: color13.h:190
COLOR13_ERROR
@ COLOR13_ERROR
Definition: color13.h:203
color13_t
Color 13 Click context object.
Definition: color13.h:152
color13_cfg_t::sda
pin_name_t sda
Definition: color13.h:174
color13_cfg_t::scl
pin_name_t scl
Definition: color13.h:173
color13_cfg_t
Color 13 Click configuration object.
Definition: color13.h:172