Move away from autogenerated enums, these values never change and its helpful

to be able to look them up.
This commit is contained in:
Andrew Thompson 2009-02-03 05:50:36 +00:00
parent 711873d44f
commit 5261ba87bc
5 changed files with 114 additions and 124 deletions

View File

@ -29,8 +29,37 @@
#include <dev/usb2/core/usb2_core.h>
USB_MAKE_DEBUG_TABLE(USB_ERR);
static const char* usb_errstr_table[USB_ERR_MAX] = {
[USB_ERR_NORMAL_COMPLETION] = "USB_ERR_NORMAL_COMPLETION",
[USB_ERR_BAD_ADDRESS] = "USB_ERR_BAD_ADDRESS",
[USB_ERR_BAD_BUFSIZE] = "USB_ERR_BAD_BUFSIZE",
[USB_ERR_BAD_CONTEXT] = "USB_ERR_BAD_CONTEXT",
[USB_ERR_BAD_FLAG] = "USB_ERR_BAD_FLAG",
[USB_ERR_CANCELLED] = "USB_ERR_CANCELLED",
[USB_ERR_DMA_LOAD_FAILED] = "USB_ERR_DMA_LOAD_FAILED",
[USB_ERR_INTERRUPTED] = "USB_ERR_INTERRUPTED",
[USB_ERR_INVAL] = "USB_ERR_INVAL",
[USB_ERR_IN_USE] = "USB_ERR_IN_USE",
[USB_ERR_IOERROR] = "USB_ERR_IOERROR",
[USB_ERR_NOMEM] = "USB_ERR_NOMEM",
[USB_ERR_NOT_CONFIGURED] = "USB_ERR_NOT_CONFIGURED",
[USB_ERR_NOT_LOCKED] = "USB_ERR_NOT_LOCKED",
[USB_ERR_NOT_STARTED] = "USB_ERR_NOT_STARTED",
[USB_ERR_NO_ADDR] = "USB_ERR_NO_ADDR",
[USB_ERR_NO_CALLBACK] = "USB_ERR_NO_CALLBACK",
[USB_ERR_NO_INTR_THREAD] = "USB_ERR_NO_INTR_THREAD",
[USB_ERR_NO_PIPE] = "USB_ERR_NO_PIPE",
[USB_ERR_NO_POWER] = "USB_ERR_NO_POWER",
[USB_ERR_NO_ROOT_HUB] = "USB_ERR_NO_ROOT_HUB",
[USB_ERR_PENDING_REQUESTS] = "USB_ERR_PENDING_REQUESTS",
[USB_ERR_SET_ADDR_FAILED] = "USB_ERR_SET_ADDR_FAILED",
[USB_ERR_SHORT_XFER] = "USB_ERR_SHORT_XFER",
[USB_ERR_STALLED] = "USB_ERR_STALLED",
[USB_ERR_TIMEOUT] = "USB_ERR_TIMEOUT",
[USB_ERR_TOO_DEEP] = "USB_ERR_TOO_DEEP",
[USB_ERR_ZERO_MAXP] = "USB_ERR_ZERO_MAXP",
[USB_ERR_ZERO_NFRAMES] = "USB_ERR_ZERO_NFRAMES",
};
/*------------------------------------------------------------------------*
* usb2_errstr
*
@ -39,5 +68,5 @@ USB_MAKE_DEBUG_TABLE(USB_ERR);
const char *
usb2_errstr(usb2_error_t err)
{
return ((err < USB_ERR_MAX) ? USB_ERR[err] : "USB_ERR_UNKNOWN");
return (err < USB_ERR_MAX ? usb_errstr_table[err] : "USB_ERR_UNKNOWN");
}

View File

@ -27,42 +27,37 @@
#ifndef _USB2_ERROR_H_
#define _USB2_ERROR_H_
/*
* The "USB_STATUS" macro defines all the USB error codes.
* NOTE: "USB_ERR_NORMAL_COMPLETION" is not an error code.
* NOTE: "USB_ERR_STARTING" is not an error code.
*/
#define USB_ERR(m,n)\
m(n, USB_ERR_NORMAL_COMPLETION)\
m(n, USB_ERR_PENDING_REQUESTS)\
m(n, USB_ERR_NOT_STARTED)\
m(n, USB_ERR_INVAL)\
m(n, USB_ERR_NOMEM)\
m(n, USB_ERR_CANCELLED)\
m(n, USB_ERR_BAD_ADDRESS)\
m(n, USB_ERR_BAD_BUFSIZE)\
m(n, USB_ERR_BAD_FLAG)\
m(n, USB_ERR_NO_CALLBACK)\
m(n, USB_ERR_IN_USE)\
m(n, USB_ERR_NO_ADDR)\
m(n, USB_ERR_NO_PIPE)\
m(n, USB_ERR_ZERO_NFRAMES)\
m(n, USB_ERR_ZERO_MAXP)\
m(n, USB_ERR_SET_ADDR_FAILED)\
m(n, USB_ERR_NO_POWER)\
m(n, USB_ERR_TOO_DEEP)\
m(n, USB_ERR_IOERROR)\
m(n, USB_ERR_NOT_CONFIGURED)\
m(n, USB_ERR_TIMEOUT)\
m(n, USB_ERR_SHORT_XFER)\
m(n, USB_ERR_STALLED)\
m(n, USB_ERR_INTERRUPTED)\
m(n, USB_ERR_DMA_LOAD_FAILED)\
m(n, USB_ERR_BAD_CONTEXT)\
m(n, USB_ERR_NO_ROOT_HUB)\
m(n, USB_ERR_NO_INTR_THREAD)\
m(n, USB_ERR_NOT_LOCKED)\
USB_MAKE_ENUM(USB_ERR);
enum { /* keep in sync with usb_errstr_table */
USB_ERR_NORMAL_COMPLETION = 0,
USB_ERR_PENDING_REQUESTS, /* 1 */
USB_ERR_NOT_STARTED, /* 2 */
USB_ERR_INVAL, /* 3 */
USB_ERR_NOMEM, /* 4 */
USB_ERR_CANCELLED, /* 5 */
USB_ERR_BAD_ADDRESS, /* 6 */
USB_ERR_BAD_BUFSIZE, /* 7 */
USB_ERR_BAD_FLAG, /* 8 */
USB_ERR_NO_CALLBACK, /* 9 */
USB_ERR_IN_USE, /* 10 */
USB_ERR_NO_ADDR, /* 11 */
USB_ERR_NO_PIPE, /* 12 */
USB_ERR_ZERO_NFRAMES, /* 13 */
USB_ERR_ZERO_MAXP, /* 14 */
USB_ERR_SET_ADDR_FAILED, /* 15 */
USB_ERR_NO_POWER, /* 16 */
USB_ERR_TOO_DEEP, /* 17 */
USB_ERR_IOERROR, /* 18 */
USB_ERR_NOT_CONFIGURED, /* 19 */
USB_ERR_TIMEOUT, /* 20 */
USB_ERR_SHORT_XFER, /* 21 */
USB_ERR_STALLED, /* 22 */
USB_ERR_INTERRUPTED, /* 23 */
USB_ERR_DMA_LOAD_FAILED, /* 24 */
USB_ERR_BAD_CONTEXT, /* 25 */
USB_ERR_NO_ROOT_HUB, /* 26 */
USB_ERR_NO_INTR_THREAD, /* 27 */
USB_ERR_NOT_LOCKED, /* 28 */
USB_ERR_MAX
};
#endif /* _USB2_ERROR_H_ */

