Liam Staskawicz avatar Liam Staskawicz committed 5117b64

enumerator example: be more flexible in the event of failures, and try to probe more parts of the device

Comments (0)

Files changed (1)

example/enumerator/main.c

 
 void dumpDeviceInfo(UsbusDevice *d, struct UsbusDeviceDescriptor *desc)
 {
-    int r = usbusClaimInterface(d, 0);
-    if (r != UsbusOK) {
-        return;
-    }
-
     /*
      * Dump string descriptors
      */
         printf("mfgr: %s\n", str);
     }
 
+    int r;
+
     // iterate each device configuration
     unsigned c;
     for (c = 0; c < desc->bNumConfigurations; ++c) {
         unsigned i;
         for (i = 0; i < cfgDesc.bNumInterfaces; ++i) {
 
+            if (usbusClaimInterface(d, i) != UsbusOK) {
+                continue;
+            }
+
             struct UsbusInterfaceDescriptor intfDesc;
-            r = usbusGetInterfaceDescriptor(d, i, 0, &intfDesc);
-            if (r != UsbusOK) {
-                printf("intf descriptor: fail\n");
-                return;
+            // XXX: only ever checking the first alt setting
+            if (usbusGetInterfaceDescriptor(d, i, 0, &intfDesc) != UsbusOK) {
+                continue;
             }
 
             printf("intf descriptor %d: bNumEndpoints %d\n", i, intfDesc.bNumEndpoints);
             for (e = 0; e < intfDesc.bNumEndpoints; ++e) {
 
                 struct UsbusEndpointDescriptor epDesc;
-                r = usbusGetEndpointDescriptor(d, intfDesc.iInterface, e, &epDesc);
-                if (r != UsbusOK) {
-                    printf("ep descriptor %d: fail\n", e);
-                    return;
+                if (usbusGetEndpointDescriptor(d, i, e, &epDesc) != UsbusOK) {
+                    continue;
                 }
 
                 printf("ep descriptor %d: bEndpointAddress 0x%02x, bInterval %d, wMaxPacketSize %d\n",
                        e, epDesc.bEndpointAddress, epDesc.bInterval, epDesc.wMaxPacketSize);
             }
+
+            usbusReleaseInterface(d, i);
         }
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.