libusbgx-0.3.0
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;
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;
}
udc_name = usbg_get_udc_name(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;
out:
return ret;
}
const char * usbg_strerror(usbg_error e)
Get the short description of error.
Definition usbg_error.c:123
const char * usbg_get_udc_name(usbg_udc *u)
Get name of udc.
Definition usbg.c:1598
#define usbg_for_each_udc(u, s)
Definition usbg.h:1127
int usbg_init(const char *configfs_path, usbg_state **state)
Initialize the libusbgx library state.
Definition usbg.c:1091
const char * usbg_get_gadget_name(usbg_gadget *g)
Get gadget name.
Definition usbg.c:1585
void usbg_cleanup(usbg_state *s)
Clean up the libusbgx library state.
Definition usbg.c:1136
usbg_gadget * usbg_get_udc_gadget(usbg_udc *u)
Get gadget which is attached to this UDC.
Definition usbg.c:1678
const char * usbg_error_name(usbg_error e)
Get the error name as a constant string.
Definition usbg_error.c:62
Definition usbg_internal.h:103
Definition usbg_internal.h:93
Definition usbg_internal.h:153