diff options
author | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-12-23 00:04:29 +0100 |
---|---|---|
committer | Krzysztof Opasiak <k.opasiak@samsung.com> | 2015-12-23 00:49:03 +0100 |
commit | 54eff8a3449fb6c5df6b580aa2f68557d3181f42 (patch) | |
tree | 5ecf94314fd4fadeb0d6f85bd606901b0c794653 | |
parent | 5637edd5589fd3f992227f7951264f80c3e14efc (diff) | |
download | libusbg-54eff8a3449fb6c5df6b580aa2f68557d3181f42.tar.gz libusbg-54eff8a3449fb6c5df6b580aa2f68557d3181f42.tar.bz2 libusbg-54eff8a3449fb6c5df6b580aa2f68557d3181f42.zip |
libusbgx: examples: Port all examples to new API
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
-rw-r--r-- | examples/gadget-ffs.c | 11 | ||||
-rw-r--r-- | examples/gadget-midi.c | 18 | ||||
-rw-r--r-- | examples/gadget-ms.c | 20 | ||||
-rw-r--r-- | examples/show-gadgets.c | 51 |
4 files changed, 54 insertions, 46 deletions
diff --git a/examples/gadget-ffs.c b/examples/gadget-ffs.c index 6274c15..b95f13b 100644 --- a/examples/gadget-ffs.c +++ b/examples/gadget-ffs.c @@ -63,12 +63,6 @@ int main(void) .configuration = "2xFFS" }; - usbg_function_attrs f_attrs = { - .attrs.ffs = { - .dev_name = "my_awesome_dev_name", - }, - }; - usbg_ret = usbg_init("/sys/kernel/config", &s); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error on USB gadget init\n"); @@ -93,9 +87,8 @@ int main(void) goto out2; } - /* When NULL is passed as instance name, dev_name take from f_attrs - is used as instance name for this function */ - usbg_ret = usbg_create_function(g, F_FFS, NULL, &f_attrs, &f_ffs2); + usbg_ret = usbg_create_function(g, F_FFS, "my_other_dev_name", + NULL, &f_ffs2); if (usbg_ret != USBG_SUCCESS) { fprintf(stderr, "Error creating ffs2 function\n"); fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret), diff --git a/examples/gadget-midi.c b/examples/gadget-midi.c index f795de1..61556cc 100644 --- a/examples/gadget-midi.c +++ b/examples/gadget-midi.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <linux/usb/ch9.h> #include <usbg/usbg.h> +#include <usbg/function/midi.h> #define VENDOR 0x1d6b #define PRODUCT 0x0104 @@ -51,16 +52,13 @@ int main() { .configuration = "1xMIDI" }; - usbg_function_attrs f_attrs = { - .header.attrs_type = USBG_F_ATTRS_MIDI, - .attrs.midi = { - .index = 0, - .id = "usb0", - .buflen = 128, - .qlen = 16, - .in_ports = 2, - .out_ports = 3, - }, + struct usbg_f_midi_attrs f_attrs = { + .index = 0, + .id = "usb0", + .buflen = 128, + .qlen = 16, + .in_ports = 2, + .out_ports = 3, }; usbg_ret = usbg_init("/sys/kernel/config", &s); diff --git a/examples/gadget-ms.c b/examples/gadget-ms.c index d6c4aaf..017a6d1 100644 --- a/examples/gadget-ms.c +++ b/examples/gadget-ms.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <linux/usb/ch9.h> #include <usbg/usbg.h> +#include <usbg/function/ms.h> #define VENDOR 0x1d6b #define PRODUCT 0x0104 @@ -55,25 +56,25 @@ int main(int argc, char **argv) .str_prd = "Bar Gadget" /* Product string */ }; - usbg_f_ms_lun_attrs f_ms_luns_array[] = { + struct usbg_f_ms_lun_attrs f_ms_luns_array[] = { { .id = -1, /* allows to place in any position */ .cdrom = 1, .ro = 0, .nofua = 0, .removable = 1, - .filename = "", + .file = "", }, { .id = -1, /* allows to place in any position */ .cdrom = 0, .ro = 0, .nofua = 0, .removable = 1, - .filename = argv[1], + .file = argv[1], } }; - usbg_f_ms_lun_attrs *f_ms_luns[] = { + struct usbg_f_ms_lun_attrs *f_ms_luns[] = { /* * When id in lun structure is below 0 we can place it in any * arbitrary position @@ -83,13 +84,10 @@ int main(int argc, char **argv) NULL, }; - usbg_function_attrs f_attrs = { - .header.attrs_type = USBG_F_ATTRS_MS, - .attrs.ms = { - .stall = 0, - .nluns = 2, - .luns = f_ms_luns, - }, + struct usbg_f_ms_attrs f_attrs = { + .stall = 0, + .nluns = 2, + .luns = f_ms_luns, }; usbg_config_strs c_strs = { diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c index d27cde5..7f8aefd 100644 --- a/examples/show-gadgets.c +++ b/examples/show-gadgets.c @@ -19,6 +19,12 @@ #include <string.h> #include <netinet/ether.h> #include <usbg/usbg.h> +#include <usbg/function/ms.h> +#include <usbg/function/net.h> +#include <usbg/function/ffs.h> +#include <usbg/function/phonet.h> +#include <usbg/function/midi.h> + /** * @file show-gadgets.c @@ -91,7 +97,14 @@ void show_function(usbg_function *f) const char *instance; usbg_function_type type; int usbg_ret; - usbg_function_attrs f_attrs; + union { + struct usbg_f_net_attrs net; + char *ffs_dev_name; + struct usbg_f_ms_attrs ms; + struct usbg_f_midi_attrs midi; + int serial_port_num; + char *phonet_ifname; + } f_attrs; instance = usbg_get_function_instance(f); if (!instance) { @@ -110,15 +123,21 @@ void show_function(usbg_function *f) fprintf(stdout, " Function, type: %s instance: %s\n", usbg_get_function_type_str(type), instance); - switch (f_attrs.header.attrs_type) { - case USBG_F_ATTRS_SERIAL: + switch (type) { + case F_ACM: + case F_OBEX: + case F_SERIAL: fprintf(stdout, " port_num\t\t%d\n", - f_attrs.attrs.serial.port_num); + f_attrs.serial_port_num); break; - case USBG_F_ATTRS_NET: + case F_ECM: + case F_SUBSET: + case F_NCM: + case F_EEM: + case F_RNDIS: { - usbg_f_net_attrs *f_net_attrs = &f_attrs.attrs.net; + struct usbg_f_net_attrs *f_net_attrs = &f_attrs.net; fprintf(stdout, " dev_addr\t\t%s\n", ether_ntoa(&f_net_attrs->dev_addr)); @@ -129,17 +148,17 @@ void show_function(usbg_function *f) break; } - case USBG_F_ATTRS_PHONET: - fprintf(stdout, " ifname\t\t%s\n", f_attrs.attrs.phonet.ifname); + case F_PHONET: + fprintf(stdout, " ifname\t\t%s\n", f_attrs.phonet_ifname); break; - case USBG_F_ATTRS_FFS: - fprintf(stdout, " dev_name\t\t%s\n", f_attrs.attrs.ffs.dev_name); + case F_FFS: + fprintf(stdout, " dev_name\t\t%s\n", f_attrs.ffs_dev_name); break; - case USBG_F_ATTRS_MS: + case F_MASS_STORAGE: { - usbg_f_ms_attrs *attrs = &f_attrs.attrs.ms; + struct usbg_f_ms_attrs *attrs = &f_attrs.ms; int i; fprintf(stdout, " stall\t\t%d\n", attrs->stall); @@ -150,14 +169,14 @@ void show_function(usbg_function *f) fprintf(stdout, " ro\t\t%d\n", attrs->luns[i]->ro); fprintf(stdout, " nofua\t\t%d\n", attrs->luns[i]->nofua); fprintf(stdout, " removable\t\t%d\n", attrs->luns[i]->removable); - fprintf(stdout, " file\t\t%s\n", attrs->luns[i]->filename); + fprintf(stdout, " file\t\t%s\n", attrs->luns[i]->file); } break; } - case USBG_F_ATTRS_MIDI: + case F_MIDI: { - usbg_f_midi_attrs *attrs = &f_attrs.attrs.midi; + struct usbg_f_midi_attrs *attrs = &f_attrs.midi; fprintf(stdout, " index\t\t%d\n", attrs->index); fprintf(stdout, " id\t\t\t%s\n", attrs->id); @@ -172,7 +191,7 @@ void show_function(usbg_function *f) fprintf(stdout, " UNKNOWN\n"); } - usbg_cleanup_function_attrs(&f_attrs); + usbg_cleanup_function_attrs(f, &f_attrs); } void show_config(usbg_config *c) |