From cd9a329a054196ed6e949b3ded0f8449853191f1 Mon Sep 17 00:00:00 2001 From: schlaepfer Date: Fri, 5 May 2006 08:16:39 +0000 Subject: [PATCH] - some USB constants added - javadoc updates git-svn-id: https://svn.code.sf.net/p/libusbjava/code/trunk@141 94ad28fe-ef68-46b1-9651-e7ae4fcf1c4c --- mcdp/src/ch/ntb/usb/Device.java | 22 +++++++---- mcdp/src/ch/ntb/usb/LibusbWin.java | 14 +++++++ mcdp/src/ch/ntb/usb/USB.java | 4 +- .../src/ch/ntb/usb/Usb_Config_Descriptor.java | 2 + .../src/ch/ntb/usb/Usb_Device_Descriptor.java | 37 +++++++++++++++++++ .../ch/ntb/usb/Usb_Endpoint_Descriptor.java | 13 +++++++ mcdp/src/ch/ntb/usb/Usb_Interface.java | 2 + .../ch/ntb/usb/Usb_Interface_Descriptor.java | 2 + 8 files changed, 86 insertions(+), 10 deletions(-) diff --git a/mcdp/src/ch/ntb/usb/Device.java b/mcdp/src/ch/ntb/usb/Device.java index 8255821..bd39532 100644 --- a/mcdp/src/ch/ntb/usb/Device.java +++ b/mcdp/src/ch/ntb/usb/Device.java @@ -135,7 +135,7 @@ public class Device { } /** - * Release the claimed interface and close the opened device. + * Release the claimed interface and close the opened device.
* * @throws USBException */ @@ -156,7 +156,8 @@ public class Device { /** * Sends an USB reset to the device. The device handle will no longer be - * valid. To use the device again, open must be called. + * valid. To use the device again, {@link #open(int, int, int)} must be + * called. * * @throws USBException */ @@ -297,7 +298,7 @@ public class Device { } /** - * Claim an interface to send and receive USB data. + * Claim an interface to send and receive USB data.
* * @param usb_dev_handle * the handle of the device (MUST BE VALID) @@ -328,7 +329,7 @@ public class Device { } /** - * Release a previously claimed interface. + * Release a previously claimed interface.
* * @param dev_handle * the handle of the device (MUST BE VALID) @@ -396,7 +397,10 @@ public class Device { * Returns the maximum packet size in bytes which is allowed to be * transmitted at once.
* The value is determined by reading the endpoint descriptor(s) when - * opening the device. It is invalid before the device is opened! + * opening the device. It is invalid before the device is opened! Note that + * if some endpoints use different packet sizes the maximum packet size is + * return. This value may be used to determine if a device is opened in + * fullspeed or highspeed mode. * * @return the maximum packet size */ @@ -405,13 +409,15 @@ public class Device { } /** - * If enabled, the device is reset when first opened. This will only happen - * once. + * If enabled, the device is reset when first opened.
+ * This will only happen once. When the application is started, the device + * state is unknown. If the device is not reset, read or write may result in + * a {@link USBTimeoutException}. * * @param enable + * true if the device should be reset when first opened */ public void setResetOnFirstOpen(boolean enable) { resetOnFirstOpen = enable; } - } diff --git a/mcdp/src/ch/ntb/usb/LibusbWin.java b/mcdp/src/ch/ntb/usb/LibusbWin.java index d2d6311..2acee76 100644 --- a/mcdp/src/ch/ntb/usb/LibusbWin.java +++ b/mcdp/src/ch/ntb/usb/LibusbWin.java @@ -1,5 +1,19 @@ package ch.ntb.usb; +/** + * This class represents the Java Native Interface to the LibUsbWin.dll.
+ *
+ *

Project Description

+ * Java LibUsb-Win32 is a Java wrapper for the LibUsb-Win32 USB library. LibUsb-Win32 is a port of + * the USB library libusb to the + * Windows operating systems. The library allows user space applications to + * access any USB device on Windows in a generic way without writing any line of + * kernel driver code. + * + * @author schlaepfer + * + */ public class LibusbWin { // Core diff --git a/mcdp/src/ch/ntb/usb/USB.java b/mcdp/src/ch/ntb/usb/USB.java index da726a6..26a1622 100644 --- a/mcdp/src/ch/ntb/usb/USB.java +++ b/mcdp/src/ch/ntb/usb/USB.java @@ -32,7 +32,7 @@ public class USB { /** * Create a new device an register it in a device queue or get an already - * created device. + * created device.
* * @param idVendor * the vendor id of the USB device @@ -55,7 +55,7 @@ public class USB { } /** - * Get an already registered device or null if the device does not exist. + * Get an already registered device or null if the device does not exist.
* * @param idVendor * the vendor id of the USB device diff --git a/mcdp/src/ch/ntb/usb/Usb_Config_Descriptor.java b/mcdp/src/ch/ntb/usb/Usb_Config_Descriptor.java index 023fe11..d6fcace 100644 --- a/mcdp/src/ch/ntb/usb/Usb_Config_Descriptor.java +++ b/mcdp/src/ch/ntb/usb/Usb_Config_Descriptor.java @@ -1,6 +1,8 @@ package ch.ntb.usb; public class Usb_Config_Descriptor { + public static final int USB_MAXCONFIG = 8; + public byte bLength; public byte bDescriptorType; diff --git a/mcdp/src/ch/ntb/usb/Usb_Device_Descriptor.java b/mcdp/src/ch/ntb/usb/Usb_Device_Descriptor.java index b3881b9..5105e28 100644 --- a/mcdp/src/ch/ntb/usb/Usb_Device_Descriptor.java +++ b/mcdp/src/ch/ntb/usb/Usb_Device_Descriptor.java @@ -1,6 +1,43 @@ package ch.ntb.usb; public class Usb_Device_Descriptor { + /* + * Device and/or Interface Class codes + */ + public static final int USB_CLASS_PER_INTERFACE = 0; + public static final int USB_CLASS_AUDIO = 1; + public static final int USB_CLASS_COMM = 2; + public static final int USB_CLASS_HID = 3; + public static final int USB_CLASS_PRINTER = 7; + public static final int USB_CLASS_MASS_STORAGE = 8; + public static final int USB_CLASS_HUB = 9; + public static final int USB_CLASS_DATA = 10; + public static final int USB_CLASS_VENDOR_SPEC = 0xff; + + /* + * Descriptor types + */ + public static final int USB_DT_DEVICE = 0x01; + public static final int USB_DT_CONFIG = 0x02; + public static final int USB_DT_STRING = 0x03; + public static final int USB_DT_INTERFACE = 0x04; + public static final int USB_DT_ENDPOINT = 0x05; + + public static final int USB_DT_HID = 0x21; + public static final int USB_DT_REPORT = 0x22; + public static final int USB_DT_PHYSICAL = 0x23; + public static final int USB_DT_HUB = 0x29; + + /* + * Descriptor sizes per descriptor type + */ + public static final int USB_DT_DEVICE_SIZE = 18; + public static final int USB_DT_CONFIG_SIZE = 9; + public static final int USB_DT_INTERFACE_SIZE = 9; + public static final int USB_DT_ENDPOINT_SIZE = 7; + public static final int USB_DT_ENDPOINT_AUDIO_SIZE = 9; /* Audio extension */ + public static final int USB_DT_HUB_NONVAR_SIZE = 7; + public byte bLength; public byte bDescriptorType; diff --git a/mcdp/src/ch/ntb/usb/Usb_Endpoint_Descriptor.java b/mcdp/src/ch/ntb/usb/Usb_Endpoint_Descriptor.java index f6d3586..f8720da 100644 --- a/mcdp/src/ch/ntb/usb/Usb_Endpoint_Descriptor.java +++ b/mcdp/src/ch/ntb/usb/Usb_Endpoint_Descriptor.java @@ -1,6 +1,19 @@ package ch.ntb.usb; public class Usb_Endpoint_Descriptor { + public static final int USB_MAXENDPOINTS = 32; + + /* in bEndpointAddress */ + public static final int USB_ENDPOINT_ADDRESS_MASK = 0x0f; + public static final int USB_ENDPOINT_DIR_MASK = 0x80; + + /* in bmAttributes */ + public static final int USB_ENDPOINT_TYPE_MASK = 0x03; + public static final int USB_ENDPOINT_TYPE_CONTROL = 0; + public static final int USB_ENDPOINT_TYPE_ISOCHRONOUS = 1; + public static final int USB_ENDPOINT_TYPE_BULK = 2; + public static final int USB_ENDPOINT_TYPE_INTERRUPT = 3; + public byte bLength; public byte bDescriptorType; diff --git a/mcdp/src/ch/ntb/usb/Usb_Interface.java b/mcdp/src/ch/ntb/usb/Usb_Interface.java index ed80163..bcf8066 100644 --- a/mcdp/src/ch/ntb/usb/Usb_Interface.java +++ b/mcdp/src/ch/ntb/usb/Usb_Interface.java @@ -1,6 +1,8 @@ package ch.ntb.usb; public class Usb_Interface { + public static final int USB_MAXALTSETTING = 128; /* Hard limit */ + public Usb_Interface_Descriptor[] altsetting; public int num_altsetting; diff --git a/mcdp/src/ch/ntb/usb/Usb_Interface_Descriptor.java b/mcdp/src/ch/ntb/usb/Usb_Interface_Descriptor.java index 205c632..ad70235 100644 --- a/mcdp/src/ch/ntb/usb/Usb_Interface_Descriptor.java +++ b/mcdp/src/ch/ntb/usb/Usb_Interface_Descriptor.java @@ -1,6 +1,8 @@ package ch.ntb.usb; public class Usb_Interface_Descriptor { + public static final int USB_MAXINTERFACES = 32; + public byte bLength; public byte bDescriptorType;