Lines Matching +full:als +full:- +full:it

5  * SPDX-License-Identifier: Apache-2.0
30 * 16-bit command register addresses
41 * Devicetree psm-mode property value for "PSM disabled"
46 * ALS integration time setting values.
53 0x0C, /* 25 - 0b1100 */
54 0x08, /* 50 - 0b1000 */
55 0x00, /* 100 - 0b0000 */
56 0x01, /* 200 - 0b0001 */
57 0x02, /* 400 - 0b0010 */
58 0x03, /* 800 - 0b0011 */
85 enum veml7700_als_it it; member
126 switch (data->it) { in veml7700_sleep_by_integration_time()
151 if (!is_veml7700_gain_in_range(data->gain) || !is_veml7700_it_in_range(data->it)) { in veml7700_counts_to_lux()
152 return -EINVAL; in veml7700_counts_to_lux()
154 *lux = counts * veml7700_resolution[data->gain][data->it]; in veml7700_counts_to_lux()
161 if (!is_veml7700_gain_in_range(data->gain) || !is_veml7700_it_in_range(data->it)) { in veml7700_lux_to_counts()
162 return -EINVAL; in veml7700_lux_to_counts()
164 *counts = lux / veml7700_resolution[data->gain][data->it]; in veml7700_lux_to_counts()
170 return val->val1 >= VEML7700_ALS_GAIN_1 && val->val1 <= VEML7700_ALS_GAIN_1_4; in veml7700_check_gain()
175 return val->val1 >= VEML7700_ALS_IT_25 && val->val1 <= VEML7700_ALS_IT_800; in veml7700_check_it()
180 return (val->val1 >= VEML7700_ALS_PERS_1 && val->val1 <= VEML7700_ALS_PERS_8) || in veml7700_check_int_mode()
181 val->val1 == VEML7700_INT_DISABLED; in veml7700_check_int_mode()
186 if (!is_veml7700_gain_in_range(data->gain) || !is_veml7700_it_in_range(data->it)) { in veml7700_build_als_conf_param()
187 return -EINVAL; in veml7700_build_als_conf_param()
190 /* Bits 15:13 -> reserved */ in veml7700_build_als_conf_param()
191 /* Bits 12:11 -> gain selection (ALS_GAIN) */ in veml7700_build_als_conf_param()
192 param |= data->gain << 11; in veml7700_build_als_conf_param()
193 /* Bit 10 -> reserved */ in veml7700_build_als_conf_param()
194 /* Bits 9:6 -> integration time (ALS_IT) */ in veml7700_build_als_conf_param()
195 param |= veml7700_it_values[data->it] << 6; in veml7700_build_als_conf_param()
196 /* Bits 5:4 -> interrupt persistent protection (ALS_PERS) */ in veml7700_build_als_conf_param()
197 if (data->int_mode != VEML7700_INT_DISABLED) { in veml7700_build_als_conf_param()
198 param |= data->int_mode << 4; in veml7700_build_als_conf_param()
199 /* Bit 1 -> interrupt enable (ALS_INT_EN) */ in veml7700_build_als_conf_param()
202 /* Bits 3:2 -> reserved */ in veml7700_build_als_conf_param()
203 /* Bit 0 -> shut down setting (ALS_SD) */ in veml7700_build_als_conf_param()
204 if (data->shut_down) { in veml7700_build_als_conf_param()
214 return conf->psm; in veml7700_build_psm_param()
219 const struct veml7700_config *conf = dev->config; in veml7700_write()
225 return i2c_write_dt(&conf->bus, send_buf, ARRAY_SIZE(send_buf)); in veml7700_write()
230 const struct veml7700_config *conf = dev->config; in veml7700_read()
233 int ret = i2c_write_read_dt(&conf->bus, &cmd, sizeof(cmd), &recv_buf, ARRAY_SIZE(recv_buf)); in veml7700_read()
245 const struct veml7700_data *data = dev->data; in veml7700_write_als_conf()
253 LOG_DBG("Writing ALS configuration: 0x%04x", param); in veml7700_write_als_conf()
259 const struct veml7700_config *conf = dev->config; in veml7700_write_psm()
269 const struct veml7700_data *data = dev->data; in veml7700_write_thresh_low()
271 LOG_DBG("Writing low threshold counts: %d", data->thresh_low); in veml7700_write_thresh_low()
272 return veml7700_write(dev, VEML7700_CMDCODE_ALS_WL, data->thresh_low); in veml7700_write_thresh_low()
277 const struct veml7700_data *data = dev->data; in veml7700_write_thresh_high()
279 LOG_DBG("Writing high threshold counts: %d", data->thresh_high); in veml7700_write_thresh_high()
280 return veml7700_write(dev, VEML7700_CMDCODE_ALS_WH, data->thresh_high); in veml7700_write_thresh_high()
285 struct veml7700_data *data = dev->data; in veml7700_set_shutdown_flag()
289 prev_sd = data->shut_down; in veml7700_set_shutdown_flag()
290 data->shut_down = new_val; in veml7700_set_shutdown_flag()
294 data->shut_down = prev_sd; in veml7700_set_shutdown_flag()
301 struct veml7700_data *data = dev->data; in veml7700_fetch_als()
310 data->als_counts = counts; in veml7700_fetch_als()
311 ret = veml7700_counts_to_lux(data, counts, &data->als_lux); in veml7700_fetch_als()
316 LOG_DBG("Read ALS measurement: counts=%d, lux=%d", data->als_counts, data->als_lux); in veml7700_fetch_als()
323 struct veml7700_data *data = dev->data; in veml7700_fetch_white()
332 data->white_counts = counts; in veml7700_fetch_white()
333 LOG_DBG("Read White Light measurement: counts=%d", data->white_counts); in veml7700_fetch_white()
340 struct veml7700_data *data = dev->data; in veml7700_fetch_int_flags()
349 data->int_flags = int_flags & VEML7700_ALS_INT_MASK; in veml7700_fetch_int_flags()
350 LOG_DBG("Read int state: 0x%02x", data->int_flags); in veml7700_fetch_int_flags()
359 return -ENOTSUP; in veml7700_attr_set()
362 struct veml7700_data *data = dev->data; in veml7700_attr_set()
366 ret = veml7700_lux_to_counts(data, val->val1, &data->thresh_low); in veml7700_attr_set()
372 ret = veml7700_lux_to_counts(data, val->val1, &data->thresh_high); in veml7700_attr_set()
379 data->gain = (enum veml7700_als_gain)val->val1; in veml7700_attr_set()
382 return -EINVAL; in veml7700_attr_set()
386 data->it = (enum veml7700_als_it)val->val1; in veml7700_attr_set()
389 return -EINVAL; in veml7700_attr_set()
393 data->int_mode = (enum veml7700_int_mode)val->val1; in veml7700_attr_set()
396 return -EINVAL; in veml7700_attr_set()
399 return -ENOTSUP; in veml7700_attr_set()
407 return -ENOTSUP; in veml7700_attr_get()
410 struct veml7700_data *data = dev->data; in veml7700_attr_get()
413 val->val1 = data->thresh_low; in veml7700_attr_get()
415 val->val1 = data->thresh_high; in veml7700_attr_get()
417 val->val1 = data->gain; in veml7700_attr_get()
419 val->val1 = data->it; in veml7700_attr_get()
421 val->val1 = data->int_mode; in veml7700_attr_get()
423 return -ENOTSUP; in veml7700_attr_get()
426 val->val2 = 0; in veml7700_attr_get()
433 struct veml7700_data *data = dev->data; in veml7700_perform_single_measurement()
442 /* Wait for sensor to finish it's startup sequence */ in veml7700_perform_single_measurement()
453 const struct veml7700_config *conf = dev->config; in veml7700_sample_fetch()
459 conf->psm == VEML7700_PSM_DISABLED) { in veml7700_sample_fetch()
469 data = dev->data; in veml7700_sample_fetch()
470 if (data->int_mode != VEML7700_INT_DISABLED) { in veml7700_sample_fetch()
473 return -ENOTSUP; in veml7700_sample_fetch()
478 data = dev->data; in veml7700_sample_fetch()
479 if (data->int_mode != VEML7700_INT_DISABLED) { in veml7700_sample_fetch()
491 return -ENOTSUP; in veml7700_sample_fetch()
498 struct veml7700_data *data = dev->data; in veml7700_channel_get()
501 val->val1 = data->als_lux; in veml7700_channel_get()
503 val->val1 = data->als_counts; in veml7700_channel_get()
505 val->val1 = data->white_counts; in veml7700_channel_get()
507 val->val1 = data->int_flags; in veml7700_channel_get()
509 return -ENOTSUP; in veml7700_channel_get()
512 val->val2 = 0; in veml7700_channel_get()
521 const struct veml7700_config *conf = dev->config; in veml7700_pm_action()
523 if (conf->psm != VEML7700_PSM_DISABLED) { in veml7700_pm_action()
532 return -ENOTSUP; in veml7700_pm_action()
543 const struct veml7700_config *conf = dev->config; in veml7700_init()
544 struct veml7700_data *data = dev->data; in veml7700_init()
547 if (!i2c_is_ready_dt(&conf->bus)) { in veml7700_init()
549 return -ENODEV; in veml7700_init()
559 data->thresh_low = 0; in veml7700_init()
560 data->thresh_high = 0xFFFF; in veml7700_init()
561 data->gain = VEML7700_ALS_GAIN_1_4; in veml7700_init()
562 data->it = VEML7700_ALS_IT_100; in veml7700_init()
563 data->int_mode = VEML7700_INT_DISABLED; in veml7700_init()
564 data->als_counts = 0; in veml7700_init()
565 data->als_lux = 0; in veml7700_init()
566 data->white_counts = 0; in veml7700_init()
567 data->shut_down = (conf->psm != VEML7700_PSM_DISABLED) ? 0 : 1; in veml7700_init()