-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: kscan: Introduce SDL mouse driver
Introduces a new SDL mouse driver for the keyboard scan (kscan) interface. Driver is implemented as SDL event filter Signed-off-by: Pavlo Hamov <pavlo_hamov@jabil.com>
- Loading branch information
1 parent
8ccccbb
commit 687f407
Showing
5 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2020 Jabil Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config KSCAN_SDL | ||
bool "SDL event filter for touch panel emulation" | ||
depends on HAS_SDL | ||
help | ||
Enable driver for the SDL mouse event filter. | ||
|
||
config SDL_POINTER_KSCAN_DEV_NAME | ||
string "SDL kscan device name" | ||
depends on KSCAN_SDL | ||
default LVGL_POINTER_KSCAN_DEV_NAME if LVGL | ||
default "SDL_KSCAN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (c) 2020 Jabil Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <drivers/kscan.h> | ||
#include <logging/log.h> | ||
|
||
#include <SDL.h> | ||
|
||
LOG_MODULE_REGISTER(kscan, CONFIG_KSCAN_LOG_LEVEL); | ||
|
||
struct sdl_data { | ||
kscan_callback_t callback; | ||
bool enabled; | ||
}; | ||
|
||
static int sdl_filter(void *arg, SDL_Event *event) | ||
{ | ||
struct device *dev = arg; | ||
struct sdl_data *data = dev->driver_data; | ||
u32_t row = 0; | ||
u32_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(dev, row, column, pressed); | ||
} | ||
return 1; | ||
} | ||
|
||
static int sdl_configure(struct device *dev, kscan_callback_t callback) | ||
{ | ||
struct sdl_data *data = dev->driver_data; | ||
|
||
if (!callback) { | ||
LOG_ERR("Callback is null"); | ||
return -EINVAL; | ||
} | ||
LOG_DBG("%s: set callback", dev->config->name); | ||
|
||
data->callback = callback; | ||
|
||
return 0; | ||
} | ||
|
||
static int sdl_enable_callback(struct device *dev) | ||
{ | ||
struct sdl_data *data = dev->driver_data; | ||
|
||
LOG_DBG("%s: enable cb", dev->config->name); | ||
data->enabled = true; | ||
return 0; | ||
} | ||
|
||
static int sdl_disable_callback(struct device *dev) | ||
{ | ||
struct sdl_data *data = dev->driver_data; | ||
|
||
LOG_DBG("%s: disable cb", dev->config->name); | ||
data->enabled = false; | ||
return 0; | ||
} | ||
|
||
static int sdl_init(struct device *dev) | ||
{ | ||
LOG_INF("Init '%s' device", dev->config->name); | ||
SDL_AddEventWatch(sdl_filter, dev); | ||
|
||
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_AND_API_INIT(sdl, CONFIG_SDL_POINTER_KSCAN_DEV_NAME, sdl_init, | ||
&sdl_data, NULL, | ||
POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY, | ||
&sdl_driver_api); |