Lines Matching +full:integration +full:- +full:time
4 * SPDX-License-Identifier: Apache-2.0
18 const struct tsl2591_config *config = dev->config; in tsl2591_reg_read()
21 return i2c_write_read_dt(&config->i2c, &cmd, 1U, buf, size); in tsl2591_reg_read()
26 const struct tsl2591_config *config = dev->config; in tsl2591_reg_write()
29 return i2c_write_dt(&config->i2c, cmd, 2U); in tsl2591_reg_write()
52 struct tsl2591_data *data = dev->data; in tsl2591_sample_fetch()
65 /* Check if ALS has completed an integration cycle since AEN asserted. in tsl2591_sample_fetch()
66 * If not, sleep for the duration of an integration cycle to ensure valid reading. in tsl2591_sample_fetch()
69 k_msleep((data->atime / 100) * TSL2591_MAX_TIME_STEP); in tsl2591_sample_fetch()
81 LOG_ERR("Failed to re-enable ALS"); in tsl2591_sample_fetch()
94 data->vis_count = sys_get_le16(als_data); in tsl2591_sample_fetch()
95 data->ir_count = sys_get_le16(als_data + 2); in tsl2591_sample_fetch()
104 data->vis_count = sys_get_le16(als_data); in tsl2591_sample_fetch()
113 data->ir_count = sys_get_le16(als_data); in tsl2591_sample_fetch()
117 return -ENOTSUP; in tsl2591_sample_fetch()
121 uint16_t max_count = data->atime == 100 ? TSL2591_MAX_ADC_100 : TSL2591_MAX_ADC; in tsl2591_sample_fetch()
123 (data->vis_count >= max_count); in tsl2591_sample_fetch()
125 (data->ir_count >= max_count); in tsl2591_sample_fetch()
128 return -EOVERFLOW; in tsl2591_sample_fetch()
138 const struct tsl2591_data *data = dev->data; in tsl2591_channel_get()
139 int64_t cpl = (int64_t)data->atime * (int64_t)data->again; in tsl2591_channel_get()
154 if (data->vis_count > 0) { in tsl2591_channel_get()
157 (data->vis_count - data->ir_count) * in tsl2591_channel_get()
158 (1000000 - (((int64_t)data->ir_count * 1000000) / data->vis_count)); in tsl2591_channel_get()
164 strength = data->vis_count; in tsl2591_channel_get()
167 strength = data->ir_count; in tsl2591_channel_get()
171 return -ENOTSUP; in tsl2591_channel_get()
175 val->val1 = strength / cpl; in tsl2591_channel_get()
176 val->val2 = ((strength % cpl) * 1000000) / cpl; in tsl2591_channel_get()
185 const struct tsl2591_data *data = dev->data; in tsl2591_set_threshold()
186 const struct tsl2591_config *config = dev->config; in tsl2591_set_threshold()
195 cpl = data->atime * data->again; in tsl2591_set_threshold()
196 raw = ((val->val1 * cpl) / TSL2591_LUX_DF) + in tsl2591_set_threshold()
197 ((val->val2 * cpl) / (1000000U * TSL2591_LUX_DF)); in tsl2591_set_threshold()
201 return -EOVERFLOW; in tsl2591_set_threshold()
210 ret = i2c_write_dt(&config->i2c, cmd, 3U); in tsl2591_set_threshold()
274 return -EINVAL; in tsl2591_set_persist()
288 struct tsl2591_data *data = dev->data; in tsl2591_set_gain()
294 data->again = TSL2591_GAIN_SCALE_LOW; in tsl2591_set_gain()
298 data->again = TSL2591_GAIN_SCALE_MED; in tsl2591_set_gain()
302 data->again = TSL2591_GAIN_SCALE_HIGH; in tsl2591_set_gain()
306 data->again = TSL2591_GAIN_SCALE_MAX; in tsl2591_set_gain()
311 return -EINVAL; in tsl2591_set_gain()
324 struct tsl2591_data *data = dev->data; in tsl2591_set_integration()
348 LOG_ERR("Invalid integration time"); in tsl2591_set_integration()
349 return -EINVAL; in tsl2591_set_integration()
354 LOG_ERR("Failed to set integration time"); in tsl2591_set_integration()
358 data->atime = integration_time; in tsl2591_set_integration()
366 const struct tsl2591_data *data = dev->data; in tsl2591_attr_set()
381 ret = -ENOTSUP; in tsl2591_attr_set()
389 ret = tsl2591_set_gain(dev, (enum sensor_gain_tsl2591)val->val1); in tsl2591_attr_set()
392 ret = tsl2591_set_integration(dev, val->val1); in tsl2591_attr_set()
397 ret = tsl2591_set_persist(dev, val->val1); in tsl2591_attr_set()
402 ret = -EINVAL; in tsl2591_attr_set()
407 if (data->powered_on) { in tsl2591_attr_set()
417 struct tsl2591_data *data = dev->data; in tsl2591_setup()
435 return -ENOTSUP; in tsl2591_setup()
439 data->again = TSL2591_GAIN_SCALE_LOW; in tsl2591_setup()
440 data->atime = 100U; in tsl2591_setup()
448 data->powered_on = true; in tsl2591_setup()
455 const struct tsl2591_config *config = dev->config; in tsl2591_init()
458 if (!i2c_is_ready_dt(&config->i2c)) { in tsl2591_init()
459 LOG_ERR("I2C dev %s not ready", config->i2c.bus->name); in tsl2591_init()
460 return -ENODEV; in tsl2591_init()
491 struct tsl2591_data *data = dev->data; in tsl2591_pm_action()
503 data->powered_on = true; in tsl2591_pm_action()
513 data->powered_on = false; in tsl2591_pm_action()
517 return -ENOTSUP; in tsl2591_pm_action()