View File

@ -29,14 +29,6 @@
#ifndef _USB2_MFUNC_H_
#define _USB2_MFUNC_H_
#define USB_MAKE_001(n,ENUM) ENUM,
#define USB_MAKE_ENUM(m) \
enum { m(USB_MAKE_001,) m##_MAX }
#define USB_MAKE_002(n,ENUM) #ENUM,
#define USB_MAKE_DEBUG_TABLE(m) \
static const char * m[m##_MAX] = { m(USB_MAKE_002,) }
#define USB_LOG2(n) ( \
((x) <= (1<<0x00)) ? 0x00 : \
((x) <= (1<<0x01)) ? 0x01 : \

View File

@ -27,41 +27,39 @@
#ifndef _USB2_REVISION_H_
#define _USB2_REVISION_H_
#include <dev/usb2/include/usb2_mfunc.h>
/*
* The "USB_SPEED" macro defines all the supported USB speeds.
*/
#define USB_SPEED(m,n)\
m(n, USB_SPEED_VARIABLE)\
m(n, USB_SPEED_LOW)\
m(n, USB_SPEED_FULL)\
m(n, USB_SPEED_HIGH)\
m(n, USB_SPEED_SUPER)\
USB_MAKE_ENUM(USB_SPEED);
enum {
USB_SPEED_VARIABLE,
USB_SPEED_LOW,
USB_SPEED_FULL,
USB_SPEED_HIGH,
USB_SPEED_SUPER,
USB_SPEED_MAX
};
/*
* The "USB_REV" macro defines all the supported USB revisions.
*/
#define USB_REV(m,n)\
m(n, USB_REV_UNKNOWN)\
m(n, USB_REV_PRE_1_0)\
m(n, USB_REV_1_0)\
m(n, USB_REV_1_1)\
m(n, USB_REV_2_0)\
m(n, USB_REV_2_5)\
m(n, USB_REV_3_0)\
USB_MAKE_ENUM(USB_REV);
enum {
USB_REV_UNKNOWN,
USB_REV_PRE_1_0,
USB_REV_1_0,
USB_REV_1_1,
USB_REV_2_0,
USB_REV_2_5,
USB_REV_3_0,
USB_REV_MAX
};
/*
* The "USB_MODE" macro defines all the supported USB modes.
*/
#define USB_MODE(m,n)\
m(n, USB_MODE_HOST)\
m(n, USB_MODE_DEVICE)\
USB_MAKE_ENUM(USB_MODE);
enum {
USB_MODE_HOST,
USB_MODE_DEVICE,
USB_MODE_MAX
};
#endif /* _USB2_REVISION_H_ */

View File

@ -28,56 +28,32 @@
#define _USB2_QUIRK_H_
/* NOTE: UQ_NONE is not a valid quirk */
#define USB_QUIRK(m,n) \
m(n, UQ_NONE) \
/* left and right sound channels are swapped */ \
m(n, UQ_AUDIO_SWAP_LR) \
/* input is async despite claim of adaptive */ \
m(n, UQ_AU_INP_ASYNC) \
/* don't adjust for fractional samples */ \
m(n, UQ_AU_NO_FRAC) \
/* audio device has broken extension unit */ \
m(n, UQ_AU_NO_XU) \
/* bad audio spec version number */ \
m(n, UQ_BAD_ADC) \
/* device claims audio class, but isn't */ \
m(n, UQ_BAD_AUDIO) \
/* printer has broken bidir mode */ \
m(n, UQ_BROKEN_BIDIR) \
/* device is bus powered, despite claim */ \
m(n, UQ_BUS_POWERED) \
/* device should be ignored by hid class */ \
m(n, UQ_HID_IGNORE) \
/* device should be ignored by kbd class */ \
m(n, UQ_KBD_IGNORE) \
/* doesn't identify properly */ \
m(n, UQ_MS_BAD_CLASS) \
/* mouse sends an unknown leading byte */ \
m(n, UQ_MS_LEADING_BYTE) \
/* mouse has Z-axis reversed */ \
m(n, UQ_MS_REVZ) \
/* string descriptors are broken */ \
m(n, UQ_NO_STRINGS) \
/* device needs clear endpoint stall */ \
m(n, UQ_OPEN_CLEARSTALL) \
/* hub lies about power status */ \
m(n, UQ_POWER_CLAIM) \
/* spurious mouse button up events */ \
m(n, UQ_SPUR_BUT_UP) \
/* has some Unicode strings swapped */ \
m(n, UQ_SWAP_UNICODE) \
/* select configuration index 1 by default */ \
m(n, UQ_CFG_INDEX_1) \
/* select configuration index 2 by default */ \
m(n, UQ_CFG_INDEX_2) \
/* select configuration index 3 by default */ \
m(n, UQ_CFG_INDEX_3) \
/* select configuration index 4 by default */ \
m(n, UQ_CFG_INDEX_4) \
/* select configuration index 0 by default */ \
m(n, UQ_CFG_INDEX_0)
USB_MAKE_ENUM(USB_QUIRK);
enum {
UQ_NONE,
UQ_AUDIO_SWAP_LR, /* left and right sound channels are swapped */
UQ_AU_INP_ASYNC, /* input is async despite claim of adaptive */
UQ_AU_NO_FRAC, /* don't adjust for fractional samples */
UQ_AU_NO_XU, /* audio device has broken extension unit */
UQ_BAD_ADC, /* bad audio spec version number */
UQ_BAD_AUDIO, /* device claims audio class, but isn't */
UQ_BROKEN_BIDIR, /* printer has broken bidir mode */
UQ_BUS_POWERED, /* device is bus powered, despite claim */
UQ_HID_IGNORE, /* device should be ignored by hid class */
UQ_KBD_IGNORE, /* device should be ignored by kbd class */
UQ_MS_BAD_CLASS, /* doesn't identify properly */
UQ_MS_LEADING_BYTE, /* mouse sends an unknown leading byte */
UQ_MS_REVZ, /* mouse has Z-axis reversed */
UQ_NO_STRINGS, /* string descriptors are broken */
UQ_OPEN_CLEARSTALL, /* device needs clear endpoint stall */
UQ_POWER_CLAIM, /* hub lies about power status */
UQ_SPUR_BUT_UP, /* spurious mouse button up events */
UQ_SWAP_UNICODE, /* has some Unicode strings swapped */
UQ_CFG_INDEX_1, /* select configuration index 1 by default */
UQ_CFG_INDEX_2, /* select configuration index 2 by default */
UQ_CFG_INDEX_3, /* select configuration index 3 by default */
UQ_CFG_INDEX_4, /* select configuration index 4 by default */
UQ_CFG_INDEX_0, /* select configuration index 0 by default */
USB_QUIRK_MAX
};
#endif /* _USB2_QUIRK_H_ */