|
| 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