source: mainline/uspace/lib/usb/include/usb/usb.h@ 4b4c797

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

Directory structure reorganization

USB class-specific headers are in separate directory.

Removed unused/unreachable code.

  • Property mode set to 100644
File size: 3.5 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 usb
30 * @{
31 */
32/** @file
33 * @brief Base USB types.
34 */
35#ifndef LIBUSB_USB_H_
36#define LIBUSB_USB_H_
37
38#include <sys/types.h>
39#include <ipc/ipc.h>
40
41/** USB transfer type. */
42typedef enum {
43 USB_TRANSFER_CONTROL = 0,
44 USB_TRANSFER_ISOCHRONOUS = 1,
45 USB_TRANSFER_BULK = 2,
46 USB_TRANSFER_INTERRUPT = 3
47} usb_transfer_type_t;
48
49const char * usb_str_transfer_type(usb_transfer_type_t t);
50
51/** USB data transfer direction. */
52typedef enum {
53 USB_DIRECTION_IN,
54 USB_DIRECTION_OUT
55} usb_direction_t;
56
57/** USB transaction outcome. */
58typedef enum {
59 USB_OUTCOME_OK,
60 USB_OUTCOME_CRCERROR,
61 USB_OUTCOME_BABBLE
62} usb_transaction_outcome_t;
63
64const char * usb_str_transaction_outcome(usb_transaction_outcome_t o);
65
66/** USB address type.
67 * Negative values could be used to indicate error.
68 */
69typedef int usb_address_t;
70
71/** USB endpoint number type.
72 * Negative values could be used to indicate error.
73 */
74typedef int usb_endpoint_t;
75
76/** Maximum endpoint number in USB 1.1.
77 */
78#define USB11_ENDPOINT_MAX 16
79
80
81/** USB complete address type.
82 * Pair address + endpoint is identification of transaction recipient.
83 */
84typedef struct {
85 usb_address_t address;
86 usb_endpoint_t endpoint;
87} usb_target_t;
88
89static inline int usb_target_same(usb_target_t a, usb_target_t b)
90{
91 return (a.address == b.address)
92 && (a.endpoint == b.endpoint);
93}
94
95/** General handle type.
96 * Used by various USB functions as opaque handle.
97 */
98typedef ipcarg_t usb_handle_t;
99
100/** USB packet identifier. */
101typedef enum {
102#define _MAKE_PID_NIBBLE(tag, type) \
103 ((uint8_t)(((tag) << 2) | (type)))
104#define _MAKE_PID(tag, type) \
105 ( \
106 _MAKE_PID_NIBBLE(tag, type) \
107 | ((~_MAKE_PID_NIBBLE(tag, type)) << 4) \
108 )
109 USB_PID_OUT = _MAKE_PID(0, 1),
110 USB_PID_IN = _MAKE_PID(2, 1),
111 USB_PID_SOF = _MAKE_PID(1, 1),
112 USB_PID_SETUP = _MAKE_PID(3, 1),
113
114 USB_PID_DATA0 = _MAKE_PID(0 ,3),
115 USB_PID_DATA1 = _MAKE_PID(2 ,3),
116
117 USB_PID_ACK = _MAKE_PID(0 ,2),
118 USB_PID_NAK = _MAKE_PID(2 ,2),
119 USB_PID_STALL = _MAKE_PID(3 ,2),
120
121 USB_PID_PRE = _MAKE_PID(3 ,0),
122 /* USB_PID_ = _MAKE_PID( ,), */
123#undef _MAKE_PID
124#undef _MAKE_PID_NIBBLE
125} usb_packet_id;
126
127#endif
128/**
129 * @}
130 */
Note: See TracBrowser for help on using the repository browser.