Skip to content

Commit fc0d496

Browse files
laudominikChromeos LUCI
authored andcommitted
drivers: input: common properties parsing for touchscreen drivers
Adds a way of reporting touchscreen events taking common properties into account. (cherry picked from commit 74e84a9) Original-Signed-off-by: Dominik Lau <[email protected]> Original-Signed-off-by: Filip Kokosinski <[email protected]> GitOrigin-RevId: 74e84a9 Cr-Build-Id: 8738238973287044049 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8738238973287044049 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I1d5864198c229916d0ef5b93aeff99c3b4cc6495 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5827583 Reviewed-by: Ting Shen <[email protected]> Tested-by: ChromeOS Prod (Robot) <[email protected]> Commit-Queue: Ting Shen <[email protected]> Tested-by: Ting Shen <[email protected]>
1 parent 9d6e8cd commit fc0d496

File tree

6 files changed

+128
-0
lines changed

6 files changed

+128
-0
lines changed

doc/services/input/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ Analog Axis API Reference
131131
*************************
132132

133133
.. doxygengroup:: input_analog_axis
134+
135+
Touchscreen API Reference
136+
*************************
137+
138+
.. doxygengroup:: touch_events

drivers/input/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_INPUT_PINNACLE input_pinnacle.c)
2626
zephyr_library_sources_ifdef(CONFIG_INPUT_PMW3610 input_pmw3610.c)
2727
zephyr_library_sources_ifdef(CONFIG_INPUT_SBUS input_sbus.c)
2828
zephyr_library_sources_ifdef(CONFIG_INPUT_STMPE811 input_stmpe811.c)
29+
zephyr_library_sources_ifdef(CONFIG_INPUT_TOUCH input_touch.c)
2930
zephyr_library_sources_ifdef(CONFIG_INPUT_XEC_KBD input_xec_kbd.c)
3031
zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c)
3132
# zephyr-keep-sorted-stop

drivers/input/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ source "drivers/input/Kconfig.pmw3610"
2929
source "drivers/input/Kconfig.sbus"
3030
source "drivers/input/Kconfig.sdl"
3131
source "drivers/input/Kconfig.stmpe811"
32+
source "drivers/input/Kconfig.touch"
3233
source "drivers/input/Kconfig.xec"
3334
source "drivers/input/Kconfig.xpt2046"
3435
# zephyr-keep-sorted-stop

drivers/input/Kconfig.touch

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2024 Antmicro Ltd <www.antmicro.com>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config INPUT_TOUCH
5+
bool
6+
help
7+
Enable library used for touchscreen drivers.

drivers/input/input_touch.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2024 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/input/input_touch.h>
7+
8+
void input_touchscreen_report_pos(const struct device *dev,
9+
uint32_t x, uint32_t y,
10+
k_timeout_t timeout)
11+
{
12+
const struct input_touchscreen_common_config *cfg = dev->config;
13+
const uint32_t reported_x_code = cfg->swapped_x_y ? INPUT_ABS_Y : INPUT_ABS_X;
14+
const uint32_t reported_y_code = cfg->swapped_x_y ? INPUT_ABS_X : INPUT_ABS_Y;
15+
const uint32_t reported_x = cfg->inverted_x ? cfg->screen_width - x : x;
16+
const uint32_t reported_y = cfg->inverted_y ? cfg->screen_height - y : y;
17+
18+
input_report_abs(dev, reported_x_code, reported_x, false, timeout);
19+
input_report_abs(dev, reported_y_code, reported_y, false, timeout);
20+
}

include/zephyr/input/input_touch.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2024 Antmicro <www.antmicro.com>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#ifndef ZEPHYR_INCLUDE_INPUT_TOUCH_H_
7+
#define ZEPHYR_INCLUDE_INPUT_TOUCH_H_
8+
9+
/**
10+
* @brief Touch Events API
11+
* @defgroup touch_events Touchscreen Event Report API
12+
* @since 3.7
13+
* @version 0.1.0
14+
* @ingroup io_interfaces
15+
* @{
16+
*/
17+
18+
#include <zephyr/input/input.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Common touchscreen config.
26+
*
27+
* This structure **must** be placed first in the driver's config structure.
28+
*
29+
* @param screen_width Horizontal resolution of touchscreen
30+
* @param screen_height Vertical resolution of touchscreen
31+
* @param inverted_x X axis is inverted
32+
* @param inverted_y Y axis is inverted
33+
* @param swapped_x_y X and Y axes are swapped
34+
*
35+
* see touchscreem-common.yaml for more details
36+
*/
37+
struct input_touchscreen_common_config {
38+
uint32_t screen_width;
39+
uint32_t screen_height;
40+
bool inverted_x;
41+
bool inverted_y;
42+
bool swapped_x_y;
43+
};
44+
45+
/**
46+
* @brief Initialize common touchscreen config from devicetree
47+
*
48+
* @param node_id The devicetree node identifier.
49+
*/
50+
#define INPUT_TOUCH_DT_COMMON_CONFIG_INIT(node_id) \
51+
{ \
52+
.screen_width = DT_PROP(node_id, screen_width), \
53+
.screen_height = DT_PROP(node_id, screen_height), \
54+
.inverted_x = DT_PROP(node_id, inverted_x), \
55+
.inverted_y = DT_PROP(node_id, inverted_y), \
56+
.swapped_x_y = DT_PROP(node_id, swapped_x_y) \
57+
}
58+
59+
/**
60+
* @brief Initialize common touchscreen config from devicetree instance.
61+
*
62+
* @param inst Instance.
63+
*/
64+
#define INPUT_TOUCH_DT_INST_COMMON_CONFIG_INIT(inst) \
65+
INPUT_TOUCH_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst))
66+
67+
/**
68+
* @brief Validate the offset of the common config structure.
69+
*
70+
* @param config Name of the config structure.
71+
*/
72+
#define INPUT_TOUCH_STRUCT_CHECK(config) \
73+
BUILD_ASSERT(offsetof(config, common) == 0, \
74+
"struct input_touchscreen_common_config must be placed first");
75+
76+
/**
77+
* @brief Common utility for reporting touchscreen position events.
78+
*
79+
* @param dev Touchscreen controller
80+
* @param x X coordinate as reported by the controller
81+
* @param y Y coordinate as reported by the controller
82+
* @param timeout Timeout for reporting the event
83+
*/
84+
void input_touchscreen_report_pos(const struct device *dev,
85+
uint32_t x, uint32_t y,
86+
k_timeout_t timeout);
87+
88+
#ifdef __cplusplus
89+
}
90+
#endif
91+
92+
/** @} */
93+
94+
#endif /* ZEPHYR_INCLUDE_INPUT_TOUCH_H_ */

0 commit comments

Comments
 (0)