Skip to content

Commit 8f67fa0

Browse files
laudominikChromeos LUCI
authored andcommitted
drivers: input: use generic touch report in stmpe811
Adds the use of generic touch reporting method for stmpe811 driver. (cherry picked from commit 4ca2400) Original-Signed-off-by: Dominik Lau <[email protected]> Original-Signed-off-by: Filip Kokosinski <[email protected]> GitOrigin-RevId: 4ca2400 Cr-Build-Id: 8738238973287044049 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8738238973287044049 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I9ff50c0fe631290e0aa4e9e5992243201d051144 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5827585 Tested-by: Ting Shen <[email protected]> Commit-Queue: Ting Shen <[email protected]> Tested-by: ChromeOS Prod (Robot) <[email protected]> Reviewed-by: Ting Shen <[email protected]>
1 parent 6547dee commit 8f67fa0

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

drivers/input/Kconfig.stmpe811

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ config INPUT_STMPE811
66
default y
77
depends on DT_HAS_ST_STMPE811_ENABLED
88
select I2C
9+
select INPUT_TOUCH
910
help
1011
Enable driver for STMPE811 touch panel.

drivers/input/input_stmpe811.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
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

113114
struct 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+
136138
static 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)
331333
static 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), \

dts/bindings/input/st,stmpe811.yaml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: STMPE811 I2C touchscreen controller
55

66
compatible: "st,stmpe811"
77

8-
include: i2c-device.yaml
8+
include: [i2c-device.yaml, touchscreen-common.yaml]
99

1010
properties:
1111
int-gpios:
@@ -14,20 +14,6 @@ properties:
1414
Interrupt GPIO. Used by the controller to signal touch data is
1515
available. Active low.
1616
17-
screen-width:
18-
type: int
19-
default: 0
20-
description: |
21-
Screen width for scaling the reported coordinates.
22-
Default: raw touchscreen resolution.
23-
24-
screen-height:
25-
type: int
26-
default: 0
27-
description: |
28-
Screen height for scaling the reported coordinates.
29-
Default: raw touchscreen resolution.
30-
3117
raw-x-min:
3218
type: int
3319
description: |

0 commit comments

Comments
 (0)