pe       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ DA decoded 16 bits Binary Coded Decimal using 4 bits for each digit. Type of USB exceptions. Other exception. 1Operation not supported or unimplemented on this  platform. Insufficient memory. 1System call interrupted (perhaps due to signal). Pipe exception.  Overflow. Operation timed out. Resource busy. Entity not found. 0No such device (it may have been disconnected). *Access denied (insufficient permissions). Invalid parameter. Input/output exception. See: USB 2.0 Spec. table 9-7 Number of bytes transferred. LA timeout in millseconds. A timeout defines how long a transfer should wait O before giving up due to no response being received. For no timeout, use value  0. (Handy type synonym for write transfers. A  WriteAction is a function which takes a  and the   to write. The function returns an  * action which, when exectued, returns the Lnumber of bytes that were actually written paired with an indication if the transfer timed out. !'Handy type synonym for read transfers. A  ReadAction is a function which takes a  and a  which defines 0how many bytes to read. The function returns an   action which, when 3executed, performs the actual read and returns the   that was read 5paired with an indication if the transfer timed out. "&Type of indici of string descriptors. .Can be retrieved by all the *StrIx functions. %DThe language ID consists of the primary language identifier and the *sublanguage identififier as described in:  2http://www.usb.org/developers/docs/USB_LANGIDs.pdf 0For a mapping between IDs and languages see the usb-id-database package at:  2http://hackage.haskell.org/package/usb-id-database  To see which % s are supported by a device see . &#Number of additional transactions. =5The direction of data transfer relative to the host. >,In transfer direction (device -> host) used  for reading. ?-Out transfer direction (host -> device) used  for writing. @The address of an endpoint. BMust be >= 0 and <= 15 D?A structure representing the standard USB endpoint descriptor. QThis descriptor is documented in section 9.6.3 of the USB 2.0 specification. All <multiple-byte fields are represented in host-endian format. E&The address of the endpoint described  by the descriptor. FAttributes which apply to the ( endpoint when it is configured using  the \. G$Maximum packet size the endpoint is  capable of sending/ receiving. H"Interval for polling endpoint for ' data transfers. Expressed in frames # or microframes depending on the ( device operating speed (i.e., either # 1 millisecond or 125 s units). IFor audio devices only: the rate at % which synchronization feedback is  provided. JFor audio devices only: the address  if the synch endpoint. KExtra descriptors. If libusb  encounters unknown endpoint  descriptors, it will store ! them here, should you wish to  parse them. L@A structure representing the standard USB interface descriptor. MThis descriptor is documented in section 9.6.5 of the USB 2.0 specification. &This structure can be retrieved using a. MNumber of the  interface. NValue used to select  the alternate setting  for the interface. OUSB-IF class code for  the interface. PUSB-IF subclass code for  the interface,  qualified by the  O value. QUSB-IF protocol code for  the interface,  qualified by the  O and  P  values. RIndex of string  descriptor describing  the interface. SList of endpoints  supported by the  interface. TExtra descriptors. If  libusb encounters  unknown interface  descriptors, it will  store them here, should  you wish to parse them. W.The Remote Wakeup field indicates whether the 1 device is currently enabled to request remote - wakeup. The default mode for devices that & support remote wakeup is disabled. X-The Self Powered field indicates whether the $ device is currently self-powered ZGAn interface is represented as a list of alternate interface settings. [DA structure representing the standard USB configuration descriptor. MThis descriptor is documented in section 9.6.3 of the USB 2.0 specification. #This structure can be retrieved by r. \Identifier value for the  configuration. ]Index of string descriptor ! describing the configuration. ^Configuration characteristics. _!Maximum power consumption of the " USB device from the bus in the $ configuration when the device is $ fully operational. Expressed in # 2 mA units (i.e., 50 = 100 mA). `"Number of interfaces supported by  the configuration. a List of interfaces supported by  the configuration. % Note that the length of this list  should equal  `. bExtra descriptors. If libusb $ encounters unknown configuration # descriptors, it will store them " here, should you wish to parse  them. e=A structure representing the standard USB device descriptor. MThis descriptor is documented in section 9.6.1 of the USB 2.0 specification. #This structure can be retrieved by y. fUSB specification release  number in binary-coded  decimal. gUSB-IF class code for the  device. hUSB-IF subclass code for the  device, qualified by the  g value. iUSB-IF protocol code for the  device, qualified by the  g and  h values. jMaximum packet size for  endpoint 0. kUSB-IF vendor ID. lUSB-IF product ID. mDevice release number in  binary-coded decimal. nIndex of string descriptor  describing manufacturer. oIndex of string descriptor  describing product. pIndex of string descriptor  containing device serial  number. qNumber of possible  configurations. rList of configurations  supported by the device. s-Identifier for interface alternate settings. Can be retrieved by N. tIdentifier for interfaces. Can be retrieved by M. uIdentifier for configurations. Can be retrieved by  or by \. vIAbstract type representing a handle on a USB device, usually originating from . $A device handle is used to perform I/+O and other operations. When finished with 1a device handle, you should close it by applying  to it. w Retrieve the x from the v. xHAbstract type representing a USB device detected on the system, usually originating from . ICertain operations can be performed on a device, but in order to do any I/O you will have to first obtain a v using . Alternatively you  can use the usb-safe8 package which provides type-safe device handling. See:  +http://hackage.haskell.org/package/usb-safe NJust because you have a reference to a device does not mean it is necessarily Kusable. The device may have been unplugged, you may not have permission to Koperate such device, or another program or driver may be using the device. MTo get additional information about a device you can retrieve its descriptor using y. This reference to the  is needed so that it won't * get garbage collected so the finalizer  p'libusb_exit ( only gets run when all references to Devices are gone. y*Get the USB device descriptor for a given  device. zMessage verbosity {.Informational messages are printed to stdout, 4 warning and error messages are printed to stderr |1Warning and error messages are printed to stderr }%Error messages are printed to stderr ~,No messages are ever printed by the library *Abstract type representing a USB session. OThe concept of individual sessions allows your program to use multiple threads Lthat can independently use this library without interfering with eachother. (Sessions are created and initialized by  and are automatically closed when garbage collected. "The only functions that receive a Ctx are  and . )Create and initialize a new USB context. This function may throw s. Set message verbosity. The default level is ~#, which means no messages are ever Qprinted. If you choose to increase the message verbosity level, ensure that your %application does not close the stdout/stderr file descriptors. You are advised to set level |". libusb is conservative with its Pmessage logging and most of the time, will only log messages that explain error Gconditions and other oddities. This will help you debug your software. NIf the LIBUSB_DEBUG environment variable was set when libusb was initialized, Othis function does nothing: the message verbosity is fixed to the value in the environment variable. PIf libusb was compiled without any message logging, this function does nothing: you'll never get any messages. NIf libusb was compiled with verbose debug message logging, this function does  nothing: you'(ll always get messages from all levels. @Returns a list of USB devices currently attached to the system. ?This is your entry point into finding a USB device to operate.  Exceptions:  ! on a memory allocation failure. 9Get the number of the bus that a device is connected to. =Get the address of the device on the bus it is connected to. *Open a device and obtain a device handle.  A handle allows you to perform I/O on the device in question. DThis is a non-blocking function; no requests are sent over the bus. It is advised to use % because it automatically closes the (device when the computation terminates.  Exceptions:  * if there is a memory allocation failure.   + if the user has insufficient permissions.   & if the device has been disconnected.  Another . Close a device handle. DShould be called on all open handles before your application exits. DThis is a non-blocking function; no requests are sent over the bus. withDeviceHandle dev act opens the x dev and passes (the resulting handle to the computation act$. The handle will be closed on exit from withDeviceHandle0 whether by normal termination or by raising an  exception. :Determine the bConfigurationValue of the currently active configuration. MYou could formulate your own control request to obtain this information, but Pthis function has the advantage that it may be able to retrieve the information "from operating system caches (no I/ O involved). QIf the OS does not cache this information, then this function will block while a ;control transfer is submitted to retrieve the information. OThis function will return a value of 0 if the device is in unconfigured state.  Exceptions:   & if the device has been disconnected.  Aanother . +Set the active configuration for a device. PThe operating system may or may not have already set an active configuration on Pthe device. It is up to your application to ensure the correct configuration is Nselected before you attempt to claim interfaces and perform other operations. KIf you call this function on a device already configured with the selected Mconfiguration, then this function will act as a lightweight device reset: it Pwill issue a SET_CONFIGURATION request using the current configuration, causing Nmost USB-related device state to be reset (altsetting reset to zero, endpoint halts cleared, toggles reset). You cannot change/?reset configuration if your application has claimed interfaces - you should free them with  first. You cannot change/reset Hconfiguration if other applications or drivers have claimed interfaces. OA configuration value of -1 will put the device in unconfigured state. The USB Nspecifications state that a configuration value of 0 does this, however buggy 5devices exist which actually have a configuration 0. EYou should always use this function rather than formulating your own LSET_CONFIGURATION control request. This is because the underlying operating /system needs to know when such changes happen. This is a blocking function.  Exceptions:   0 if the requested configuration does not exist.   & if interfaces are currently claimed.   % if the device has been disconnected  Another . -Claim an interface on a given device handle. EYou must claim the interface you wish to use before you can perform I/ O on any of its endpoints. QIt is legal to attempt to claim an already-claimed interface, in which case this .function just returns without doing anything. LClaiming of interfaces is a purely logical operation; it does not cause any Mrequests to be sent over the bus. Interface claiming is used to instruct the Nunderlying operating system that your application wishes to take ownership of the interface. !This is a non-blocking function.  Exceptions:   , if the requested interface does not exist.   & if the interface is already claimed.   & if the device has been disconnected.  Another . -Release an interface previously claimed with . JYou should release all claimed interfaces before closing a device handle. QThis is a blocking function. A SET_INTERFACE control request will be sent to the Bdevice, resetting interface state to the first alternate setting.  Exceptions:   # if the interface was not claimed.   % if the device has been disconnected  Another . withClaimedInterface6 claims the interface on the given device handle then -executes the given computation. On exit from withClaimedInterface, the Pinterface is released whether by normal termination or by raising an exception. 0Activate an alternate setting for an interface. 5The interface must have been previously claimed with  or withInterfaceHandle. EYou should always use this function rather than formulating your own OSET_INTERFACE control request. This is because the underlying operating system (needs to know when such changes happen. This is a blocking function.  Exceptions:   3 if the interface was not claimed or the requested % alternate setting does not exist.   & if the device has been disconnected.  Another . Clear the halt/!stall condition for an endpoint. QEndpoints with halt status are unable to receive or transmit data until the halt condition is stalled. LYou should cancel all pending transfers before attempting to clear the halt  condition. This is a blocking function.  Exceptions:   ! if the endpoint does not exist.   & if the device has been disconnected.  Another . 3Perform a USB port reset to reinitialize a device. LThe system will attempt to restore the previous configuration and alternate (settings after the reset has completed. LIf the reset fails, the descriptors change, or the previous state cannot be Prestored, the device will appear to be disconnected and reconnected. This means Othat the device handle is no longer valid (you should close it) and rediscover the device. A  ( is raised to indicate that this is the case. EThis is a blocking function which usually incurs a noticeable delay.  Exceptions:   * if re-enumeration is required, or if the ! device has been disconnected.  Another . 8Determine if a kernel driver is active on an interface. QIf a kernel driver is active, you cannot claim the interface, and libusb will be unable to perform I/O.  Exceptions:   & if the device has been disconnected.  Another . *Detach a kernel driver from an interface. IIf successful, you will then be able to claim the interface and perform I/O.  Exceptions:   ! if no kernel driver was active.   " if the interface does not exist.   & if the device has been disconnected.  Another . Re-attach an interface'&s kernel driver, which was previously detached using .  Exceptions:   ! if no kernel driver was active.   " if the interface does not exist.   & if the device has been disconnected.   8 if the driver cannot be attached because the interface & is claimed by a program or driver.  Another . FIf a kernel driver is active on the specified interface the driver is Pdetached and the given action is executed. If the action terminates, whether by Mnormal termination or by raising an exception, the kernel driver is attached Qagain. If a kernel driver is not active on the specified interface the action is just executed.  Exceptions:   & if the device has been disconnected.  Another . (Retrieve a list of supported languages. This function may throw s. /putStrDesc devHndl strIx langId maxSize dataPtr retrieves the string descriptor strIx in the language langId from the devHndl and writes at most maxSize* bytes from that string descriptor to the location that dataPtr. points to. So ensure there is at least space for maxSize8 bytes there. Next, the header of the string descriptor !is checked for correctness. If it's incorrect an  is >thrown. Finally, the size reported in the header is returned. ,Retrieve a string descriptor from a device. PThis is a convenience function which formulates the appropriate control message Oto retrieve the descriptor. The string returned is Unicode, as detailed in the USB specifications. This function may throw s. ERetrieve a string descriptor from a device using the first supported  language. PThis is a convenience function which formulates the appropriate control message Oto retrieve the descriptor. The string returned is Unicode, as detailed in the USB specifications. This function may throw s. Perform a USB control& request that does not transfer data. The value and index3 values should be given in host-endian byte order.  Exceptions:   if the transfer timed out.  8 if the control request was not supported by the device   & if the device has been disconnected.  Another . Perform a USB control read. The value and index3 values should be given in host-endian byte order.  Exceptions:  8 if the control request was not supported by the device   & if the device has been disconnected.  Another . Perform a USB control write. The value and index3 values should be given in host-endian byte order.  Exceptions:  8 if the control request was not supported by the device   & if the device has been disconnected.  Another . !See: USB 2.0 Spec. section 9.4.9 !See: USB 2.0 Spec. section 9.4.1 !See: USB 2.0 Spec. section 9.4.9 !See: USB 2.0 Spec. section 9.4.9 . TODO: What about vendor-specific test modes? !See: USB 2.0 Spec. section 9.4.4 !See: USB 2.0 Spec. section 9.4.5 !See: USB 2.0 Spec. section 9.4.5 !See: USB 2.0 Spec. section 9.4.6 "See: USB 2.0 Spec. section 9.4.11 Perform a USB bulk read.  Exceptions:   if the endpoint halted.  " if the device offered more data,  see Packets and overflows in the libusb documentation:   9http://libusb.sourceforge.net/api-1.0/packetoverflow.html.   & if the device has been disconnected.  Another . Perform a USB bulk write.  Exceptions:   if the endpoint halted.  " if the device offered more data,  see Packets and overflows in the libusb documentation:   9http://libusb.sourceforge.net/api-1.0/packetoverflow.html.   & if the device has been disconnected.  Another . Perform a USB  interrupt read.  Exceptions:   if the endpoint halted.  " if the device offered more data,  see Packets and overflows in the libusb documentation:   9http://libusb.sourceforge.net/api-1.0/packetoverflow.html.   & if the device has been disconnected.  Another . Perform a USB  interrupt write.  Exceptions:   if the endpoint halted.  " if the device offered more data,  see Packets and overflows in the libusb documentation:   9http://libusb.sourceforge.net/api-1.0/packetoverflow.html.   & if the device has been disconnected.  Another . handleUSBException action executes action. If action returned an  error code other than 'c\'LIBUSB_SUCCESS', the error is converted to a   and thrown. checkUSBException action executes action. If action returned a 0 negative integer the integer is converted to a  and thrown. If  not, the integer is returned.  Convert a 'C\'libusb_error' to a  . If the C'libusb_error is  unknown an   is thrown. Association list mapping s to s. decodeBCD bitsInDigit n" decodes the Binary Coded Decimal n to a list of its encoded digits.  bitsInDigit,, which is usually 4, is the number of bits $used to encode a single digit. See:  1http://en.wikipedia.org/wiki/Binary-coded_decimal  bits s e b extract bit s to e (including) from b. 0Execute the given action but ignore the result. A generalized   that works on any   type. A generalized   that returns any   type. input  doWrite first converts the input  ByteString to an  array of Word8s, then doWrite+ is executed by pointing it to the size of 9 this array and the array itself. Finally, the result of doWrite is  returned. @Make sure not to return the pointer to the array from @doWrite@! KNote that the converion from the @ByteString@ to the @Word8@ array is O(1).   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~    !"#$%&)(''()*+,-+,-.10//012654334567;:9889:;<=?>>?@ABCABCDEFGHIJKEFGHIJKL MNOPQRSTMNOPQRSTUVWXVWXYZ[\]^_`ab\]^_`abcdefghijklmnopqrfghijklmnopqrstuvwwxyyz~}|{{|}~#Bas van Dijk <v.dijk.bas@gmail.com>  #Bas van Dijk <v.dijk.bas@gmail.com>U"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrxefghijklmnopqrfghijklmnopqrdc[\]^_`ab\]^_`abZYUVWXLMNOPQRSTMNOPQRSTDEFGHIJKEFGHIJK@ABC=?><7;:9826543.10/*+,-&)('%$#"#Bas van Dijk <v.dijk.bas@gmail.com>stuvwvwwuts#Bas van Dijk <v.dijk.bas@gmail.com>xyxyy#Bas van Dijk <v.dijk.bas@gmail.com>z{|}~z~}|{#Bas van Dijk <v.dijk.bas@gmail.com>#Bas van Dijk <v.dijk.bas@gmail.com># !#! #Bas van Dijk <v.dijk.bas@gmail.com>  !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ !"#$%&'()*+,-./0123456789:;;<=>?@ABCDEFGHIJKLMNOPPQRSTUVWXYZ[\]^_`abcddefghijklmnopqrstuvwxyz{|}~     S[isusb-0.3System.USB.DescriptorsSystem.USB.ExceptionsSystem.USB.IO.SynchronousSystem.USB.DeviceHandlingSystem.USB.EnumerationSystem.USB.Initialization$System.USB.IO.Synchronous.EnumeratorSystem.USB.Internalbytestring-0.9.1.5Data.ByteStringbase System.IOPreludebindings-libusb-1.4.2Bindings.Libusb.Miscellaneous System.USBBCD4 USBExceptionOtherExceptionNotSupportedExceptionNoMemExceptionInterruptedException PipeExceptionOverflowExceptionTimeoutException BusyExceptionNotFoundExceptionNoDeviceExceptionAccessExceptionInvalidParamException IOExceptionTestModeTest_Force_Enable Test_Packet Test_SE0_NAKTest_KTest_J RecipientToOther ToEndpoint ToInterfaceToDevice RequestTypeVendorClassStandardSizeTimeout WriteAction ReadActionStrIx SubLangId PrimaryLangIdLangIdTransactionOpportunitiesTwoOneZero MaxPacketSize maxPacketSizetransactionOpportunitiesUsageImplicitFeedbackDataSynchronization SynchronousAdaptive AsynchronousNoSynchronization TransferType InterruptBulk IsochronousControlEndpointAttribsTransferDirectionInOutEndpointAddressendpointNumbertransferDirection EndpointDescendpointAddressendpointAttribsendpointMaxPacketSizeendpointIntervalendpointRefreshendpointSynchAddress endpointExtra InterfaceDescinterfaceNumberinterfaceAltSettinginterfaceClassinterfaceSubClassinterfaceProtocolinterfaceStrIxinterfaceEndpointsinterfaceExtra DeviceStatus remoteWakeup selfPowered ConfigAttribs Interface ConfigDesc configValue configStrIx configAttribsconfigMaxPowerconfigNumInterfacesconfigInterfaces configExtra ProductIdVendorId DeviceDescdeviceUSBSpecReleaseNumber deviceClassdeviceSubClassdeviceProtocoldeviceMaxPacketSize0deviceVendorIddeviceProductIddeviceReleaseNumberdeviceManufacturerStrIxdeviceProductStrIxdeviceSerialNumberStrIxdeviceNumConfigs deviceConfigsInterfaceAltSettingInterfaceNumber ConfigValue DeviceHandle getDeviceDevice deviceDesc Verbosity PrintInfo PrintWarnings PrintErrors PrintNothingCtxnewCtxsetDebug getDevices busNumber deviceAddress openDevice closeDevicewithDeviceHandle getConfig setConfigclaimInterfacereleaseInterfacewithClaimedInterfacesetInterfaceAltSetting clearHalt resetDevicekernelDriverActivedetachKernelDriverattachKernelDriverwithDetachedKernelDriver getLanguages getStrDescgetStrDescFirstLangcontrol readControl writeControlsetHaltclearRemoteWakeupsetRemoteWakeupsetStandardTestModegetInterfaceAltSettinggetDeviceStatusgetEndpointStatussetDeviceAddress synchFramereadBulk writeBulk readInterruptwriteInterrupt enumReadBulkenumReadInterruptData.ByteString.Internal ByteString GHC.IOBaseIO_ctx putStrDeschandleUSBExceptioncheckUSBExceptionconvertUSBExceptionGHC.Errerrorlibusb_error_to_USBExceptionC'libusb_error decodeBCDbitsignore genToEnumGHC.EnumtoEnumGHC.RealIntegral genFromEnumfromEnum writeWithC'TransferFunc getDevHndlPtr getDevFrgnPtrunCtx withCtxPtr withDevicePtrconvertDeviceDescunmarshalConfigAttribs getConfigDescconvertConfigDescconvertInterfaceconvertInterfaceDescconvertEndpointDescunmarshalEndpointAddressmarshalEndpointAddressunmarshalEndpointAttribsunmarshalMaxPacketSizestrDescHeaderSizeunmarshalLangId marshalLangIdmarshalRequestTyperemoteWakeupFeature haltFeaturetestModeFeature readTransfer writeTransfertransferunknownLibUsbError unmarshalBCD4betweenifM