input: Add a command to show mouse input

This reads mouse input and shows it on the terminal. It is useful for
testing mice.

Change-Id: Ifebe6452f38904689e3e2142fc08a623131ed0de
Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2020-02-13 13:44:11 -07:00
parent 6c848941e7
commit 9e1888ee68
3 changed files with 79 additions and 0 deletions

View File

@@ -2971,6 +2971,15 @@ config CMD_LOG
maximum log level for emitting of records). It also provides access
to a command used for testing the log system.
config CMD_MOUSE
bool "mouse - Show mouse input"
default y if MOUSE
help
This shows the data produced by a mouse. If a mouse device is
available records are printed when the mouse is moved. This can be
useful for checking that a mouse is working correctly within
U-Boot.
config CMD_TRACE
bool "trace - Support tracing of function calls and timing"
depends on TRACE

View File

@@ -129,6 +129,7 @@ obj-$(CONFIG_CMD_CLONE) += clone.o
ifneq ($(CONFIG_CMD_NAND)$(CONFIG_CMD_SF),)
obj-y += legacy-mtd-utils.o
endif
obj-$(CONFIG_CMD_MOUSE) += mouse.o
obj-$(CONFIG_CMD_MUX) += mux.o
obj-$(CONFIG_CMD_NAND) += nand.o
ifdef CONFIG_NET

69
cmd/mouse.c Normal file
View File

@@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Mouse testing
*
* Copyright 2020 Google LLC
* Written by Simon Glass <sjg@chromium.org>
*/
#include <command.h>
#include <console.h>
#include <dm.h>
#include <mouse.h>
#include <u-boot/schedule.h>
static int do_mouse_dump(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct udevice *dev;
bool running;
int count;
int ret;
ret = uclass_first_device_err(UCLASS_MOUSE, &dev);
if (ret) {
printf("Mouse not found (err=%d)\n", ret);
return CMD_RET_FAILURE;
}
for (running = true, count = 0; running;) {
struct mouse_event evt;
ret = mouse_get_event(dev, &evt);
if (!ret) {
switch (evt.type) {
case MOUSE_EV_BUTTON: {
struct mouse_button *but = &evt.button;
printf("button: button==%d, press=%d, clicks=%d, X=%d, Y=%d\n",
but->button, but->press_state,
but->clicks, but->x, but->y);
break;
}
case MOUSE_EV_MOTION: {
struct mouse_motion *motion = &evt.motion;
printf("motion: Xrel=%d, Yrel=%d, X=%d, Y=%d, but=%d\n",
motion->xrel, motion->yrel, motion->x,
motion->y, motion->state);
break;
}
case MOUSE_EV_NULL:
break;
}
count++;
} else if (ret != -EAGAIN) {
return log_msg_ret("get_event", ret);
}
schedule();
if (ctrlc())
running = false;
}
printf("%d events received\n", count);
return 0;
}
static char mouse_help_text[] =
"dump - Dump input from a mouse";
U_BOOT_CMD_WITH_SUBCMDS(mouse, "Mouse input", mouse_help_text,
U_BOOT_SUBCMD_MKENT(dump, 1, 1, do_mouse_dump));