1unit libusb; 2 3{$IFDEF FPC} 4{$mode objfpc} 5{$PACKRECORDS C} 6{$ENDIF} 7 8interface 9{$ifdef MSWINDOWS} 10uses windows; 11{$else} 12uses ctypes,sockets,unixtype; 13{$endif} 14 15 16 17 18 { 19 * Public libusb header file 20 * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com> 21 * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org> 22 * Copyright © 2012 Pete Batard <pete@akeo.ie> 23 * Copyright © 2012 Nathan Hjelm <hjelmn@cs.unm.edu> 24 * For more information, please visit: http://libusb.info 25 * 26 * This library is free software; you can redistribute it and/or 27 * modify it under the terms of the GNU Lesser General Public 28 * License as published by the Free Software Foundation; either 29 * version 2.1 of the License, or (at your option) any later version. 30 * 31 * This library is distributed in the hope that it will be useful, 32 * but WITHOUT ANY WARRANTY; without even the implied warranty of 33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 34 * Lesser General Public License for more details. 35 * 36 * You should have received a copy of the GNU Lesser General Public 37 * License along with this library; if not, write to the Free Software 38 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 39 } 40{$ifndef LIBUSB_H} 41{$define LIBUSB_H} 42{$ifdef MSWINDOWS} 43 44{$ifdef WIN64} 45 type 46 ssize_t = int64; 47{$else} 48 type 49 ssize_t = longint; 50{$endif WIN64} 51 ptimeval = pointer; 52 53{$else} 54 type 55 ssize_t = ptrint; 56{$endif MSWINDOWS} 57 58 59 type 60 puint8_t = ^uint8_t; 61 uint8_t = byte; 62 63 uint16_t = word; 64 65 uint32_t = dword; 66 67{* \def LIBUSB_CALL 68 * \ingroup misc 69 * libusb's Windows calling convention. 70 * 71 * Under Windows, the selection of available compilers and configurations 72 * means that, unlike other platforms, there is not <em>one true calling 73 * convention</em> (calling convention: the manner in which parameters are 74 * passed to functions in the generated assembly code). 75 * 76 * Matching the Windows API itself, libusb uses the WINAPI convention (which 77 * translates to the <tt>stdcall</tt> convention) and guarantees that the 78 * library is compiled in this way. The public header file also includes 79 * appropriate annotations so that your own software will use the right 80 * convention, even if another convention is being used by default within 81 * your codebase. 82 * 83 * The one consideration that you must apply in your software is to mark 84 * all functions which you use as libusb callbacks with this LIBUSB_CALL 85 * annotation, so that they too get compiled for the correct calling 86 * convention. 87 * 88 * On non-Windows operating systems, this macro is defined as nothing. This 89 * means that you can apply it to your code without worrying about 90 * cross-platform compatibility. 91 } 92{ LIBUSB_CALL must be defined on both definition and declaration of libusb 93 * functions. You'd think that declaration would be enough, but cygwin will 94 * complain about conflicting types unless both are marked this way. 95 * The placement of this macro is important too; it must appear after the 96 * return type, before the function name. See internal documentation for 97 * API_EXPORTED. 98 } 99{$macro on} 100 101{$ifdef MSWINDOWS} 102 103const libusb1='libusb-1.0.dll'; 104{$define LIBUSB_CALL := WINAPI } 105{$else} 106const libusb1='libusb-1.0.so'; 107{$define LIBUSB_CALL := cdecl } 108{$endif} 109 110{* \def LIBUSB_API_VERSION 111 * \ingroup misc 112 * libusb's API version. 113 * 114 * Since version 1.0.13, to help with feature detection, libusb defines 115 * a LIBUSB_API_VERSION macro that gets increased every time there is a 116 * significant change to the API, such as the introduction of a new call, 117 * the definition of a new macro/enum member, or any other element that 118 * libusb applications may want to detect at compilation time. 119 * 120 * The macro is typically used in an application as follows: 121 * \code 122 * #if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01001234) 123 * // Use one of the newer features from the libusb API 124 * #endif 125 * \endcode 126 * 127 * Internally, LIBUSB_API_VERSION is defined as follows: 128 * (libusb major << 24) | (libusb minor << 16) | (16 bit incremental) 129 } 130 131 const 132 LIBUSB_API_VERSION = $01000104; 133 { The following is kept for compatibility, but will be deprecated in the future } 134 LIBUSBX_API_VERSION = LIBUSB_API_VERSION; 135{ C++ extern C conditionnal removed } 136{* 137 * \ingroup misc 138 * Convert a 16-bit value from host-endian to little-endian format. On 139 * little endian systems, this function does nothing. On big endian systems, 140 * the bytes are swapped. 141 * \param x the host-endian value to convert 142 * \returns the value in little-endian byte order 143 } 144 145function libusb_cpu_to_le16(const x:uint16_t):uint16_t; 146 147 148 {* \def libusb_le16_to_cpu 149 * \ingroup misc 150 * Convert a 16-bit value from little-endian to host-endian format. On 151 * little endian systems, this function does nothing. On big endian systems, 152 * the bytes are swapped. 153 * \param x the little-endian value to convert 154 * \returns the value in host-endian byte order 155 } 156 157function libusb_le16_to_cpu(const x:uint16_t):uint16_t; 158 159{ standard USB stuff } 160{* \ingroup desc 161 * Device and/or Interface Class codes } 162type 163 libusb_class_code = ( 164 {* In the context of a \ref libusb_device_descriptor "device descriptor", 165 * this bDeviceClass value indicates that each interface specifies its 166 * own class information and all interfaces operate independently. 167 } 168 LIBUSB_CLASS_PER_INTERFACE = 0, 169 {* Audio class } 170 LIBUSB_CLASS_AUDIO = 1, 171 {* Communications class } 172 LIBUSB_CLASS_COMM = 2, 173 {* Human Interface Device class } 174 LIBUSB_CLASS_HID = 3, 175 {* Physical } 176 LIBUSB_CLASS_PHYSICAL = 5, 177 {* Printer class } 178 LIBUSB_CLASS_PRINTER = 7, 179 {* Image class } { legacy name from libusb-0.1 usb.h } 180 LIBUSB_CLASS_PTP = 6,LIBUSB_CLASS_IMAGE = 6, 181 {* Mass storage class } 182 LIBUSB_CLASS_MASS_STORAGE = 8, 183 {* Hub class } 184 LIBUSB_CLASS_HUB = 9, 185 {* Data class } 186 LIBUSB_CLASS_DATA = 10, 187 {* Smart Card } 188 LIBUSB_CLASS_SMART_CARD = $0b, 189 {* Content Security } 190 LIBUSB_CLASS_CONTENT_SECURITY = $0d, 191 {* Video } 192 LIBUSB_CLASS_VIDEO = $0e, 193 {* Personal Healthcare } 194 LIBUSB_CLASS_PERSONAL_HEALTHCARE = $0f, 195 {* Diagnostic Device } 196 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = $dc, 197 {* Wireless class } 198 LIBUSB_CLASS_WIRELESS = $e0, 199 {* Application class } 200 LIBUSB_CLASS_APPLICATION = $fe, 201 {* Class is vendor-specific } 202 LIBUSB_CLASS_VENDOR_SPEC = $ff); 203 204 {* \ingroup desc 205 * Descriptor types as defined by the USB specification. } 206 libusb_descriptor_type = ( 207 {* Device descriptor. See libusb_device_descriptor. } 208 LIBUSB_DT_DEVICE = $01, 209 {* Configuration descriptor. See libusb_config_descriptor. } 210 LIBUSB_DT_CONFIG = $02, 211 {* String descriptor } 212 LIBUSB_DT_STRING = $03, 213 {* Interface descriptor. See libusb_interface_descriptor. } 214 LIBUSB_DT_INTERFACE = $04, 215 {* Endpoint descriptor. See libusb_endpoint_descriptor. } 216 LIBUSB_DT_ENDPOINT = $05, 217 {* BOS descriptor } 218 LIBUSB_DT_BOS = $0f, 219 {* Device Capability descriptor } 220 LIBUSB_DT_DEVICE_CAPABILITY = $10, 221 {* HID descriptor } 222 LIBUSB_DT_HID = $21, 223 {* HID report descriptor } 224 LIBUSB_DT_REPORT = $22, 225 {* Physical descriptor } 226 LIBUSB_DT_PHYSICAL = $23, 227 {* Hub descriptor } 228 LIBUSB_DT_HUB = $29, 229 {* SuperSpeed Hub descriptor } 230 LIBUSB_DT_SUPERSPEED_HUB = $2a, 231 {* SuperSpeed Endpoint Companion descriptor } 232 LIBUSB_DT_SS_ENDPOINT_COMPANION = $30 233 ); 234 235 { Descriptor sizes per descriptor type } 236 237 const 238 LIBUSB_DT_DEVICE_SIZE = 18; 239 LIBUSB_DT_CONFIG_SIZE = 9; 240 LIBUSB_DT_INTERFACE_SIZE = 9; 241 LIBUSB_DT_ENDPOINT_SIZE = 7; 242 { Audio extension } 243 LIBUSB_DT_ENDPOINT_AUDIO_SIZE = 9; 244 LIBUSB_DT_HUB_NONVAR_SIZE = 7; 245 LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE = 6; 246 LIBUSB_DT_BOS_SIZE = 5; 247 LIBUSB_DT_DEVICE_CAPABILITY_SIZE = 3; 248 { BOS descriptor sizes } 249 LIBUSB_BT_USB_2_0_EXTENSION_SIZE = 7; 250 LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE = 10; 251 LIBUSB_BT_CONTAINER_ID_SIZE = 20; 252 { We unwrap the BOS => define its max size } 253 254 { was #define dname def_expr } 255 256 { was #define dname def_expr } 257 258const LIBUSB_DT_BOS_MAX_SIZE = 259 ((LIBUSB_DT_BOS_SIZE) + 260 (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) + 261 (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) + 262 (LIBUSB_BT_CONTAINER_ID_SIZE)); 263 264{ in bEndpointAddress } 265const 266 LIBUSB_ENDPOINT_ADDRESS_MASK = $0f; 267 LIBUSB_ENDPOINT_DIR_MASK = $80; 268 269{* \ingroup desc 270 * Endpoint direction. Values for bit 7 of the 271 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme. 272 } 273type 274 libusb_endpoint_direction = ( 275 {* In: device-to-host } 276 LIBUSB_ENDPOINT_IN = $80, 277 {* Out: host-to-device } 278 LIBUSB_ENDPOINT_OUT = $00 279 ); 280 281 { in bmAttributes } 282 283const 284 LIBUSB_TRANSFER_TYPE_MASK = $03; 285 286{* \ingroup desc 287 * Endpoint transfer type. Values for bits 0:1 of the 288 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field. 289 } 290type 291 libusb_transfer_type = ( 292 {* Control endpoint } 293 LIBUSB_TRANSFER_TYPE_CONTROL = 0, 294 {* Isochronous endpoint } 295 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1, 296 {* Bulk endpoint } 297 LIBUSB_TRANSFER_TYPE_BULK = 2, 298 {* Interrupt endpoint } 299 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3, 300 {* Stream endpoint } 301 LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4 302 ); 303 304 {* \ingroup misc 305 * Standard requests, as defined in table 9-5 of the USB 3.0 specifications } 306 libusb_standard_request = ( 307 {* Request status of the specific recipient } 308 LIBUSB_REQUEST_GET_STATUS = $00, 309 {* Clear or disable a specific feature } 310 LIBUSB_REQUEST_CLEAR_FEATURE = $01, 311 { 0x02 is reserved } 312 {* Set or enable a specific feature } 313 LIBUSB_REQUEST_SET_FEATURE = $03, 314 { 0x04 is reserved } 315 {* Set device address for all future accesses } 316 LIBUSB_REQUEST_SET_ADDRESS = $05, 317 {* Get the specified descriptor } 318 LIBUSB_REQUEST_GET_DESCRIPTOR = $06, 319 {* Used to update existing descriptors or add new descriptors } 320 LIBUSB_REQUEST_SET_DESCRIPTOR = $07, 321 {* Get the current device configuration value } 322 LIBUSB_REQUEST_GET_CONFIGURATION = $08, 323 {* Set device configuration } 324 LIBUSB_REQUEST_SET_CONFIGURATION = $09, 325 {* Return the selected alternate setting for the specified interface } 326 LIBUSB_REQUEST_GET_INTERFACE = $0A, 327 {* Select an alternate interface for the specified interface } 328 LIBUSB_REQUEST_SET_INTERFACE = $0B, 329 {* Set then report an endpoint's synchronization frame } 330 LIBUSB_REQUEST_SYNCH_FRAME = $0C, 331 {* Sets both the U1 and U2 Exit Latency } 332 LIBUSB_REQUEST_SET_SEL = $30, 333 {* Delay from the time a host transmits a packet to the time it is 334 * received by the device. } 335 LIBUSB_SET_ISOCH_DELAY = $31); 336 337{* \ingroup misc 338 * Request type bits of the 339 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control 340 * transfers. } 341 libusb_request_type = ( 342 {* Standard } 343 LIBUSB_REQUEST_TYPE_STANDARD = $00 shl 5, 344 {* Class } 345 LIBUSB_REQUEST_TYPE_CLASS = $01 shl 5, 346 {* Vendor } 347 LIBUSB_REQUEST_TYPE_VENDOR = $02 shl 5, 348 {* Reserved } 349 LIBUSB_REQUEST_TYPE_RESERVED = $03 shl 5 350 ); 351 352{* \ingroup misc 353 * Recipient bits of the 354 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control 355 * transfers. Values 4 through 31 are reserved. } 356 libusb_request_recipient = ( 357 {* Device } 358 LIBUSB_RECIPIENT_DEVICE = $00, 359 {* Interface } 360 LIBUSB_RECIPIENT_INTERFACE = $01, 361 {* Endpoint } 362 LIBUSB_RECIPIENT_ENDPOINT = $02, 363 {* Other } 364 LIBUSB_RECIPIENT_OTHER = $03 365 ); 366 367 368const 369 LIBUSB_ISO_SYNC_TYPE_MASK = $0C; 370 {* \ingroup desc 371 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the 372 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in 373 * libusb_endpoint_descriptor. 374 } 375type 376 libusb_iso_sync_type = ( 377 {* No synchronization } 378 LIBUSB_ISO_SYNC_TYPE_NONE = 0, 379 {* Asynchronous } 380 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1, 381 {* Adaptive } 382 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2, 383 {* Synchronous } 384 LIBUSB_ISO_SYNC_TYPE_SYNC = 3); 385 386 387const 388 LIBUSB_ISO_USAGE_TYPE_MASK = $30; 389 {* \ingroup desc 390 * Usage type for isochronous endpoints. Values for bits 4:5 of the 391 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in 392 * libusb_endpoint_descriptor. 393 } 394type 395 libusb_iso_usage_type = ( 396 {* Data endpoint } 397 LIBUSB_ISO_USAGE_TYPE_DATA = 0, 398 {* Feedback endpoint } 399 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1, 400 {* Implicit feedback Data endpoint } 401 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2 402 ); 403 404 {* \ingroup desc 405 * A structure representing the standard USB device descriptor. This 406 * descriptor is documented in section 9.6.1 of the USB 3.0 specification. 407 * All multiple-byte fields are represented in host-endian format. 408 } 409 {* Size of this descriptor (in bytes) } 410 {* Descriptor type. Will have value 411 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this 412 * context. } 413 {* USB specification release number in binary-coded decimal. A value of 414 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. } 415 {* USB-IF class code for the device. See \ref libusb_class_code. } 416 {* USB-IF subclass code for the device, qualified by the bDeviceClass 417 * value } 418 {* USB-IF protocol code for the device, qualified by the bDeviceClass and 419 * bDeviceSubClass values } 420 {* Maximum packet size for endpoint 0 } 421 {* USB-IF vendor ID } 422 {* USB-IF product ID } 423 {* Device release number in binary-coded decimal } 424 {* Index of string descriptor describing manufacturer } 425 {* Index of string descriptor describing product } 426 {* Index of string descriptor containing device serial number } 427 {* Number of possible configurations } 428 libusb_device_descriptor = record 429 bLength : uint8_t; 430 bDescriptorType : uint8_t; 431 bcdUSB : uint16_t; 432 bDeviceClass : uint8_t; 433 bDeviceSubClass : uint8_t; 434 bDeviceProtocol : uint8_t; 435 bMaxPacketSize0 : uint8_t; 436 idVendor : uint16_t; 437 idProduct : uint16_t; 438 bcdDevice : uint16_t; 439 iManufacturer : uint8_t; 440 iProduct : uint8_t; 441 iSerialNumber : uint8_t; 442 bNumConfigurations : uint8_t; 443 end; 444 445 {* \ingroup desc 446 * A structure representing the standard USB endpoint descriptor. This 447 * descriptor is documented in section 9.6.6 of the USB 3.0 specification. 448 * All multiple-byte fields are represented in host-endian format. 449 } 450 {* Size of this descriptor (in bytes) } 451 {* Descriptor type. Will have value 452 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in 453 * this context. } 454 {* The address of the endpoint described by this descriptor. Bits 0:3 are 455 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction, 456 * see \ref libusb_endpoint_direction. 457 } 458 {* Attributes which apply to the endpoint when it is configured using 459 * the bConfigurationValue. Bits 0:1 determine the transfer type and 460 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for 461 * isochronous endpoints and correspond to \ref libusb_iso_sync_type. 462 * Bits 4:5 are also only used for isochronous endpoints and correspond to 463 * \ref libusb_iso_usage_type. Bits 6:7 are reserved. 464 } 465 {* Maximum packet size this endpoint is capable of sending/receiving. } 466 {* Interval for polling endpoint for data transfers. } 467 {* For audio devices only: the rate at which synchronization feedback 468 * is provided. } 469 {* For audio devices only: the address if the synch endpoint } 470 {* Extra descriptors. If libusb encounters unknown endpoint descriptors, 471 * it will store them here, should you wish to parse them. } 472(* Const before type ignored *) 473 {* Length of the extra descriptors, in bytes. } 474 plibusb_endpoint_descriptor = ^libusb_endpoint_descriptor; 475 libusb_endpoint_descriptor = record 476 bLength : uint8_t; 477 bDescriptorType : uint8_t; 478 bEndpointAddress : uint8_t; 479 bmAttributes : uint8_t; 480 wMaxPacketSize : uint16_t; 481 bInterval : uint8_t; 482 bRefresh : uint8_t; 483 bSynchAddress : uint8_t; 484 extra : ^byte; 485 extra_length : longint; 486 end; 487 488 {* \ingroup desc 489 * A structure representing the standard USB interface descriptor. This 490 * descriptor is documented in section 9.6.5 of the USB 3.0 specification. 491 * All multiple-byte fields are represented in host-endian format. 492 } 493 {* Size of this descriptor (in bytes) } 494 {* Descriptor type. Will have value 495 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE 496 * in this context. } 497 {* Number of this interface } 498 {* Value used to select this alternate setting for this interface } 499 {* Number of endpoints used by this interface (excluding the control 500 * endpoint). } 501 {* USB-IF class code for this interface. See \ref libusb_class_code. } 502 {* USB-IF subclass code for this interface, qualified by the 503 * bInterfaceClass value } 504 {* USB-IF protocol code for this interface, qualified by the 505 * bInterfaceClass and bInterfaceSubClass values } 506 {* Index of string descriptor describing this interface } 507 {* Array of endpoint descriptors. This length of this array is determined 508 * by the bNumEndpoints field. } 509(* Const before type ignored *) 510 {* Extra descriptors. If libusb encounters unknown interface descriptors, 511 * it will store them here, should you wish to parse them. } 512(* Const before type ignored *) 513 {* Length of the extra descriptors, in bytes. } 514 libusb_interface_descriptor = record 515 bLength : uint8_t; 516 bDescriptorType : uint8_t; 517 bInterfaceNumber : uint8_t; 518 bAlternateSetting : uint8_t; 519 bNumEndpoints : uint8_t; 520 bInterfaceClass : uint8_t; 521 bInterfaceSubClass : uint8_t; 522 bInterfaceProtocol : uint8_t; 523 iInterface : uint8_t; 524 endpoint : ^libusb_endpoint_descriptor; 525 extra : ^byte; 526 extra_length : longint; 527 end; 528 529 {* \ingroup desc 530 * A collection of alternate settings for a particular USB interface. 531 } 532 {* Array of interface descriptors. The length of this array is determined 533 * by the num_altsetting field. } 534(* Const before type ignored *) 535 {* The number of alternate settings that belong to this interface } 536 libusb_interface = record 537 altsetting : ^libusb_interface_descriptor; 538 num_altsetting : longint; 539 end; 540 541 {* \ingroup desc 542 * A structure representing the standard USB configuration descriptor. This 543 * descriptor is documented in section 9.6.3 of the USB 3.0 specification. 544 * All multiple-byte fields are represented in host-endian format. 545 } 546 {* Size of this descriptor (in bytes) } 547 {* Descriptor type. Will have value 548 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG 549 * in this context. } 550 {* Total length of data returned for this configuration } 551 {* Number of interfaces supported by this configuration } 552 {* Identifier value for this configuration } 553 {* Index of string descriptor describing this configuration } 554 {* Configuration characteristics } 555 {* Maximum power consumption of the USB device from this bus in this 556 * configuration when the device is fully operation. Expressed in units 557 * of 2 mA when the device is operating in high-speed mode and in units 558 * of 8 mA when the device is operating in super-speed mode. } 559 {* Array of interfaces supported by this configuration. The length of 560 * this array is determined by the bNumInterfaces field. } 561(* Const before type ignored *) 562 {* Extra descriptors. If libusb encounters unknown configuration 563 * descriptors, it will store them here, should you wish to parse them. } 564(* Const before type ignored *) 565 {* Length of the extra descriptors, in bytes. } 566 plibusb_config_descriptor=^libusb_config_descriptor; 567 libusb_config_descriptor = record 568 bLength : uint8_t; 569 bDescriptorType : uint8_t; 570 wTotalLength : uint16_t; 571 bNumInterfaces : uint8_t; 572 bConfigurationValue : uint8_t; 573 iConfiguration : uint8_t; 574 bmAttributes : uint8_t; 575 MaxPower : uint8_t; 576 interface_ : ^libusb_interface; 577 extra : ^byte; 578 extra_length : longint; 579 end; 580 581 {* \ingroup desc 582 * A structure representing the superspeed endpoint companion 583 * descriptor. This descriptor is documented in section 9.6.7 of 584 * the USB 3.0 specification. All multiple-byte fields are represented in 585 * host-endian format. 586 } 587 {* Size of this descriptor (in bytes) } 588 {* Descriptor type. Will have value 589 * \ref libusb_descriptor_type::LIBUSB_DT_SS_ENDPOINT_COMPANION in 590 * this context. } 591 {* The maximum number of packets the endpoint can send or 592 * recieve as part of a burst. } 593 {* In bulk EP: bits 4:0 represents the maximum number of 594 * streams the EP supports. In isochronous EP: bits 1:0 595 * represents the Mult - a zero based value that determines 596 * the maximum number of packets within a service interval } 597 {* The total number of bytes this EP will transfer every 598 * service interval. valid only for periodic EPs. } 599 plibusb_ss_endpoint_companion_descriptor = ^libusb_ss_endpoint_companion_descriptor; 600 libusb_ss_endpoint_companion_descriptor = record 601 bLength : uint8_t; 602 bDescriptorType : uint8_t; 603 bMaxBurst : uint8_t; 604 bmAttributes : uint8_t; 605 wBytesPerInterval : uint16_t; 606 end; 607 608 {* \ingroup desc 609 * A generic representation of a BOS Device Capability descriptor. It is 610 * advised to check bDevCapabilityType and call the matching 611 * libusb_get_*_descriptor function to get a structure fully matching the type. 612 } 613 {* Size of this descriptor (in bytes) } 614 {* Descriptor type. Will have value 615 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 616 * LIBUSB_DT_DEVICE_CAPABILITY in this context. } 617 {* Device Capability type } 618 {* Device Capability data (bLength - 3 bytes) } 619 620 type 621 plibusb_bos_dev_capability_descriptor = ^libusb_bos_dev_capability_descriptor; 622 libusb_bos_dev_capability_descriptor = record 623 bLength : uint8_t; 624 bDescriptorType : uint8_t; 625 bDevCapabilityType : uint8_t; 626 dev_capability_data : array[0..0] of uint8_t; 627 end; 628 629 {* \ingroup desc 630 * A structure representing the Binary Device Object Store (BOS) descriptor. 631 * This descriptor is documented in section 9.6.2 of the USB 3.0 specification. 632 * All multiple-byte fields are represented in host-endian format. 633 } 634 {* Size of this descriptor (in bytes) } 635 {* Descriptor type. Will have value 636 * \ref libusb_descriptor_type::LIBUSB_DT_BOS LIBUSB_DT_BOS 637 * in this context. } 638 {* Length of this descriptor and all of its sub descriptors } 639 {* The number of separate device capability descriptors in 640 * the BOS } 641 {* bNumDeviceCap Device Capability Descriptors } 642 643 type 644 plibusb_bos_descriptor = ^libusb_bos_descriptor; 645 libusb_bos_descriptor = record 646 bLength : uint8_t; 647 bDescriptorType : uint8_t; 648 wTotalLength : uint16_t; 649 bNumDeviceCaps : uint8_t; 650 dev_capability : array[0..0] of ^libusb_bos_dev_capability_descriptor; 651 end; 652 653 {* \ingroup desc 654 * A structure representing the USB 2.0 Extension descriptor 655 * This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification. 656 * All multiple-byte fields are represented in host-endian format. 657 } 658 {* Size of this descriptor (in bytes) } 659 {* Descriptor type. Will have value 660 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 661 * LIBUSB_DT_DEVICE_CAPABILITY in this context. } 662 {* Capability type. Will have value 663 * \ref libusb_capability_type::LIBUSB_BT_USB_2_0_EXTENSION 664 * LIBUSB_BT_USB_2_0_EXTENSION in this context. } 665 {* Bitmap encoding of supported device level features. 666 * A value of one in a bit location indicates a feature is 667 * supported; a value of zero indicates it is not supported. 668 * See \ref libusb_usb_2_0_extension_attributes. } 669 plibusb_usb_2_0_extension_descriptor = ^libusb_usb_2_0_extension_descriptor; 670 libusb_usb_2_0_extension_descriptor = record 671 bLength : uint8_t; 672 bDescriptorType : uint8_t; 673 bDevCapabilityType : uint8_t; 674 bmAttributes : uint32_t; 675 end; 676 677 {* \ingroup desc 678 * A structure representing the SuperSpeed USB Device Capability descriptor 679 * This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification. 680 * All multiple-byte fields are represented in host-endian format. 681 } 682 {* Size of this descriptor (in bytes) } 683 {* Descriptor type. Will have value 684 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 685 * LIBUSB_DT_DEVICE_CAPABILITY in this context. } 686 {* Capability type. Will have value 687 * \ref libusb_capability_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY 688 * LIBUSB_BT_SS_USB_DEVICE_CAPABILITY in this context. } 689 {* Bitmap encoding of supported device level features. 690 * A value of one in a bit location indicates a feature is 691 * supported; a value of zero indicates it is not supported. 692 * See \ref libusb_ss_usb_device_capability_attributes. } 693 {* Bitmap encoding of the speed supported by this device when 694 * operating in SuperSpeed mode. See \ref libusb_supported_speed. } 695 {* The lowest speed at which all the functionality supported 696 * by the device is available to the user. For example if the 697 * device supports all its functionality when connected at 698 * full speed and above then it sets this value to 1. } 699 {* U1 Device Exit Latency. } 700 {* U2 Device Exit Latency. } 701 plibusb_ss_usb_device_capability_descriptor = ^libusb_ss_usb_device_capability_descriptor; 702 libusb_ss_usb_device_capability_descriptor = record 703 bLength : uint8_t; 704 bDescriptorType : uint8_t; 705 bDevCapabilityType : uint8_t; 706 bmAttributes : uint8_t; 707 wSpeedSupported : uint16_t; 708 bFunctionalitySupport : uint8_t; 709 bU1DevExitLat : uint8_t; 710 bU2DevExitLat : uint16_t; 711 end; 712 713 {* \ingroup desc 714 * A structure representing the Container ID descriptor. 715 * This descriptor is documented in section 9.6.2.3 of the USB 3.0 specification. 716 * All multiple-byte fields, except UUIDs, are represented in host-endian format. 717 } 718 {* Size of this descriptor (in bytes) } 719 {* Descriptor type. Will have value 720 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE_CAPABILITY 721 * LIBUSB_DT_DEVICE_CAPABILITY in this context. } 722 {* Capability type. Will have value 723 * \ref libusb_capability_type::LIBUSB_BT_CONTAINER_ID 724 * LIBUSB_BT_CONTAINER_ID in this context. } 725 {* Reserved field } 726 {* 128 bit UUID } 727 plibusb_container_id_descriptor = ^libusb_container_id_descriptor; 728 libusb_container_id_descriptor = record 729 bLength : uint8_t; 730 bDescriptorType : uint8_t; 731 bDevCapabilityType : uint8_t; 732 bReserved : uint8_t; 733 ContainerID : array[0..15] of uint8_t; 734 end; 735 736 {* \ingroup asyncio 737 * Setup packet for control transfers. } 738 {* Request type. Bits 0:4 determine recipient, see 739 * \ref libusb_request_recipient. Bits 5:6 determine type, see 740 * \ref libusb_request_type. Bit 7 determines data transfer direction, see 741 * \ref libusb_endpoint_direction. 742 } 743 {* Request. If the type bits of bmRequestType are equal to 744 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD 745 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to 746 * \ref libusb_standard_request. For other cases, use of this field is 747 * application-specific. } 748 {* Value. Varies according to request } 749 {* Index. Varies according to request, typically used to pass an index 750 * or offset } 751 {* Number of bytes to transfer } 752 plibusb_control_setup = ^libusb_control_setup; 753 libusb_control_setup = record 754 bmRequestType : uint8_t; 755 bRequest : uint8_t; 756 wValue : uint16_t; 757 wIndex : uint16_t; 758 wLength : uint16_t; 759 end; 760 761 const LIBUSB_CONTROL_SETUP_SIZE = sizeof(libusb_control_setup); 762 763type 764 { libusb } 765 plibusb_context = ^libusb_context; 766 libusb_context = record 767 {undefined structure} 768 end; 769 770 plibusb_device=^libusb_device; 771 libusb_device = record 772 {undefined structure} 773 end; 774 775 plibusb_device_handle=^libusb_device_handle; 776 libusb_device_handle = record 777 {undefined structure} 778 end; 779 780 {* \ingroup lib 781 * Structure providing the version of the libusb runtime 782 } 783 784 785 786(* Const before type ignored *) 787 788(* Const before type ignored *) 789 790(* Const before type ignored *) 791 792(* Const before type ignored *) 793 794(* Const before type ignored *) 795 plibusb_version = ^libusb_version; 796 libusb_version = record 797 {* Library major version. } 798 major : uint16_t; 799 {* Library minor version. } 800 minor : uint16_t; 801 {* Library micro version. } 802 micro : uint16_t; 803 {* Library nano version. } 804 nano : uint16_t; 805 {* Library release candidate suffix string, e.g. "-rc4". } 806 rc : ^ansichar; 807 {* For ABI compatibility only. } 808 describe : ^ansichar; 809 end; 810 811{* \ingroup lib 812 * Structure representing a libusb session. The concept of individual libusb 813 * sessions allows for your program to use two libraries (or dynamically 814 * load two modules) which both independently use libusb. This will prevent 815 * interference between the individual libusb users - for example 816 * libusb_set_debug() will not affect the other user of the library, and 817 * libusb_exit() will not destroy resources that the other user is still 818 * using. 819 * 820 * Sessions are created by libusb_init() and destroyed through libusb_exit(). 821 * If your application is guaranteed to only ever include a single libusb 822 * user (i.e. you), you do not have to worry about contexts: pass NULL in 823 * every function call where a context is required. The default context 824 * will be used. 825 * 826 * For more information, see \ref contexts. 827 } 828{* \ingroup dev 829 * Structure representing a USB device detected on the system. This is an 830 * opaque type for which you are only ever provided with a pointer, usually 831 * originating from libusb_get_device_list(). 832 * 833 * Certain operations can be performed on a device, but in order to do any 834 * I/O you will have to first obtain a device handle using libusb_open(). 835 * 836 * Devices are reference counted with libusb_ref_device() and 837 * libusb_unref_device(), and are freed when the reference count reaches 0. 838 * New devices presented by libusb_get_device_list() have a reference count of 839 * 1, and libusb_free_device_list() can optionally decrease the reference count 840 * on all devices in the list. libusb_open() adds another reference which is 841 * later destroyed by libusb_close(). 842 } 843{* \ingroup dev 844 * Structure representing a handle on a USB device. This is an opaque type for 845 * which you are only ever provided with a pointer, usually originating from 846 * libusb_open(). 847 * 848 * A device handle is used to perform I/O and other operations. When finished 849 * with a device handle, you should call libusb_close(). 850 } 851{* \ingroup dev 852 * Speed codes. Indicates the speed at which the device is operating. 853 } 854 libusb_speed = ( 855 {* The OS doesn't report or know the device speed. } 856 LIBUSB_SPEED_UNKNOWN = 0, 857 {* The device is operating at low speed (1.5MBit/s). } 858 LIBUSB_SPEED_LOW = 1, 859 {* The device is operating at full speed (12MBit/s). } 860 LIBUSB_SPEED_FULL = 2, 861 {* The device is operating at high speed (480MBit/s). } 862 LIBUSB_SPEED_HIGH = 3, 863 {* The device is operating at super speed (5000MBit/s). } 864 LIBUSB_SPEED_SUPER = 4); 865 866{* \ingroup dev 867 * Supported speeds (wSpeedSupported) bitfield. Indicates what 868 * speeds the device supports. 869 } 870 libusb_supported_speed = ( 871 {* Low speed operation supported (1.5MBit/s). } 872 LIBUSB_LOW_SPEED_OPERATION = 1, 873 {* Full speed operation supported (12MBit/s). } 874 LIBUSB_FULL_SPEED_OPERATION = 2, 875 {* High speed operation supported (480MBit/s). } 876 LIBUSB_HIGH_SPEED_OPERATION = 4, 877 {* Superspeed operation supported (5000MBit/s). } 878 LIBUSB_SUPER_SPEED_OPERATION = 8 879 ); 880 881{* \ingroup dev 882 * Masks for the bits of the 883 * \ref libusb_usb_2_0_extension_descriptor::bmAttributes "bmAttributes" field 884 * of the USB 2.0 Extension descriptor. 885 } 886 {* Supports Link Power Management (LPM) } 887 libusb_usb_2_0_extension_attributes = (LIBUSB_BM_LPM_SUPPORT = 2); 888 889{* \ingroup dev 890 * Masks for the bits of the 891 * \ref libusb_ss_usb_device_capability_descriptor::bmAttributes "bmAttributes" field 892 * field of the SuperSpeed USB Device Capability descriptor. 893 } 894 {* Supports Latency Tolerance Messages (LTM) } 895 libusb_ss_usb_device_capability_attributes = (LIBUSB_BM_LTM_SUPPORT = 2); 896 897{* \ingroup dev 898 * USB capability types 899 } 900 libusb_bos_type = ( 901 {* Wireless USB device capability } 902 LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1, 903 {* USB 2.0 extensions } 904 LIBUSB_BT_USB_2_0_EXTENSION = 2, 905 {* SuperSpeed USB device capability } 906 LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3, 907 {* Container ID type } 908 LIBUSB_BT_CONTAINER_ID = 4); 909 910{* \ingroup misc 911 * Error codes. Most libusb functions return 0 on success or one of these 912 * codes on failure. 913 * You can call libusb_error_name() to retrieve a string representation of an 914 * error code or libusb_strerror() to get an end-user suitable description of 915 * an error code. 916 } 917{ NB: Remember to update LIBUSB_ERROR_COUNT below as well as the 918 message strings in strerror.c when adding new error codes here. } 919 libusb_error = ( 920 {* Success (no error) } 921 LIBUSB_SUCCESS = 0, 922 {* Input/output error } 923 LIBUSB_ERROR_IO = -(1), 924 {* Invalid parameter } 925 LIBUSB_ERROR_INVALID_PARAM = -(2), 926 {* Access denied (insufficient permissions) } 927 LIBUSB_ERROR_ACCESS = -(3), 928 {* No such device (it may have been disconnected) } 929 LIBUSB_ERROR_NO_DEVICE = -(4), 930 {* Entity not found } 931 LIBUSB_ERROR_NOT_FOUND = -(5), 932 {* Resource busy } 933 LIBUSB_ERROR_BUSY = -(6), 934 {* Operation timed out } 935 LIBUSB_ERROR_TIMEOUT = -(7), 936 {* Overflow } 937 LIBUSB_ERROR_OVERFLOW = -(8), 938 {* Pipe error } 939 LIBUSB_ERROR_PIPE = -(9), 940 {* System call interrupted (perhaps due to signal) } 941 LIBUSB_ERROR_INTERRUPTED = -(10), 942 {* Insufficient memory } 943 LIBUSB_ERROR_NO_MEM = -(11), 944 {* Operation not supported or unimplemented on this platform } 945 LIBUSB_ERROR_NOT_SUPPORTED = -(12), 946 {* Other error } 947 LIBUSB_ERROR_OTHER = -(99) 948 ); 949 950{ Total number of error codes in enum libusb_error } 951const 952 LIBUSB_ERROR_COUNT = 14; 953 954 {* \ingroup asyncio 955 * Transfer status codes } 956 957 958 959 960 961type 962 libusb_transfer_status = ( 963 {* Transfer completed without error. Note that this does not indicate 964 * that the entire amount of requested data was transferred. } 965 LIBUSB_TRANSFER_COMPLETED, 966 {* Transfer failed } 967 LIBUSB_TRANSFER_ERROR, 968 {* Transfer timed out } 969 LIBUSB_TRANSFER_TIMED_OUT, 970 {* Transfer was cancelled } 971 LIBUSB_TRANSFER_CANCELLED, 972 {* For bulk/interrupt endpoints: halt condition detected (endpoint 973 * stalled). For control endpoints: control request not supported. } 974 LIBUSB_TRANSFER_STALL, 975 {* Device was disconnected } 976 LIBUSB_TRANSFER_NO_DEVICE, 977 {* Device sent more data than requested } 978 LIBUSB_TRANSFER_OVERFLOW); 979 980 { NB! Remember to update libusb_error_name() 981 when adding new status codes here. } 982 983 984{* \ingroup asyncio 985 * libusb_transfer.flags values } 986 libusb_transfer_flags = ( 987 {* Report short frames as errors } 988 LIBUSB_TRANSFER_SHORT_NOT_OK = 1 shl 0, 989 {* Automatically free() transfer buffer during libusb_free_transfer() } 990 LIBUSB_TRANSFER_FREE_BUFFER = 1 shl 1, 991 {* Automatically call libusb_free_transfer() after callback returns. 992 * If this flag is set, it is illegal to call libusb_free_transfer() 993 * from your transfer callback, as this will result in a double-free 994 * when this flag is acted upon. } 995 LIBUSB_TRANSFER_FREE_TRANSFER = 1 shl 2, 996 {* Terminate transfers that are a multiple of the endpoint's 997 * wMaxPacketSize with an extra zero length packet. This is useful 998 * when a device protocol mandates that each logical request is 999 * terminated by an incomplete packet (i.e. the logical requests are 1000 * not separated by other means). 1001 * 1002 * This flag only affects host-to-device transfers to bulk and interrupt 1003 * endpoints. In other situations, it is ignored. 1004 * 1005 * This flag only affects transfers with a length that is a multiple of 1006 * the endpoint's wMaxPacketSize. On transfers of other lengths, this 1007 * flag has no effect. Therefore, if you are working with a device that 1008 * needs a ZLP whenever the end of the logical request falls on a packet 1009 * boundary, then it is sensible to set this flag on <em>every</em> 1010 * transfer (you do not have to worry about only setting it on transfers 1011 * that end on the boundary). 1012 * 1013 * This flag is currently only supported on Linux. 1014 * On other systems, libusb_submit_transfer() will return 1015 * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set. 1016 * 1017 * Available since libusb-1.0.9. 1018 } 1019 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 shl 3 1020 ); 1021 1022{* \ingroup asyncio 1023 * Isochronous packet descriptor. } 1024{* Length of data to request in this packet } 1025{* Amount of data that was actually transferred } 1026{* Status code for this packet } 1027 libusb_iso_packet_descriptor = record 1028 length : dword; 1029 actual_length : dword; 1030 status : libusb_transfer_status; 1031 end; 1032 {* \ingroup asyncio 1033 * Asynchronous transfer callback function type. When submitting asynchronous 1034 * transfers, you pass a pointer to a callback function of this type via the 1035 * \ref libusb_transfer::callback "callback" member of the libusb_transfer 1036 * structure. libusb will call this function later, when the transfer has 1037 * completed or failed. See \ref asyncio for more information. 1038 * \param transfer The libusb_transfer struct the callback function is being 1039 * notified about. 1040 } 1041 plibusb_transfer=^libusb_transfer; 1042 1043 libusb_transfer_cb_fn = procedure (transfer:plibusb_transfer);LIBUSB_CALL; 1044 1045 {* \ingroup asyncio 1046 * The generic USB transfer structure. The user populates this structure and 1047 * then submits it in order to request a transfer. After the transfer has 1048 * completed, the library populates the transfer with the results and passes 1049 * it back to the user. 1050 } 1051 {* Handle of the device that this transfer will be submitted to } 1052 {* A bitwise OR combination of \ref libusb_transfer_flags. } 1053 {* Address of the endpoint where this transfer will be sent. } 1054 {* Type of the endpoint from \ref libusb_transfer_type } 1055 {* Timeout for this transfer in millseconds. A value of 0 indicates no 1056 * timeout. } 1057 {* The status of the transfer. Read-only, and only for use within 1058 * transfer callback function. 1059 * 1060 * If this is an isochronous transfer, this field may read COMPLETED even 1061 * if there were errors in the frames. Use the 1062 * \ref libusb_iso_packet_descriptor::status "status" field in each packet 1063 * to determine if errors occurred. } 1064 {* Length of the data buffer } 1065 {* Actual length of data that was transferred. Read-only, and only for 1066 * use within transfer callback function. Not valid for isochronous 1067 * endpoint transfers. } 1068 {* Callback function. This will be invoked when the transfer completes, 1069 * fails, or is cancelled. } 1070 {* User context data to pass to the callback function. } 1071 {* Data buffer } 1072 {* Number of isochronous packets. Only used for I/O with isochronous 1073 * endpoints. } 1074 {* Isochronous packet descriptors, for isochronous transfers only. } 1075 1076 libusb_transfer = record 1077 dev_handle : ^libusb_device_handle; 1078 flags : uint8_t; 1079 endpoint : byte; 1080 _type : byte; 1081 timeout : dword; 1082 status : libusb_transfer_status; 1083 length : longint; 1084 actual_length : longint; 1085 callback : libusb_transfer_cb_fn; 1086 user_data : pointer; 1087 buffer : ^byte; 1088 num_iso_packets : longint; 1089 iso_packet_desc : array[0..0] of libusb_iso_packet_descriptor; 1090 end; 1091 1092 1093 1094 1095{* \ingroup misc 1096 * Capabilities supported by an instance of libusb on the current running 1097 * platform. Test if the loaded library supports a given capability by calling 1098 * \ref libusb_has_capability(). 1099 } 1100 libusb_capability = ( 1101 {* The libusb_has_capability() API is available. } 1102 LIBUSB_CAP_HAS_CAPABILITY = $0000, 1103 {* Hotplug support is available on this platform. } 1104 LIBUSB_CAP_HAS_HOTPLUG = $0001, 1105 {* The library can access HID devices without requiring user intervention. 1106 * Note that before being able to actually access an HID device, you may 1107 * still have to call additional libusb functions such as 1108 * \ref libusb_detach_kernel_driver(). } 1109 LIBUSB_CAP_HAS_HID_ACCESS = $0100, 1110 {* The library supports detaching of the default USB driver, using 1111 * \ref libusb_detach_kernel_driver(), if one is set by the OS kernel } 1112 LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = $0101 1113 ); 1114 1115{* \ingroup lib 1116 * Log message levels. 1117 * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default) 1118 * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr 1119 * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr 1120 * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning 1121 * and error messages are printed to stderr 1122 * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout, 1123 * warnings and errors to stderr 1124 } 1125 libusb_log_level = ( 1126 LIBUSB_LOG_LEVEL_NONE = 0, 1127 LIBUSB_LOG_LEVEL_ERROR, 1128 LIBUSB_LOG_LEVEL_WARNING, 1129 LIBUSB_LOG_LEVEL_INFO, 1130 LIBUSB_LOG_LEVEL_DEBUG); 1131 1132 1133function libusb_init(var ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1134 1135procedure libusb_exit(ctx:plibusb_context);LIBUSB_CALL;external libusb1; 1136procedure libusb_set_debug(ctc:plibusb_context;level:integer);LIBUSB_CALL;external libusb1; 1137 1138function libusb_get_version():libusb_version;LIBUSB_CALL;external libusb1; 1139function libusb_has_capability(capability:uint32_t):integer;LIBUSB_CALL;external libusb1; 1140 1141function libusb_error_name(errcode:integer):pansichar;LIBUSB_CALL;external libusb1; 1142 1143function libusb_setlocale(const locale:pansichar):integer;LIBUSB_CALL;external libusb1; 1144 1145function libusb_strerror(errcode:libusb_error):pansichar;LIBUSB_CALL;external libusb1; 1146function libusb_get_device_list(ctx:plibusb_context;var list:plibusb_device):ssize_t;LIBUSB_CALL;external libusb1; 1147procedure libusb_free_device_list(list:plibusb_device;unref_devices:integer);LIBUSB_CALL;external libusb1; 1148function libusb_ref_device(dev:plibusb_device):plibusb_device;LIBUSB_CALL;external libusb1; 1149procedure libusb_unref_device(dev:plibusb_device);LIBUSB_CALL;external libusb1; 1150function libusb_get_configuration(dev:plibusb_device_handle; 1151 config:pinteger):integer;LIBUSB_CALL;external libusb1; 1152function libusb_get_device_descriptor(dev:plibusb_device; 1153 var desc:libusb_device_descriptor):integer;LIBUSB_CALL;external libusb1; 1154function libusb_get_active_config_descriptor(dev:plibusb_device; 1155 var config:plibusb_config_descriptor):integer;LIBUSB_CALL;external libusb1; 1156function libusb_get_config_descriptor(dev:plibusb_device; 1157 config_index:uint8_t ; var config:plibusb_config_descriptor):integer;LIBUSB_CALL;external libusb1; 1158 1159function libusb_get_config_descriptor_by_value(dev:plibusb_device; 1160 bConfigurationValue:uint8_t;var config:plibusb_config_descriptor):integer;LIBUSB_CALL;external libusb1; 1161 1162procedure libusb_free_config_descriptor(config:plibusb_config_descriptor);LIBUSB_CALL;external libusb1; 1163 1164function libusb_get_ss_endpoint_companion_descriptor( 1165 ctx:plibusb_context; 1166 endpoint:plibusb_endpoint_descriptor; 1167 var ep_comp:plibusb_ss_endpoint_companion_descriptor):integer;LIBUSB_CALL;external libusb1; 1168 1169procedure libusb_free_ss_endpoint_companion_descriptor( 1170 ep_comp:plibusb_ss_endpoint_companion_descriptor);LIBUSB_CALL;external libusb1; 1171 1172function libusb_get_bos_descriptor( 1173 handle:plibusb_device_handle; 1174 var bos:plibusb_bos_descriptor):integer;LIBUSB_CALL;external libusb1; 1175 1176procedure libusb_free_bos_descriptor(bos:plibusb_bos_descriptor);LIBUSB_CALL;external libusb1; 1177 1178function libusb_get_usb_2_0_extension_descriptor( 1179 ctx:plibusb_context; 1180 dev_cap:plibusb_bos_dev_capability_descriptor; 1181 var usb_2_0_extension:plibusb_usb_2_0_extension_descriptor):integer;LIBUSB_CALL;external libusb1; 1182 1183procedure libusb_free_usb_2_0_extension_descriptor( 1184 usb_2_0_extension:plibusb_usb_2_0_extension_descriptor);LIBUSB_CALL;external libusb1; 1185 1186 1187function libusb_get_ss_usb_device_capability_descriptor( 1188 ctx:plibusb_context; 1189 dev_cap:plibusb_bos_dev_capability_descriptor; 1190 var ss_usb_device_cap:plibusb_ss_usb_device_capability_descriptor):integer;LIBUSB_CALL;external libusb1; 1191 1192procedure libusb_free_ss_usb_device_capability_descriptor( 1193 ss_usb_device_cap:plibusb_ss_usb_device_capability_descriptor);LIBUSB_CALL;external libusb1; 1194 1195function libusb_get_container_id_descriptor( 1196 ctx:plibusb_context; 1197 dev_cap:plibusb_bos_dev_capability_descriptor; 1198 var container_id:plibusb_container_id_descriptor):integer;LIBUSB_CALL;external libusb1; 1199 1200procedure libusb_free_container_id_descriptor( 1201 container_id:plibusb_container_id_descriptor);LIBUSB_CALL;external libusb1; 1202 1203function libusb_get_bus_number(dev:plibusb_device):uint8_t;LIBUSB_CALL;external libusb1; 1204function libusb_get_port_number(dev:plibusb_device):uint8_t;LIBUSB_CALL;external libusb1; 1205 1206function libusb_get_port_numbers( 1207 dev:plibusb_device; 1208 port_numbers:puint8_t; 1209 port_numbers_len:integer):integer;LIBUSB_CALL;external libusb1; 1210 1211function libusb_get_port_path( 1212 ctx:plibusb_context; 1213 dev:plibusb_device; 1214 path:puint8_t; 1215 path_length:uint8_t):integer;LIBUSB_CALL;external libusb1; 1216 1217function libusb_get_parent(dev:plibusb_device):plibusb_device;LIBUSB_CALL;external libusb1; 1218 1219function libusb_get_device_address(dev:plibusb_device):uint8_t;LIBUSB_CALL;external libusb1; 1220 1221function libusb_get_device_speed(dev:plibusb_device):integer;LIBUSB_CALL;external libusb1; 1222 1223function libusb_get_max_packet_size( 1224 dev:plibusb_device; 1225 endpoint:uint8_t):integer;LIBUSB_CALL;external libusb1; 1226 1227function libusb_get_max_iso_packet_size( 1228 dev:plibusb_device; 1229 endpoint:uint8_t):integer;LIBUSB_CALL;external libusb1; 1230 1231function libusb_open( 1232 dev:plibusb_device; 1233 var handle:plibusb_device_handle):integer;LIBUSB_CALL;external libusb1; 1234 1235procedure libusb_close(dev_handle:plibusb_device_handle);LIBUSB_CALL;external libusb1; 1236 1237function libusb_get_device(dev_handle:plibusb_device_handle):plibusb_device;LIBUSB_CALL;external libusb1; 1238 1239function libusb_set_configuration( 1240 dev:plibusb_device_handle; 1241 configuration:integer):integer;LIBUSB_CALL;external libusb1; 1242 1243function libusb_claim_interface( 1244 dev:plibusb_device_handle; 1245 interface_number:integer):integer;LIBUSB_CALL;external libusb1; 1246 1247function libusb_release_interface( 1248 dev:plibusb_device_handle; 1249 interface_number:integer):integer;LIBUSB_CALL;external libusb1; 1250 1251function libusb_open_device_with_vid_pid( 1252 ctx:plibusb_context; 1253 vendor_id:uint16_t; 1254 product_id:uint16_t):plibusb_device_handle;LIBUSB_CALL ;external libusb1; 1255 1256function libusb_set_interface_alt_setting( 1257 dev:plibusb_device_handle; 1258 interface_number:integer; 1259 alternate_setting:integer):integer;LIBUSB_CALL;external libusb1; 1260 1261function libusb_clear_halt( 1262 dev:plibusb_device_handle; 1263 endpoint:uint8_t):integer;LIBUSB_CALL;external libusb1; 1264 1265function libusb_reset_device(dev:plibusb_device_handle):integer;LIBUSB_CALL;external libusb1; 1266 1267function libusb_alloc_streams( 1268 dev:plibusb_device_handle; 1269 num_streams:uint32_t; 1270 endpoints:puint8_t; 1271 num_endpoints:integer):integer;LIBUSB_CALL;external libusb1; 1272 1273function libusb_free_streams( 1274 dev:plibusb_device_handle; 1275 endpoints:puint8_t; 1276 num_endpoints:integer):integer;LIBUSB_CALL;external libusb1; 1277 1278function libusb_kernel_driver_active( 1279 dev:plibusb_device_handle; 1280 interface_number:integer):integer;LIBUSB_CALL;external libusb1; 1281 1282function libusb_detach_kernel_driver( 1283 dev:plibusb_device_handle; 1284 interface_number:integer):integer;LIBUSB_CALL;external libusb1; 1285 1286function libusb_attach_kernel_driver( 1287 dev:plibusb_device_handle; 1288 interface_number:integer):integer;LIBUSB_CALL;external libusb1; 1289 1290function libusb_set_auto_detach_kernel_driver( 1291 dev:plibusb_device_handle; 1292 enable:integer):integer;LIBUSB_CALL;external libusb1; 1293 1294{ async I/O } 1295{* \ingroup asyncio 1296 * Get the data section of a control transfer. This convenience function is here 1297 * to remind you that the data does not start until 8 bytes into the actual 1298 * buffer, as the setup packet comes first. 1299 * 1300 * Calling this function only makes sense from a transfer callback function, 1301 * or situations where you have already allocated a suitably sized buffer at 1302 * transfer->buffer. 1303 * 1304 * \param transfer a transfer 1305 * \returns pointer to the first byte of the data section 1306 } 1307 1308function libusb_control_transfer_get_data( 1309 transfer:plibusb_transfer):puint8_t;inline; 1310 1311 1312 1313{* \ingroup asyncio 1314 * Get the control setup packet of a control transfer. This convenience 1315 * function is here to remind you that the control setup occupies the first 1316 * 8 bytes of the transfer data buffer. 1317 * 1318 * Calling this function only makes sense from a transfer callback function, 1319 * or situations where you have already allocated a suitably sized buffer at 1320 * transfer->buffer. 1321 * 1322 * \param transfer a transfer 1323 * \returns a casted pointer to the start of the transfer data buffer 1324 } 1325 1326function libusb_control_transfer_get_setup( 1327 transfer:plibusb_transfer):plibusb_control_setup; 1328 1329 1330{* \ingroup asyncio 1331 * Helper function to populate the setup packet (first 8 bytes of the data 1332 * buffer) for a control transfer. The wIndex, wValue and wLength values should 1333 * be given in host-endian byte order. 1334 * 1335 * \param buffer buffer to output the setup packet into 1336 * This pointer must be aligned to at least 2 bytes boundary. 1337 * \param bmRequestType see the 1338 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of 1339 * \ref libusb_control_setup 1340 * \param bRequest see the 1341 * \ref libusb_control_setup::bRequest "bRequest" field of 1342 * \ref libusb_control_setup 1343 * \param wValue see the 1344 * \ref libusb_control_setup::wValue "wValue" field of 1345 * \ref libusb_control_setup 1346 * \param wIndex see the 1347 * \ref libusb_control_setup::wIndex "wIndex" field of 1348 * \ref libusb_control_setup 1349 * \param wLength see the 1350 * \ref libusb_control_setup::wLength "wLength" field of 1351 * \ref libusb_control_setup 1352 } 1353 1354procedure libusb_fill_control_setup( 1355 buffer:puint8_t; 1356 bmRequestType:uint8_t; 1357 bRequest: uint8_t; 1358 wValue:uint16_t; 1359 wIndex:uint16_t; 1360 wLength:uint16_t); 1361 1362function libusb_alloc_transfer(iso_packets:integer):plibusb_transfer;LIBUSB_CALL;external libusb1; 1363function libusb_submit_transfer(transfer:plibusb_transfer):integer;LIBUSB_CALL;external libusb1; 1364function libusb_cancel_transfer(transfer:plibusb_transfer):integer;LIBUSB_CALL;external libusb1; 1365procedure libusb_free_transfer(transfer:plibusb_transfer);LIBUSB_CALL;external libusb1; 1366procedure libusb_transfer_set_stream_id( 1367 transfer:plibusb_transfer;stream_id:uint32_t);LIBUSB_CALL;external libusb1; 1368function libusb_transfer_get_stream_id( 1369 transfer:plibusb_transfer):uint32_t;LIBUSB_CALL;external libusb1; 1370 1371 1372{* \ingroup asyncio 1373 * Helper function to populate the required \ref libusb_transfer fields 1374 * for a control transfer. 1375 * 1376 * If you pass a transfer buffer to this function, the first 8 bytes will 1377 * be interpreted as a control setup packet, and the wLength field will be 1378 * used to automatically populate the \ref libusb_transfer::length "length" 1379 * field of the transfer. Therefore the recommended approach is: 1380 * -# Allocate a suitably sized data buffer (including space for control setup) 1381 * -# Call libusb_fill_control_setup() 1382 * -# If this is a host-to-device transfer with a data stage, put the data 1383 * in place after the setup packet 1384 * -# Call this function 1385 * -# Call libusb_submit_transfer() 1386 * 1387 * It is also legal to pass a NULL buffer to this function, in which case this 1388 * function will not attempt to populate the length field. Remember that you 1389 * must then populate the buffer and length fields later. 1390 * 1391 * \param transfer the transfer to populate 1392 * \param dev_handle handle of the device that will handle the transfer 1393 * \param buffer data buffer. If provided, this function will interpret the 1394 * first 8 bytes as a setup packet and infer the transfer length from that. 1395 * This pointer must be aligned to at least 2 bytes boundary. 1396 * \param callback callback function to be invoked on transfer completion 1397 * \param user_data user data to pass to callback function 1398 * \param timeout timeout for the transfer in milliseconds 1399 } 1400 1401procedure libusb_fill_control_transfer( 1402 transfer:plibusb_transfer; 1403 dev_handle:plibusb_device_handle; 1404 buffer:puint8_t; 1405 callback:libusb_transfer_cb_fn; 1406 user_data:pointer; 1407 timeout:cardinal); 1408 1409 1410{* \ingroup asyncio 1411 * Helper function to populate the required \ref libusb_transfer fields 1412 * for a bulk transfer. 1413 * 1414 * \param transfer the transfer to populate 1415 * \param dev_handle handle of the device that will handle the transfer 1416 * \param endpoint address of the endpoint where this transfer will be sent 1417 * \param buffer data buffer 1418 * \param length length of data buffer 1419 * \param callback callback function to be invoked on transfer completion 1420 * \param user_data user data to pass to callback function 1421 * \param timeout timeout for the transfer in milliseconds 1422 } 1423 1424procedure libusb_fill_bulk_transfer( 1425 transfer:plibusb_transfer; 1426 dev_handle:plibusb_device_handle; 1427 endpoint:uint8_t; 1428 buffer:puint8_t; 1429 length:integer; 1430 callback:libusb_transfer_cb_fn; 1431 user_data:pointer; 1432 timeout:cardinal); 1433 1434 1435{* \ingroup asyncio 1436 * Helper function to populate the required \ref libusb_transfer fields 1437 * for a bulk transfer using bulk streams. 1438 * 1439 * Since version 1.0.19, \ref LIBUSB_API_VERSION >= 0x01000103 1440 * 1441 * \param transfer the transfer to populate 1442 * \param dev_handle handle of the device that will handle the transfer 1443 * \param endpoint address of the endpoint where this transfer will be sent 1444 * \param stream_id bulk stream id for this transfer 1445 * \param buffer data buffer 1446 * \param length length of data buffer 1447 * \param callback callback function to be invoked on transfer completion 1448 * \param user_data user data to pass to callback function 1449 * \param timeout timeout for the transfer in milliseconds 1450 } 1451 1452procedure libusb_fill_bulk_stream_transfer( 1453 transfer:plibusb_transfer; 1454 dev_handle:plibusb_device_handle; 1455 endpoint:uint8_t; 1456 stream_id:uint32_t; 1457 buffer:puint8_t; 1458 length:integer; 1459 callback:libusb_transfer_cb_fn; 1460 user_data:pointer; 1461 timeout:cardinal); 1462 1463 1464{* \ingroup asyncio 1465 * Helper function to populate the required \ref libusb_transfer fields 1466 * for an interrupt transfer. 1467 * 1468 * \param transfer the transfer to populate 1469 * \param dev_handle handle of the device that will handle the transfer 1470 * \param endpoint address of the endpoint where this transfer will be sent 1471 * \param buffer data buffer 1472 * \param length length of data buffer 1473 * \param callback callback function to be invoked on transfer completion 1474 * \param user_data user data to pass to callback function 1475 * \param timeout timeout for the transfer in milliseconds 1476 } 1477 1478procedure libusb_fill_interrupt_transfer( 1479 transfer:plibusb_transfer; 1480 dev_handle:plibusb_device_handle; 1481 endpoint:uint8_t; 1482 buffer:puint8_t; 1483 length:integer; 1484 callback:libusb_transfer_cb_fn; 1485 user_data:pointer; 1486 timeout:cardinal); 1487 1488 1489{* \ingroup asyncio 1490 * Helper function to populate the required \ref libusb_transfer fields 1491 * for an isochronous transfer. 1492 * 1493 * \param transfer the transfer to populate 1494 * \param dev_handle handle of the device that will handle the transfer 1495 * \param endpoint address of the endpoint where this transfer will be sent 1496 * \param buffer data buffer 1497 * \param length length of data buffer 1498 * \param num_iso_packets the number of isochronous packets 1499 * \param callback callback function to be invoked on transfer completion 1500 * \param user_data user data to pass to callback function 1501 * \param timeout timeout for the transfer in milliseconds 1502 } 1503 1504procedure libusb_fill_iso_transfer(transfer:plibusb_transfer; 1505 dev_handle:plibusb_device_handle; 1506 endpoint:uint8_t; 1507 buffer:puint8_t; 1508 length:integer; 1509 num_iso_packets:integer; 1510 callback:libusb_transfer_cb_fn; 1511 user_data:pointer; 1512 timeout:cardinal); 1513 1514 1515{* \ingroup asyncio 1516 * Convenience function to set the length of all packets in an isochronous 1517 * transfer, based on the num_iso_packets field in the transfer structure. 1518 * 1519 * \param transfer a transfer 1520 * \param length the length to set in each isochronous packet descriptor 1521 * \see libusb_get_max_packet_size() 1522 } 1523 1524procedure libusb_set_iso_packet_lengths( 1525 transfer:plibusb_transfer; 1526 length:cardinal); 1527 1528 1529{* \ingroup asyncio 1530 * Convenience function to locate the position of an isochronous packet 1531 * within the buffer of an isochronous transfer. 1532 * 1533 * This is a thorough function which loops through all preceding packets, 1534 * accumulating their lengths to find the position of the specified packet. 1535 * Typically you will assign equal lengths to each packet in the transfer, 1536 * and hence the above method is sub-optimal. You may wish to use 1537 * libusb_get_iso_packet_buffer_simple() instead. 1538 * 1539 * \param transfer a transfer 1540 * \param packet the packet to return the address of 1541 * \returns the base address of the packet buffer inside the transfer buffer, 1542 * or NULL if the packet does not exist. 1543 * \see libusb_get_iso_packet_buffer_simple() 1544 } 1545 1546function libusb_get_iso_packet_buffer( 1547 transfer:plibusb_transfer; 1548 packet:cardinal):puint8_t; 1549 1550 1551{* \ingroup asyncio 1552 * Convenience function to locate the position of an isochronous packet 1553 * within the buffer of an isochronous transfer, for transfers where each 1554 * packet is of identical size. 1555 * 1556 * This function relies on the assumption that every packet within the transfer 1557 * is of identical size to the first packet. Calculating the location of 1558 * the packet buffer is then just a simple calculation: 1559 * <tt>buffer + (packet_size * packet)</tt> 1560 * 1561 * Do not use this function on transfers other than those that have identical 1562 * packet lengths for each packet. 1563 * 1564 * \param transfer a transfer 1565 * \param packet the packet to return the address of 1566 * \returns the base address of the packet buffer inside the transfer buffer, 1567 * or NULL if the packet does not exist. 1568 * \see libusb_get_iso_packet_buffer() 1569 } 1570 1571function libusb_get_iso_packet_buffer_simple( 1572 transfer:plibusb_transfer; 1573 packet:cardinal):puint8_t; 1574 1575 1576{ sync I/O } 1577 1578function libusb_control_transfer( 1579 dev_handle:plibusb_device_handle; 1580 request_type:uint8_t; 1581 bRequest:uint8_t; 1582 wValue:uint16_t; 1583 wIndex:uint16_t; 1584 data:puint8_t; 1585 wLength:uint16_t; 1586 timeout:cardinal):integer;LIBUSB_CALL;external libusb1; 1587 1588function libusb_bulk_transfer( 1589 dev_handle:plibusb_device_handle; 1590 endpoint:uint8_t; 1591 data:puint8_t; 1592 length:integer; 1593 var actual_length:integer; 1594 timeout:cardinal):integer;LIBUSB_CALL;external libusb1; 1595 1596function libusb_interrupt_transfer( 1597 dev_handle:plibusb_device_handle; 1598 endpoint:uint8_t; 1599 data:puint8_t; 1600 length:integer; 1601 var actual_length:integer; 1602 timeout:cardinal):integer;LIBUSB_CALL;external libusb1; 1603 1604{* \ingroup desc 1605 * Retrieve a descriptor from the default control pipe. 1606 * This is a convenience function which formulates the appropriate control 1607 * message to retrieve the descriptor. 1608 * 1609 * \param dev a device handle 1610 * \param desc_type the descriptor type, see \ref libusb_descriptor_type 1611 * \param desc_index the index of the descriptor to retrieve 1612 * \param data output buffer for descriptor 1613 * \param length size of data buffer 1614 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure 1615 } 1616 1617function libusb_get_descriptor( 1618 dev:plibusb_device_handle; 1619 desc_type:uint8_t; 1620 desc_index:uint8_t; 1621 data:puint8_t; 1622 length:integer):integer; 1623 1624 1625{* \ingroup desc 1626 * Retrieve a descriptor from a device. 1627 * This is a convenience function which formulates the appropriate control 1628 * message to retrieve the descriptor. The string returned is Unicode, as 1629 * detailed in the USB specifications. 1630 * 1631 * \param dev a device handle 1632 * \param desc_index the index of the descriptor to retrieve 1633 * \param langid the language ID for the string descriptor 1634 * \param data output buffer for descriptor 1635 * \param length size of data buffer 1636 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure 1637 * \see libusb_get_string_descriptor_ascii() 1638 } 1639 1640function libusb_get_string_descriptor( 1641 dev:plibusb_device_handle; 1642 desc_index:uint8_t; 1643 langid:uint16_t; 1644 data:puint8_t; 1645 length:integer):integer; { wrapper function } 1646 1647function libusb_get_string_descriptor_ascii( 1648 dev:plibusb_device_handle; 1649 desc_index:uint8_t; 1650 data:puint8_t; 1651 length:integer):integer;LIBUSB_CALL;external libusb1; 1652 1653(* polling and timeouts *) 1654 1655function libusb_try_lock_events(ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1656procedure libusb_lock_events(ctx:plibusb_context);LIBUSB_CALL;external libusb1; 1657procedure libusb_unlock_events(ctx:plibusb_context);LIBUSB_CALL;external libusb1; 1658function libusb_event_handling_ok(ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1659function libusb_event_handler_active(ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1660procedure libusb_lock_event_waiters(ctx:plibusb_context);LIBUSB_CALL;external libusb1; 1661procedure libusb_unlock_event_waiters(ctx:plibusb_context);LIBUSB_CALL;external libusb1; 1662function libusb_wait_for_event(ctx:plibusb_context; tv:ptimeval):integer;LIBUSB_CALL;external libusb1; 1663 1664function libusb_handle_events_timeout(ctx:plibusb_context; 1665 tv:ptimeval):integer;LIBUSB_CALL;external libusb1; 1666function libusb_handle_events_timeout_completed(ctx:plibusb_context; 1667 tv:ptimeval;var completed:integer):integer;LIBUSB_CALL;external libusb1; 1668function libusb_handle_events(ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1669function libusb_handle_events_completed(ctx:plibusb_context; var completed:integer):integer;LIBUSB_CALL;external libusb1; 1670function libusb_handle_events_locked(ctx:plibusb_context; 1671 tv:ptimeval):integer;LIBUSB_CALL;external libusb1; 1672function libusb_pollfds_handle_timeouts(ctx:plibusb_context):integer;LIBUSB_CALL;external libusb1; 1673function libusb_get_next_timeout(ctx:plibusb_context; 1674 tv:ptimeval):integer;LIBUSB_CALL;external libusb1; 1675 1676 1677{* \ingroup poll 1678 * File descriptor for polling 1679 } 1680{* Numeric file descriptor } 1681{* Event flags to poll for from <poll.h>. POLLIN indicates that you 1682 * should monitor this file descriptor for becoming ready to read from, 1683 * and POLLOUT indicates that you should monitor this file descriptor for 1684 * nonblocking write readiness. } 1685 1686type 1687 plibusb_pollfd = ^libusb_pollfd; 1688 libusb_pollfd = record 1689 fd : longint; 1690 events : smallint; 1691 end; 1692 1693{* \ingroup poll 1694 * Callback function, invoked when a new file descriptor should be added 1695 * to the set of file descriptors monitored for events. 1696 * \param fd the new file descriptor 1697 * \param events events to monitor for, see \ref libusb_pollfd for a 1698 * description 1699 * \param user_data User data pointer specified in 1700 * libusb_set_pollfd_notifiers() call 1701 * \see libusb_set_pollfd_notifiers() 1702 } 1703 1704type 1705 libusb_pollfd_added_cb = procedure( 1706 fd:integer; 1707 events:smallint; 1708 user_data:pointer);LIBUSB_CALL; 1709 1710 1711{* \ingroup poll 1712 * Callback function, invoked when a file descriptor should be removed from 1713 * the set of file descriptors being monitored for events. After returning 1714 * from this callback, do not use that file descriptor again. 1715 * \param fd the file descriptor to stop monitoring 1716 * \param user_data User data pointer specified in 1717 * libusb_set_pollfd_notifiers() call 1718 * \see libusb_set_pollfd_notifiers() 1719 } 1720 1721type 1722 libusb_pollfd_removed_cb = procedure( 1723 fd:integer; 1724 user_data:pointer);LIBUSB_CALL; 1725 1726 libusb_get_pollfds = function( 1727 ctx:plibusb_context):plibusb_pollfd;LIBUSB_CALL; 1728 1729 libusb_set_pollfd_notifiers = procedure ( 1730 ctx:plibusb_context; 1731 added_cb:libusb_pollfd_added_cb; 1732 removed_cb:libusb_pollfd_removed_cb; 1733 user_data:pointer);LIBUSB_CALL; 1734 1735 1736 1737{* \ingroup hotplug 1738 * Callback handle. 1739 * 1740 * Callbacks handles are generated by libusb_hotplug_register_callback() 1741 * and can be used to deregister callbacks. Callback handles are unique 1742 * per libusb_context and it is safe to call libusb_hotplug_deregister_callback() 1743 * on an already deregisted callback. 1744 * 1745 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1746 * 1747 * For more information, see \ref hotplug. 1748 } 1749 1750 libusb_hotplug_callback_handle = longint; 1751{* \ingroup hotplug 1752 * 1753 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1754 * 1755 * Flags for hotplug events } 1756{* Default value when not using any flags. } 1757{* Arm the callback and fire it for all matching currently attached devices. } 1758 1759 libusb_hotplug_flag = (LIBUSB_HOTPLUG_NO_FLAGS = 0, LIBUSB_HOTPLUG_ENUMERATE = 1 1760 ); 1761{* \ingroup hotplug 1762 * 1763 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1764 * 1765 * Hotplug events } 1766{* A device has been plugged in and is ready to use } 1767{* A device has left and is no longer available. 1768 * It is the user's responsibility to call libusb_close on any handle associated with a disconnected device. 1769 * It is safe to call libusb_get_device_descriptor on a device that has left } 1770 1771 libusb_hotplug_event = (LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = $01, 1772 LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = $02 1773 ); 1774{* \ingroup hotplug 1775 * Wildcard matching for hotplug events } 1776 1777const 1778 LIBUSB_HOTPLUG_MATCH_ANY = -(1); 1779 1780{* \ingroup hotplug 1781 * Hotplug callback function type. When requesting hotplug event notifications, 1782 * you pass a pointer to a callback function of this type. 1783 * 1784 * This callback may be called by an internal event thread and as such it is 1785 * recommended the callback do minimal processing before returning. 1786 * 1787 * libusb will call this function later, when a matching event had happened on 1788 * a matching device. See \ref hotplug for more information. 1789 * 1790 * It is safe to call either libusb_hotplug_register_callback() or 1791 * libusb_hotplug_deregister_callback() from within a callback function. 1792 * 1793 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1794 * 1795 * \param ctx context of this notification 1796 * \param device libusb_device this event occurred on 1797 * \param event event that occurred 1798 * \param user_data user data provided when this callback was registered 1799 * \returns bool whether this callback is finished processing events. 1800 * returning 1 will cause this callback to be deregistered 1801 } 1802 1803type 1804 libusb_hotplug_callback_fn = function( 1805 ctx:plibusb_context; 1806 device:plibusb_device; 1807 event:libusb_hotplug_event; 1808 user_data:pointer):integer;LIBUSB_CALL; 1809 1810{* \ingroup hotplug 1811 * Register a hotplug callback function 1812 * 1813 * Register a callback with the libusb_context. The callback will fire 1814 * when a matching event occurs on a matching device. The callback is 1815 * armed until either it is deregistered with libusb_hotplug_deregister_callback() 1816 * or the supplied callback returns 1 to indicate it is finished processing events. 1817 * 1818 * If the \ref LIBUSB_HOTPLUG_ENUMERATE is passed the callback will be 1819 * called with a \ref LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED for all devices 1820 * already plugged into the machine. Note that libusb modifies its internal 1821 * device list from a separate thread, while calling hotplug callbacks from 1822 * libusb_handle_events(), so it is possible for a device to already be present 1823 * on, or removed from, its internal device list, while the hotplug callbacks 1824 * still need to be dispatched. This means that when using \ref 1825 * LIBUSB_HOTPLUG_ENUMERATE, your callback may be called twice for the arrival 1826 * of the same device, once from libusb_hotplug_register_callback() and once 1827 * from libusb_handle_events(); and/or your callback may be called for the 1828 * removal of a device for which an arrived call was never made. 1829 * 1830 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1831 * 1832 * \param[in] ctx context to register this callback with 1833 * \param[in] events bitwise or of events that will trigger this callback. See \ref 1834 * libusb_hotplug_event 1835 * \param[in] flags hotplug callback flags. See \ref libusb_hotplug_flag 1836 * \param[in] vendor_id the vendor id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1837 * \param[in] product_id the product id to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1838 * \param[in] dev_class the device class to match or \ref LIBUSB_HOTPLUG_MATCH_ANY 1839 * \param[in] cb_fn the function to be invoked on a matching event/device 1840 * \param[in] user_data user data to pass to the callback function 1841 * \param[out] handle pointer to store the handle of the allocated callback (can be NULL) 1842 * \returns LIBUSB_SUCCESS on success LIBUSB_ERROR code on failure 1843 } 1844 1845 function libusb_hotplug_register_callback( 1846 ctx:plibusb_context; 1847 events:libusb_hotplug_event; 1848 flags:libusb_hotplug_flag; 1849 vendor_id:integer; 1850 product_id:integer; 1851 dev_class:integer; 1852 cb_fn:libusb_hotplug_callback_fn; 1853 user_data:pointer; 1854 var handle:libusb_hotplug_callback_handle):integer;LIBUSB_CALL;external libusb1; 1855 1856 1857{* \ingroup hotplug 1858 * Deregisters a hotplug callback. 1859 * 1860 * Deregister a callback from a libusb_context. This function is safe to call from within 1861 * a hotplug callback. 1862 * 1863 * Since version 1.0.16, \ref LIBUSB_API_VERSION >= 0x01000102 1864 * 1865 * \param[in] ctx context this callback is registered with 1866 * \param[in] handle the handle of the callback to deregister 1867 } 1868 procedure libusb_hotplug_deregister_callback( 1869 ctx:plibusb_context; 1870 handle:libusb_hotplug_callback_handle);LIBUSB_CALL;external libusb1; 1871 1872 1873{$endif} 1874 1875 1876implementation 1877 1878 1879 1880function libusb_cpu_to_le16(const x:uint16_t):uint16_t;inline; 1881type 1882 w_union=record 1883 case byte of 1884 0:(b8:array[0..1] of uint8_t); 1885 1:(b16:uint16_t); 1886 end; 1887var 1888 _tmp:w_union; 1889begin 1890 _tmp.b8[1] := uint8_t (x shl 8); 1891 _tmp.b8[0] := uint8_t (x and $ff); 1892 Result:=_tmp.b16; 1893end; 1894 1895function libusb_le16_to_cpu(const x:uint16_t):uint16_t;inline; 1896begin 1897 Result:=libusb_cpu_to_le16(x); 1898end; 1899 1900function libusb_control_transfer_get_data( 1901 transfer:plibusb_transfer):puint8_t;inline; 1902begin 1903 result := pointer(transfer^.buffer) + LIBUSB_CONTROL_SETUP_SIZE; 1904end; 1905 1906function libusb_control_transfer_get_setup( 1907 transfer:plibusb_transfer):plibusb_control_setup;inline; 1908begin 1909 Result:= plibusb_control_setup(transfer^.buffer); 1910end; 1911 1912 1913procedure libusb_fill_control_setup( 1914 buffer:puint8_t; 1915 bmRequestType:uint8_t; 1916 bRequest: uint8_t; 1917 wValue:uint16_t; 1918 wIndex:uint16_t; 1919 wLength:uint16_t);inline; 1920var setup:plibusb_control_setup; 1921begin 1922 setup := plibusb_control_setup(buffer); 1923 setup^.bmRequestType := bmRequestType; 1924 setup^.bRequest := bRequest; 1925 setup^.wValue := libusb_cpu_to_le16(wValue); 1926 setup^.wIndex := libusb_cpu_to_le16(wIndex); 1927 setup^.wLength := libusb_cpu_to_le16(wLength); 1928end; 1929 1930procedure libusb_fill_control_transfer( 1931 transfer:plibusb_transfer; 1932 dev_handle:plibusb_device_handle; 1933 buffer:puint8_t; 1934 callback:libusb_transfer_cb_fn; 1935 user_data:pointer; 1936 timeout:cardinal);inline; 1937var 1938 setup:plibusb_control_setup; 1939begin 1940 setup := plibusb_control_setup(buffer); 1941 transfer^.dev_handle := dev_handle; 1942 transfer^.endpoint := 0; 1943 transfer^._type := byte(LIBUSB_TRANSFER_TYPE_CONTROL); 1944 transfer^.timeout := timeout; 1945 transfer^.buffer := buffer; 1946 if (setup<>nil) then 1947 transfer^.length := (LIBUSB_CONTROL_SETUP_SIZE 1948 + libusb_le16_to_cpu(setup^.wLength)); 1949 transfer^.user_data := user_data; 1950 transfer^.callback := callback; 1951end; 1952 1953procedure libusb_fill_bulk_transfer( 1954 transfer:plibusb_transfer; 1955 dev_handle:plibusb_device_handle; 1956 endpoint:uint8_t; 1957 buffer:puint8_t; 1958 length:integer; 1959 callback:libusb_transfer_cb_fn; 1960 user_data:pointer; 1961 timeout:cardinal);inline; 1962begin 1963 transfer^.dev_handle := dev_handle; 1964 transfer^.endpoint := endpoint; 1965 transfer^._type := byte(LIBUSB_TRANSFER_TYPE_BULK); 1966 transfer^.timeout := timeout; 1967 transfer^.buffer := buffer; 1968 transfer^.length := length; 1969 transfer^.user_data := user_data; 1970 transfer^.callback := callback; 1971end; 1972 1973procedure libusb_fill_bulk_stream_transfer( 1974 transfer:plibusb_transfer; 1975 dev_handle:plibusb_device_handle; 1976 endpoint:uint8_t; 1977 stream_id:uint32_t; 1978 buffer:puint8_t; 1979 length:integer; 1980 callback:libusb_transfer_cb_fn; 1981 user_data:pointer; 1982 timeout:cardinal);inline; 1983begin 1984 libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, 1985 length, callback, user_data, timeout); 1986 transfer^._type := byte(LIBUSB_TRANSFER_TYPE_BULK_STREAM); 1987 libusb_transfer_set_stream_id(transfer, stream_id); 1988end; 1989 1990procedure libusb_fill_interrupt_transfer( 1991 transfer:plibusb_transfer; 1992 dev_handle:plibusb_device_handle; 1993 endpoint:uint8_t; 1994 buffer:puint8_t; 1995 length:integer; 1996 callback:libusb_transfer_cb_fn; 1997 user_data:pointer; 1998 timeout:cardinal);inline; 1999begin 2000 transfer^.dev_handle := dev_handle; 2001 transfer^.endpoint := endpoint; 2002 transfer^._type := byte(LIBUSB_TRANSFER_TYPE_INTERRUPT); 2003 transfer^.timeout := timeout; 2004 transfer^.buffer := buffer; 2005 transfer^.length := length; 2006 transfer^.user_data := user_data; 2007 transfer^.callback := callback; 2008end; 2009 2010procedure libusb_fill_iso_transfer(transfer:plibusb_transfer; 2011 dev_handle:plibusb_device_handle; 2012 endpoint:uint8_t; 2013 buffer:puint8_t; 2014 length:integer; 2015 num_iso_packets:integer; 2016 callback:libusb_transfer_cb_fn; 2017 user_data:pointer; 2018 timeout:cardinal);inline; 2019begin 2020 transfer^.dev_handle := dev_handle; 2021 transfer^.endpoint := endpoint; 2022 transfer^._type := byte(LIBUSB_TRANSFER_TYPE_ISOCHRONOUS); 2023 transfer^.timeout := timeout; 2024 transfer^.buffer := buffer; 2025 transfer^.length := length; 2026 transfer^.num_iso_packets := num_iso_packets; 2027 transfer^.user_data := user_data; 2028 transfer^.callback := callback; 2029end; 2030 2031procedure libusb_set_iso_packet_lengths( 2032 transfer:plibusb_transfer; 2033 length:cardinal);inline; 2034var 2035 i:integer; 2036begin 2037 for i := 0 to transfer^.num_iso_packets-1 do 2038 transfer^.iso_packet_desc[i].length := length; 2039end; 2040 2041function libusb_get_iso_packet_buffer( 2042 transfer:plibusb_transfer; 2043 packet:cardinal):puint8_t;inline; 2044var 2045 i:integer; 2046 offset:size_t; 2047 _packet:integer; 2048begin 2049 (* oops..slight bug in the API. packet is an unsigned int, but we use 2050 * signed integers almost everywhere else. range-check and convert to 2051 * signed to avoid compiler warnings. FIXME for libusb-2. *) 2052 if (packet > MaxInt) then 2053 begin 2054 Result:=nil; 2055 exit;; 2056 end; 2057 2058 _packet := integer(packet); 2059 2060 if (_packet >= transfer^.num_iso_packets) then 2061 begin 2062 Result:=nil; 2063 exit;; 2064 end; 2065 2066 for i := 0 to _packet-1 do 2067 offset := offset + transfer^.iso_packet_desc[i].length; 2068 2069 Result := pointer(transfer^.buffer) + offset; 2070end; 2071 2072 2073function libusb_get_iso_packet_buffer_simple( 2074 transfer:plibusb_transfer; 2075 packet:cardinal):puint8_t;inline; 2076var 2077 _packet:integer; 2078begin 2079 (* oops..slight bug in the API. packet is an unsigned int, but we use 2080 * signed integers almost everywhere else. range-check and convert to 2081 * signed to avoid compiler warnings. FIXME for libusb-2. *) 2082 if (packet > MaxInt) then 2083 begin 2084 Result:=nil; 2085 exit;; 2086 end; 2087 2088 _packet := integer(packet); 2089 2090 if (_packet >= transfer^.num_iso_packets) then 2091 begin 2092 Result:=nil; 2093 exit;; 2094 end; 2095 2096 Result := pointer(transfer^.buffer) + integer(transfer^.iso_packet_desc[0].length * _packet); 2097end; 2098 2099 2100function libusb_get_descriptor( 2101 dev:plibusb_device_handle; 2102 desc_type:uint8_t; 2103 desc_index:uint8_t; 2104 data:puint8_t; 2105 length:integer):integer; 2106begin 2107 Result := libusb_control_transfer(dev, byte(LIBUSB_ENDPOINT_IN), 2108 byte(LIBUSB_REQUEST_GET_DESCRIPTOR), uint16_t( (desc_type shl 8) or desc_index), 2109 0, data, uint16_t(length), 1000); 2110end; 2111 2112 2113function libusb_get_string_descriptor( 2114 dev:plibusb_device_handle; 2115 desc_index:uint8_t; 2116 langid:uint16_t; 2117 data:puint8_t; 2118 length:integer):integer; 2119begin 2120 result:= libusb_control_transfer(dev, byte(LIBUSB_ENDPOINT_IN), 2121 byte(LIBUSB_REQUEST_GET_DESCRIPTOR), uint16_t((byte(LIBUSB_DT_STRING) shl 8) or desc_index), 2122 langid, data, uint16_t (length), 1000); 2123end; 2124 2125 2126end. 2127