Input: support virtual objects on touchscreens
Subsystems (3)
v2 cover Input: support virtual objects on touchscreens
Some touchscreens are shipped with a physical layer on top of them where a number of buttons and a resized touchscreen surface might be available.
In order to generate proper key events by overlay buttons and adjust the touch events to a clipped surface, these patches offer a documented, device-tree-based solution by means of helper functions.
An implementation for a specific touchscreen driver is also included.
The functions in ts-virtobj provide a simple workflow to acquire physical objects from the device tree, map them into the device driver structures as virtual objects and generate events according to the object descriptions.
This feature has been tested with a JT240MHQS-E3 display, which consists of an st1624 as the base touchscreen and an overlay with two buttons and a frame that clips its effective surface mounted on it.
---
Changes in v2:
- PATCH 1/4: remove preprocessor directives (the module is selected by
the drivers that support the feature). Typo in the commit message.
- PATCH 2/4: more detailed documentation. Images and examples were added.
- PATCH 3/4: select ts-virtobj automatically.
- Link to v1: https://lore.kernel.org/r/20230510-feature-ts_virtobj_patch-v1-0-5ae5e81bc264@wolfvision.net
---
Javier Carrasco (4):
Input: ts-virtobj - Add touchscreen virtual object handling
dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Input: st1232 - add virtual touchscreen and buttons handling
dt-bindings: input: touchscreen: st1232: add example with ts-virtobj
.../input/touchscreen/sitronix,st1232.yaml | 40 +++ .../bindings/input/touchscreen/touchscreen.yaml | 139 ++++++++ MAINTAINERS | 7 + drivers/input/touchscreen/Kconfig | 10 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/st1232.c | 87 +++-- drivers/input/touchscreen/ts-virtobj.c | 356 +++++++++++++++++++++ include/linux/input/ts-virtobj.h | 43 +++ 8 files changed, 665 insertions(+), 18 deletions(-)
---
base-commit: ac9a78681b921877518763ba0e89202254349d1b
change-id: 20230510-feature-ts_virtobj_patch-e267540aae74
Best regards,
Signature · 1 line
Javier Carrasco <[email protected]>
PATCH v2 1/4 Input: ts-virtobj - Add touchscreen virtual object handling
Some touchscreens provide mechanical overlays with different objects like buttons or clipped touchscreen surfaces.
In order to support these objects, add a series of helper functions to the input subsystem to transform them into virtual objects via device tree nodes.
These virtual objects consume the raw touch events and report the expected input events depending on the object properties.
--- MAINTAINERS | 7 + drivers/input/touchscreen/Kconfig | 9 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/ts-virtobj.c | 356 +++++++++++++++++++++++++++++++++ include/linux/input/ts-virtobj.h | 43 ++++ 5 files changed, 416 insertions(+)
MAINTAINERS +7 -0
@@ -21434,6 +21434,13 @@ W: https://github.com/srcres258/linux-doc T: git git://github.com/srcres258/linux-doc.git doc-zh-tw F: Documentation/translations/zh_TW/ +TOUCHSCREEN VIRTUAL OBJECTS +M: Javier Carrasco <[email protected]> +L: [email protected] +S: Maintained +F: drivers/input/touchscreen/ts-virtobj.c +F: include/linux/input/ts-virtobj.h + TTY LAYER M: Greg Kroah-Hartman <[email protected]> M: Jiri Slaby <[email protected]>
drivers/input/touchscreen/Kconfig +9 -0
@@ -1388,4 +1388,13 @@ config TOUCHSCREEN_HIMAX_HX83112B To compile this driver as a module, choose M here: the module will be called himax_hx83112b. +config TOUCHSCREEN_TS_VIRTOBJ + tristate "Touchscreen Virtual Objects" + help + Say Y here if you are using a touchscreen driver that supports + printed overlays with keys or a clipped touchscreen area. + + Should be selected by the touchscren drivers that support + this feature. + endif
drivers/input/touchscreen/Makefile +1 -0
@@ -117,3 +117,4 @@ obj-$(CONFIG_TOUCHSCREEN_RASPBERRYPI_FW) += raspberrypi-ts.o obj-$(CONFIG_TOUCHSCREEN_IQS5XX) += iqs5xx.o obj-$(CONFIG_TOUCHSCREEN_ZINITIX) += zinitix.o obj-$(CONFIG_TOUCHSCREEN_HIMAX_HX83112B) += himax_hx83112b.o +obj-$(CONFIG_TOUCHSCREEN_TS_VIRTOBJ) += ts-virtobj.o
drivers/input/touchscreen/ts-virtobj.c new file +356 -0
356 lines not on this page · raw message
include/linux/input/ts-virtobj.h new file +43 -0
43 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v2 2/4 dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
In reply to Javier CarrascoThe virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
--- .../bindings/input/touchscreen/touchscreen.yaml | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/touchscreen.yaml +139 -0
@@ -80,6 +80,145 @@ properties: touchscreen-y-plate-ohms: description: Resistance of the Y-plate in Ohms + virtual-touchscreen: + description: Clipped touchscreen area + + This object can be used to describe a frame that restricts the area + within touch events are reported, ignoring the events that occur outside + this area. This is of special interest if the touchscreen is shipped + with a physical overlay on top of it with a frame that hides some part + of the original touchscreen area. + + The x-origin and y-origin properties of this object define the offset of + a new origin from where the touchscreen events are referenced. + This offset is applied to the events accordingly. The x-size and y-size + properties define the size of the virtual-touchscreen (effective area). + + The following example shows the new touchscreen area and the new origin + (0',0') for the touch events generated by the device. + + Touchscreen (full area) + ┌────────────────────────────────────────┐ + │ ┌───────────────────────────────┐ │ + │ │ │ │ + │ ├ y-size │ │ + │ │ │ │ + │ │ virtual-touchscreen │ │ + │ │ │ │ + │ │ │ │ + │ │ x-size │ │ + │ ┌└──────────────┴────────────────┘ │ + │(0',0') │ + ┌└────────────────────────────────────────┘ + (0,0) + + where (0',0') = (0+x-origin,0+y-origin) + + type: object + + properties: + x-origin: + description: horizontal origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the clipped area + $ref: /schemas/types.yaml#/definitions/uint32 + + virtual-buttons: + description: list of nodes defining the buttons on the touchscreen + + This object can be used to describe buttons on the touchscreen area, + reporting the touch events on their surface as key events instead of + the original touch events. + + This is of special interest if the touchscreen is shipped with a + physical overlay on top of it where a number of buttons with some + predefined functionality are printed. In that case a specific behavior + is expected from those buttons instead of raw touch events. + + The virtual-buttons properties define a per-button area as well as an + origin relative to the real touchscreen origin. Touch events within the + button area are reported as the key event defined in the linux,code + property. Given that the key events do not provide coordinates, the + button origin is only used to place the button area on the touchscreen + surface. Any event outside the virtual-buttons object is reported as a + touch event with no coordinate transformation. + + The following example shows a touchscreen with a single button on it + + Touchscreen (full area) + ┌───────────────────────────────────┐ + │ │ + │ │ + │ ┌─────────┐ │ + │ │button 0 │ │ + │ │KEY_POWER│ │ + │ └─────────┘ │ + │ │ + │ │ + ┌└───────────────────────────────────┘ + (0,0) + + The virtual-buttons object can be combined with the virtual-touchscreen + object as shown in the following example. In that case only the events + within the virtual-touchscreen object are reported as touch events. + + Touchscreen (full area) + ┌─────────┬──────────────────────────────┐ + │ │ │ + │ │ ┌───────────────────────┐ │ + │ button 0│ │ │ │ + │KEY_POWER│ │ │ │ + │ │ │ │ │ + ├─────────┤ │ virtual-touchscreen │ │ + │ │ │ │ │ + │ │ │ │ │ + │ button 1│ │ │ │ + │ KEY_INFO│ ┌└───────────────────────┘ │ + │ │(0',0') │ + ┌└─────────┴──────────────────────────────┘ + (0,0) + + type: object + + patternProperties: + '^button-': + type: object + description: + Each button (key) is represented as a sub-node. + + properties: + label: + $ref: /schemas/types.yaml#/definitions/string + description: descriptive name of the button + + linux,code: true + + x-origin: + description: horizontal origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-origin: + description: vertical origin of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + x-size: + description: horizontal resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + + y-size: + description: vertical resolution of the button area + $ref: /schemas/types.yaml#/definitions/uint32 + dependencies: touchscreen-size-x: [ touchscreen-size-y ] touchscreen-size-y: [ touchscreen-size-x ]
Signature · 1 line
2.39.2
Re: [PATCH v2 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Quoted 11 lines · Javier Carrasco
The virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
Signed-off-by Javier Carrasco <[email protected]>---
Best regards,
Krzysztof
Re: [PATCH v2 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Javier Carrasco
The virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Javier Carrasco <[email protected]>---
Reviewed-by Krzysztof Kozlowski <[email protected]>
Apologies, second thoughts - why calling all this binding and properties "virtual"? That's the word which immediately raises questions, because bindings are only for real things, not virtual.
Touchscreen is just clipped, not virtual, so maybe "clipped-area" instead of virtual-touchscreen? Buttons are real, so maybe just "buttons"?
Best regards,
Krzysztof
Re: [PATCH v2 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Quoted 21 lines · Krzysztof Kozlowski
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Javier Carrasco
The virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Javier Carrasco <[email protected]>---
Reviewed-by Krzysztof Kozlowski <[email protected]>Apologies, second thoughts - why calling all this binding and properties "virtual"? That's the word which immediately raises questions, because bindings are only for real things, not virtual.
Quoted 6 lines
Touchscreen is just clipped, not virtual, so maybe "clipped-area" instead of virtual-touchscreen? Buttons are real, so maybe just "buttons"?
Best regards,
Krzysztof
I guess it is a matter of perspective. For a user the buttons and the clipped area are 100% real, but for a driver developer they are virtual in the sense that there is not an "active" hardware behind apart from the original touchscreen.
I just wanted to avoid misunderstandings when implementing this feature for other drivers. One might wonder if the touchscreen now has mechanical keys attached to it. With the "virtual-" prefix it is clear that the objects are not additional pieces of hardware or extensions of the touchscreen functionality.
For the virtual-touchscreen your point is stronger because there is indeed a real touchscreen hardware no matter the area you define, but my approach was keeping homogeneous names for the different objects in case some new ones might appear in the future: every object that gets on top of the touchscreen area is virtual, so add a new object type and name it virtual-xxx.
I have nothing against about doing some renaming and I will do it if it is required, but with the documentation I think it is now more clear what everything means and in the end it might make more sense for the drivers so they can differentiate between real and virtual devices.
Re: [PATCH v2 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Quoted 25 lines · Javier Carrasco
Quoted 24 lines · Krzysztof Kozlowski
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Javier Carrasco
The virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Javier Carrasco <[email protected]>---
Reviewed-by Krzysztof Kozlowski <[email protected]>Apologies, second thoughts - why calling all this binding and properties "virtual"? That's the word which immediately raises questions, because bindings are only for real things, not virtual.
Touchscreen is just clipped, not virtual, so maybe "clipped-area" instead of virtual-touchscreen? Buttons are real, so maybe just "buttons"?
Quoted 7 lines
Quoted 3 lines
Best regards,
KrzysztofI guess it is a matter of perspective. For a user the buttons and the clipped area are 100% real, but for a driver developer they are virtual in the sense that there is not an "active" hardware behind apart from the original touchscreen.
The feature describes the hardware, not driver. To understand what does it mean, look from hardware point of view - does it have some virtual area or clipped area?
Quoted 6 lines
I just wanted to avoid misunderstandings when implementing this feature for other drivers. One might wonder if the touchscreen now has mechanical keys attached to it. With the "virtual-" prefix it is clear that the objects are not additional pieces of hardware or extensions of the touchscreen functionality.
But what if actual physical buttons are added there? You still would have clipped/virtual area, just without virtual buttons.
Quoted 7 lines
For the virtual-touchscreen your point is stronger because there is indeed a real touchscreen hardware no matter the area you define, but my approach was keeping homogeneous names for the different objects in case some new ones might appear in the future: every object that gets on top of the touchscreen area is virtual, so add a new object type and name it virtual-xxx.
To me, word "virtual" suggests something which does not exist. Kind of something abstracted or symbolic. Opposite to "real". Here all this really exists. You have physical stickers on the touchscreen.
Maybe this should be then "dedicated"? or "isolated"?
Or just "overlay-area"?
Quoted 5 lines
I have nothing against about doing some renaming and I will do it if it is required, but with the documentation I think it is now more clear what everything means and in the end it might make more sense for the drivers so they can differentiate between real and virtual devices.
Best regards,
Krzysztof
Re: [PATCH v2 2/4] dt-bindings: touchscreen: add virtual-touchscreen and virtual-buttons properties
Quoted 66 lines · Krzysztof Kozlowski
Quoted 25 lines · Javier Carrasco
Quoted 24 lines · Krzysztof Kozlowski
Quoted 10 lines · Krzysztof Kozlowski
Quoted 9 lines · Javier Carrasco
The virtual-touchscreen object defines an area within the touchscreen where touch events are reported and their coordinates get converted to the virtual origin. This object avoids getting events from areas that are physically hidden by overlay frames.
For touchscreens where overlay buttons on the touchscreen surface are provided, the virtual-buttons object contains a node for every button and the key event that should be reported when pressed.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Javier Carrasco <[email protected]>---
Reviewed-by Krzysztof Kozlowski <[email protected]>Apologies, second thoughts - why calling all this binding and properties "virtual"? That's the word which immediately raises questions, because bindings are only for real things, not virtual.
Touchscreen is just clipped, not virtual, so maybe "clipped-area" instead of virtual-touchscreen? Buttons are real, so maybe just "buttons"?
Quoted 7 lines
Quoted 3 lines
Best regards,
KrzysztofI guess it is a matter of perspective. For a user the buttons and the clipped area are 100% real, but for a driver developer they are virtual in the sense that there is not an "active" hardware behind apart from the original touchscreen.
The feature describes the hardware, not driver. To understand what does it mean, look from hardware point of view - does it have some virtual area or clipped area?
Quoted 6 lines
I just wanted to avoid misunderstandings when implementing this feature for other drivers. One might wonder if the touchscreen now has mechanical keys attached to it. With the "virtual-" prefix it is clear that the objects are not additional pieces of hardware or extensions of the touchscreen functionality.
But what if actual physical buttons are added there? You still would have clipped/virtual area, just without virtual buttons.
Quoted 7 lines
For the virtual-touchscreen your point is stronger because there is indeed a real touchscreen hardware no matter the area you define, but my approach was keeping homogeneous names for the different objects in case some new ones might appear in the future: every object that gets on top of the touchscreen area is virtual, so add a new object type and name it virtual-xxx.
To me, word "virtual" suggests something which does not exist. Kind of something abstracted or symbolic. Opposite to "real". Here all this really exists. You have physical stickers on the touchscreen.
Maybe this should be then "dedicated"? or "isolated"?
Or just "overlay-area"?
Quoted 1 line
Quoted 8 lines
Quoted 4 lines
I have nothing against about doing some renaming and I will do it if it is required, but with the documentation I think it is now more clear what everything means and in the end it might make more sense for the drivers so they can differentiate between real and virtual devices.
Best regards,
Krzysztof
I think the word "overlay" is more precise and does not lead to any misunderstanding, so I will rename everything to xxx-overlay and overlay-xxx in the code and the documentation if that is ok. virtual-buttons -> overlay-buttons ts_virtobj_xxx()->ts_overlay_xxx()
etc.
PATCH v2 3/4 Input: st1232 - add virtual touchscreen and buttons handling
In reply to Javier CarrascoUse ts-virtobj to support overlay objects such as buttons and resized frames defined in the device tree.
If a virtual-touchscreen is provided, ignore touch events outside of the area defined by its properties. Otherwise, transform the event coordinates to the virtual-touchscreen x and y-axis if required.
If buttons are provided, register an additional device to report key events separately. A key event will be generated if the coordinates of a touch event are within the area defined by the button properties.
--- drivers/input/touchscreen/Kconfig | 1 + drivers/input/touchscreen/st1232.c | 87 ++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 18 deletions(-)
drivers/input/touchscreen/Kconfig +1 -0
@@ -1215,6 +1215,7 @@ config TOUCHSCREEN_SIS_I2C config TOUCHSCREEN_ST1232 tristate "Sitronix ST1232 or ST1633 touchscreen controllers" depends on I2C + select TOUCHSCREEN_TS_VIRTOBJ help Say Y here if you want to support the Sitronix ST1232 or ST1633 touchscreen controller.
drivers/input/touchscreen/st1232.c +69 -18
145 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH v2 4/4 dt-bindings: input: touchscreen: st1232: add example with ts-virtobj
In reply to Javier CarrascoThe st1232 driver supports the virtual-touchscreen and virtual-buttons objects defined in the generic touchscreen bindings and implemented in the ts-virtobj module. Add an example where nodes for a virtual touchscreen and virtual buttons are defined.
--- .../input/touchscreen/sitronix,st1232.yaml | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/sitronix,st1232.yaml +40 -0
@@ -48,3 +48,43 @@ examples: gpios = <&gpio1 166 0>; }; }; + - | + #include <dt-bindings/input/linux-event-codes.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + touchscreen@55 { + compatible = "sitronix,st1232"; + reg = <0x55>; + interrupts = <2 0>; + gpios = <&gpio1 166 0>; + + virtual-touchscreen { + x-origin = <0>; + x-size = <240>; + y-origin = <40>; + y-size = <280>; + }; + + virtual-buttons { + button-light { + label = "Camera light"; + linux,code = <KEY_LIGHTS_TOGGLE>; + x-origin = <40>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + + button-suspend { + label = "Suspend"; + linux,code = <KEY_SUSPEND>; + x-origin = <160>; + x-size = <40>; + y-origin = <0>; + y-size = <40>; + }; + }; + }; + };
Signature · 1 line
2.39.2