Lines Matching +full:touch +full:- +full:average +full:- +full:control
3 * SPDX-License-Identifier: Apache-2.0
19 /* Touch Screen Pins definition */
51 /* Touch detected bit */
64 #define STMPE811_INT_BIT_TOUCH BIT(0) /* Touch/release is detected interrupt */
67 /* Reset control */
82 * Touch Screen Control
84 * - bits [1-3] X, Y only acquisition mode
89 * Analog-to-digital Converter
91 * - bit [3] selects 12 bit ADC
92 * - bits [4-6] select ADC conversion time = 80
99 * - 00 : 1.625 MHz
100 * - 01 : 3.25 MHz
101 * - 10 : 6.5 MHz
102 * - 11 : 6.5 MHz
109 * - Fractional part : 7
110 * - Whole part : 1
140 const struct stmpe811_config *config = dev->config; in stmpe811_reset()
143 int ret = i2c_reg_write_byte_dt(&config->bus, STMPE811_SYS_CTRL1_REG, in stmpe811_reset()
152 ret = i2c_reg_write_byte_dt(&config->bus, STMPE811_SYS_CTRL1_REG, in stmpe811_reset()
164 const struct stmpe811_config *config = dev->config; in stmpe811_io_enable_af()
167 return i2c_reg_update_byte_dt(&config->bus, STMPE811_IO_AF_REG, io_pin, 0); in stmpe811_io_enable_af()
172 const struct stmpe811_config *config = dev->config; in stmpe811_tsc_config_bits()
176 * - bits [0-2] : panel driver settling time in stmpe811_tsc_config_bits()
177 * - bits [3-5] : touch detect delay in stmpe811_tsc_config_bits()
178 * - bits [6-7] : touch average control in stmpe811_tsc_config_bits()
181 return config->panel_driver_settling_time_us | config->touch_detect_delay_us << 3 | in stmpe811_tsc_config_bits()
182 config->touch_average_control << 6; in stmpe811_tsc_config_bits()
187 const struct stmpe811_config *config = dev->config; in stmpe811_tsc_control_bits()
190 * Touch Screen Control in stmpe811_tsc_control_bits()
192 * - bit [0] enables TSC in stmpe811_tsc_control_bits()
193 * - bits [1-3] X, Y only acquisition mode in stmpe811_tsc_control_bits()
194 * - bits [4-6] window tracking index (set from config) in stmpe811_tsc_control_bits()
195 * - bit [7] TSC status (writing has no effect) in stmpe811_tsc_control_bits()
198 return STMPE811_TSC_CTRL_CONF | config->tracking_index << 4; in stmpe811_tsc_control_bits()
203 const struct stmpe811_config *config = dev->config; in stmpe811_ts_init()
219 * Bits [0-3] disable functionalities if set to 1 (reset value: 0x0f) in stmpe811_ts_init()
223 err = i2c_reg_update_byte_dt(&config->bus, STMPE811_SYS_CTRL2_REG, in stmpe811_ts_init()
231 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_ADC_CTRL1_REG, STMPE811_ADC_CTRL1_CONF); in stmpe811_ts_init()
237 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_ADC_CTRL2_REG, STMPE811_ADC_CLOCK_SPEED); in stmpe811_ts_init()
242 /* Touch screen configuration */ in stmpe811_ts_init()
243 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_TSC_CFG_REG, in stmpe811_ts_init()
249 /* Configure the touch FIFO threshold */ in stmpe811_ts_init()
250 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_FIFO_TH_REG, in stmpe811_ts_init()
257 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_FIFO_STA_REG, STMPE811_FIFO_STA_CLEAR); in stmpe811_ts_init()
263 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_TSC_FRACT_XYZ_REG, in stmpe811_ts_init()
270 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_TSC_I_DRIVE_REG, in stmpe811_ts_init()
276 /* Touch screen control configuration */ in stmpe811_ts_init()
277 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_TSC_CTRL_REG, in stmpe811_ts_init()
286 * This is an 8-bit register, so writing 0xFF clears all. in stmpe811_ts_init()
288 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_INT_STA_REG, STMPE811_INT_ALL); in stmpe811_ts_init()
294 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_FIFO_STA_REG, in stmpe811_ts_init()
300 /* Enable FIFO and touch interrupts */ in stmpe811_ts_init()
301 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_INT_EN_REG, in stmpe811_ts_init()
313 const struct stmpe811_config *config = dev->config; in stmpe811_ts_get_data()
314 struct stmpe811_data *data = dev->data; in stmpe811_ts_get_data()
319 int ret = i2c_burst_read_dt(&config->bus, STMPE811_TSC_DATA_NON_INC_REG, data_xy, in stmpe811_ts_get_data()
327 data->touch_x = (uldata_xy >> 12U) & BIT_MASK(12); in stmpe811_ts_get_data()
328 data->touch_y = uldata_xy & BIT_MASK(12); in stmpe811_ts_get_data()
335 const struct stmpe811_config *config = dev->config; in stmpe811_report_touch()
336 const struct input_touchscreen_common_config *common = &config->common; in stmpe811_report_touch()
337 struct stmpe811_data *data = dev->data; in stmpe811_report_touch()
338 int x = data->touch_x; in stmpe811_report_touch()
339 int y = data->touch_y; in stmpe811_report_touch()
341 if (common->screen_width > 0 && common->screen_height > 0) { in stmpe811_report_touch()
342 x = (((int)data->touch_x - config->raw_x_min) * common->screen_width) / in stmpe811_report_touch()
343 (config->raw_x_max - config->raw_x_min); in stmpe811_report_touch()
344 y = (((int)data->touch_y - config->raw_y_min) * common->screen_height) / in stmpe811_report_touch()
345 (config->raw_y_max - config->raw_y_min); in stmpe811_report_touch()
347 x = CLAMP(x, 0, common->screen_width); in stmpe811_report_touch()
348 y = CLAMP(y, 0, common->screen_height); in stmpe811_report_touch()
357 const struct stmpe811_config *config = dev->config; in stmpe811_process()
362 err = i2c_reg_read_byte_dt(&config->bus, STMPE811_INT_STA_REG, &int_sta); in stmpe811_process()
368 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_INT_STA_REG, int_sta); in stmpe811_process()
384 err = i2c_reg_read_byte_dt(&config->bus, STMPE811_FIFO_SIZE_REG, in stmpe811_process()
405 /* TOUCH interrupt also gets triggered at release */ in stmpe811_process()
407 err = i2c_reg_read_byte_dt(&config->bus, STMPE811_TSC_CTRL_REG, &tsc_ctrl); in stmpe811_process()
412 /* TOUCH interrupt + no touch detected in TSC_CTRL reg <=> release */ in stmpe811_process()
424 const struct stmpe811_config *config = data->dev->config; in stmpe811_work_handler()
426 stmpe811_process(data->dev); in stmpe811_work_handler()
429 * IRQ is edge-triggered, so otherwise it would never be triggered again. in stmpe811_work_handler()
431 if (gpio_pin_get_dt(&config->int_gpio)) { in stmpe811_work_handler()
432 k_work_submit(&data->processing_work); in stmpe811_work_handler()
441 k_work_submit(&data->processing_work); in stmpe811_interrupt_handler()
446 const struct stmpe811_config *config = dev->config; in stmpe811_verify_chip_id()
449 i2c_burst_read_dt(&config->bus, STMPE811_CHP_ID_LSB_REG, buf, 2); in stmpe811_verify_chip_id()
452 return -EINVAL; in stmpe811_verify_chip_id()
460 const struct stmpe811_config *config = dev->config; in stmpe811_init()
461 struct stmpe811_data *data = dev->data; in stmpe811_init()
464 if (!i2c_is_ready_dt(&config->bus)) { in stmpe811_init()
466 return -ENODEV; in stmpe811_init()
469 data->dev = dev; in stmpe811_init()
471 k_work_init(&data->processing_work, stmpe811_work_handler); in stmpe811_init()
483 LOG_ERR("Touch screen controller initialization failed (%d)", err); in stmpe811_init()
488 if (!gpio_is_ready_dt(&config->int_gpio)) { in stmpe811_init()
490 return -ENODEV; in stmpe811_init()
493 err = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); in stmpe811_init()
499 err = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); in stmpe811_init()
505 gpio_init_callback(&data->int_gpio_cb, stmpe811_interrupt_handler, in stmpe811_init()
506 BIT(config->int_gpio.pin)); in stmpe811_init()
507 err = gpio_add_callback_dt(&config->int_gpio, &data->int_gpio_cb); in stmpe811_init()
514 err = i2c_reg_write_byte_dt(&config->bus, STMPE811_INT_CTRL_REG, in stmpe811_init()
527 "raw-x-max should be larger than raw-x-min"); \
530 "raw-y-max should be larger than raw-y-min"); \