libusb.pp 76 KB

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