| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 namespace usb { |
| 6 |
| 7 // Direction, Recipient and RequestType all map to their namesakes within the |
| 8 // USB specification. |
| 9 enum Direction {in, out}; |
| 10 enum Recipient {device, _interface, endpoint, other}; |
| 11 enum RequestType {standard, class, vendor, reserved}; |
| 12 |
| 13 // A Device encapsulates everything that is needed to communicate with a USB |
| 14 // device. They are returned by findDevice calls and have all of their |
| 15 // fields populated before being returned. |
| 16 dictionary Device { |
| 17 long handle; |
| 18 long vendorId; |
| 19 long productId; |
| 20 }; |
| 21 |
| 22 // ControlTransferInfo represents that parameters to a single USB control |
| 23 // transfer. |
| 24 dictionary ControlTransferInfo { |
| 25 // The direction of this transfer. |
| 26 Direction direction; |
| 27 |
| 28 // The intended recipient for this transfer. |
| 29 Recipient recipient; |
| 30 |
| 31 // The type of this request. |
| 32 RequestType requestType; |
| 33 |
| 34 long request; |
| 35 long value; |
| 36 long index; |
| 37 |
| 38 // If this transfer is an input transfer, then this field must be set to |
| 39 // indicate the expected data length. If this is an output transfer, then |
| 40 // this field is ignored. |
| 41 long? length; |
| 42 |
| 43 // The data payload carried by this transfer. If this is an output tranfer |
| 44 // then this field must be set. |
| 45 ArrayBuffer? data; |
| 46 }; |
| 47 |
| 48 // GenericTransferInfo is used by both bulk and interrupt transfers to |
| 49 // specify the parameters of the transfer. |
| 50 dictionary GenericTransferInfo { |
| 51 // The direction of this transfer. |
| 52 Direction direction; |
| 53 |
| 54 long endpoint; |
| 55 |
| 56 // If this is an input transfer then this field indicates the size of the |
| 57 // input buffer. If this is an output transfer then this field is ignored. |
| 58 long? length; |
| 59 |
| 60 // If this is an output transfer then this field must be populated. |
| 61 // Otherwise, it will be ignored. |
| 62 ArrayBuffer? data; |
| 63 }; |
| 64 |
| 65 // IsochronousTransferInfo describes a single multi-packet isochronous |
| 66 // transfer. |
| 67 dictionary IsochronousTransferInfo { |
| 68 // All of the normal transfer parameters are encapsulated in the |
| 69 // transferInfo parameters. Note that the data specified in this parameter |
| 70 // block is split along packetLength boundaries to form the individual |
| 71 // packets of the transfer. |
| 72 GenericTransferInfo transferInfo; |
| 73 |
| 74 // The total number of packets in this transfer. |
| 75 long packets; |
| 76 |
| 77 // The length of each of the packets in this transfer. |
| 78 long packetLength; |
| 79 }; |
| 80 |
| 81 dictionary TransferResultInfo { |
| 82 // A value of 0 indicates that the transfer was a success. Other values |
| 83 // indicate failure. |
| 84 long? resultCode; |
| 85 |
| 86 // If the transfer was an input transfer then this field will contain all |
| 87 // of the input data requested. |
| 88 ArrayBuffer? data; |
| 89 }; |
| 90 |
| 91 // FindDevicesOptions describes the properties of devices which are found and |
| 92 // opened via findDevices. |
| 93 dictionary FindDevicesOptions { |
| 94 long vendorId; |
| 95 long productId; |
| 96 }; |
| 97 |
| 98 callback VoidCallback = void (); |
| 99 callback FindDevicesCallback = void (Device[] device); |
| 100 callback CloseDeviceCallback = void (); |
| 101 callback TransferCallback = void (TransferResultInfo info); |
| 102 |
| 103 interface Functions { |
| 104 // Finds the first instance of the USB device specified by the vendorId/ |
| 105 // productId pair and, if permissions allow, opens it for use. |
| 106 // Upon successfully opening a device the callback is invoked with a |
| 107 // populated Device object. On failure, the callback is invoked with null. |
| 108 // |options|: The properties to search for on target devices. |
| 109 // |callback|: Invoked with the opened Device on success. |
| 110 static void findDevices(FindDevicesOptions options, |
| 111 FindDevicesCallback callback); |
| 112 |
| 113 // Closes an open device instance. Invoking operations on a device after it |
| 114 // has been closed is a safe operation, but causes no action to be taken. |
| 115 // |device|: The device to close. |
| 116 // |callback|: The callback to invoke once the device is closed. |
| 117 static void closeDevice(Device device, |
| 118 optional CloseDeviceCallback callback); |
| 119 |
| 120 // Claims an interface on the specified USB device. |
| 121 // |device|: The device on which the interface is to be claimed. |
| 122 // |interface|: The interface number to be claimed. |
| 123 // |callback|: The callback to invoke once the interface is claimed. |
| 124 static void claimInterface(Device device, long interfaceNumber, |
| 125 VoidCallback callback); |
| 126 |
| 127 // Releases a claim to an interface on the provided device. |
| 128 // |device|: The device on which the interface is to be released. |
| 129 // |interface|: The interface number to be released. |
| 130 // |callback|: The callback to invoke once the interface is released. |
| 131 static void releaseInterface(Device device, long interfaceNumber, |
| 132 VoidCallback callback); |
| 133 |
| 134 // Selects an alternate setting on a previously claimed interface on a |
| 135 // device. |
| 136 // |device|: The device on which the interface settings are to be set. |
| 137 // |interface|: The interface number to be set. |
| 138 // |alternateSetting|: The alternate setting to set. |
| 139 // |callback|: The callback to invoke once the interface setting is set. |
| 140 static void setInterfaceAlternateSetting(Device device, |
| 141 long interfaceNumber, long alternateSetting, VoidCallback callback); |
| 142 |
| 143 // Performs a control transfer on the specified device. See the |
| 144 // ControlTransferInfo structure for the parameters required to make a |
| 145 // transfer. |
| 146 // |device|: An open device to make the transfer on. |
| 147 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. |
| 148 // |callback|: Invoked once the transfer has completed. |
| 149 static void controlTransfer(Device device, |
| 150 ControlTransferInfo transferInfo, TransferCallback callback); |
| 151 |
| 152 // Performs a bulk transfer on the specified device. |
| 153 // |device|: An open device to make the transfer on. |
| 154 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
| 155 // |callback|: Invoked once the transfer has completed. |
| 156 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, |
| 157 TransferCallback callback); |
| 158 |
| 159 // Performs an interrupt transfer on the specified device. |
| 160 // |device|: An open device to make the transfer on. |
| 161 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
| 162 // |callback|: Invoked once the transfer has completed. |
| 163 static void interruptTransfer(Device device, |
| 164 GenericTransferInfo transferInfo, TransferCallback callback); |
| 165 |
| 166 // Performs an isochronous transfer on the specific device. |
| 167 // |device|: An open device to make the transfer on. |
| 168 // |transferInfo|: The parameters to the transfer. See |
| 169 // IsochronousTransferInfo. |
| 170 // |callback|: Invoked once the transfer has been completed. |
| 171 static void isochronousTransfer(Device device, |
| 172 IsochronousTransferInfo transferInfo, |
| 173 TransferCallback callback); |
| 174 }; |
| 175 }; |
| OLD | NEW |