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 // Returned by |getDevices| to identify a connected USB device. |
23 // device. They are returned by findDevice calls and have all of their | 23 // |
24 // fields populated before being returned. | 24 // |vendorId| and |produceId| will always be presented by |getDevices| calls |
25 // but they only serve as checksums. You can use a directionary with only | |
scheib
2013/08/26 18:27:57
dictionary
Bei Zhang
2013/08/26 20:21:31
Done.
| |
26 // the |device| field to identify the USB device. | |
27 // | |
25 dictionary Device { | 28 dictionary Device { |
29 // The id of the USB device. It remains unchanged until the device is | |
30 // unplugged. | |
31 long device; | |
32 long? vendorId; | |
33 long? productId; | |
34 }; | |
35 | |
36 // Returned by |openDevice| to be used for USB communication. Every time a | |
37 // device is opened, a new device handle is created. All device handles can | |
38 // work together if the device allows it. The device handle will be closed | |
39 // when the app is reloaded or suspended. | |
40 // | |
41 // |vendorId| and |produceId| will always be presented by |findDevices| and | |
42 // |openDevice| calls but they only serve as checksums. You can use a | |
43 // directionary with only the |handle| field to identify the device handle. | |
scheib
2013/08/26 18:27:57
dictionary
Bei Zhang
2013/08/26 20:21:31
Done.
| |
44 // | |
45 // When a device handle is closed by calling |closeDevice| or unplugging the | |
46 // device physically, all the interfaces it claimed will be released and all | |
47 // the transfers in progress will be canceled immediately. | |
48 dictionary DeviceHandle { | |
49 // The id of the device handle. | |
26 long handle; | 50 long handle; |
27 long vendorId; | 51 long? vendorId; |
28 long productId; | 52 long? productId; |
29 }; | 53 }; |
30 | 54 |
31 dictionary EndpointDescriptor { | 55 dictionary EndpointDescriptor { |
32 long address; | 56 long address; |
33 TransferType type; | 57 TransferType type; |
34 Direction direction; | 58 Direction direction; |
35 long maximumPacketSize; | 59 long maximumPacketSize; |
36 | 60 |
37 // Used for isochronous mode. | 61 // Used for isochronous mode. |
38 SynchronizationType? synchronization; | 62 SynchronizationType? synchronization; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 dictionary TransferResultInfo { | 138 dictionary TransferResultInfo { |
115 // A value of 0 indicates that the transfer was a success. Other values | 139 // A value of 0 indicates that the transfer was a success. Other values |
116 // indicate failure. | 140 // indicate failure. |
117 long? resultCode; | 141 long? resultCode; |
118 | 142 |
119 // If the transfer was an input transfer then this field will contain all | 143 // If the transfer was an input transfer then this field will contain all |
120 // of the input data requested. | 144 // of the input data requested. |
121 ArrayBuffer? data; | 145 ArrayBuffer? data; |
122 }; | 146 }; |
123 | 147 |
124 // FindDevicesOptions describes the properties of devices which are found and | 148 // Describes the properties of devices which are found via |getDevices| and |
125 // opened via findDevices. | 149 // |findDevices|. |
126 dictionary FindDevicesOptions { | 150 dictionary EnumerateDevicesOptions { |
151 long vendorId; | |
152 long productId; | |
153 long? interfaceId; | |
154 }; | |
155 | |
156 // Describes the properties of devices which are found via |getDevices| and | |
157 // |findDevices|. | |
158 dictionary EnumerateDevicesOptions2 { | |
scheib
2013/08/26 18:27:57
Why are two dictionaries with the same members nee
Bei Zhang
2013/08/26 20:21:31
ಠ_ಠ Who did this? I've no memory of doing it.
asargent_no_longer_on_chrome
2013/08/26 22:15:19
Do you mean you have no memory of writing this cod
| |
127 long vendorId; | 159 long vendorId; |
128 long productId; | 160 long productId; |
129 long? interfaceId; | 161 long? interfaceId; |
130 }; | 162 }; |
131 | 163 |
132 callback VoidCallback = void (); | 164 callback VoidCallback = void (); |
133 callback FindDevicesCallback = void (Device[] device); | 165 callback GetDevicesCallback = void (Device[] devices); |
166 callback OpenDeviceCallback = void (DeviceHandle handle); | |
167 callback FindDevicesCallback = void (DeviceHandle[] handles); | |
134 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); | 168 callback ListInterfacesCallback = void (InterfaceDescriptor[] descriptors); |
135 callback CloseDeviceCallback = void (); | 169 callback CloseDeviceCallback = void (); |
136 callback TransferCallback = void (TransferResultInfo info); | 170 callback TransferCallback = void (TransferResultInfo info); |
137 callback ResetDeviceCallback = void(boolean result); | 171 callback ResetDeviceCallback = void(boolean result); |
138 | 172 |
139 interface Functions { | 173 interface Functions { |
140 // Finds the first instance of the USB device specified by the vendorId/ | 174 // 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. | 175 // |options|: The properties to search for on target devices. |
145 // |callback|: Invoked with the opened Device on success. | 176 // |callback|: Invoked with a list of |Device|s on complete. |
146 static void findDevices(FindDevicesOptions options, | 177 static void getDevices(EnumerateDevicesOptions options, |
147 FindDevicesCallback callback); | 178 GetDevicesCallback callback); |
148 | 179 |
149 // Closes an open device instance. Invoking operations on a device after it | 180 // Opens a USB device retured by |getDevices|. |
scheib
2013/08/26 18:27:57
returned
Bei Zhang
2013/08/26 20:21:31
Done.
| |
181 // |device|: The device to open. | |
182 // |callback|: Invoked with the created DeviceHandle on complete. | |
183 static void openDevice(Device device, OpenDeviceCallback callback); | |
184 | |
185 // Finds USB devices specified by the vendorId/productId pair and, | |
186 // if permissions allow, opens them for use. | |
187 // | |
188 // If a device is failed to be opened, its handles will not be returned. | |
189 // | |
190 // Calling this method is equivalent to a |getDevices| followed by | |
191 // a series of |openDevice| calls, and returning all the successfully opened | |
192 // device handles. | |
193 // |options|: The properties to search for on target devices. | |
194 // |callback|: Invoked with the opened DeviceHandle on complete. | |
195 static void findDevices(EnumerateDevicesOptions2 options, | |
196 FindDevicesCallback callback); | |
197 | |
198 // Closes a device handle. Invoking operations on a device after it | |
150 // has been closed is a safe operation, but causes no action to be taken. | 199 // has been closed is a safe operation, but causes no action to be taken. |
151 // |device|: The device to close. | 200 // |handle|: The device handle to close. |
152 // |callback|: The callback to invoke once the device is closed. | 201 // |callback|: The callback to invoke once the device is closed. |
153 static void closeDevice(Device device, | 202 static void closeDevice(DeviceHandle handle, |
154 optional CloseDeviceCallback callback); | 203 optional CloseDeviceCallback callback); |
155 | 204 |
156 // Lists all the interfaces on the USB device. | 205 // Lists all the interfaces on the USB device. |
157 // |device|: The device from which the interfaces should be listed. | 206 // |handle|: The device from which the interfaces should be listed. |
158 // |callback|: The callback to invoke when the interfaces are enumerated. | 207 // |callback|: The callback to invoke when the interfaces are enumerated. |
159 static void listInterfaces(Device device, | 208 static void listInterfaces(DeviceHandle handle, |
160 ListInterfacesCallback callback); | 209 ListInterfacesCallback callback); |
161 | 210 |
162 // Claims an interface on the specified USB device. | 211 // Claims an interface on the specified USB device. |
163 // |device|: The device on which the interface is to be claimed. | 212 // Before you can transfer data with endpoints, you must claim their parent |
213 // interfaces. Only one device handle on the same host can claim each | |
214 // interface. If the interface is already claimed, this call will fail. | |
215 // | |
216 // You shall call releaseInterface when the interface is not needed anymore. | |
217 // | |
218 // |handle|: The device on which the interface is to be claimed. | |
164 // |interface|: The interface number to be claimed. | 219 // |interface|: The interface number to be claimed. |
165 // |callback|: The callback to invoke once the interface is claimed. | 220 // |callback|: The callback to invoke once the interface is claimed. |
166 static void claimInterface(Device device, long interfaceNumber, | 221 static void claimInterface(DeviceHandle handle, long interfaceNumber, |
167 VoidCallback callback); | 222 VoidCallback callback); |
168 | 223 |
169 // Releases a claim to an interface on the provided device. | 224 // Releases a claim to an interface on the provided device. |
170 // |device|: The device on which the interface is to be released. | 225 // |handle|: The device on which the interface is to be released. |
171 // |interface|: The interface number to be released. | 226 // |interface|: The interface number to be released. |
172 // |callback|: The callback to invoke once the interface is released. | 227 // |callback|: The callback to invoke once the interface is released. |
173 static void releaseInterface(Device device, long interfaceNumber, | 228 static void releaseInterface(DeviceHandle handle, long interfaceNumber, |
174 VoidCallback callback); | 229 VoidCallback callback); |
175 | 230 |
176 // Selects an alternate setting on a previously claimed interface on a | 231 // Selects an alternate setting on a previously claimed interface on a |
177 // device. | 232 // device. |
178 // |device|: The device on which the interface settings are to be set. | 233 // |handle|: The device on which the interface settings are to be set. |
179 // |interface|: The interface number to be set. | 234 // |interface|: The interface number to be set. |
180 // |alternateSetting|: The alternate setting to set. | 235 // |alternateSetting|: The alternate setting to set. |
181 // |callback|: The callback to invoke once the interface setting is set. | 236 // |callback|: The callback to invoke once the interface setting is set. |
182 static void setInterfaceAlternateSetting(Device device, | 237 static void setInterfaceAlternateSetting(DeviceHandle handle, |
183 long interfaceNumber, long alternateSetting, VoidCallback callback); | 238 long interfaceNumber, |
239 long alternateSetting, | |
240 VoidCallback callback); | |
184 | 241 |
185 // Performs a control transfer on the specified device. See the | 242 // Performs a control transfer on the specified device. See the |
186 // ControlTransferInfo structure for the parameters required to make a | 243 // ControlTransferInfo structure for the parameters required to make a |
187 // transfer. | 244 // transfer. |
188 // |device|: An open device to make the transfer on. | 245 // |
246 // Conceptually control transfer talks to the device itself. You do not need | |
247 // to claim interface 0 to perform a control transfer. | |
248 // | |
249 // |handle|: A device handle to make the transfer on. | |
189 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. | 250 // |transferInfo|: The parameters to the transfer. See ControlTransferInfo. |
190 // |callback|: Invoked once the transfer has completed. | 251 // |callback|: Invoked once the transfer has completed. |
191 static void controlTransfer(Device device, | 252 static void controlTransfer(DeviceHandle handle, |
192 ControlTransferInfo transferInfo, TransferCallback callback); | 253 ControlTransferInfo transferInfo, |
254 TransferCallback callback); | |
193 | 255 |
194 // Performs a bulk transfer on the specified device. | 256 // Performs a bulk transfer on the specified device. |
195 // |device|: An open device to make the transfer on. | 257 // |handle|: A device handle to make the transfer on. |
196 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | 258 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
197 // |callback|: Invoked once the transfer has completed. | 259 // |callback|: Invoked once the transfer has completed. |
198 static void bulkTransfer(Device device, GenericTransferInfo transferInfo, | 260 static void bulkTransfer(DeviceHandle handle, |
199 TransferCallback callback); | 261 GenericTransferInfo transferInfo, |
262 TransferCallback callback); | |
200 | 263 |
201 // Performs an interrupt transfer on the specified device. | 264 // Performs an interrupt transfer on the specified device. |
202 // |device|: An open device to make the transfer on. | 265 // |handle|: A device handle to make the transfer on. |
203 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. | 266 // |transferInfo|: The paramters to the transfer. See GenericTransferInfo. |
204 // |callback|: Invoked once the transfer has completed. | 267 // |callback|: Invoked once the transfer has completed. |
205 static void interruptTransfer(Device device, | 268 static void interruptTransfer(DeviceHandle handle, |
206 GenericTransferInfo transferInfo, TransferCallback callback); | 269 GenericTransferInfo transferInfo, |
270 TransferCallback callback); | |
207 | 271 |
208 // Performs an isochronous transfer on the specific device. | 272 // Performs an isochronous transfer on the specific device. |
209 // |device|: An open device to make the transfer on. | 273 // |handle|: A device handle to make the transfer on. |
210 // |transferInfo|: The parameters to the transfer. See | 274 // |transferInfo|: The parameters to the transfer. See |
211 // IsochronousTransferInfo. | 275 // IsochronousTransferInfo. |
212 // |callback|: Invoked once the transfer has been completed. | 276 // |callback|: Invoked once the transfer has been completed. |
213 static void isochronousTransfer(Device device, | 277 static void isochronousTransfer(DeviceHandle handle, |
214 IsochronousTransferInfo transferInfo, | 278 IsochronousTransferInfo transferInfo, |
215 TransferCallback callback); | 279 TransferCallback callback); |
216 | 280 |
217 // Try to reset the USB device and restore the previous status. | 281 // Tries to reset the USB device and restores it to the previous status. |
282 // If the reset fails, the given device handle will be closed and the USB | |
283 // device will appear to be disconected then reconnected. In that case you | |
284 // must call |getDevices| or |findDevices| again to acquire the device. | |
218 // | 285 // |
219 // If the reset fails, the given device will be closed and the USB device | 286 // |handle|: A device handle to reset. |
220 // will appear to be disconected and reconnected. | |
221 // You must call <code>findDevice</code> again to acquire the device. | |
222 // | |
223 // |device|: An opened device to reset. | |
224 // |callback|: Invoked once the device is reset with a boolean indicating | 287 // |callback|: Invoked once the device is reset with a boolean indicating |
225 // whether the reset is completed successfully. | 288 // whether the reset is completed successfully. |
226 static void resetDevice(Device device, | 289 static void resetDevice(DeviceHandle handle, |
227 ResetDeviceCallback callback); | 290 ResetDeviceCallback callback); |
228 }; | 291 }; |
229 }; | 292 }; |
OLD | NEW |