diff --git a/cmd/Kconfig b/cmd/Kconfig index 1d7ddb4ed36..1bb4f2cc2bb 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -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 diff --git a/cmd/Makefile b/cmd/Makefile index d1f369deec0..5fc6419e62f 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/touch.c b/cmd/touch.c new file mode 100644 index 00000000000..89c4b2f160b --- /dev/null +++ b/cmd/touch.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 BayLibre, SAS + * Author: Neil Armstrong + */ +#include +#include +#include + +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 - Get touchpanel device info\n" + "touch get - Get touches" +);