| 1 | /*
|
|---|
| 2 | * Copyright (c) 2010 Vojtech Horky
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libusb
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | * Common USB functions.
|
|---|
| 34 | */
|
|---|
| 35 | #include <usb/usb.h>
|
|---|
| 36 | #include <errno.h>
|
|---|
| 37 |
|
|---|
| 38 | #define ARR_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
|
|---|
| 39 |
|
|---|
| 40 | static const char *str_speed[] = {
|
|---|
| 41 | [USB_SPEED_LOW] = "low",
|
|---|
| 42 | [USB_SPEED_FULL] = "full",
|
|---|
| 43 | [USB_SPEED_HIGH] = "high",
|
|---|
| 44 | };
|
|---|
| 45 |
|
|---|
| 46 | static const char *str_transfer_type[] = {
|
|---|
| 47 | [USB_TRANSFER_CONTROL] = "control",
|
|---|
| 48 | [USB_TRANSFER_ISOCHRONOUS] = "isochronous",
|
|---|
| 49 | [USB_TRANSFER_BULK] = "bulk",
|
|---|
| 50 | [USB_TRANSFER_INTERRUPT] = "interrupt",
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 | static const char *str_transfer_type_short[] = {
|
|---|
| 54 | [USB_TRANSFER_CONTROL] = "ctrl",
|
|---|
| 55 | [USB_TRANSFER_ISOCHRONOUS] = "iso",
|
|---|
| 56 | [USB_TRANSFER_BULK] = "bulk",
|
|---|
| 57 | [USB_TRANSFER_INTERRUPT] = "intr",
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | static const char *str_direction[] = {
|
|---|
| 61 | [USB_DIRECTION_IN] = "in",
|
|---|
| 62 | [USB_DIRECTION_OUT] = "out",
|
|---|
| 63 | [USB_DIRECTION_BOTH] = "both",
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | /** String representation for USB transfer type.
|
|---|
| 67 | *
|
|---|
| 68 | * @param t Transfer type.
|
|---|
| 69 | * @return Transfer type as a string (in English).
|
|---|
| 70 | */
|
|---|
| 71 | const char *usb_str_transfer_type(usb_transfer_type_t t)
|
|---|
| 72 | {
|
|---|
| 73 | if (t >= ARR_SIZE(str_transfer_type)) {
|
|---|
| 74 | return "invalid";
|
|---|
| 75 | }
|
|---|
| 76 | return str_transfer_type[t];
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /** String representation for USB transfer type (short version).
|
|---|
| 80 | *
|
|---|
| 81 | * @param t Transfer type.
|
|---|
| 82 | * @return Transfer type as a short string for debugging messages.
|
|---|
| 83 | */
|
|---|
| 84 | const char *usb_str_transfer_type_short(usb_transfer_type_t t)
|
|---|
| 85 | {
|
|---|
| 86 | if (t >= ARR_SIZE(str_transfer_type_short)) {
|
|---|
| 87 | return "invl";
|
|---|
| 88 | }
|
|---|
| 89 | return str_transfer_type_short[t];
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | /** String representation of USB direction.
|
|---|
| 93 | *
|
|---|
| 94 | * @param d The direction.
|
|---|
| 95 | * @return Direction as a string (in English).
|
|---|
| 96 | */
|
|---|
| 97 | const char *usb_str_direction(usb_direction_t d)
|
|---|
| 98 | {
|
|---|
| 99 | if (d >= ARR_SIZE(str_direction)) {
|
|---|
| 100 | return "invalid";
|
|---|
| 101 | }
|
|---|
| 102 | return str_direction[d];
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | /** String representation of USB speed.
|
|---|
| 106 | *
|
|---|
| 107 | * @param s The speed.
|
|---|
| 108 | * @return USB speed as a string (in English).
|
|---|
| 109 | */
|
|---|
| 110 | const char *usb_str_speed(usb_speed_t s)
|
|---|
| 111 | {
|
|---|
| 112 | if (s >= ARR_SIZE(str_speed)) {
|
|---|
| 113 | return "invalid";
|
|---|
| 114 | }
|
|---|
| 115 | return str_speed[s];
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * @}
|
|---|
| 120 | */
|
|---|