source: mainline/uspace/lib/usb/src/usb.c@ 85c47729

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 85c47729 was a90fc0c, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Refactoring of "enum to string" functions

  • Property mode set to 100644
File size: 2.7 KB
Line 
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
40static const char *str_speed[] = {
41 "low",
42 "full",
43 "high"
44};
45
46static const char *str_transfer_type[] = {
47 "control",
48 "isochronous",
49 "bulk",
50 "interrupt"
51};
52
53static const char *str_transfer_type_short[] = {
54 "ctrl",
55 "iso",
56 "bulk",
57 "intr"
58};
59
60/** String representation for USB transfer type.
61 *
62 * @param t Transfer type.
63 * @return Transfer type as a string (in English).
64 */
65const char *usb_str_transfer_type(usb_transfer_type_t t)
66{
67 if (t >= ARR_SIZE(str_transfer_type)) {
68 return "invalid";
69 }
70 return str_transfer_type[t];
71}
72
73/** String representation for USB transfer type (short version).
74 *
75 * @param t Transfer type.
76 * @return Transfer type as a short string for debugging messages.
77 */
78const char *usb_str_transfer_type_short(usb_transfer_type_t t)
79{
80 if (t >= ARR_SIZE(str_transfer_type_short)) {
81 return "invl";
82 }
83 return str_transfer_type_short[t];
84}
85
86/** String representation of USB speed.
87 *
88 * @param s The speed.
89 * @return USB speed as a string (in English).
90 */
91const char *usb_str_speed(usb_speed_t s)
92{
93 if (s >= ARR_SIZE(str_speed)) {
94 return "invalid";
95 }
96 return str_speed[s];
97}
98
99/**
100 * @}
101 */
Note: See TracBrowser for help on using the repository browser.