88#include <zephyr/drivers/gpio.h>
99#include <zephyr/drivers/i2c.h>
1010#include <zephyr/input/input.h>
11+ #include <zephyr/input/input_touch.h>
1112#include <zephyr/sys/byteorder.h>
1213
1314#include <zephyr/logging/log.h>
@@ -111,14 +112,13 @@ LOG_MODULE_REGISTER(stmpe811, CONFIG_INPUT_LOG_LEVEL);
111112#define STMPE811_TSC_FRACT_XYZ_CONF 1
112113
113114struct stmpe811_config {
115+ struct input_touchscreen_common_config common ;
114116 struct i2c_dt_spec bus ;
115117 struct gpio_dt_spec int_gpio ;
116118 uint8_t panel_driver_settling_time_us ;
117119 uint8_t touch_detect_delay_us ;
118120 uint8_t touch_average_control ;
119121 uint8_t tracking_index ;
120- uint16_t screen_width ;
121- uint16_t screen_height ;
122122 int raw_x_min ;
123123 int raw_y_min ;
124124 uint16_t raw_x_max ;
@@ -133,6 +133,8 @@ struct stmpe811_data {
133133 uint32_t touch_y ;
134134};
135135
136+ INPUT_TOUCH_STRUCT_CHECK (struct stmpe811_config );
137+
136138static int stmpe811_reset (const struct device * dev )
137139{
138140 const struct stmpe811_config * config = dev -> config ;
@@ -331,22 +333,22 @@ static int stmpe811_ts_get_data(const struct device *dev)
331333static void stmpe811_report_touch (const struct device * dev )
332334{
333335 const struct stmpe811_config * config = dev -> config ;
336+ const struct input_touchscreen_common_config * common = & config -> common ;
334337 struct stmpe811_data * data = dev -> data ;
335338 int x = data -> touch_x ;
336339 int y = data -> touch_y ;
337340
338- if (config -> screen_width > 0 && config -> screen_height > 0 ) {
339- x = (((int )data -> touch_x - config -> raw_x_min ) * config -> screen_width ) /
341+ if (common -> screen_width > 0 && common -> screen_height > 0 ) {
342+ x = (((int )data -> touch_x - config -> raw_x_min ) * common -> screen_width ) /
340343 (config -> raw_x_max - config -> raw_x_min );
341- y = (((int )data -> touch_y - config -> raw_y_min ) * config -> screen_height ) /
344+ y = (((int )data -> touch_y - config -> raw_y_min ) * common -> screen_height ) /
342345 (config -> raw_y_max - config -> raw_y_min );
343346
344- x = CLAMP (x , 0 , config -> screen_width );
345- y = CLAMP (y , 0 , config -> screen_height );
347+ x = CLAMP (x , 0 , common -> screen_width );
348+ y = CLAMP (y , 0 , common -> screen_height );
346349 }
347350
348- input_report_abs (dev , INPUT_ABS_X , x , false, K_FOREVER );
349- input_report_abs (dev , INPUT_ABS_Y , y , false, K_FOREVER );
351+ input_touchscreen_report_pos (dev , x , y , K_FOREVER );
350352 input_report_key (dev , INPUT_BTN_TOUCH , 1 , true, K_FOREVER );
351353}
352354
@@ -527,12 +529,11 @@ static int stmpe811_init(const struct device *dev)
527529 DT_INST_PROP_OR(index, raw_y_min, 0), \
528530 "raw-y-max should be larger than raw-y-min"); \
529531 static const struct stmpe811_config stmpe811_config_##index = { \
532+ .common = INPUT_TOUCH_DT_INST_COMMON_CONFIG_INIT(index), \
530533 .bus = I2C_DT_SPEC_INST_GET(index), \
531534 .int_gpio = GPIO_DT_SPEC_INST_GET(index, int_gpios), \
532535 .panel_driver_settling_time_us = \
533536 DT_INST_ENUM_IDX(index, panel_driver_settling_time_us), \
534- .screen_width = DT_INST_PROP(index, screen_width), \
535- .screen_height = DT_INST_PROP(index, screen_height), \
536537 .raw_x_min = DT_INST_PROP_OR(index, raw_x_min, 0), \
537538 .raw_y_min = DT_INST_PROP_OR(index, raw_y_min, 0), \
538539 .raw_x_max = DT_INST_PROP_OR(index, raw_x_max, 4096), \
0 commit comments