1 /* ----------------------------------------------------------------------------
2 * "THE BEER-WARE LICENSE" (Revision 42) (by Poul-Henning Kamp):
3 * <joerg@FreeBSD.ORG> wrote this file. As long as you retain this notice you
4 * can do whatever you want with this stuff. If we meet some day, and you think
5 * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch
6 * ----------------------------------------------------------------------------
12 * Helper functions common to all examples
20 #include <libusb20_desc.h>
25 * Return a textual description for error "r".
28 usb_error(enum libusb20_error r)
30 const char *msg = "UNKNOWN";
34 case LIBUSB20_SUCCESS:
38 case LIBUSB20_ERROR_IO:
42 case LIBUSB20_ERROR_INVALID_PARAM:
43 msg = "Invalid parameter";
46 case LIBUSB20_ERROR_ACCESS:
47 msg = "Access denied";
50 case LIBUSB20_ERROR_NO_DEVICE:
51 msg = "No such device";
54 case LIBUSB20_ERROR_NOT_FOUND:
55 msg = "Entity not found";
58 case LIBUSB20_ERROR_BUSY:
59 msg = "Resource busy";
62 case LIBUSB20_ERROR_TIMEOUT:
63 msg = "Operation timed out";
66 case LIBUSB20_ERROR_OVERFLOW:
70 case LIBUSB20_ERROR_PIPE:
74 case LIBUSB20_ERROR_INTERRUPTED:
75 msg = "System call interrupted";
78 case LIBUSB20_ERROR_NO_MEM:
79 msg = "Insufficient memory";
82 case LIBUSB20_ERROR_NOT_SUPPORTED:
83 msg = "Operation not supported";
86 case LIBUSB20_ERROR_OTHER:
95 * Print "len" bytes from "buf" in hex, followed by an ASCII
96 * representation (somewhat resembling the output of hd(1)).
99 print_formatted(uint8_t *buf, uint32_t len)
103 for (j = 0; j < len; j += 16)
107 for (i = 0; i < 16 && i + j < len; i++)
108 printf("%02x ", buf[i + j]);
110 for (i = 0; i < 16 && i + j < len; i++)
112 uint8_t c = buf[i + j];
113 if(c >= ' ' && c <= '~')
114 printf("%c", (char)c);