[PATCH 9/9] libusbg: Add example how to use usbg_udc structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This example shows how to learn what udcs are available
in system and also how to find out what gadgets are
enabled on them.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 examples/Makefile.am |    3 ++-
 examples/show-udcs.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 1 deletion(-)
 create mode 100644 examples/show-udcs.c

diff --git a/examples/Makefile.am b/examples/Makefile.am
index a77d890..d7a3b48 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,9 +1,10 @@
-bin_PROGRAMS = show-gadgets gadget-acm-ecm gadget-vid-pid-remove gadget-ffs gadget-export gadget-import
+bin_PROGRAMS = show-gadgets gadget-acm-ecm gadget-vid-pid-remove gadget-ffs gadget-export gadget-import show-udcs
 gadget_acm_ecm_SOURCES = gadget-acm-ecm.c
 show_gadgets_SOURCES = show-gadgets.c
 gadget_vid_pid_remove_SOURCES = gadget-vid-pid-remove.c
 gadget_ffs_SOURCES = gadget-ffs.c
 gadget_export_SOURCE = gadget-export.c
 gadget_import_SOURCE = gadget-import.c
+show_udcs_SOURCE = show-udcs.c
 AM_CPPFLAGS=-I$(top_srcdir)/include/
 AM_LDFLAGS=-L../src/ -lusbg
diff --git a/examples/show-udcs.c b/examples/show-udcs.c
new file mode 100644
index 0000000..66e950f
--- /dev/null
+++ b/examples/show-udcs.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2014 Samsung Electronics
+ *
+ * Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/**
+ * @file show-udcs.c
+ * @example show-udcs.c
+ * This is an example of how to learn about UDCs available in system
+ * and find out what gadget are enabled on them.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <usbg/usbg.h>
+
+int main(void)
+{
+	int usbg_ret;
+	int ret = -EINVAL;
+	usbg_state *s;
+	usbg_gadget *g;
+	usbg_udc *u;
+	const char *udc_name, *gadget_name;
+
+	usbg_ret = usbg_init("/sys/kernel/config", &s);
+	if (usbg_ret != USBG_SUCCESS) {
+		fprintf(stderr, "Error on USB state init\n");
+		fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+				usbg_strerror(usbg_ret));
+		goto out;
+	}
+
+	usbg_for_each_udc(u, s) {
+		udc_name = usbg_get_udc_name(u);
+		g = usbg_get_udc_gadget(u);
+		if (g)
+			/* some gadget is enabled */
+			gadget_name = usbg_get_gadget_name(g);
+		else
+			gadget_name = "";
+
+		fprintf(stdout, "%s <-> %s\n", udc_name, gadget_name);
+	}
+
+	ret = 0;
+	usbg_cleanup(s);
+out:
+	return ret;
+}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux