UsbEndpoint.java revision acc29cc91be634070c92a807df412ced97b9b375
1/*
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
17package android.hardware.usb;
18
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * A class representing an endpoint on a {@link android.hardware.usb.UsbInterface}.
25 */
26public class UsbEndpoint implements Parcelable {
27
28    private final int mAddress;
29    private final int mAttributes;
30    private final int mMaxPacketSize;
31    private final int mInterval;
32
33    /**
34     * UsbEndpoint should only be instantiated by UsbService implementation
35     * @hide
36     */
37    public UsbEndpoint(int address, int attributes, int maxPacketSize, int interval) {
38        mAddress = address;
39        mAttributes = attributes;
40        mMaxPacketSize = maxPacketSize;
41        mInterval = interval;
42    }
43
44    /**
45     * Returns the endpoint's address field.
46     *
47     * @return the endpoint's address
48     */
49    public int getAddress() {
50        return mAddress;
51    }
52
53    /**
54     * Extracts the endpoint's endpoint number from its address
55     *
56     * @return the endpoint's endpoint number
57     */
58    public int getEndpointNumber() {
59        return mAddress & UsbConstants.USB_ENDPOINT_NUMBER_MASK;
60    }
61
62    /**
63     * Returns the endpoint's direction.
64     * Returns {@link android.hardware.usb.UsbConstants#USB_DIR_OUT}
65     * if the direction is host to device, and
66     * {@link android.hardware.usb.UsbConstants#USB_DIR_IN} if the
67     * direction is device to host.
68     *
69     * @return the endpoint's direction
70     */
71    public int getDirection() {
72        return mAddress & UsbConstants.USB_ENDPOINT_DIR_MASK;
73    }
74
75    /**
76     * Returns the endpoint's attributes field.
77     *
78     * @return the endpoint's attributes
79     */
80    public int getAttributes() {
81        return mAttributes;
82    }
83
84    /**
85     * Returns the endpoint's type.
86     * Possible results are:
87     * <ul>
88     * <li>{@link android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_CONTROL} (endpoint zero)
89     * <li>{@link android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_ISOC} (isochronous endpoint)
90     * <li>{@link android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_BULK} (bulk endpoint)
91     * <li>{@link android.hardware.usb.UsbConstants#USB_ENDPOINT_XFER_INT} (interrupt endpoint)
92     * </ul>
93     *
94     * @return the endpoint's type
95     */
96    public int getType() {
97        return mAttributes & UsbConstants.USB_ENDPOINT_XFERTYPE_MASK;
98    }
99
100    /**
101     * Returns the endpoint's maximum packet size.
102     *
103     * @return the endpoint's maximum packet size
104     */
105    public int getMaxPacketSize() {
106        return mMaxPacketSize;
107    }
108
109    /**
110     * Returns the endpoint's interval field.
111     *
112     * @return the endpoint's interval
113     */
114    public int getInterval() {
115        return mInterval;
116    }
117
118    @Override
119    public String toString() {
120        return "UsbEndpoint[mAddress=" + mAddress + ",mAttributes=" + mAttributes +
121                ",mMaxPacketSize=" + mMaxPacketSize + ",mInterval=" + mInterval +"]";
122    }
123
124    public static final Parcelable.Creator<UsbEndpoint> CREATOR =
125        new Parcelable.Creator<UsbEndpoint>() {
126        public UsbEndpoint createFromParcel(Parcel in) {
127            int address = in.readInt();
128            int attributes = in.readInt();
129            int maxPacketSize = in.readInt();
130            int interval = in.readInt();
131            return new UsbEndpoint(address, attributes, maxPacketSize, interval);
132        }
133
134        public UsbEndpoint[] newArray(int size) {
135            return new UsbEndpoint[size];
136        }
137    };
138
139    public int describeContents() {
140        return 0;
141    }
142
143    public void writeToParcel(Parcel parcel, int flags) {
144        parcel.writeInt(mAddress);
145        parcel.writeInt(mAttributes);
146        parcel.writeInt(mMaxPacketSize);
147        parcel.writeInt(mInterval);
148   }
149}
150