blob: 82117e725a7b1efca17947c5044a8ef6b22c54a5 [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
Mike Lockwoode7d511e2010-12-30 13:39:37 -050019import android.os.Parcel;
20import android.os.Parcelable;
21
22/**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040023 * A class representing an endpoint on a {@link UsbInterface}.
24 * Endpoints are the channels for sending and receiving data over USB.
25 * Typically bulk endpoints are used for sending non-trivial amounts of data.
26 * Interrupt endpoints are used for sending small amounts of data, typically events,
27 * separately from the main data streams.
28 * The endpoint zero is a special endpoint for control messages sent from the host
29 * to device.
30 * Isochronous endpoints are currently unsupported.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050031 */
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050032public class UsbEndpoint implements Parcelable {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050033
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050034 private final int mAddress;
35 private final int mAttributes;
36 private final int mMaxPacketSize;
37 private final int mInterval;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050038
39 /**
40 * UsbEndpoint should only be instantiated by UsbService implementation
41 * @hide
42 */
43 public UsbEndpoint(int address, int attributes, int maxPacketSize, int interval) {
44 mAddress = address;
45 mAttributes = attributes;
46 mMaxPacketSize = maxPacketSize;
47 mInterval = interval;
48 }
49
50 /**
51 * Returns the endpoint's address field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040052 * The address is a bitfield containing both the endpoint number
53 * as well as the data direction of the endpoint.
54 * the endpoint number and direction can also be accessed via
55 * {@link #getEndpointNumber} and {@link #getDirection}.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050056 *
57 * @return the endpoint's address
58 */
59 public int getAddress() {
60 return mAddress;
61 }
62
63 /**
64 * Extracts the endpoint's endpoint number from its address
65 *
66 * @return the endpoint's endpoint number
67 */
68 public int getEndpointNumber() {
69 return mAddress & UsbConstants.USB_ENDPOINT_NUMBER_MASK;
70 }
71
72 /**
73 * Returns the endpoint's direction.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040074 * Returns {@link UsbConstants#USB_DIR_OUT}
Mike Lockwoode7d511e2010-12-30 13:39:37 -050075 * if the direction is host to device, and
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040076 * {@link UsbConstants#USB_DIR_IN} if the
Mike Lockwoode7d511e2010-12-30 13:39:37 -050077 * direction is device to host.
Elliot Waite54de7742017-01-11 15:30:35 -080078 * @see UsbConstants#USB_DIR_IN
79 * @see UsbConstants#USB_DIR_OUT
Mike Lockwoode7d511e2010-12-30 13:39:37 -050080 *
81 * @return the endpoint's direction
82 */
83 public int getDirection() {
84 return mAddress & UsbConstants.USB_ENDPOINT_DIR_MASK;
85 }
86
87 /**
88 * Returns the endpoint's attributes field.
89 *
90 * @return the endpoint's attributes
91 */
92 public int getAttributes() {
93 return mAttributes;
94 }
95
96 /**
97 * Returns the endpoint's type.
98 * Possible results are:
99 * <ul>
Mike Lockwood11dd5ae2011-04-01 14:00:08 -0400100 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_CONTROL} (endpoint zero)
101 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_ISOC} (isochronous endpoint)
102 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_BULK} (bulk endpoint)
103 * <li>{@link UsbConstants#USB_ENDPOINT_XFER_INT} (interrupt endpoint)
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500104 * </ul>
105 *
106 * @return the endpoint's type
107 */
108 public int getType() {
109 return mAttributes & UsbConstants.USB_ENDPOINT_XFERTYPE_MASK;
110 }
111
112 /**
113 * Returns the endpoint's maximum packet size.
114 *
115 * @return the endpoint's maximum packet size
116 */
117 public int getMaxPacketSize() {
118 return mMaxPacketSize;
119 }
120
121 /**
122 * Returns the endpoint's interval field.
123 *
124 * @return the endpoint's interval
125 */
126 public int getInterval() {
127 return mInterval;
128 }
129
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500130 @Override
131 public String toString() {
132 return "UsbEndpoint[mAddress=" + mAddress + ",mAttributes=" + mAttributes +
133 ",mMaxPacketSize=" + mMaxPacketSize + ",mInterval=" + mInterval +"]";
134 }
135
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -0700136 public static final @android.annotation.NonNull Parcelable.Creator<UsbEndpoint> CREATOR =
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500137 new Parcelable.Creator<UsbEndpoint>() {
138 public UsbEndpoint createFromParcel(Parcel in) {
139 int address = in.readInt();
140 int attributes = in.readInt();
141 int maxPacketSize = in.readInt();
142 int interval = in.readInt();
143 return new UsbEndpoint(address, attributes, maxPacketSize, interval);
144 }
145
146 public UsbEndpoint[] newArray(int size) {
147 return new UsbEndpoint[size];
148 }
149 };
150
151 public int describeContents() {
152 return 0;
153 }
154
155 public void writeToParcel(Parcel parcel, int flags) {
156 parcel.writeInt(mAddress);
157 parcel.writeInt(mAttributes);
158 parcel.writeInt(mMaxPacketSize);
159 parcel.writeInt(mInterval);
160 }
161}