2023-04-04 19:17:38 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Jabil Inc.
|
2023-07-05 16:00:26 +08:00
|
|
|
* Copyright (c) 2023 Nordic Semiconductor
|
2023-04-04 19:17:38 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT zephyr_input_sdl_touch
|
|
|
|
|
2023-07-05 16:00:26 +08:00
|
|
|
#include <stdbool.h>
|
2023-04-04 19:17:38 +08:00
|
|
|
#include <zephyr/input/input.h>
|
|
|
|
#include <zephyr/logging/log.h>
|
2023-07-05 16:00:26 +08:00
|
|
|
#include "input_sdl_touch_bottom.h"
|
2023-04-04 19:17:38 +08:00
|
|
|
|
|
|
|
LOG_MODULE_REGISTER(sdl_input, CONFIG_INPUT_LOG_LEVEL);
|
|
|
|
|
2023-07-05 16:00:26 +08:00
|
|
|
static void sdl_input_callback(struct sdl_input_data *data)
|
2023-04-04 19:17:38 +08:00
|
|
|
{
|
2023-07-05 16:00:26 +08:00
|
|
|
if (data->just_released == true) {
|
2023-04-04 19:17:38 +08:00
|
|
|
input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
|
2023-07-05 16:00:26 +08:00
|
|
|
data->just_released = false;
|
2023-04-04 19:17:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data->pressed) {
|
|
|
|
input_report_abs(data->dev, INPUT_ABS_X, data->x, false, K_FOREVER);
|
|
|
|
input_report_abs(data->dev, INPUT_ABS_Y, data->y, false, K_FOREVER);
|
|
|
|
input_report_key(data->dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sdl_init(const struct device *dev)
|
|
|
|
{
|
2023-07-05 16:00:26 +08:00
|
|
|
struct sdl_input_data *data = dev->data;
|
2023-04-04 19:17:38 +08:00
|
|
|
|
|
|
|
LOG_INF("Init '%s' device", dev->name);
|
2023-07-05 16:00:26 +08:00
|
|
|
|
|
|
|
data->dev = dev;
|
|
|
|
data->callback = sdl_input_callback;
|
|
|
|
sdl_input_init_bottom(data);
|
2023-04-04 19:17:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:00:26 +08:00
|
|
|
static struct sdl_input_data sdl_data_0;
|
2023-04-04 19:17:38 +08:00
|
|
|
|
|
|
|
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
|
|
|
|
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
|