input: convert the kscan_sdl driver from kscan to input

Convert the SDL driver to use the input subsystem. This is specifically
meant to emulate touchscreen drivers, so it's setup to send triplet of
x, y, touch for touch-on events and just touch off on touch off events.

Renamed the driver to input-sdl-touch since now we can also develop an
sdl driver for simulating key events.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2023-04-04 12:17:38 +01:00 committed by Carles Cufí
parent fad2da39aa
commit b76ac9a851
11 changed files with 86 additions and 130 deletions

View file

@ -22,7 +22,7 @@
zephyr,flash-controller = &flashcontroller0; zephyr,flash-controller = &flashcontroller0;
zephyr,display = &sdl_dc; zephyr,display = &sdl_dc;
zephyr,canbus = &can_loopback0; zephyr,canbus = &can_loopback0;
zephyr,keyboard-scan = &sdl_kscan; zephyr,keyboard-scan = &kscan_input;
}; };
aliases { aliases {
@ -30,7 +30,7 @@
i2c-0 = &i2c0; i2c-0 = &i2c0;
spi-0 = &spi0; spi-0 = &spi0;
led0 = &led0; led0 = &led0;
kscan0 = &sdl_kscan; kscan0 = &kscan_input;
rtc = &rtc; rtc = &rtc;
}; };
@ -178,8 +178,11 @@
width = <320>; width = <320>;
}; };
sdl_kscan: sdl_kscan { input-sdl-touch {
compatible = "zephyr,sdl-kscan"; compatible = "zephyr,input-sdl-touch";
kscan_input: kscan-input {
compatible = "zephyr,kscan-input";
};
}; };
can_loopback0: can_loopback0 { can_loopback0: can_loopback0 {

View file

@ -5,3 +5,4 @@ zephyr_library_property(ALLOW_EMPTY TRUE)
zephyr_library_sources_ifdef(CONFIG_INPUT_FT5336 input_ft5336.c) zephyr_library_sources_ifdef(CONFIG_INPUT_FT5336 input_ft5336.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c) zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_KEYS input_gpio_keys.c)
zephyr_library_sources_ifdef(CONFIG_INPUT_SDL_TOUCH input_sdl_touch.c)

View file

@ -7,6 +7,7 @@ menu "Input drivers"
source "drivers/input/Kconfig.ft5336" source "drivers/input/Kconfig.ft5336"
source "drivers/input/Kconfig.gpio_keys" source "drivers/input/Kconfig.gpio_keys"
source "drivers/input/Kconfig.sdl"
endmenu # Input Drivers endmenu # Input Drivers

View file

@ -1,10 +1,10 @@
# Copyright (c) 2020 Jabil Inc. # Copyright (c) 2020 Jabil Inc.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
config KSCAN_SDL config INPUT_SDL_TOUCH
bool "SDL event filter for touch panel emulation" bool "SDL event filter for touch panel emulation"
default y default y
depends on DT_HAS_ZEPHYR_SDL_KSCAN_ENABLED depends on DT_HAS_ZEPHYR_INPUT_SDL_TOUCH_ENABLED
depends on HAS_SDL depends on HAS_SDL
help help
Enable driver for the SDL mouse event filter. Enable driver for the SDL mouse event filter.

View file

@ -0,0 +1,67 @@
/*
* Copyright (c) 2020 Jabil Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT zephyr_input_sdl_touch
#include <zephyr/input/input.h>
#include <zephyr/logging/log.h>
#include <SDL.h>
LOG_MODULE_REGISTER(sdl_input, CONFIG_INPUT_LOG_LEVEL);
struct sdl_data {
const struct device *dev;
int x;
int y;
bool pressed;
};
static int sdl_filter(void *arg, SDL_Event *event)
{
struct sdl_data *data = arg;
switch (event->type) {
case SDL_MOUSEBUTTONUP:
data->pressed = false;
input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
break;
case SDL_MOUSEBUTTONDOWN:
data->pressed = true;
break;
case SDL_MOUSEMOTION:
data->x = event->button.x;
data->y = event->button.y;
break;
default:
return 1;
}
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);
}
return 1;
}
static int sdl_init(const struct device *dev)
{
struct sdl_data *data = dev->data;
data->dev = dev;
LOG_INF("Init '%s' device", dev->name);
SDL_AddEventWatch(sdl_filter, data);
return 0;
}
static struct sdl_data sdl_data_0;
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);

View file

@ -5,7 +5,6 @@ zephyr_library()
zephyr_library_sources_ifdef(CONFIG_KSCAN_GT911 kscan_gt911.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_GT911 kscan_gt911.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_ITE_IT8XXX2 kscan_ite_it8xxx2.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_ITE_IT8XXX2 kscan_ite_it8xxx2.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_SDL kscan_sdl.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_HT16K33 kscan_ht16k33.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_CST816S kscan_cst816s.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_CST816S kscan_cst816s.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_CAP1203 kscan_cap1203.c) zephyr_library_sources_ifdef(CONFIG_KSCAN_CAP1203 kscan_cap1203.c)

View file

@ -13,7 +13,6 @@ if KSCAN
source "drivers/kscan/Kconfig.gt911" source "drivers/kscan/Kconfig.gt911"
source "drivers/kscan/Kconfig.it8xxx2" source "drivers/kscan/Kconfig.it8xxx2"
source "drivers/kscan/Kconfig.xec" source "drivers/kscan/Kconfig.xec"
source "drivers/kscan/Kconfig.sdl"
source "drivers/kscan/Kconfig.ht16k33" source "drivers/kscan/Kconfig.ht16k33"
source "drivers/kscan/Kconfig.cst816s" source "drivers/kscan/Kconfig.cst816s"
source "drivers/kscan/Kconfig.cap1203" source "drivers/kscan/Kconfig.cap1203"

View file

@ -1,114 +0,0 @@
/*
* Copyright (c) 2020 Jabil Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT zephyr_sdl_kscan
#include <zephyr/drivers/kscan.h>
#include <zephyr/logging/log.h>
#include <SDL.h>
LOG_MODULE_REGISTER(kscan, CONFIG_KSCAN_LOG_LEVEL);
struct sdl_data {
const struct device *dev;
kscan_callback_t callback;
bool enabled;
};
static int sdl_filter(void *arg, SDL_Event *event)
{
struct sdl_data *data = arg;
uint32_t row = 0;
uint32_t column = 0;
bool pressed = 0;
switch (event->type) {
case SDL_MOUSEBUTTONDOWN: {
pressed = 1;
column = event->button.x;
row = event->button.y;
} break;
case SDL_MOUSEBUTTONUP: {
pressed = 0;
column = event->button.x;
row = event->button.y;
} break;
case SDL_MOUSEMOTION: {
if (!event->motion.state)
break;
pressed = 1;
column = event->button.x;
row = event->button.y;
} break;
default:
return 1;
}
if (data->enabled && data->callback) {
data->callback(data->dev, row, column, pressed);
}
return 1;
}
static int sdl_configure(const struct device *dev, kscan_callback_t callback)
{
struct sdl_data *data = dev->data;
if (!callback) {
LOG_ERR("Callback is null");
return -EINVAL;
}
LOG_DBG("%s: set callback", dev->name);
data->callback = callback;
return 0;
}
static int sdl_enable_callback(const struct device *dev)
{
struct sdl_data *data = dev->data;
LOG_DBG("%s: enable cb", dev->name);
data->enabled = true;
return 0;
}
static int sdl_disable_callback(const struct device *dev)
{
struct sdl_data *data = dev->data;
LOG_DBG("%s: disable cb", dev->name);
data->enabled = false;
return 0;
}
static int sdl_init(const struct device *dev)
{
struct sdl_data *data = dev->data;
data->dev = dev;
LOG_INF("Init '%s' device", dev->name);
SDL_AddEventWatch(sdl_filter, data);
return 0;
}
static const struct kscan_driver_api sdl_driver_api = {
.config = sdl_configure,
.enable_callback = sdl_enable_callback,
.disable_callback = sdl_disable_callback,
};
static struct sdl_data sdl_data;
DEVICE_DT_INST_DEFINE(0, sdl_init,
NULL, &sdl_data, NULL,
POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY,
&sdl_driver_api);

View file

@ -0,0 +1,6 @@
# Copyright (c) 2022 Kumar Gala <galak@kernel.org>
# SPDX-License-Identifier: Apache-2.0
description: SDL based emulated touch panel
compatible: "zephyr,input-sdl-touch"

View file

@ -1,8 +0,0 @@
# Copyright (c) 2022 Kumar Gala <galak@kernel.org>
# SPDX-License-Identifier: Apache-2.0
description: SDL based emulated keyboard matrix devices
compatible: "zephyr,sdl-kscan"
include: kscan.yaml

View file

@ -5,6 +5,8 @@
*/ */
/ { / {
/delete-node/ input-sdl-touch;
fake_input_device: fake-device { fake_input_device: fake-device {
compatible = "vnd,input-device"; compatible = "vnd,input-device";
kscan_input: kscan-input { kscan_input: kscan-input {