From patchwork Mon Sep 15 10:46:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 306 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933263; bh=wnImVK8vmyAo5avOV6rn4L0+iCj3j8NlxKnXNtrG02g=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=ouOS8dt5genR8MUg34TaG9YbOY8pI1jpDYTNwviiSqx2g0eOBP7uN5VZ3NAo3ajt7 bSFXkRgob2jXV2R7RHPoATlnZMU25hIHi72uuPrT3fSiQV5oBK/s+gNbItttR/OIfB C0IRkamrU+Q16nOkROkzakSMGETIxzeyamQ+mS/K2GPP0fisuXep3g6kxBv+fh9Hf8 fLoVwdUL9B5nBhgltOYyUIwgG4KH5Xmh9W6vw0hNGjddE/AO2OJf6Q3p4JDBH/K1tt NWCc5qatCIXc38pQQeao/M0G24e7yNaZYR519jfaYFkl4ETH+6LvxBbLPtct75vu9N AP/mvYtQ6Mi2A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2AC3967BBC for ; Mon, 15 Sep 2025 04:47:43 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id TA1JeELSGZH2 for ; Mon, 15 Sep 2025 04:47:43 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933262; bh=wnImVK8vmyAo5avOV6rn4L0+iCj3j8NlxKnXNtrG02g=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Kbf7igiJteKdDLtbdKMDtLc1xupFSxzIn+ve5bOG5WR1M7Iv6CCARF/EjbK8WQvmg +vAGjkcBZwoKaA2t8Jw6GuAHfbOzJ1R8Oivw3vxKnZQSG4Yrkb8dnCMQ99wzlM8WWb /7pz2JpENt/5QPlgvsl7Udq0KszoeGOPPjARiy5ugMHbIXyO018tNEr578i6Ty5yhq krcIxboUhhY7ZMEeRs6FaCbxX8NkWdIBVZvL3BpDjP/MkJ6/gVFtaAhhkLZJCbzOPr hCnOyOaGBnXpO+f6F9Uspojpm+K2jQ/y9yqmpwpue5/FgE1D9+D0aeV0jsLZ8N/ykP 4hAfdyx617SVg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 17F4067B44 for ; Mon, 15 Sep 2025 04:47:42 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933259; bh=2/H0mYbwwyx7MCjnqjRGVLNlGnCswU9CtrZrVYy+0HE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ahl7lt01wrO8pB9VBXX7+wrW15Ff6QRpFr5nfnghjA8XfuVNFElGTyfe86C2UOitr A4+CIiEHeTAZ3GamoXkpORkpIMLy+BL6Cwlnhf7Q4+PSQagQimvKqL9jdXYEX4fyb6 yViGV9ZKfY++FAjtZrv6YToBKTFIenEiWKtPyzkQJBUe6pypdjPBriknNqVJCOrGXG +C0ShOTBLzlHKJrGa8XCD8SYTF0XWJnlUgCCGF0Cw4pyigjLsw6CeEyrtNtp5bfTV0 uJLUPgKKVGbePHr/giz/Z6ORcUvd08Pe3SHEBT/PQsZO52JHU48AkUG0Hjyt1jT0Kx CUq11GVxoB4YA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E512E67B3C; Mon, 15 Sep 2025 04:47:39 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id HCGAwPu57Q6j; Mon, 15 Sep 2025 04:47:39 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1757933258; bh=4m9PtwHSHLdCXo46f9HIA5z6gpiSkgLZdGFgFdFJAao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CQ0Zo5P+XJRSpRwGS7A2m/6CXp44VcRmaH+2SSvenupjaFcoRL22f2+cj6URrxUvh Rmklz46eLSsaAhwP7Q8iyggrV00HS9Mcbp923voEgyaP1Ppv3W5EqsSOzu6w9axvzu YXYR9wJjh6LhsMD9QdlhxSlrRvwV9mQCDKQ05ix0ZVS8B5DvWeWzFIUee5jB9ELHNB e27hSVRp999UwA+BVfLQY3UV2ILXBAgpv+OWINJqagRvsgQDGlutGM6BIyjjbXsk0c NdghURY9ShlhIMwx3/0Q3hOi5Y/WPk/a/qYZ97VY/lg1cod/8NfYhHrq8r/WGrxfDt MeBhLBlyQBGbg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 5E4B767A99; Mon, 15 Sep 2025 04:47:38 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Mon, 15 Sep 2025 04:46:48 -0600 Message-ID: <20250915044657.7.Ifebe6452f38904689e3e2142fc08a623131ed0de@changeid> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250915104705.937780-1-sjg@u-boot.org> References: <20250915104705.937780-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ZCBBKAHMORSZ5OMCCWVV4H75BC6UMVLI X-Message-ID-Hash: ZCBBKAHMORSZ5OMCCWVV4H75BC6UMVLI X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 07/17] input: Add a command to show mouse input List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass This reads mouse input and shows it on the terminal. It is useful for testing mice. Signed-off-by: Simon Glass --- cmd/Kconfig | 9 +++++++ cmd/Makefile | 1 + cmd/mouse.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 cmd/mouse.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 8037827930b..af79770b4c6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -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 diff --git a/cmd/Makefile b/cmd/Makefile index 75ef9fab922..1d65703b625 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/mouse.c b/cmd/mouse.c new file mode 100644 index 00000000000..60210b9f868 --- /dev/null +++ b/cmd/mouse.c @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Mouse testing + * + * Copyright 2020 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include + +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));