color17  2.1.0.0
color17.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 COLOR17_H
29 #define COLOR17_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define COLOR17_REG_CH0_EXP_RESMSB 0x00
70 #define COLOR17_REG_CH0_RESMSB_CNT_CRC 0x01
71 #define COLOR17_REG_CH1_EXP_RES_MSB 0x02
72 #define COLOR17_REG_CH1_RESMSB_CNT_CRC 0x03
73 #define COLOR17_REG_CH2_EXP_RES_MSB 0x04
74 #define COLOR17_REG_CH2_RESMSB_CNT_CRC 0x05
75 #define COLOR17_REG_CH3_EXP_RES_MSB 0x06
76 #define COLOR17_REG_CH4_RESMSB_CNT_CRC 0x07
77 #define COLOR17_REG_THLD_EXP_RES_L 0x08
78 #define COLOR17_REG_THLD_EXP_RES_H 0x09
79 #define COLOR17_REG_CONFIG_0 0x0A
80 #define COLOR17_REG_CONFIG_1 0x0B
81 #define COLOR17_REG_CONFIG_2 0x0C
82 #define COLOR17_REG_DEVICE_ID 0x11
83  // color17_reg
85 
100 #define COLOR17_DEVICE_ID 0x0821u
101 
106 #define COLOR17_CONFIG_0_QWAKE_DIS 0x00
107 #define COLOR17_CONFIG_0_QWAKE_EN 0x01
108 #define COLOR17_CONFIG_0_RANGE_2_2KLUX 0x00
109 #define COLOR17_CONFIG_0_RANGE_4_5KLUX 0x01
110 #define COLOR17_CONFIG_0_RANGE_9KLUX 0x02
111 #define COLOR17_CONFIG_0_RANGE_18KLUX 0x03
112 #define COLOR17_CONFIG_0_RANGE_36KLUX 0x04
113 #define COLOR17_CONFIG_0_RANGE_72KLUX 0x05
114 #define COLOR17_CONFIG_0_RANGE_144KLUX 0x06
115 #define COLOR17_CONFIG_0_RANGE_AUTO 0x0C
116 #define COLOR17_CONFIG_0_CONV_600US 0x00
117 #define COLOR17_CONFIG_0_CONV_1_MS 0x01
118 #define COLOR17_CONFIG_0_CONV_1_8MS 0x02
119 #define COLOR17_CONFIG_0_CONV_3_4MS 0x03
120 #define COLOR17_CONFIG_0_CONV_6_5MS 0x04
121 #define COLOR17_CONFIG_0_CONV_12_7MS 0x05
122 #define COLOR17_CONFIG_0_CONV_25MS 0x06
123 #define COLOR17_CONFIG_0_CONV_50MS 0x07
124 #define COLOR17_CONFIG_0_CONV_100MS 0x08
125 #define COLOR17_CONFIG_0_CONV_200MS 0x09
126 #define COLOR17_CONFIG_0_CONV_400MS 0x0A
127 #define COLOR17_CONFIG_0_CONV_800MS 0x0B
128 #define COLOR17_CONFIG_0_OP_MODE_PD 0x00
129 #define COLOR17_CONFIG_0_OP_MODE_F_ONESHOT 0x01
130 #define COLOR17_CONFIG_0_OP_MODE_ONESHOT 0x02
131 #define COLOR17_CONFIG_0_OP_MODE_CONTINUOUS 0x03
132 #define COLOR17_CONFIG_0_LATCH_DIS 0x00
133 #define COLOR17_CONFIG_0_LATCH_EN 0x01
134 #define COLOR17_CONFIG_0_INT_POL_LOW 0x00
135 #define COLOR17_CONFIG_0_INT_POL_HIGH 0x01
136 #define COLOR17_CONFIG_0_FAULT_COUNT_0 0x00
137 #define COLOR17_CONFIG_0_FAULT_COUNT_2 0x01
138 #define COLOR17_CONFIG_0_FAULT_COUNT_4 0x02
139 #define COLOR17_CONFIG_0_FAULT_COUNT_8 0x03
140 
145 #define COLOR17_CONFIG_1_MUST_READ_WRITE 0x8000u
146 #define COLOR17_CONFIG_1_THRESHOLD_CH0 0x00
147 #define COLOR17_CONFIG_1_THRESHOLD_CH1 0x01
148 #define COLOR17_CONFIG_1_THRESHOLD_CH2 0x02
149 #define COLOR17_CONFIG_1_THRESHOLD_CH3 0x03
150 #define COLOR17_CONFIG_1_INT_DIR_INPUT 0x00
151 #define COLOR17_CONFIG_1_INT_DIR_OUTPUT 0x01
152 #define COLOR17_CONFIG_1_INT_CFG_SMBUS_ALR 0x00
153 #define COLOR17_CONFIG_1_INT_CFG_NEXT_CH 0x01
154 #define COLOR17_CONFIG_1_INT_CFG_ALL_CH 0x03
155 #define COLOR17_CONFIG_1_I2C_BURST_DISABLE 0x00
156 #define COLOR17_CONFIG_1_I2C_BURST_ENABLE 0x01
157 
162 #define COLOR17_CONFIG_2_FLAG_DISABLE 0x00
163 #define COLOR17_CONFIG_2_FLAG_ENABLE 0x01
164 
169 #define COLOR17_SEL_CHANNEL_0 0x00
170 #define COLOR17_SEL_CHANNEL_1 0x01
171 #define COLOR17_SEL_CHANNEL_2 0x02
172 #define COLOR17_SEL_CHANNEL_3 0x03
173 
179 #define COLOR17_DEVICE_ADDRESS_GND 0x44
180 #define COLOR17_DEVICE_ADDRESS_VCC 0x45
181  // color17_set
183 
198 #define COLOR17_MAP_MIKROBUS( cfg, mikrobus ) \
199  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
200  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
201  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
202  // color17_map // color17
205 
210 typedef struct
211 {
212  // Input pins
213  digital_in_t int_pin;
215  // Modules
216  i2c_master_t i2c;
218  // I2C slave address
219  uint8_t slave_address;
221 } color17_t;
222 
227 typedef struct
228 {
229  pin_name_t scl;
230  pin_name_t sda;
232  pin_name_t int_pin;
234  uint32_t i2c_speed;
235  uint8_t i2c_address;
237 } color17_cfg_t;
238 
243 typedef struct
244 {
245  uint8_t qwake;
246  uint8_t range;
247  uint8_t conv_time;
248  uint8_t op_mode;
249  uint8_t latch;
250  uint8_t int_pol;
251  uint8_t fault_cnt;
252  uint8_t thld_ch_sel;
253  uint8_t int_dir;
254  uint8_t int_cfg;
255  uint8_t i2c_burst;
258 
263 typedef struct
264 {
265  uint8_t ovld_flag;
266  uint8_t conv_ready_flag;
267  uint8_t flag_h;
268  uint8_t flag_l;
271 
276 typedef enum
277 {
279  COLOR17_ERROR = -1
280 
282 
299 
313 err_t color17_init ( color17_t *ctx, color17_cfg_t *cfg );
314 
328 
343 err_t color17_generic_write ( color17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
344 
359 err_t color17_generic_read ( color17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
360 
375 err_t color17_write_reg ( color17_t *ctx, uint8_t reg, uint16_t data_in );
376 
391 err_t color17_read_reg ( color17_t *ctx, uint8_t reg, uint16_t *data_out );
392 
406 err_t color17_get_device_id ( color17_t *ctx, uint16_t *device_id );
407 
423 
439 
453 err_t color17_get_ch_measurement ( color17_t *ctx, uint8_t ch, uint32_t *adc_codes );
454 
469 err_t color17_get_measurement ( color17_t *ctx, uint32_t *adc_codes );
470 
486 err_t color17_get_cct ( color17_t *ctx, float *cct, float *light_intensity );
487 
500 
501 #ifdef __cplusplus
502 }
503 #endif
504 #endif // COLOR17_H
505  // color17
507 
508 // ------------------------------------------------------------------------ END
color17_config_t::int_cfg
uint8_t int_cfg
Definition: color17.h:254
COLOR17_ERROR
@ COLOR17_ERROR
Definition: color17.h:279
color17_get_device_id
err_t color17_get_device_id(color17_t *ctx, uint16_t *device_id)
Color 17 gets device ID function.
color17_cfg_setup
void color17_cfg_setup(color17_cfg_t *cfg)
Color 17 configuration object setup function.
color17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: color17.h:234
color17_default_cfg
err_t color17_default_cfg(color17_t *ctx)
Color 17 default configuration function.
color17_cfg_t::sda
pin_name_t sda
Definition: color17.h:230
color17_cfg_t::scl
pin_name_t scl
Definition: color17.h:229
COLOR17_OK
@ COLOR17_OK
Definition: color17.h:278
color17_t::i2c
i2c_master_t i2c
Definition: color17.h:216
color17_t::int_pin
digital_in_t int_pin
Definition: color17.h:213
color17_generic_read
err_t color17_generic_read(color17_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 17 I2C reading function.
color17_config_t::thld_ch_sel
uint8_t thld_ch_sel
Definition: color17.h:252
color17_get_ch_measurement
err_t color17_get_ch_measurement(color17_t *ctx, uint8_t ch, uint32_t *adc_codes)
Color 17 gets the channel measurements data function.
color17_config_t::qwake
uint8_t qwake
Definition: color17.h:245
color17_status_flag_t::flag_l
uint8_t flag_l
Definition: color17.h:268
color17_status_flag_t::ovld_flag
uint8_t ovld_flag
Definition: color17.h:265
color17_t::slave_address
uint8_t slave_address
Definition: color17.h:219
color17_get_status_flag
err_t color17_get_status_flag(color17_t *ctx, color17_status_flag_t *status_flag)
Color 17 gets the status flag function.
color17_config_t::latch
uint8_t latch
Definition: color17.h:249
color17_status_flag_t::conv_ready_flag
uint8_t conv_ready_flag
Definition: color17.h:266
color17_get_measurement
err_t color17_get_measurement(color17_t *ctx, uint32_t *adc_codes)
Color 17 gets light and color measurement data function.
color17_set_config
err_t color17_set_config(color17_t *ctx, color17_config_t config)
Color 17 set the configuration function.
color17_get_cct
err_t color17_get_cct(color17_t *ctx, float *cct, float *light_intensity)
Color 17 gets correlated color temperature data function.
color17_generic_write
err_t color17_generic_write(color17_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 17 I2C writing function.
color17_config_t::int_dir
uint8_t int_dir
Definition: color17.h:253
color17_status_flag_t::flag_h
uint8_t flag_h
Definition: color17.h:267
color17_status_flag_t
Color 17 Click status flag object.
Definition: color17.h:264
color17_cfg_t::int_pin
pin_name_t int_pin
Definition: color17.h:232
color17_config_t::op_mode
uint8_t op_mode
Definition: color17.h:248
color17_get_int_pin
uint8_t color17_get_int_pin(color17_t *ctx)
Color 17 gets interrupt function.
color17_config_t
Color 17 Click configuration data object.
Definition: color17.h:244
color17_cfg_t::i2c_address
uint8_t i2c_address
Definition: color17.h:235
color17_config_t::fault_cnt
uint8_t fault_cnt
Definition: color17.h:251
color17_config_t::int_pol
uint8_t int_pol
Definition: color17.h:250
color17_t
Color 17 Click context object.
Definition: color17.h:211
color17_init
err_t color17_init(color17_t *ctx, color17_cfg_t *cfg)
Color 17 initialization function.
color17_config_t::conv_time
uint8_t conv_time
Definition: color17.h:247
color17_config_t::i2c_burst
uint8_t i2c_burst
Definition: color17.h:255
color17_config_t::range
uint8_t range
Definition: color17.h:246
color17_return_value_t
color17_return_value_t
Color 17 Click return value data.
Definition: color17.h:277
color17_read_reg
err_t color17_read_reg(color17_t *ctx, uint8_t reg, uint16_t *data_out)
Color 17 read register function.
color17_write_reg
err_t color17_write_reg(color17_t *ctx, uint8_t reg, uint16_t data_in)
Color 17write register function.
color17_cfg_t
Color 17 Click configuration object.
Definition: color17.h:228