1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 16:52:14 +02:00

cmd: Add 'touch' command to enumerate touchpanel devices

This command can be used to list and access devices with uclass
UCLASS_TOUCHPANEL.

Signed-off-by: Ondrej Jirman <megous@megous.com>
This commit is contained in:
Ondrej Jirman
2018-07-09 07:21:03 +02:00
committed by Ondrej Jirman
parent 517b25ddf5
commit 15b23000bb
3 changed files with 142 additions and 0 deletions

View File

@@ -1650,6 +1650,12 @@ config CMD_TSI148
This provides various sub-commands to initialise and configure the
Turndra tsi148 device. See the command help for full details.
config CMD_TOUCH
bool "touch - Read input from touchpanel"
select DM_TOUCHPANEL
help
Shows list of touches on the touch panel device.
config CMD_UFS
bool "ufs - Universal Flash Storage commands"
depends on UFS

View File

@@ -181,6 +181,7 @@ obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
obj-$(CONFIG_CMD_TIME) += time.o
obj-$(CONFIG_CMD_TIMER) += timer.o
obj-$(CONFIG_CMD_TOUCH) += touch.o
obj-$(CONFIG_CMD_TRACE) += trace.o
obj-$(CONFIG_HUSH_PARSER) += test.o
obj-$(CONFIG_CMD_TPM) += tpm-common.o

135
cmd/touch.c Normal file
View File

@@ -0,0 +1,135 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2018 BayLibre, SAS
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#include <command.h>
#include <dm.h>
#include <touchpanel.h>
static int do_touch_list(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct udevice *dev;
int ret;
ret = uclass_first_device_err(UCLASS_TOUCHPANEL, &dev);
if (ret) {
printf("No available touchpanel device\n");
return CMD_RET_FAILURE;
}
do {
printf("- %s\n", dev->name);
uclass_next_device(&dev);
} while (dev);
return CMD_RET_SUCCESS;
}
static int do_touch_info(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct touchpanel_priv *uc_priv;
struct udevice *dev;
int ret;
if (argc < 2)
return CMD_RET_USAGE;
ret = uclass_get_device_by_name(UCLASS_TOUCHPANEL, argv[1], &dev);
if (ret) {
printf("Unknown touchpanel device %s\n", argv[1]);
return CMD_RET_FAILURE;
}
uc_priv = dev_get_uclass_priv(dev);
printf("Touchpanel Device '%s' :\n", argv[1]);
printf("size_x: %d\n", uc_priv->size_x);
printf("size_y: %d\n", uc_priv->size_y);
return CMD_RET_SUCCESS;
}
static int do_touch_get(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
//struct touchpanel_priv *uc_priv;
struct touchpanel_touch touches[10];
struct udevice *dev;
int ret, i;
if (argc < 2)
return CMD_RET_USAGE;
ret = uclass_get_device_by_name(UCLASS_TOUCHPANEL, argv[1], &dev);
if (ret) {
printf("Unknown touchpanel device %s\n", argv[1]);
return CMD_RET_FAILURE;
}
//uc_priv = dev_get_uclass_priv(dev);
printf("Touchpanel Device '%s' :\n", argv[1]);
ret = touchpanel_start(dev);
if (ret < 0) {
printf("Failed to start %s, err=%d\n", argv[1], ret);
return CMD_RET_FAILURE;
}
ret = touchpanel_get_touches(dev, touches, ARRAY_SIZE(touches));
if (ret < 0) {
printf("Failed to get touches from %s, err=%d\n", argv[1], ret);
return CMD_RET_FAILURE;
}
for (i = 0; i < ret; i++) {
printf("touch: id=%d x=%d y=%d\n", touches[i].id, touches[i].x,
touches[i].y);
}
ret = touchpanel_stop(dev);
if (ret < 0) {
printf("Failed to stop %s, err=%d\n", argv[1], ret);
return CMD_RET_FAILURE;
}
return CMD_RET_SUCCESS;
}
static struct cmd_tbl cmd_touch_sub[] = {
U_BOOT_CMD_MKENT(list, 1, 1, do_touch_list, "", ""),
U_BOOT_CMD_MKENT(info, 2, 1, do_touch_info, "", ""),
U_BOOT_CMD_MKENT(get, 2, 1, do_touch_get, "", ""),
};
static int do_touch(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct cmd_tbl *c;
if (argc < 2)
return CMD_RET_USAGE;
/* Strip off leading 'touch' command argument */
argc--;
argv++;
c = find_cmd_tbl(argv[0], &cmd_touch_sub[0], ARRAY_SIZE(cmd_touch_sub));
if (c)
return c->cmd(cmdtp, flag, argc, argv);
else
return CMD_RET_USAGE;
}
U_BOOT_CMD(
touch, 4, 1, do_touch,
"Touchpanel subsystem",
"list - list touchpanel devices\n"
"touch info <name> - Get touchpanel device info\n"
"touch get <name> - Get touches"
);