blob: 753a447f96f2b90eafdf890d7da4ff34995d2243 [file] [log] [blame]
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Mike Lockwoodc4308f02011-03-01 08:04:54 -080017package android.hardware.usb;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050018
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040024 * A class representing an endpoint on a {@link UsbInterface}.
25 * Endpoints are the channels for sending and receiving data over USB.
26 * Typically bulk endpoints are used for sending non-trivial amounts of data.
27 * Interrupt endpoints are used for sending small amounts of data, typically events,
28 * separately from the main data streams.
29 * The endpoint zero is a special endpoint for control messages sent from the host
30 * to device.
31 * Isochronous endpoints are currently unsupported.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050032 */
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050033public class UsbEndpoint implements Parcelable {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050034
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050035 private final int mAddress;
36 private final int mAttributes;
37 private final int mMaxPacketSize;
38 private final int mInterval;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050039
40 /**
41 * UsbEndpoint should only be instantiated by UsbService implementation
42 * @hide
43 */
44 public UsbEndpoint(int address, int attributes, int maxPacketSize, int interval) {
45 mAddress = address;
46 mAttributes = attributes;
47 mMaxPacketSize = maxPacketSize;
48 mInterval = interval;
49 }
50
51 /**
52 * Returns the endpoint's address field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040053 * The address is a bitfield containing both the endpoint number
54 * as well as the data direction of the endpoint.
55 * the endpoint number and direction can also be accessed via
56 * {@link #getEndpointNumber} and {@link #getDirection}.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050057 *
58 * @return the endpoint's address
59 */
60 public int getAddress() {
61 return mAddress;
62 }
63
64 /**
65 * Extracts the endpoint's endpoint number from its address
66 *
67 * @return the endpoint's endpoint number
68 */
69 public int getEndpointNumber() {
70 return mAddress & UsbConstants.USB_ENDPOINT_NUMBER_MASK;
71 }
72
73 /**
74 * Returns the endpoint's direction.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040075 * Returns {@link UsbConstants#USB_DIR_OUT}
Mike Lockwoode7d511e2010-12-30 13:39:37 -050076 * if the direction is host to device, and
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040077 * {@link UsbConstants#USB_DIR_IN} if the
Mike Lockwoode7d511e2010-12-30 13:39:37 -050078 * direction is device to host.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040079 * @see {@link UsbConstants#USB_DIR_IN}
80 * @see {@link UsbConstants#USB_DIR_OUT}
Mike Lockwoode7d511e2010-12-30 13:39:37 -050081 *
82 * @return the endpoint's direction
83 */
84 public int getDirection() {
85 return mAddress & UsbConstants.USB_ENDPOINT_DIR_MASK;
86 }
87
88 /**
89 * Returns the endpoint's attributes field.
90 *
91 * @return the endpoint's attributes
92 */
93 public int getAttributes() {
94 return mAttributes;
95 }
96
97 /**
98 * Returns the endpoint's type.
99 * Possible results are:
100 * <ul>
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400101 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_CONTROL} (endpoint zero)
102 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_ISOC} (isochronous endpoint)
103 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_BULK} (bulk endpoint)
104 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_INT} (interrupt endpoint)
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500105 * </ul>
106 *
107 * @return the endpoint's type
108 */
109 public int getType() {
110 return mAttributes & UsbConstants.USB_ENDPOINT_XFERTYPE_MASK;
111 }
112
113 /**
114 * Returns the endpoint's maximum packet size.
115 *
116 * @return the endpoint's maximum packet size
117 */
118 public int getMaxPacketSize() {
119 return mMaxPacketSize;
120 }
121
122 /**
123 * Returns the endpoint's interval field.
124 *
125 * @return the endpoint's interval
126 */
127 public int getInterval() {
128 return mInterval;
129 }
130
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500131 @Override
132 public String toString() {
133 return "UsbEndpoint[mAddress=" + mAddress + ",mAttributes=" + mAttributes +
134 ",mMaxPacketSize=" + mMaxPacketSize + ",mInterval=" + mInterval +"]";
135 }
136
137 public static final Parcelable.Creator<UsbEndpoint> CREATOR =
138 new Parcelable.Creator<UsbEndpoint>() {
139 public UsbEndpoint createFromParcel(Parcel in) {
140 int address = in.readInt();
141 int attributes = in.readInt();
142 int maxPacketSize = in.readInt();
143 int interval = in.readInt();
144 return new UsbEndpoint(address, attributes, maxPacketSize, interval);
145 }
146
147 public UsbEndpoint[] newArray(int size) {
148 return new UsbEndpoint[size];
149 }
150 };
151
152 public int describeContents() {
153 return 0;
154 }
155
156 public void writeToParcel(Parcel parcel, int flags) {
157 parcel.writeInt(mAddress);
158 parcel.writeInt(mAttributes);
159 parcel.writeInt(mMaxPacketSize);
160 parcel.writeInt(mInterval);
161 }
162}