Browse Source

drivers: input: common properties parsing for touchscreen drivers

Adds a way of reporting touchscreen events
taking common properties into account.

Signed-off-by: Dominik Lau <dlau@internships.antmicro.com>
Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
pull/77306/head
Dominik Lau 11 months ago committed by Anas Nashif
parent
commit
74e84a9dfd
  1. 5
      doc/services/input/index.rst
  2. 1
      drivers/input/CMakeLists.txt
  3. 1
      drivers/input/Kconfig
  4. 7
      drivers/input/Kconfig.touch
  5. 20
      drivers/input/input_touch.c
  6. 94
      include/zephyr/input/input_touch.h

5
doc/services/input/index.rst

@ -131,3 +131,8 @@ Analog Axis API Reference @@ -131,3 +131,8 @@ Analog Axis API Reference
*************************
.. doxygengroup:: input_analog_axis
Touchscreen API Reference
*************************
.. doxygengroup:: touch_events

1
drivers/input/CMakeLists.txt

@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_INPUT_PINNACLE input_pinnacle.c) @@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_INPUT_PINNACLE input_pinnacle.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_PMW3610 input_pmw3610.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_SBUS input_sbus.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_STMPE811 input_stmpe811.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_TOUCH input_touch.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_XEC_KBD input_xec_kbd.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c)
# zephyr-keep-sorted-stop

1
drivers/input/Kconfig

@ -29,6 +29,7 @@ source "drivers/input/Kconfig.pmw3610" @@ -29,6 +29,7 @@ source "drivers/input/Kconfig.pmw3610"
source "drivers/input/Kconfig.sbus"
source "drivers/input/Kconfig.sdl"
source "drivers/input/Kconfig.stmpe811"
source "drivers/input/Kconfig.touch"
source "drivers/input/Kconfig.xec"
source "drivers/input/Kconfig.xpt2046"
# zephyr-keep-sorted-stop

7
drivers/input/Kconfig.touch

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
# Copyright (c) 2024 Antmicro Ltd <www.antmicro.com>
# SPDX-License-Identifier: Apache-2.0
config INPUT_TOUCH
bool
help
Enable library used for touchscreen drivers.

20
drivers/input/input_touch.c

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/input/input_touch.h>
void input_touchscreen_report_pos(const struct device *dev,
uint32_t x, uint32_t y,
k_timeout_t timeout)
{
const struct input_touchscreen_common_config *cfg = dev->config;
const uint32_t reported_x_code = cfg->swapped_x_y ? INPUT_ABS_Y : INPUT_ABS_X;
const uint32_t reported_y_code = cfg->swapped_x_y ? INPUT_ABS_X : INPUT_ABS_Y;
const uint32_t reported_x = cfg->inverted_x ? cfg->screen_width - x : x;
const uint32_t reported_y = cfg->inverted_y ? cfg->screen_height - y : y;
input_report_abs(dev, reported_x_code, reported_x, false, timeout);
input_report_abs(dev, reported_y_code, reported_y, false, timeout);
}

94
include/zephyr/input/input_touch.h

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
/*
* Copyright (c) 2024 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_INPUT_TOUCH_H_
#define ZEPHYR_INCLUDE_INPUT_TOUCH_H_
/**
* @brief Touch Events API
* @defgroup touch_events Touchscreen Event Report API
* @since 3.7
* @version 0.1.0
* @ingroup io_interfaces
* @{
*/
#include <zephyr/input/input.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Common touchscreen config.
*
* This structure **must** be placed first in the driver's config structure.
*
* @param screen_width Horizontal resolution of touchscreen
* @param screen_height Vertical resolution of touchscreen
* @param inverted_x X axis is inverted
* @param inverted_y Y axis is inverted
* @param swapped_x_y X and Y axes are swapped
*
* see touchscreem-common.yaml for more details
*/
struct input_touchscreen_common_config {
uint32_t screen_width;
uint32_t screen_height;
bool inverted_x;
bool inverted_y;
bool swapped_x_y;
};
/**
* @brief Initialize common touchscreen config from devicetree
*
* @param node_id The devicetree node identifier.
*/
#define INPUT_TOUCH_DT_COMMON_CONFIG_INIT(node_id) \
{ \
.screen_width = DT_PROP(node_id, screen_width), \
.screen_height = DT_PROP(node_id, screen_height), \
.inverted_x = DT_PROP(node_id, inverted_x), \
.inverted_y = DT_PROP(node_id, inverted_y), \
.swapped_x_y = DT_PROP(node_id, swapped_x_y) \
}
/**
* @brief Initialize common touchscreen config from devicetree instance.
*
* @param inst Instance.
*/
#define INPUT_TOUCH_DT_INST_COMMON_CONFIG_INIT(inst) \
INPUT_TOUCH_DT_COMMON_CONFIG_INIT(DT_DRV_INST(inst))
/**
* @brief Validate the offset of the common config structure.
*
* @param config Name of the config structure.
*/
#define INPUT_TOUCH_STRUCT_CHECK(config) \
BUILD_ASSERT(offsetof(config, common) == 0, \
"struct input_touchscreen_common_config must be placed first");
/**
* @brief Common utility for reporting touchscreen position events.
*
* @param dev Touchscreen controller
* @param x X coordinate as reported by the controller
* @param y Y coordinate as reported by the controller
* @param timeout Timeout for reporting the event
*/
void input_touchscreen_report_pos(const struct device *dev,
uint32_t x, uint32_t y,
k_timeout_t timeout);
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* ZEPHYR_INCLUDE_INPUT_TOUCH_H_ */
Loading…
Cancel
Save