libusb.pp 76 KB

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