1 /*
2  * Copyright (c) 2020 Jabil Inc.
3  * Copyright (c) 2023 Nordic Semiconductor
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #define DT_DRV_COMPAT zephyr_input_sdl_touch
9 
10 #include <stdbool.h>
11 #include <zephyr/input/input.h>
12 #include <zephyr/logging/log.h>
13 #include "input_sdl_touch_bottom.h"
14 
15 LOG_MODULE_REGISTER(sdl_input, CONFIG_INPUT_LOG_LEVEL);
16 
sdl_input_callback(struct sdl_input_data * data)17 static void sdl_input_callback(struct sdl_input_data *data)
18 {
19 	if (data->just_released == true) {
20 		input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
21 		data->just_released = false;
22 	}
23 
24 	if (data->pressed) {
25 		input_report_abs(data->dev, INPUT_ABS_X, data->x, false, K_FOREVER);
26 		input_report_abs(data->dev, INPUT_ABS_Y, data->y, false, K_FOREVER);
27 		input_report_key(data->dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
28 	}
29 }
30 
sdl_init(const struct device * dev)31 static int sdl_init(const struct device *dev)
32 {
33 	struct sdl_input_data *data = dev->data;
34 
35 	LOG_INF("Init '%s' device", dev->name);
36 
37 	data->dev = dev;
38 	data->callback = sdl_input_callback;
39 	sdl_input_init_bottom(data);
40 
41 	return 0;
42 }
43 
44 static struct sdl_input_data sdl_data_0;
45 
46 DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
47 		    POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
48