File: Usb_Endpoint_Descriptor.java

package info (click to toggle)
libusb-java 0.8%2Bztex20090101-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 416 kB
  • ctags: 810
  • sloc: java: 1,102; ansic: 605; makefile: 98; sh: 29
file content (156 lines) | stat: -rw-r--r-- 3,874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 
 * Java libusb wrapper
 * Copyright (c) 2005-2006 Andreas Schlaepfer <spandi at users.sourceforge.net>
 *
 * http://libusbjava.sourceforge.net
 * This library is covered by the LGPL, read LGPL.txt for details.
 */
package ch.ntb.usb;

/**
 * Represents the descriptor of an USB endpoint.<br>
 * Endpoint descriptors are used to describe endpoints other than endpoint zero.
 * Endpoint zero is always assumed to be a control endpoint and is configured
 * before any descriptors are even requested. The host will use the information
 * returned from these descriptors to determine the bandwidth requirements of
 * the bus.<br>
 * <br>
 * The length of the configuration descriptor is
 * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT_SIZE} and the type is
 * {@link ch.ntb.usb.Usb_Descriptor#USB_DT_ENDPOINT}.
 * 
 */
public class Usb_Endpoint_Descriptor extends Usb_Descriptor {

	/**
	 * Maximum number of endpoints
	 */
	public static final int USB_MAXENDPOINTS = 32;

	/**
	 * Endpoint address mask (in bEndpointAddress).
	 */
	public static final int USB_ENDPOINT_ADDRESS_MASK = 0x0f,
			USB_ENDPOINT_DIR_MASK = 0x80;

	/**
	 * Endpoint type mask (in bmAttributes).
	 */
	public static final int USB_ENDPOINT_TYPE_MASK = 0x03;

	/**
	 * Possible endpoint types (in bmAttributes).
	 */
	public static final int USB_ENDPOINT_TYPE_CONTROL = 0,
			USB_ENDPOINT_TYPE_ISOCHRONOUS = 1, USB_ENDPOINT_TYPE_BULK = 2,
			USB_ENDPOINT_TYPE_INTERRUPT = 3;

	private byte bEndpointAddress;

	private byte bmAttributes;

	private short wMaxPacketSize;

	private byte bInterval;

	private byte bRefresh;

	private byte bSynchAddress;

	private byte[] extra; /* Extra descriptors */

	private int extralen;

	/**
	 * Returns the endpoint address.<br>
	 * <br>
	 * Bits 3..0: Endpoint number <br>
	 * Bits 6..4: Reserved. Set to zero <br>
	 * Bit 7: Direction. 0 = Out, 1 = In (ignored for control endpoints)<br>
	 * 
	 * @return the endpoint address
	 */
	public byte getBEndpointAddress() {
		return bEndpointAddress;
	}

	/**
	 * Returns the intervall for polling endpoint data transfers.<br>
	 * Value in frame counts. Ignored for Bulk & Control eEndpoints. Isochronous
	 * endpoints must equal 1 and field may range from 1 to 255 for interrupt
	 * endpoints.
	 * 
	 * @return the intervall for polling endpoint data transfers
	 */
	public byte getBInterval() {
		return bInterval;
	}

	/**
	 * Returns the attributes of this endpoint.<br>
	 * 
	 * Bits 1..0: Transfer Type (see <i>USB_ENDPOINT_TYPE_XXX</i>).<br>
	 * Bits 7..2: Reserved.<br>
	 * 
	 * <pre>
	 * 	If isochronous endpoint:
	 * 		Bits 3..2: Synchronisation type
	 *  		00 = No synchronisation
	 * 			01 = Asynchronous
	 *          10 = Adaptive
	 *          11 = Synchronous
	 *     	Bits 5..4: Usage Type
	 *      	00 = Data endpoint
	 *      	01 = Feedback endpoint
	 *      	10 = Explicit feedback data endpoint
	 *      	11 = Reserved
	 * </pre>
	 * 
	 * @return the attributes of this endpoint
	 */
	public byte getBmAttributes() {
		return bmAttributes;
	}

	public byte getBRefresh() {
		return bRefresh;
	}

	public byte getBSynchAddress() {
		return bSynchAddress;
	}

	/**
	 * Returns the data of extra descriptor(s) if available.<br>
	 * 
	 * @return null or a byte array with the extra descriptor data
	 */
	public byte[] getExtra() {
		return extra;
	}

	/**
	 * Returns the number of bytes of the extra descriptor.<br>
	 * 
	 * @return the number of bytes of the extra descriptor
	 */
	public int getExtralen() {
		return extralen;
	}

	/**
	 * Returns the maximum packet size of this endpoint is capable of sending or
	 * receiving.<br>
	 * 
	 * @return the maximum packet size
	 */
	public short getWMaxPacketSize() {
		return wMaxPacketSize;
	}

	@Override
	public String toString() {
		return "Usb_Endpoint_Descriptor bEndpointAddress: 0x"
				+ Integer.toHexString(bEndpointAddress & 0xFF);
	}
}