1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 08:42:12 +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
parent f5b78f1b17
commit 7547808ccd
3 changed files with 144 additions and 0 deletions

View File

@@ -1204,6 +1204,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_UNIVERSE
bool "universe - Command to set up the Turndra Universe controller"
help

View File

@@ -129,6 +129,7 @@ obj-$(CONFIG_CMD_STRINGS) += strings.o
obj-$(CONFIG_CMD_SMC) += smccc.o
obj-$(CONFIG_CMD_TERMINAL) += terminal.o
obj-$(CONFIG_CMD_TIME) += time.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

137
cmd/touch.c Normal file
View File

@@ -0,0 +1,137 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2018 BayLibre, SAS
* Author: Neil Armstrong <narmstrong@baylibre.com>
*/
#include <common.h>
#include <command.h>
#include <dm.h>
#include <touchpanel.h>
static int do_touch_list(cmd_tbl_t *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);
ret = uclass_next_device(&dev);
if (ret)
return CMD_RET_FAILURE;
} while (dev);
return CMD_RET_SUCCESS;
}
static int do_touch_info(cmd_tbl_t *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(cmd_tbl_t *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 cmd_tbl_t 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(cmd_tbl_t *cmdtp, int flag, int argc,
char *const argv[])
{
cmd_tbl_t *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;
}
static char touch_help_text[] =
"list - list touchpanel devices\n"
"touch info <name> - Get touchpanel device info\n"
"touch get <name> - Get touches";
U_BOOT_CMD(touch, 4, 1, do_touch, "Touchpanel sub-system", touch_help_text);