Browse Source
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
6 changed files with 128 additions and 0 deletions
@ -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. |
@ -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); |
||||||
|
} |
@ -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…
Reference in new issue