| Maintainer | Bas van Dijk <v.dijk.bas@gmail.com> |
|---|
System.USB.Internal
Contents
Description
This module is not intended for end users. It provides internal and unsafe functions used for extending this package.
- type C'TransferFunc = Ptr C'libusb_device_handle -> CUChar -> Ptr CUChar -> CInt -> Ptr CInt -> CUInt -> IO CInt
- withDevHndlPtr :: DeviceHandle -> (Ptr C'libusb_device_handle -> IO α) -> IO α
- convertUSBException :: Num α => α -> USBException
- unmarshalReleaseNumber :: Word16 -> ReleaseNumber
- unmarshalStrIx :: Word8 -> Maybe StrIx
- marshalEndpointAddress :: (Bits α, Num α) => EndpointAddress -> α
- unmarshalEndpointAddress :: Word8 -> EndpointAddress
- type C'TransferType = CUChar
- threaded :: Bool
- allocaTransfer :: Int -> (Ptr C'libusb_transfer -> IO α) -> IO α
- withCallback :: (Ptr C'libusb_transfer -> IO ()) -> (C'libusb_transfer_cb_fn -> IO α) -> IO α
- data SumLength = SumLength !Int !Int
- sumLength :: [Int] -> SumLength
- peekIsoPacketDescs :: Int -> Ptr C'libusb_transfer -> IO [C'libusb_iso_packet_descriptor]
- initIsoPacketDesc :: Size -> C'libusb_iso_packet_descriptor
- getCtx :: Device -> Ctx
- getEventManager :: Ctx -> Maybe (EventManager, Maybe (IO ()))
- data Lock
- newLock :: IO Lock
- acquire :: Lock -> IO ()
- release :: Lock -> IO ()
Documentation
type C'TransferFunc = Ptr C'libusb_device_handle -> CUChar -> Ptr CUChar -> CInt -> Ptr CInt -> CUInt -> IO CIntSource
Handy type synonym for the libusb transfer functions.
withDevHndlPtr :: DeviceHandle -> (Ptr C'libusb_device_handle -> IO α) -> IO αSource
convertUSBException :: Num α => α -> USBExceptionSource
Convert a C'libusb_error to a USBException. If the C'libusb_error is
unknown an error is thrown.
unmarshalReleaseNumber :: Word16 -> ReleaseNumberSource
Unmarshal a a 16bit word as a release number. The 16bit word should be encoded as a Binary Coded Decimal using 4 bits for each of the 4 decimals. Also see:
unmarshalStrIx :: Word8 -> Maybe StrIxSource
Unmarshal an 8bit word to a string descriptor index. 0 denotes that a
string descriptor is not available and unmarshals to Nothing.
Marshal and unmarshal endpoint addresses
The address should be encoded according to section 9.6.6 of the USB 2.0 specification.
- Bits 0-3 denote the
endpointNumber. - Bit 7 denotes the
transferDirection. 0 denotesOutand 1 denotesIn.
marshalEndpointAddress :: (Bits α, Num α) => EndpointAddress -> αSource
Marshal an endpoint address so that it can be used by the libusb transfer
functions.
unmarshalEndpointAddress :: Word8 -> EndpointAddressSource
Unmarshal an 8bit word as an endpoint address. This function is primarily used when unmarshalling USB descriptors.
Useful types and functions for asynchronous implementations
type C'TransferType = CUCharSource
allocaTransfer :: Int -> (Ptr C'libusb_transfer -> IO α) -> IO αSource
Allocate a transfer with the given number of isochronous packets and apply the function to the resulting pointer. The transfer is automatically freed when the function terminates (whether normally or by raising an exception).
A NoMemException may be thrown.
withCallback :: (Ptr C'libusb_transfer -> IO ()) -> (C'libusb_transfer_cb_fn -> IO α) -> IO αSource
Create a FunPtr to the given transfer callback function and pass it to
the continuation function. The FunPtr is automatically freed when the
continuation terminates (whether normally or by raising an exception).
peekIsoPacketDescs :: Int -> Ptr C'libusb_transfer -> IO [C'libusb_iso_packet_descriptor]Source
Retrieve the isochronous packet descriptors from the given transfer.
initIsoPacketDesc :: Size -> C'libusb_iso_packet_descriptorSource
An isochronous packet descriptor with all fields zero except for the length.
This reference to the Ctx is needed so that it won't
get garbage collected. The finalizer p'libusb_exit is
run only when all references to Devices are gone.
getEventManager :: Ctx -> Maybe (EventManager, Maybe (IO ()))Source
Retrieve the optional event manager from the context
and the optional IO action for handling events.
Locks
acquire :: Lock -> IO ()Source
Acquires the Lock. Blocks if another thread has acquired the Lock.
acquire behaves as follows:
- When the state is "unlocked"
acquirechanges the state to "locked". - When the state is "locked"
acquireblocks until a call toreleasein another thread wakes the calling thread. Upon awakening it will change the state to "locked".