usb.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef LIBUSB_USB_H_
00036 #define LIBUSB_USB_H_
00037 
00038 #include <sys/types.h>
00039 #include <byteorder.h>
00040 
00042 #define uint16_host2usb(n) host2uint16_t_le((n))
00043 
00045 #define uint32_host2usb(n) host2uint32_t_le((n))
00046 
00048 #define uint16_usb2host(n) uint16_t_le2host((n))
00049 
00051 #define uint32_usb2host(n) uint32_t_le2host((n))
00052 
00053 
00055 typedef enum {
00056         USB_TRANSFER_CONTROL = 0,
00057         USB_TRANSFER_ISOCHRONOUS = 1,
00058         USB_TRANSFER_BULK = 2,
00059         USB_TRANSFER_INTERRUPT = 3
00060 } usb_transfer_type_t;
00061 
00062 const char * usb_str_transfer_type(usb_transfer_type_t t);
00063 const char * usb_str_transfer_type_short(usb_transfer_type_t t);
00064 
00066 typedef enum {
00067         USB_DIRECTION_IN,
00068         USB_DIRECTION_OUT,
00069         USB_DIRECTION_BOTH
00070 } usb_direction_t;
00071 
00073 typedef enum {
00075         USB_SPEED_LOW,
00077         USB_SPEED_FULL,
00079         USB_SPEED_HIGH,
00081         USB_SPEED_MAX
00082 } usb_speed_t;
00083 
00084 const char *usb_str_speed(usb_speed_t);
00085 
00086 
00088 typedef enum {
00089         USB_REQUEST_TYPE_STANDARD = 0,
00090         USB_REQUEST_TYPE_CLASS = 1,
00091         USB_REQUEST_TYPE_VENDOR = 2
00092 } usb_request_type_t;
00093 
00095 typedef enum {
00096         USB_REQUEST_RECIPIENT_DEVICE = 0,
00097         USB_REQUEST_RECIPIENT_INTERFACE = 1,
00098         USB_REQUEST_RECIPIENT_ENDPOINT = 2,
00099         USB_REQUEST_RECIPIENT_OTHER = 3
00100 } usb_request_recipient_t;
00101 
00105 typedef int usb_address_t;
00106 
00108 #define USB_ADDRESS_DEFAULT 0
00109 
00110 #define USB11_ADDRESS_MAX 128
00111 
00115 typedef int usb_endpoint_t;
00116 
00119 #define USB11_ENDPOINT_MAX 16
00120 
00121 
00125 typedef struct {
00126         usb_address_t address;
00127         usb_endpoint_t endpoint;
00128 } usb_target_t;
00129 
00136 static inline int usb_target_same(usb_target_t a, usb_target_t b)
00137 {
00138         return (a.address == b.address)
00139             && (a.endpoint == b.endpoint);
00140 }
00141 
00145 typedef sysarg_t usb_handle_t;
00146 
00148 typedef enum {
00149 #define _MAKE_PID_NIBBLE(tag, type) \
00150         ((uint8_t)(((tag) << 2) | (type)))
00151 #define _MAKE_PID(tag, type) \
00152         ( \
00153             _MAKE_PID_NIBBLE(tag, type) \
00154             | ((~_MAKE_PID_NIBBLE(tag, type)) << 4) \
00155         )
00156         USB_PID_OUT = _MAKE_PID(0, 1),
00157         USB_PID_IN = _MAKE_PID(2, 1),
00158         USB_PID_SOF = _MAKE_PID(1, 1),
00159         USB_PID_SETUP = _MAKE_PID(3, 1),
00160 
00161         USB_PID_DATA0 = _MAKE_PID(0 ,3),
00162         USB_PID_DATA1 = _MAKE_PID(2 ,3),
00163 
00164         USB_PID_ACK = _MAKE_PID(0 ,2),
00165         USB_PID_NAK = _MAKE_PID(2 ,2),
00166         USB_PID_STALL = _MAKE_PID(3 ,2),
00167 
00168         USB_PID_PRE = _MAKE_PID(3 ,0),
00169         /* USB_PID_ = _MAKE_PID( ,), */
00170 #undef _MAKE_PID
00171 #undef _MAKE_PID_NIBBLE
00172 } usb_packet_id;
00173 
00175 #define USB_HC_DDF_CLASS_NAME "usbhc"
00176 
00177 #endif
00178 

Generated on Thu Jun 2 07:45:48 2011 for HelenOS/USB by  doxygen 1.4.7