Lines Matching +full:proximity +full:- +full:gain
4 * SPDX-License-Identifier: Apache-2.0
32 tmd2620_setup_int(data->dev->config, false); in tmd2620_gpio_callback()
35 k_work_submit(&data->work); in tmd2620_gpio_callback()
37 k_sem_give(&data->data_sem); in tmd2620_gpio_callback()
43 struct tmd2620_data *data = dev->data; in tmd2620_configure_interrupt()
44 const struct tmd2620_config *config = dev->config; in tmd2620_configure_interrupt()
49 if (!gpio_is_ready_dt(&config->int_gpio)) { in tmd2620_configure_interrupt()
51 return -ENODEV; in tmd2620_configure_interrupt()
54 ret = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); in tmd2620_configure_interrupt()
60 gpio_init_callback(&data->gpio_cb, tmd2620_gpio_callback, BIT(config->int_gpio.pin)); in tmd2620_configure_interrupt()
62 ret = gpio_add_callback(config->int_gpio.port, &data->gpio_cb); in tmd2620_configure_interrupt()
68 data->dev = dev; in tmd2620_configure_interrupt()
71 data->work.handler = tmd2620_work_cb; in tmd2620_configure_interrupt()
73 k_sem_init(&data->data_sem, 0, K_SEM_MAX_LIMIT); in tmd2620_configure_interrupt()
81 struct tmd2620_data *data = dev->data; in tmd2620_sample_fetch()
82 const struct tmd2620_config *config = dev->config; in tmd2620_sample_fetch()
88 return -ENOTSUP; in tmd2620_sample_fetch()
93 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_INTENAB_REG, TMD2620_INTENAB_PIEN, in tmd2620_sample_fetch()
102 /* Enabling proximity and powering up device */ in tmd2620_sample_fetch()
105 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, tmp); in tmd2620_sample_fetch()
113 k_sem_take(&data->data_sem, K_FOREVER); in tmd2620_sample_fetch()
115 ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_STATUS_REG, &tmp); in tmd2620_sample_fetch()
123 LOG_DBG("Proximity interrupt detected."); in tmd2620_sample_fetch()
125 ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_PDATA_REG, &data->pdata); in tmd2620_sample_fetch()
127 LOG_ERR("Failed reading proximity data."); in tmd2620_sample_fetch()
135 /* Disabling proximity and powering down device */ in tmd2620_sample_fetch()
136 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, 0); in tmd2620_sample_fetch()
143 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_STATUS_REG, TMD2620_STATUS_PINT, in tmd2620_sample_fetch()
156 struct tmd2620_data *data = dev->data; in tmd2620_channel_get()
160 val->val1 = (256 - data->pdata); in tmd2620_channel_get()
161 val->val2 = 0; in tmd2620_channel_get()
166 return -ENOTSUP; in tmd2620_channel_get()
171 const struct tmd2620_config *config = dev->config; in tmd2620_sensor_setup()
178 (void)i2c_reg_read_byte_dt(&config->i2c, TMD2620_ID_REG, &chip_id); in tmd2620_sensor_setup()
180 ret = i2c_reg_read_byte_dt(&config->i2c, TMD2620_ID_REG, &chip_id); in tmd2620_sensor_setup()
187 LOG_ERR("Chip id is invalid! Device @%02x is no TMD2620!", config->i2c.addr); in tmd2620_sensor_setup()
188 return -EIO; in tmd2620_sensor_setup()
191 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_ENABLE_REG, 0); in tmd2620_sensor_setup()
197 tmp = config->wait_time_factor; in tmd2620_sensor_setup()
198 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_WTIME_REG, tmp); in tmd2620_sensor_setup()
204 tmp = config->proximity_low_threshold; in tmd2620_sensor_setup()
205 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PILT_REG, tmp); in tmd2620_sensor_setup()
211 tmp = config->proximity_high_threshold; in tmd2620_sensor_setup()
212 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PIHT_REG, (255 - tmp)); in tmd2620_sensor_setup()
219 tmp = (config->proximity_interrupt_filter << 3); in tmd2620_sensor_setup()
220 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PERS_REG, tmp); in tmd2620_sensor_setup()
227 if (config->wait_long) { in tmd2620_sensor_setup()
233 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_CFG0_REG, tmp); in tmd2620_sensor_setup()
239 switch (config->proximity_pulse_length) { in tmd2620_sensor_setup()
253 LOG_ERR("Invalid proximity pulse length"); in tmd2620_sensor_setup()
254 return -EINVAL; in tmd2620_sensor_setup()
257 tmp |= config->proximity_pulse_count; in tmd2620_sensor_setup()
258 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PCFG0_REG, tmp); in tmd2620_sensor_setup()
264 switch (config->proximity_gain) { in tmd2620_sensor_setup()
278 LOG_ERR("Invalid proximity gain"); in tmd2620_sensor_setup()
279 return -EINVAL; in tmd2620_sensor_setup()
282 tmp |= config->proximity_led_drive_strength; in tmd2620_sensor_setup()
283 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_PCFG1_REG, tmp); in tmd2620_sensor_setup()
290 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_CFG3_REG, tmp); in tmd2620_sensor_setup()
297 ret = i2c_reg_write_byte_dt(&config->i2c, TMD2620_INTENAB_REG, tmp); in tmd2620_sensor_setup()
303 if (config->enable_wait_mode) { in tmd2620_sensor_setup()
304 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, TMD2620_ENABLE_WEN, in tmd2620_sensor_setup()
317 const struct tmd2620_config *config = dev->config; in tmd2620_init()
318 struct tmd2620_data *data = dev->data; in tmd2620_init()
324 if (!i2c_is_ready_dt(&config->i2c)) { in tmd2620_init()
326 return -ENODEV; in tmd2620_init()
329 data->pdata = 0U; in tmd2620_init()
347 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, tmp, tmp); in tmd2620_init()
361 const struct tmd2620_config *config = dev->config; in tmd2620_pm_action()
366 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, in tmd2620_pm_action()
375 ret = i2c_reg_update_byte_dt(&config->i2c, TMD2620_ENABLE_REG, in tmd2620_pm_action()
383 return -ENOTSUP; in tmd2620_pm_action()