tools: ffs-aio-example: use endpoint addresses from descriptors
authorRobert Baldyga <r.baldyga@samsung.com>
Tue, 13 Jan 2015 13:56:28 +0000 (14:56 +0100)
committerFelipe Balbi <balbi@ti.com>
Thu, 15 Jan 2015 15:41:49 +0000 (09:41 -0600)
This makes examples more platform independent and more compatible with
USB standard, as endpoint addresses in given interface may differ
between hardware platforms or even between configurations in single
USB device.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
tools/usb/ffs-aio-example/multibuff/host_app/test.c
tools/usb/ffs-aio-example/simple/host_app/test.c

index daa3abe6bebdd22b1828a36bba8cd0c70467ca2e..2cbcce6e8dd70a2f2baa62297e492d67f57bf9a9 100644 (file)
 #define VENDOR 0x1d6b
 #define PRODUCT        0x0105
 
-/* endpoints indexes */
-
-#define EP_BULK_IN     (1 | LIBUSB_ENDPOINT_IN)
-#define EP_BULK_OUT    (2 | LIBUSB_ENDPOINT_OUT)
-
 #define BUF_LEN                8192
 
 /*
@@ -159,14 +154,21 @@ void test_exit(struct test_state *state)
 int main(void)
 {
        struct test_state state;
+       struct libusb_config_descriptor *conf;
+       struct libusb_interface_descriptor const *iface;
+       unsigned char addr;
 
        if (test_init(&state))
                return 1;
 
+       libusb_get_config_descriptor(state.found, 0, &conf);
+       iface = &conf->interface[0].altsetting[0];
+       addr = iface->endpoint[0].bEndpointAddress;
+
        while (1) {
                static unsigned char buffer[BUF_LEN];
                int bytes;
-               libusb_bulk_transfer(state.handle, EP_BULK_IN, buffer, BUF_LEN,
+               libusb_bulk_transfer(state.handle, addr, buffer, BUF_LEN,
                                     &bytes, 500);
        }
        test_exit(&state);
index acd6332811f3237d80561e2667d9c1f33b0f0c5d..aed86ffff28022abff0f44ebd36386aa8482d760 100644 (file)
 #define VENDOR 0x1d6b
 #define PRODUCT        0x0105
 
-/* endpoints indexes */
-
-#define EP_BULK_IN     (1 | LIBUSB_ENDPOINT_IN)
-#define EP_BULK_OUT    (2 | LIBUSB_ENDPOINT_OUT)
-
 #define BUF_LEN                8192
 
 /*
@@ -159,16 +154,24 @@ void test_exit(struct test_state *state)
 int main(void)
 {
        struct test_state state;
+       struct libusb_config_descriptor *conf;
+       struct libusb_interface_descriptor const *iface;
+       unsigned char in_addr, out_addr;
 
        if (test_init(&state))
                return 1;
 
+       libusb_get_config_descriptor(state.found, 0, &conf);
+       iface = &conf->interface[0].altsetting[0];
+       in_addr = iface->endpoint[0].bEndpointAddress;
+       out_addr = iface->endpoint[1].bEndpointAddress;
+
        while (1) {
                static unsigned char buffer[BUF_LEN];
                int bytes;
-               libusb_bulk_transfer(state.handle, EP_BULK_IN, buffer, BUF_LEN,
+               libusb_bulk_transfer(state.handle, in_addr, buffer, BUF_LEN,
                                     &bytes, 500);
-               libusb_bulk_transfer(state.handle, EP_BULK_OUT, buffer, BUF_LEN,
+               libusb_bulk_transfer(state.handle, out_addr, buffer, BUF_LEN,
                                     &bytes, 500);
        }
        test_exit(&state);