Lines Matching +full:z +full:- +full:threshold

4  * SPDX-License-Identifier: Apache-2.0
23 uint16_t threshold; member
53 uint32_t z; member
64 /* Read all Z1, X, Y, Z2 channels using 16 Clocks-per-Conversion mode.
65 * See the manual https://www.waveshare.com/w/upload/9/98/XPT2046-EN.pdf for details.
66 * Each follow-up command interleaves with previous conversion.
79 const struct xpt2046_config *config = data->dev->config; in xpt2046_isr_handler()
81 gpio_remove_callback(config->int_gpio.port, &data->int_gpio_cb); in xpt2046_isr_handler()
82 k_work_submit(&data->work); in xpt2046_isr_handler()
95 uint8_t *buf = rx->buffers->buf; in xpt2046_read_and_cumulate()
97 meas->z += CONVERT_U16(buf, 1) + 4096 - CONVERT_U16(buf, 3); in xpt2046_read_and_cumulate()
98 meas->x += CONVERT_U16(buf, 5); in xpt2046_read_and_cumulate()
99 meas->y += CONVERT_U16(buf, 7); in xpt2046_read_and_cumulate()
108 struct xpt2046_config *config = (struct xpt2046_config *)data->dev->config; in xpt2046_release_handler()
110 if (!data->pressed) { in xpt2046_release_handler()
115 if (gpio_pin_get_dt(&config->int_gpio) == 0) { in xpt2046_release_handler()
116 data->pressed = false; in xpt2046_release_handler()
117 input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER); in xpt2046_release_handler()
119 /* Re-check later */ in xpt2046_release_handler()
120 k_work_reschedule(&data->dwork, K_MSEC(10)); in xpt2046_release_handler()
127 struct xpt2046_config *config = (struct xpt2046_config *)data->dev->config; in xpt2046_work_handler()
131 const struct spi_buf rxb = {.buf = data->rbuf, .len = sizeof(data->rbuf)}; in xpt2046_work_handler()
136 int rounds = config->reads; in xpt2046_work_handler()
140 if (xpt2046_read_and_cumulate(&config->bus, &tx_bufs, &rx_bufs, &meas) != 0) { in xpt2046_work_handler()
146 meas.z /= rounds; in xpt2046_work_handler()
150 * Use signed int32_t for calculation to ensure that we cover the roll-over to negative in xpt2046_work_handler()
153 int32_t mx = (config->screen_size_x << 16) / (config->max_x - config->min_x); in xpt2046_work_handler()
154 int32_t cx = (config->screen_size_x << 16) - mx * config->max_x; in xpt2046_work_handler()
159 int32_t my = (config->screen_size_y << 16) / (config->max_y - config->min_y); in xpt2046_work_handler()
160 int32_t cy = (config->screen_size_y << 16) - my * config->max_y; in xpt2046_work_handler()
165 bool pressed = meas.z > config->threshold; in xpt2046_work_handler()
173 input_report_abs(data->dev, INPUT_ABS_X, x, false, K_FOREVER); in xpt2046_work_handler()
174 input_report_abs(data->dev, INPUT_ABS_Y, y, false, K_FOREVER); in xpt2046_work_handler()
175 input_report_key(data->dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER); in xpt2046_work_handler()
177 data->last_x = x; in xpt2046_work_handler()
178 data->last_y = y; in xpt2046_work_handler()
179 data->pressed = pressed; in xpt2046_work_handler()
182 k_work_reschedule(&data->dwork, K_MSEC(100)); in xpt2046_work_handler()
185 ret = gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb); in xpt2046_work_handler()
195 const struct xpt2046_config *config = dev->config; in xpt2046_init()
196 struct xpt2046_data *data = dev->data; in xpt2046_init()
198 if (!spi_is_ready_dt(&config->bus)) { in xpt2046_init()
200 return -ENODEV; in xpt2046_init()
203 data->dev = dev; in xpt2046_init()
204 k_work_init(&data->work, xpt2046_work_handler); in xpt2046_init()
205 k_work_init_delayable(&data->dwork, xpt2046_release_handler); in xpt2046_init()
207 if (!gpio_is_ready_dt(&config->int_gpio)) { in xpt2046_init()
209 return -ENODEV; in xpt2046_init()
212 r = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT); in xpt2046_init()
218 r = gpio_pin_interrupt_configure_dt(&config->int_gpio, GPIO_INT_EDGE_TO_ACTIVE); in xpt2046_init()
224 gpio_init_callback(&data->int_gpio_cb, xpt2046_isr_handler, BIT(config->int_gpio.pin)); in xpt2046_init()
226 r = gpio_add_callback(config->int_gpio.port, &data->int_gpio_cb); in xpt2046_init()
232 LOG_INF("Init '%s' device", dev->name); in xpt2046_init()
246 .threshold = DT_INST_PROP(index, z_threshold), \
259 BUILD_ASSERT(DT_INST_PROP(index, z_threshold) > 10, "Too small threshold"); \