Loading...
Searching...
No Matches
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.

/*
* Copyright (C) 2014 Samsung Electronics
*
* Krzysztof Opasiak <k.opasiak@samsung.com>
*
* 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.
*/
#include <errno.h>
#include <stdio.h>
#include <sys/sysmacros.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;
}
usbg_strerror
const char * usbg_strerror(usbg_error e)
Get the short description of error.
Definition usbg_error.c:123
usbg_get_udc_name
const char * usbg_get_udc_name(usbg_udc *u)
Get name of udc.
Definition usbg.c:1598
usbg_for_each_udc
#define usbg_for_each_udc(u, s)
Definition usbg.h:1127
usbg_init
int usbg_init(const char *configfs_path, usbg_state **state)
Initialize the libusbgx library state.
Definition usbg.c:1091
usbg_get_gadget_name
const char * usbg_get_gadget_name(usbg_gadget *g)
Get gadget name.
Definition usbg.c:1585
usbg_cleanup
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1136
usbg_get_udc_gadget
usbg_gadget * usbg_get_udc_gadget(usbg_udc *u)
Get gadget which is attached to this UDC.
Definition usbg.c:1678
usbg_error_name
const char * usbg_error_name(usbg_error e)
Get the error name as a constant string.
Definition usbg_error.c:62
usbg_gadget
Definition usbg_internal.h:103
usbg_state
Definition usbg_internal.h:93
usbg_udc
Definition usbg_internal.h:153
usbg.h