OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Use the <code>chrome.usb</code> API to interact with connected USB | 5 // Use the <code>chrome.usb</code> API to interact with connected USB |
6 // devices. This API provides access to USB operations from within the context | 6 // devices. This API provides access to USB operations from within the context |
7 // of an app. Using this API, apps can function as drivers for hardware devices. | 7 // of an app. Using this API, apps can function as drivers for hardware devices. |
8 namespace usb { | 8 namespace usb { |
9 | 9 |
10 // Direction, Recipient, RequestType, and TransferType all map to their | 10 // Direction, Recipient, RequestType, and TransferType all map to their |
11 // namesakes within the USB specification. | 11 // namesakes within the USB specification. |
12 enum Direction {in, out}; | 12 enum Direction {in, out}; |
13 enum Recipient {device, _interface, endpoint, other}; | 13 enum Recipient {device, _interface, endpoint, other}; |
14 enum RequestType {standard, class, vendor, reserved}; | 14 enum RequestType {standard, class, vendor, reserved}; |
15 enum TransferType {control, interrupt, isochronous, bulk}; | 15 enum TransferType {control, interrupt, isochronous, bulk}; |
16 | 16 |
17 // For isochronous mode, SynchronizationType and UsageType map to their | 17 // For isochronous mode, SynchronizationType and UsageType map to their |
18 // namesakes within the USB specification. | 18 // namesakes within the USB specification. |
19 enum SynchronizationType {asynchronous, adaptive, synchronous}; | 19 enum SynchronizationType {asynchronous, adaptive, synchronous}; |
20 enum UsageType {data, feedback, explicitFeedback}; | 20 enum UsageType {data, feedback, explicitFeedback}; |
21 | 21 |
22 // A Device encapsulates everything that is needed to communicate with a USB | 22 // A dictionary returned by |getDevices| to identify a connected device. |
asargent_no_longer_on_chrome
2013/08/22 21:06:13
optional suggestion: you can omit the "A dictionar
Bei Zhang
2013/08/23 22:52:00
Done.
| |
23 // device. They are returned by findDevice calls and have all of their | |
24 // fields populated before being returned. | |
25 dictionary Device { | 23 dictionary Device { |
24 // The id of the device. It remains unchanged until the device is unplugged. | |
25 long device; | |
26 long? vendorId; | |
27 long? productId; | |
28 }; | |
29 | |
30 // A dictionary returned by |openDevice| to be used for USB communication. | |
asargent_no_longer_on_chrome
2013/08/22 21:06:13
same suggestion about "a dictionary".
Also, it mi
Bei Zhang
2013/08/23 22:52:00
Done.
| |
31 dictionary DeviceHandle { | |
26 long handle; | 32 long handle; |
27 long vendorId; | 33 long? vendorId; |
28 long productId; | 34 long? productId; |
asargent_no_longer_on_chrome
2013/08/22 21:06:13
Previously calls to findDevices would return a dic
Bei Zhang
2013/08/23 22:52:00
Done. Made a comment to explain it.
On 2013/08/22
| |
29 }; | 35 }; |
30 | 36 |
31 dictionary EndpointDescriptor { | 37 dictionary EndpointDescriptor { |
32 long address; | 38 long address; |
33 TransferType type; | 39 TransferType type; |
34 Direction direction; | 40 Direction direction; |
35 long maximumPacketSize; | 41 long maximumPacketSize; |
36 | 42 |
37 // Used for isochronous mode. | 43 // Used for isochronous mode. |
38 SynchronizationType? synchronization; | 44 SynchronizationType? synchronization; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 dictionary TransferResultInfo { | 120 dictionary TransferResultInfo { |
115 // A value of 0 indicates that the transfer was a success. Other values | 121 // A value of 0 indicates that the transfer was a success. Other values |
116 // indicate failure. | 122 // indicate failure. |
117 long? resultCode; | 123 long? resultCode; |
118 | 124 |
119 // If the transfer was an input transfer then this field will contain all | 125 // If the transfer was an input transfer then this field will contain all |
120 // of the input data requested. | 126 // of the input data requested. |
121 ArrayBuffer? data; | 127 ArrayBuffer? data; |
122 }; | 128 }; |
123 | 129 |
124 // FindDevicesOptions describes the properties of devices which are found and | 130 // Describes the properties of devices which are found via |getDevices| and |
125 // opened via findDevices. | 131 // |findDevices|. |
126 dictionary FindDevicesOptions { | 132 dictionary EnumerateDevicesOptions { |
133 long vendorId; | |
134 long productId; | |
135 long? interfaceId; | |
136 }; | |
137 | |
138 // Describes the properties of devices which are found via |getDevices| and | |
139 // |findDevices|. | |
140 dictionary EnumerateDevicesOptions2 { | |
127 long vendorId; | 141 long vendorId; |
128 long productId; | 142 long productId; |
129 long? interfaceId; | 143 long? interfaceId; |
130 }; | 144 }; |
131 | 145 |
132 callback VoidCallback = void (); | 146 callback VoidCallback = void (); |
133 callback FindDevicesCallback = void (Device[] device); | 147 callback GetDevicesCallback = void (Device[] device); |
148 callback OpenDeviceCallback = void (DeviceHandle device); | |
149 callback FindDevicesCallback = void (DeviceHandle[] device); | |
134 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); | 150 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); |
135 callback CloseDeviceCallback = void (); | 151 callback CloseDeviceCallback = void (); |
136 callback TransferCallback = void (TransferResultInfo info); | 152 callback TransferCallback = void (TransferResultInfo info); |
137 callback ResetDeviceCallback = void(boolean result); | 153 callback ResetDeviceCallback = void(boolean result); |
138 | 154 |
139 interface Functions { | 155 interface Functions { |
140 // Finds the first instance of the USB device specified by the vendorId/ | 156 // Lists USB devices specified by vendorId/productId pair. |
141 // productId pair and, if permissions allow, opens it for use. | |
142 // Upon successfully opening a device the callback is invoked with a | |
143 // populated Device object. On failure, the callback is invoked with null. | |
144 // |options|: The properties to search for on target devices. | 157 // |options|: The properties to search for on target devices. |
145 // |callback|: Invoked with the opened Device on success. | 158 // |callback|: Invoked with the opened DeviceHandle on complete. |
146 static void findDevices(FindDevicesOptions options, | 159 static void getDevices(EnumerateDevicesOptions options, |
147 FindDevicesCallback callback); | 160 GetDevicesCallback callback); |
161 | |
162 // Opens a USB device retured by getDevices. | |
163 // |callback|: Invoked with the opened DeviceHandle on complete. | |
164 static void openDevice(Device device, OpenDeviceCallback callback); | |
165 | |
166 // Finds USB devices specified by the vendorId/productId pair and, | |
167 // if permissions allow, opens it for use. | |
168 // Only opened device handles are returned. | |
169 // Calling this method is equivalent to a |getDevices| followed by | |
170 // a series of |getDevices| calls. | |
asargent_no_longer_on_chrome
2013/08/22 21:06:13
do you mean "a series of |openDevice| calls"?
Bei Zhang
2013/08/23 22:52:00
Done.
| |
171 // |options|: The properties to search for on target devices. | |
172 // |callback|: Invoked with the opened DeviceHandle on complete. | |
173 static void findDevices(EnumerateDevicesOptions2 options, | |
174 FindDevicesCallback callback); | |
asargent_no_longer_on_chrome
2013/08/22 21:06:13
Do we still want to have developers using findDevi
Bei Zhang
2013/08/23 22:52:00
This function might be handy to some developers. S
asargent_no_longer_on_chrome
2013/08/23 23:57:01
Ok
| |
148 | 175 |
149 // Closes an open device instance. Invoking operations on a device after it | 176 // Closes an open device instance. Invoking operations on a device after it |
150 // has been closed is a safe operation, but causes no action to be taken. | 177 // has been closed is a safe operation, but causes no action to be taken. |
151 // |device|: The device to close. | 178 // |device|: The device to close. |
152 // |callback|: The callback to invoke once the device is closed. | 179 // |callback|: The callback to invoke once the device is closed. |
153 static void closeDevice(Device device, | 180 static void closeDevice(DeviceHandle device, |
154 optional CloseDeviceCallback callback); | 181 optional CloseDeviceCallback callback); |
155 | 182 |
156 // Lists all the interfaces on the USB device. | 183 // Lists all the interfaces on the USB device. |
157 // |device|: The device from which the interfaces should be listed. | 184 // |device|: The device from which the interfaces should be listed. |
158 // |callback|: The callback to invoke when the interfaces are enumerated. | 185 // |callback|: The callback to invoke when the interfaces are enumerated. |
159 static void listInterfaces(Device device, | 186 static void listInterfaces(DeviceHandle device, |
160 ListInterfacesCallback callback); | 187 ListInterfacesCallback callback); |
161 | 188 |
162 // Claims an interface on the specified USB device. | 189 // Claims an interface on the specified USB device. |
163 // |device|: The device on which the interface is to be claimed. | 190 // |device|: The device on which the interface is to be claimed. |
164 // |interface|: The interface number to be claimed. | 191 // |interface|: The interface number to be claimed. |
165 // |callback|: The callback to invoke once the interface is claimed. | 192 // |callback|: The callback to invoke once the interface is claimed. |
166 static void claimInterface(Device device, long interfaceNumber, | 193 static void claimInterface(DeviceHandle device, long interfaceNumber, |
167 VoidCallback callback); | 194 VoidCallback callback); |
168 | 195 |
169 // Releases a claim to an interface on the provided device. | 196 // Releases a claim to an interface on the provided device. |
170 // |device|: The device on which the interface is to be released. | 197 // |device|: The device on which the interface is to be released. |
171 // |interface|: The interface number to be released. | 198 // |interface|: The interface number to be released. |
172 // |callback|: The callback to invoke once the interface is released. | 199 // |callback|: The callback to invoke once the interface is released. |
173 static void releaseInterface(Device device, long interfaceNumber, | 200 static void releaseInterface(DeviceHandle device, long interfaceNumber, |
174 VoidCallback callback); | 201 VoidCallback callback); |
175 | 202 |
176 // Selects an alternate setting on a previously claimed interface on a | 203 // Selects an alternate setting on a previously claimed interface on a |
177 // device. | 204 // device. |
178 // |device|: The device on which the interface settings are to be set. | 205 // |device|: The device on which the interface settings are to be set. |
179 // |interface|: The interface number to be set. | 206 // |interface|: The interface number to be set. |
180 // |alternateSetting|: The alternate setting to set. | 207 // |alternateSetting|: The alternate setting to set. |
181 // |callback|: The callback to invoke once the interface setting is set. | 208 // |callback|: The callback to invoke once the interface setting is set. |
182 static void setInterfaceAlternateSetting(Device device, | 209 static void setInterfaceAlternateSetting(DeviceHandle device, |
183 long interfaceNumber, long alternateSetting, VoidCallback callback); | 210 long interfaceNumber, |
211 long alternateSetting, | |
212 VoidCallback callback); | |
184 | 213 |
185 // Performs a control transfer on the specified device. See the | 214 // Performs a control transfer on the specified device. See the |
186 // ControlTransferInfo structure for the parameters required to make a | 215 // ControlTransferInfo structure for the parameters required to make a |
187 // transfer. | 216 // transfer. |
188 // |device|: An open device to make the transfer on. | 217 // |device|: An open device to make the transfer on. |
189 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. | 218 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. |
190 // |callback|: Invoked once the transfer has completed. | 219 // |callback|: Invoked once the transfer has completed. |
191 static void controlTransfer(Device device, | 220 static void controlTransfer(DeviceHandle device, |
192 ControlTransferInfo transferInfo, TransferCallback callback); | 221 ControlTransferInfo transferInfo, |
222 TransferCallback callback); | |
193 | 223 |
194 // Performs a bulk transfer on the specified device. | 224 // Performs a bulk transfer on the specified device. |
195 // |device|: An open device to make the transfer on. | 225 // |device|: An open device to make the transfer on. |
196 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | 226 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
197 // |callback|: Invoked once the transfer has completed. | 227 // |callback|: Invoked once the transfer has completed. |
198 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, | 228 static void bulkTransfer(DeviceHandle device, |
199 TransferCallback callback); | 229 GenericTransferInfo transferInfo, |
230 TransferCallback callback); | |
200 | 231 |
201 // Performs an interrupt transfer on the specified device. | 232 // Performs an interrupt transfer on the specified device. |
202 // |device|: An open device to make the transfer on. | 233 // |device|: An open device to make the transfer on. |
203 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | 234 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
204 // |callback|: Invoked once the transfer has completed. | 235 // |callback|: Invoked once the transfer has completed. |
205 static void interruptTransfer(Device device, | 236 static void interruptTransfer(DeviceHandle device, |
206 GenericTransferInfo transferInfo, TransferCallback callback); | 237 GenericTransferInfo transferInfo, |
238 TransferCallback callback); | |
207 | 239 |
208 // Performs an isochronous transfer on the specific device. | 240 // Performs an isochronous transfer on the specific device. |
209 // |device|: An open device to make the transfer on. | 241 // |device|: An open device to make the transfer on. |
210 // |transferInfo|: The parameters to the transfer. See | 242 // |transferInfo|: The parameters to the transfer. See |
211 // IsochronousTransferInfo. | 243 // IsochronousTransferInfo. |
212 // |callback|: Invoked once the transfer has been completed. | 244 // |callback|: Invoked once the transfer has been completed. |
213 static void isochronousTransfer(Device device, | 245 static void isochronousTransfer(DeviceHandle device, |
214 IsochronousTransferInfo transferInfo, | 246 IsochronousTransferInfo transferInfo, |
215 TransferCallback callback); | 247 TransferCallback callback); |
216 | 248 |
217 // Try to reset the USB device and restore the previous status. | 249 // Tries to reset the USB device and restore the previous status. |
218 // | |
219 // If the reset fails, the given device will be closed and the USB device | 250 // If the reset fails, the given device will be closed and the USB device |
220 // will appear to be disconected and reconnected. | 251 // will appear to be disconected and reconnected. That case you must call |
221 // You must call <code>findDevice</code> again to acquire the device. | 252 // |getDevices| or |findDevices| again to acquire the device. |
222 // | 253 // |
223 // |device|: An opened device to reset. | 254 // |device|: An opened device to reset. |
224 // |callback|: Invoked once the device is reset with a boolean indicating | 255 // |callback|: Invoked once the device is reset with a boolean indicating |
225 // whether the reset is completed successfully. | 256 // whether the reset is completed successfully. |
226 static void resetDevice(Device device, | 257 static void resetDevice(DeviceHandle device, |
227 ResetDeviceCallback callback); | 258 ResetDeviceCallback callback); |
228 }; | 259 }; |
229 }; | 260 }; |
OLD | NEW |