úÎ$¹(?      !"#$%&'()*+,-./0123456789:;<=>#Bas van Dijk <v.dijk.bas@gmail.com>S0Control transfers can have three request types: Standard, Class and Vendor. We disallow Standard, requests however because with them you can 9destroy the safety guarantees that this module provides. ?-Class of transfer types that support writing Write bytes to an  endpoint with either a   or    transfer type.  Exceptions:  @ if the endpoint halted.  A& if the device has been disconnected.  Another B. (Handy type synonym for write transfers. A  WriteAction; is a function which takes a timeout and the bytestring to Owrite. The function returns an action which, when exectued, returns the number Nof bytes that were actually written paired with an indication if the transfer  timed out. C.Class of transfer types that support reading. Read bytes from an  endpoint with either a   or    transfer type.  Exceptions:  @ if the endpoint halted.  D" if the device offered more data,  see Packets and overflows in the libusb documentation:   9http://libusb.sourceforge.net/api-1.0/packetoverflow.html.  A& if the device has been disconnected.  Another B. 'Handy type synonym for read transfers. A  ReadActionB is a function which takes a timeout and a size which defines how Imany bytes to read. The function returns an action which, when executed, Qperforms the actual read and returns the bytestring that was read paired with an &indication if the transfer timed out.  9In transfer direction (device -> host) used for reading. :Out transfer direction (host -> device) used for writing. I/CO operations on endpoints are type-safe. You can only read from an endpoint with an : transfer direction and you can only write to an endpoint with an  transfer direction. JReading and writing also have different implementations for the different endpoint transfer types like:   and  . I/O with endpoints of other transfer types like   and   is not possible. LThis type lifts the transfer direction and transfer type information to the type-level so that I/O operations like  and  can &specify which endpoints they support. 5You can retrieve the endpoints of an alternate using 3. E(A handle to a setted alternate setting. 'You get a handle to an alternate using 0, 1 or 2. The type variable sAlt is used to ensure that you can't )return this handle from these functions. F A supported 0 alternate setting which you can retrieve using  /. GAHandy type synonym for a regional handle to a claimed interface. DA regional handle to a claimed interface can be created by applying - (= H) or I% to the interface you wish to claim. FA supported interface of a configuration which you can retrieve using  ,. To retrieve the J! descriptors of an interface use !. KLMN This exception can be thrown in * to indicate that the $device is currently not configured. !This exception can be thrown in:  '  ), * or +  0, 1 or 2 Cto indicate that the device was already configured with a setting. A handle to an active  which you can get using: ), * or +. The type variable sCfg is used to ensure that you can't return this handle from these functions. OFA supported configuration of a USB device parameterized by the region r in which it was created. QNote that, just like a regional device handle, a configuration can be duplicated to a parent region using P. KAlso note that you can get the descriptor of the configuration by applying ! to it. Q !*Get the descriptor of a given USB entity. " This exception can be thrown in &, +,  . or 2 to indicate that no value was , found which satisfied the given predicate. #$BHandy type synonym for a regional handle to an opened USB device. EA regional handle to an opened USB device can be created by applying RH or I% to the USB device you wish to open. Note that you can also  duplicate& a regional device handle by applying P to it. SIInternally used function for getting the actual USB device handle from a  regional device handle. %GConvenience function for retrieving the device from the given regional  handle. &IConvenience function which finds the first device attached to the system Nwhich satisfies the given predicate on its descriptor, then opens that device Land applies the given continuation function to the resulting device handle.  Exceptions:  #"< if no device is found which satisfies the given predicate.  T* if there is a memory allocation failure.  U+ if the user has insufficient permissions.  A& if the device has been disconnected.  Another B. $Predicate on the device descriptor. Continuation function VFInternally used function which searches through the given list of USB J entities (like Devices, Configs, Interfaces or Alternates) for the first M entity which satisfies the given predicate on its descriptor. Then opens or L sets that entity by applying the given open or set function to the entity. With Predicate on descriptor Continuation function 'KPerform a USB port reset to reinitialize a device. The system will attempt Qto restore the previous configuration and alternate settings after the reset has  completed. Note the constraint: pr `ParentOf` cr". This allows this function to be executed in any child region cr of the parent region pr in which the given regional handle was created. <You can only reset a device when all computations passed to ), * and +# have been terminated. If you call  resetDevice+ and such a computation is still running a  exception is thrown. 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 W. is raised to indicate that this is the case. OTODO: Think about how to handle the implications of the the previous paragraph! EThis is a blocking function which usually incurs a noticeable delay.  Exceptions:  ' if a configuration has been set using ),  * and +.  W* if re-enumeration is required, or if the ! device has been disconnected.  Another B. (FRetrieve the supported configurations from the given regional handle. @Note that the configuration is parameterized by the same region r in which the Lregional handle was created. This ensures you can never use a configuration outside that region. XJInternally used function for getting all the configuration descriptors of  the given device. )CSet the active configuration for a device and then apply the given =continuation function to the resulting configuration handle. OUSB devices support multiple configurations of which only one can be active at 2any given time. When a configuration is set using ), * or +> no threads can set a new configuration until the computation Apassed to these functions terminates. If you do try to set one a  exception will be thrown. 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 Qselected before you attempt to claim interfaces and perform other operations. If 5you want to use the current active configuration use *. 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 other applications or drivers have claimed interfaces. This is a blocking function.  Exceptions:  / if a configuration has already been set using  ), * or +.  Y& if interfaces are currently claimed.  A% if the device has been disconnected  Another B. #The configuration you wish to set. Continuation function. Z(Internally used function which throws a  exception if  the given MVar was set. If the given MVar wasn't set it will be set M before the given computation is performed. When the computation terminates, 1 wheter normally or by raising an exception, the MVar will be unset again. *IApply the given continuation function to the configuration handle of the 9current active configuration of the given device handle. HThis function needs to determine the current active configuration. This <information may be cached by the operating system. If it isn't cached this Jfunction will block while a control transfer is submitted to retrieve the  information.  Exceptions:  / if a configuration has already been set using  ), * or +.  " if the device is not configured.  A& if the device has been disconnected.  Aanother B. Regional handle to the device " from which you want to use the  active configuration. Continuation function +MConvenience function which finds the first configuration of the given device Mhandle which satisfies the given predicate on its descriptor, then sets that Lconfiguration and applies the given function to the resulting configuration handle. This function calls ) so do see its documentation.  Exceptions:  / if a configuration has already been set using  ), * or +.  #"7 if no configuration is found that satisfies the given  predicate.  Y& if interfaces are currently claimed.  A% if the device has been disconnected  Another B. "Regional handle to the device for  which you want to set a  configuration. Predicate on the configuration  descriptor. Continuation function. ,ARetrieve the supported interfaces from the configuration handle. 0Note that the interface is parameterized by the sCfg of the configuration Ohandle it is derived from. This ensures that it can never be returned from the 2functions that created this configuration handle: ), * and +. NThe latter is useful because outside those functions the active configuration Emay change. If at that moment you still have an interface of the old -configuration claiming it would be an error. -3Claim the given interface in the interface region.  Note that: claim = H, which just reads better when applied to an  interface. ?Note that it is allowed to claim an already-claimed interface. 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:  Y9 if another program or driver has claimed the interface.  A& if the device has been disconnected.  Another B. Interface you wish to claim .BConvenience function which finds the first interface of the given Mconfiguration handle which satisfies the given predicate on its descriptors, Othen claims that interfaces and applies the given continuation function to the resulting regional handle.  Exceptions:  #"? if no interface was found that satisfies the fiven predicate.  Y9 if another program or driver has claimed the interface.  A& if the device has been disconnected.  Another B. #Handle to a configuration of which # you want to claim an interface. (Predicate on the interface descriptors. Continuation function. /KRetrieve the supported alternate settings from the given interface handle. ONote that the alternate setting is parameterized by the same type variables as Jthe interface handle. This ensures you can never use an alternate setting >outside the region in which the interface handle was created. 0HActivate an alternate setting for an interface and then apply the given 9continuation function to the resulting alternate handle. OSimillary to configurations, interfaces support multiple alternate settings of Owhich only one can be active at any given time. When an alternate is set using 0, 1 or 2 no threads can set a Qnew alternate until the computation passed to these functions terminates. If you do try to set one a  exception will be thrown. QThe operating system may already have set an alternate for the interface. If you .want to use this current active alternate use 1. This is a blocking function.  Exceptions:  A& if the device has been disconnected.  , if an alternate has already been set using  0, 1 or 2.  Another B. The alternate you wish to set. Continuation function. 1GApply the given function to the alternate handle of the current active (alternate of the give interface handle. KTo determine the current active alternate this function will block while a ;control transfer is submitted to retrieve the information.  Exceptions:  A& if the device has been disconnected.  , if an alternate has already been set using  0, 1 or 2.  Aanother B. Regional handle to the ! interface from which you want  to use the active alternate. Continuation function. 2LConvenience function which finds the first alternate of the given interface Mhandle which satisfies the given predicate on its descriptor, then sets that Lalternate and applies the given function to the resulting alternate handle. This function calls 0 so do see its documentation.  Exceptions:  #"3 if no alternate is found that satisfies the given  predicate.  A& if the device has been disconnected.  , if an alternate has already been set using  0, 1 or 2.  Another B. Regional handle to the  interface for which you want  to set an alternate. Predicate on the interface  descriptor. Continuation function [\3LRetrieve all the endpoints from the given alternate handle which are of the - given transfer direction and transfer type. Handle to the alternate from " which you want to retrieve its  endpoints.  Filter all endpoints which have  this transfer direction.  Filter all endpoints which have  this transfer type. 4Clear 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:  A& if the device has been disconnected.  Another B. ]^5Perform 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  A& if the device has been disconnected.  Another B. 'A handle for the device to communicate  with. The type of request. The recipient of the request.  Request. Value. Index. $Timeout (in milliseconds) that this - function should wait before giving up due ) to no response being received. For no  timeout, use value 0. 6Perform 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  A& if the device has been disconnected.  Another B. A handle for the device to  communicate with. The type of request. The recipient of the request.  Request. Value. Index. 7Perform 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  A& if the device has been disconnected.  Another B. A handle for the device to  communicate with. The type of request. The recipient of the request.  Request. Value. Index. 8(Retrieve a list of supported languages. This function may throw Bs. 9,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 Bs. /TODO: The following can be made more type-safe!  When I call 94 I would like the type system to guarantee that the given StrIx and LangId actually belong to the given Handle . In other Nwords I would like to get a type error when they are some arbitrary number or come from another device. :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 Bs. ;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:  A& if the device has been disconnected.  Another B. <*Detach a kernel driver from an interface. IIf successful, you will then be able to claim the interface and perform I/O.  Exceptions:  W! if no kernel driver was active.  `" if the interface does not exist.  A& if the device has been disconnected.  Another B. =Re-attach an interface'&s kernel driver, which was previously detached using <.  Exceptions:  W! if no kernel driver was active.  `" if the interface does not exist.  A& if the device has been disconnected.  Y8 if the driver cannot be attached because the interface & is claimed by a program or driver.  Another B. >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:  A& if the device has been disconnected.  Another B. aMonadic if ... then ... else ... MbcdIHefghijPkl  !"#$%&'()*+,-./0123456789:;<=>?$%&"# !'()*+,-./01234  56789:;<=>?   !!"##$%&'()*+,-./0123456789:;<=>m          !"#$%&'()*+,-./0123456789:;9:<9:=>9:?@AB@AC9:DEF@AG@HBI9:J9:KL9:MN9:OPQRST9:U9:VW@AX@AY@AZ@A[@A\@A]@A^@A_@A`@Aa@Abc usb-safe-0.6System.USB.Safe RequestTypeVendorClass writeEndpoint WriteAction readEndpoint ReadAction InterruptBulk IsochronousControl TransferTypeInOutTransferDirectionEndpointAlternateHandle AlternateRegionalIfHandle InterfaceNoActiveConfigSettingAlreadySet ConfigHandleConfig GetDescriptorgetDescNotFoundRegionalDeviceHandle getDevicewithDeviceWhich resetDevice getConfigs setConfiguseActiveConfigsetConfigWhich getInterfacesclaimwithInterfaceWhich getAlternates setAlternateuseActiveAlternatesetAlternateWhich getEndpoints clearHaltcontrol readControl writeControl getLanguages getStrDescgetStrDescFirstLangkernelDriverActivedetachKernelDriverattachKernelDriverwithDetachedKernelDriver WriteEndpoint usb-0.3.1System.USB.Internal PipeExceptionNoDeviceException USBException ReadEndpointOverflowException regions-0.5#Control.Monad.Trans.Region.Internalopenwith ifDevHndlIifNumifDescsdupControl.ResourcegetInternalDevHndlNoMemExceptionAccessExceptionuseWhichNotFoundExceptiongetConfigDescs BusyExceptionwithUnsettedMVareqDireqType transferWithreqTypeToInternalTimeoutExceptionInvalidParamExceptionifM liftCatch mapRegionT liftCallCC forkTopRegion runTopRegion runRegionTRegionTRegionalHandle TopRegionDupParentOf