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