input: Add mouse support

When running a simple GUI it is useful to support a mouse. This is
similar to what is provided in UEFI's boot menu. Add a simple uclass and
a way to read the mouse position.

For sandbox add a driver that reads the position from SDL. Disable input
for the tools-only build, since it is of no use there and causes build
failures.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2020-02-08 09:08:38 -07:00
parent ad59fee0e8
commit 74cf6bee6c
7 changed files with 129 additions and 1 deletions

View File

@@ -1251,6 +1251,13 @@ S: Maintained
T: git https://source.denx.de/u-boot/custodians/u-boot-i2c.git
F: drivers/i2c/
INPUT
M: Simon Glass <sjg@chromium.org>
S: Maintained
T: git https://concept.u-boot.org/u-boot/u-boot.git
F: drivers/input
F: include/mouse.h
KWBIMAGE / KWBOOT TOOLS
M: Pali Rohár <pali@kernel.org>
M: Marek Behún <kabel@kernel.org>

View File

@@ -5,7 +5,6 @@ CONFIG_DEFAULT_DEVICE_TREE="sandbox"
CONFIG_SYS_LOAD_ADDR=0x0
CONFIG_PCI=y
# CONFIG_SANDBOX_SDL is not set
# CONFIG_ULIB is not set
# CONFIG_EFI_LOADER is not set
CONFIG_ANDROID_BOOT_IMAGE=y
CONFIG_TIMESTAMP=y
@@ -30,6 +29,7 @@ CONFIG_NO_NET=y
CONFIG_AXI=y
CONFIG_AXI_SANDBOX=y
CONFIG_SANDBOX_GPIO=y
# CONFIG_INPUT is not set
CONFIG_PCI_SANDBOX=y
CONFIG_DM_RTC=y
CONFIG_SOUND=y

View File

@@ -100,3 +100,12 @@ config TWL4030_INPUT
bool "Enable TWL4030 Input controller"
help
Enable TWL4030 Input controller
config MOUSE
bool "Support for mice and other pointing devices"
default y if SANDBOX
help
This allows U-Boot to access mouse input, typically needed for
graphics boot menus and the like. The driver can provide mouse
events based on user interaction and these can be used to control
U-Boot's operation.

View File

@@ -15,3 +15,5 @@ obj-$(CONFIG_I8042_KEYB) += i8042.o
obj-$(CONFIG_TEGRA_KEYBOARD) += input.o tegra-kbc.o
obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
endif
obj-$(CONFIG_MOUSE) += mouse-uclass.o

View File

@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2019 Google LLC
* Written by Simon Glass <sjg@chromium.org>
*/
#include <dm.h>
#include <errno.h>
#include <mouse.h>
int mouse_get_event(struct udevice *dev, struct mouse_event *evt)
{
struct mouse_ops *ops = mouse_get_ops(dev);
int ret;
if (!ops->get_event)
return -ENOSYS;
ret = ops->get_event(dev, evt);
if (ret)
return ret;
return 0;
}
UCLASS_DRIVER(mouse) = {
.id = UCLASS_MOUSE,
.name = "mouse",
};

View File

@@ -97,6 +97,7 @@ enum uclass_id {
UCLASS_MISC, /* Miscellaneous device */
UCLASS_MMC, /* SD / MMC card or chip */
UCLASS_MOD_EXP, /* RSA Mod Exp device */
UCLASS_MOUSE, /* Mouse, trackpad or other pointing device */
UCLASS_MTD, /* Memory Technology Device (MTD) device */
UCLASS_MUX, /* Multiplexer device */
UCLASS_NOP, /* No-op devices */

80
include/mouse.h Normal file
View File

@@ -0,0 +1,80 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Mouse/trackpad/touchscreen input uclass
*
* Copyright 2020 Google LLC
*/
#ifndef _MOUSE_H
#define _MOUSE_H
struct udevice;
enum mouse_ev_t {
MOUSE_EV_NULL,
MOUSE_EV_MOTION,
MOUSE_EV_BUTTON,
};
enum mouse_state_t {
BUTTON_LEFT = 1 << 0,
BUTTON_MIDDLE = 1 << 1,
BUTTON_RIGHT = 1 << 2,
BUTTON_SCROLL_PLUS = 1 << 3,
BUTTON_SCROLL_MINUS = 1 << 4,
};
enum mouse_press_state_t {
BUTTON_RELEASED = 0,
BUTTON_PRESSED,
};
/**
* struct mouse_event - information about a mouse event
*
* @type: Mouse event ype
*/
struct mouse_event {
enum mouse_ev_t type;
union {
/**
* @state: Mouse state (enum mouse_state_t bitmask)
* @x: X position of mouse
* @y: Y position of mouse
* @xrel: Relative motion in X direction
* @yrel: Relative motion in Y direction
*/
struct mouse_motion {
unsigned char state;
unsigned short x;
unsigned short y;
short xrel;
short yrel;
} motion;
/**
* @button: Button number that was pressed/released (BUTTON_...)
* @state: BUTTON_PRESSED / BUTTON_RELEASED
* @clicks: number of clicks (normally 1; 2 = double-click)
* @x: X position of mouse
* @y: Y position of mouse
*/
struct mouse_button {
unsigned char button;
unsigned char press_state;
unsigned char clicks;
unsigned short x;
unsigned short y;
} button;
};
};
struct mouse_ops {
int (*get_event)(struct udevice *dev, struct mouse_event *event);
};
#define mouse_get_ops(dev) ((struct mouse_ops *)(dev)->driver->ops)
int mouse_get_event(struct udevice *dev, struct mouse_event *event);
#endif