input SDL: Split in top and bottom
Split the SDL input driver in a top and bottom to enable using it with embedded libCs. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
1e66ca0de3
commit
78ff21e1e1
|
@ -7,5 +7,13 @@ 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_GPIO_QDEC input_gpio_qdec.c)
|
zephyr_library_sources_ifdef(CONFIG_INPUT_GPIO_QDEC input_gpio_qdec.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_INPUT_NPCX_KBD input_npcx_kbd.c)
|
zephyr_library_sources_ifdef(CONFIG_INPUT_NPCX_KBD input_npcx_kbd.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_INPUT_SDL_TOUCH input_sdl_touch.c)
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c)
|
zephyr_library_sources_ifdef(CONFIG_INPUT_XPT2046 input_xpt2046.c)
|
||||||
|
|
||||||
|
if (CONFIG_INPUT_SDL_TOUCH)
|
||||||
|
zephyr_library_sources(input_sdl_touch.c)
|
||||||
|
if (CONFIG_NATIVE_APPLICATION)
|
||||||
|
zephyr_library_sources(input_sdl_touch_bottom.c)
|
||||||
|
else()
|
||||||
|
target_sources(native_simulator INTERFACE input_sdl_touch_bottom.c)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
|
@ -1,43 +1,24 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 Jabil Inc.
|
* Copyright (c) 2020 Jabil Inc.
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DT_DRV_COMPAT zephyr_input_sdl_touch
|
#define DT_DRV_COMPAT zephyr_input_sdl_touch
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <zephyr/input/input.h>
|
#include <zephyr/input/input.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
#include "input_sdl_touch_bottom.h"
|
||||||
#include <SDL.h>
|
|
||||||
|
|
||||||
LOG_MODULE_REGISTER(sdl_input, CONFIG_INPUT_LOG_LEVEL);
|
LOG_MODULE_REGISTER(sdl_input, CONFIG_INPUT_LOG_LEVEL);
|
||||||
|
|
||||||
struct sdl_data {
|
static void sdl_input_callback(struct sdl_input_data *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;
|
if (data->just_released == true) {
|
||||||
|
|
||||||
switch (event->type) {
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
data->pressed = false;
|
|
||||||
input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
|
input_report_key(data->dev, INPUT_BTN_TOUCH, 0, true, K_FOREVER);
|
||||||
break;
|
data->just_released = false;
|
||||||
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) {
|
if (data->pressed) {
|
||||||
|
@ -45,23 +26,22 @@ static int sdl_filter(void *arg, SDL_Event *event)
|
||||||
input_report_abs(data->dev, INPUT_ABS_Y, data->y, 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);
|
input_report_key(data->dev, INPUT_BTN_TOUCH, 1, true, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sdl_init(const struct device *dev)
|
static int sdl_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
struct sdl_data *data = dev->data;
|
struct sdl_input_data *data = dev->data;
|
||||||
|
|
||||||
data->dev = dev;
|
|
||||||
|
|
||||||
LOG_INF("Init '%s' device", dev->name);
|
LOG_INF("Init '%s' device", dev->name);
|
||||||
SDL_AddEventWatch(sdl_filter, data);
|
|
||||||
|
data->dev = dev;
|
||||||
|
data->callback = sdl_input_callback;
|
||||||
|
sdl_input_init_bottom(data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sdl_data sdl_data_0;
|
static struct sdl_input_data sdl_data_0;
|
||||||
|
|
||||||
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
|
DEVICE_DT_INST_DEFINE(0, sdl_init, NULL, &sdl_data_0, NULL,
|
||||||
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
|
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);
|
||||||
|
|
39
drivers/input/input_sdl_touch_bottom.c
Normal file
39
drivers/input/input_sdl_touch_bottom.c
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Jabil Inc.
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
#include "input_sdl_touch_bottom.h"
|
||||||
|
|
||||||
|
static int sdl_filter(void *arg, SDL_Event *event)
|
||||||
|
{
|
||||||
|
struct sdl_input_data *data = arg;
|
||||||
|
|
||||||
|
switch (event->type) {
|
||||||
|
case SDL_MOUSEBUTTONUP:
|
||||||
|
data->pressed = false;
|
||||||
|
data->just_released = true;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->callback(data);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sdl_input_init_bottom(struct sdl_input_data *data)
|
||||||
|
{
|
||||||
|
SDL_AddEventWatch(sdl_filter, data);
|
||||||
|
}
|
38
drivers/input/input_sdl_touch_bottom.h
Normal file
38
drivers/input/input_sdl_touch_bottom.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Nordic Semiconductor
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* "Bottom" of the SDL input driver.
|
||||||
|
* When built with the native_simulator this will be built in the runner context,
|
||||||
|
* that is, with the host C library, and with the host include paths.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DRIVERS_INPUT_INPUT_SDL_TOUCH_BOTTOM_H
|
||||||
|
#define DRIVERS_INPUT_INPUT_SDL_TOUCH_BOTTOM_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Note: None of these are public interfaces. But internal to the SDL input driver */
|
||||||
|
|
||||||
|
struct sdl_input_data {
|
||||||
|
const void *dev; /* device structure pointer */
|
||||||
|
void (*callback)(struct sdl_input_data *data);
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
bool pressed;
|
||||||
|
bool just_released;
|
||||||
|
};
|
||||||
|
|
||||||
|
void sdl_input_init_bottom(struct sdl_input_data *data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* DRIVERS_INPUT_INPUT_SDL_TOUCH_BOTTOM_H */
|
Loading…
Reference in a new issue