uac_hid: add uac hid volume report [3/3]
PD#SWPL-166429
Problem:
The SDK does not have a unified method to report the device's
volume mute and play/stop state to the host.
Solution:
Add uac_hid command to report device volume state to host.
Verify:
A113X2 AV400 Board.
Change-Id: I64c38d73436567901db8e9b40975791db242e4be
Signed-off-by: shuai.liu <shuai.liu@amlogic.com>
diff --git a/utils/Makefile b/utils/Makefile
index a0ce3d8..cc6e255 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -9,6 +9,9 @@
ifeq ($(USE_BATTERY_MONITOR),y)
UTILS += battery_monitor
endif
+ifeq ($(USE_UAC_HID),y)
+UTILS += uac_hid
+endif
.PHONY: all install clean
#CFLAGS += $(AML_UTIL_PRIV_FLAGS)
@@ -54,6 +57,9 @@
battery_monitor: battery_monitor.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $(OUT_DIR)/$@ $^ $(LDLIBS)
+uac_hid: uac_hid.c
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
fota_upgrade: fota_upgrade.c ../aml_utility/unifykey.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $(OUT_DIR)/$@ $^ $(LDLIBS) -L../fota -ldmgr -lamldeviceproperty -lm -ldl -lpthread
diff --git a/utils/uac_hid.c b/utils/uac_hid.c
new file mode 100644
index 0000000..43f448e
--- /dev/null
+++ b/utils/uac_hid.c
@@ -0,0 +1,132 @@
+// Copyright (C) 2024 Amlogic, Inc. All rights reserved.
+//
+// All information contained herein is Amlogic confidential.
+//
+// This software is provided to you pursuant to Software License
+// Agreement (SLA) with Amlogic Inc ("Amlogic"). This software may be
+// used only in accordance with the terms of this agreement.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification is strictly prohibited without prior written permission
+// from Amlogic.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <string.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "porting.h"
+
+struct options {
+ const char *opt;
+ unsigned char val;
+};
+
+/*
+ * Options val is determined by the report descriptor, refer
+ * to jira SWPL-166429. If the report descriptor changes,
+ * the corresponding val needs to be modified accordingly.
+ * */
+static struct options volume_code[] = {
+ {.opt = "--VolumeUp", .val = 0x01},
+ {.opt = "--VolumeDown", .val = 0x02},
+ {.opt = "--Mute", .val = 0x04},
+ {.opt = "--Play", .val = 0x08},
+ {.opt = NULL}
+};
+
+
+int uac_volume_command_parse(char* report, const char* buf)
+{
+ char *tok = strtok(buf, " ");
+ int key = 0;
+ int i = 0;
+
+ for (; tok != NULL; tok = strtok(NULL, " ")) {
+ for (i = 0; volume_code[i].opt != NULL; i++) {
+ if (strcmp(tok, volume_code[i].opt) == 0) {
+ *report = volume_code[i].val;
+ break;
+ }
+ }
+ if (volume_code[i].opt != NULL)
+ continue;
+
+ if (!(tok[0] == '-' && tok[1] == '-')) {
+ SLOGE("Bad options:'%s'\n", tok);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+void help(void)
+{
+ int i = 0;
+
+ SLOGE("Usage:\n");
+ SLOGE("\t\t uac_hid dev/hidgx --option:\n");
+ SLOGE("Options:\n");
+ for (i = 0; volume_code[i].opt != NULL; i++) {
+ SLOGE("\t\t%s\n", volume_code[i].opt);
+ }
+}
+
+int main(int argc, const char *argv[])
+{
+ const char *filename = NULL;
+ int fd = 0;
+ char report = 0;
+ int ret = 0;
+
+ if (argc < 2 || (strcmp(argv[1], "--help")) == 0) {
+ help();
+ return -1;
+ }
+
+ filename = argv[1];
+ if ((fd = open(filename, O_RDWR, 0666)) == -1) {
+ perror(filename);
+ return -1;
+ }
+
+ ret = uac_volume_command_parse(&report, argv[2]);
+ if (ret != 0 || 0 == report) {
+ perror(filename);
+ goto end;
+ }
+
+ ret = write(fd, &report, 1);
+ if (ret != 1) {
+ perror(filename);
+ }
+
+ /* stop volume up or volume down*/
+ report = 0;
+ ret = write(fd, &report, 1);
+ if (ret != 1) {
+ perror(filename);
+ goto end;
+ }
+end:
+ close(fd);
+
+ return ret;
+}
+