usb 0.1.0.1 → 0.2
raw patch · 9 files changed
+280/−207 lines, 9 filesdep ~bindings-libusb
Dependency ranges changed: bindings-libusb
Files
- System/USB.hs +6/−5
- System/USB/Descriptors.hs +56/−28
- System/USB/DeviceHandlingAndEnumeration.hs +0/−74
- System/USB/Devices.hs +92/−0
- System/USB/Exceptions.hs +9/−1
- System/USB/IO/Synchronous.hs +9/−0
- System/USB/Initialization.hs +9/−0
- System/USB/Internal.hs +96/−96
- usb.cabal +3/−3
System/USB.hs view
@@ -3,9 +3,7 @@ -- Module : System.USB -- Copyright : (c) 2009 Bas van Dijk -- License : BSD-style (see the file LICENSE)--- -- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>--- Stability : Experimental -- -- This library allows you to communicate with USB devices from userspace. It is -- implemented as a high-level wrapper around @bindings-libusb@ which is a@@ -28,21 +26,24 @@ -- * The USB 2.0 specification at: -- <http://www.usb.org/developers/docs/> ----- * The 'Bindings.Libusb' documentation at:+-- * The @bindings-libusb@ documentation at: -- <http://hackage.haskell.org/package/bindings-libusb> --+-- * \"USB in a NutShell\" at:+-- <http://www.beyondlogic.org/usbnutshell/usb1.htm>+-- -------------------------------------------------------------------------------- module System.USB ( module System.USB.Initialization- , module System.USB.DeviceHandlingAndEnumeration+ , module System.USB.Devices , module System.USB.Descriptors , module System.USB.IO.Synchronous , module System.USB.Exceptions ) where import System.USB.Initialization-import System.USB.DeviceHandlingAndEnumeration+import System.USB.Devices import System.USB.Descriptors import System.USB.IO.Synchronous import System.USB.Exceptions
System/USB/Descriptors.hs view
@@ -1,3 +1,25 @@+--------------------------------------------------------------------------------+-- |+-- Module : System.USB.Descriptors+-- Copyright : (c) 2009 Bas van Dijk+-- License : BSD3 (see the file LICENSE)+-- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>+--+-- USB devices report their attributes using descriptors. A descriptor is a data+-- structure with a defined format. Using descriptors allows concise storage of+-- the attributes of individual configurations because each configuration may+-- reuse descriptors or portions of descriptors from other configurations that+-- have the same characteristics. In this manner, the descriptors resemble+-- individual data records in a relational database.+--+-- Where appropriate, descriptors contain references to string descriptors+-- ('StrIx') that provide textual information describing a descriptor in+-- human-readable form. The inclusion of string descriptors is optional. If a+-- device does not support string descriptors, string reference fields must be+-- reset to zero to indicate no string descriptor is available.+--+--------------------------------------------------------------------------------+ module System.USB.Descriptors ( -- * Device descriptor DeviceDesc@@ -5,19 +27,24 @@ -- ** Querying device descriptors , deviceUSBSpecReleaseNumber- , BCD4 , deviceClass , deviceSubClass , deviceProtocol , deviceMaxPacketSize0- , deviceVendorId, VendorId- , deviceProductId, ProductId+ , deviceVendorId+ , deviceProductId , deviceReleaseNumber , deviceManufacturerStrIx , deviceProductStrIx , deviceSerialNumberStrIx , deviceNumConfigs + , BCD4++ -- | For a database of USB vendors and products see the /usb-id-database/+ -- package at: <http://hackage.haskell.org/package/usb-id-database>+ , VendorId, ProductId+ -- * Configuration descriptor , ConfigDesc @@ -28,16 +55,15 @@ -- ** Querying configuration descriptors , configValue , configStrIx- , configAttribs- , ConfigAttribs- , DeviceStatus(..)- , configMaxPower , configNumInterfaces , configInterfaces , configExtra + , ConfigAttribs+ , DeviceStatus(..)+ -- * Interface descriptor , InterfaceDesc @@ -57,24 +83,24 @@ -- ** Querying endpoint descriptors , endpointAddress+ , endpointAttribs+ , endpointMaxPacketSize+ , endpointInterval+ , endpointRefresh+ , endpointSynchAddress+ , endpointExtra+ , EndpointAddress(..) , TransferDirection(..) - , endpointAttribs , EndpointAttribs , TransferType(..) , Synchronization(..) , Usage(..) - , endpointMaxPacketSize , MaxPacketSize(..) , TransactionOpportunities(..) - , endpointInterval- , endpointRefresh- , endpointSynchAddress- , endpointExtra- -- * String descriptors , getLanguages , LangId, PrimaryLangId, SubLangId@@ -88,19 +114,22 @@ , getDeviceDesc , deviceUSBSpecReleaseNumber- , BCD4 , deviceClass , deviceSubClass , deviceProtocol , deviceMaxPacketSize0- , deviceVendorId, VendorId- , deviceProductId, ProductId+ , deviceVendorId+ , deviceProductId , deviceReleaseNumber , deviceManufacturerStrIx , deviceProductStrIx , deviceSerialNumberStrIx , deviceNumConfigs + , BCD4++ , VendorId, ProductId+ , ConfigDesc , getActiveConfigDesc@@ -109,16 +138,15 @@ , configValue , configStrIx- , configAttribs- , ConfigAttribs- , DeviceStatus(..)- , configMaxPower , configNumInterfaces , configInterfaces , configExtra + , ConfigAttribs+ , DeviceStatus(..)+ , InterfaceDesc , interfaceNumber@@ -134,23 +162,23 @@ , EndpointDesc , endpointAddress+ , endpointAttribs+ , endpointMaxPacketSize+ , endpointInterval+ , endpointRefresh+ , endpointSynchAddress+ , endpointExtra+ , EndpointAddress(..) , TransferDirection(..) - , endpointAttribs , EndpointAttribs , TransferType(..) , Synchronization(..) , Usage(..) - , endpointMaxPacketSize , MaxPacketSize(..) , TransactionOpportunities(..)-- , endpointInterval- , endpointRefresh- , endpointSynchAddress- , endpointExtra , getLanguages , LangId, PrimaryLangId, SubLangId
− System/USB/DeviceHandlingAndEnumeration.hs
@@ -1,74 +0,0 @@-module System.USB.DeviceHandlingAndEnumeration- ( -- * Enumeration- Device- , getDevices-- , getBusNumber- , getDeviceAddress- , getMaxPacketSize-- -- * Opening & closing of devices- , DeviceHandle- , openDevice- , closeDevice- , withDeviceHandle- , getDevice-- -- * Getting & setting the configuration- , ConfigValue- , getConfig- , setConfig-- -- * Claiming & releasing interfaces- , InterfaceNumber- , claimInterface- , releaseInterface- , withInterface- , InterfaceAltSetting- , setInterfaceAltSetting-- -- * Clearing & Resetting devices- , clearHalt- , resetDevice-- -- * USB kernel drivers- , kernelDriverActive- , detachKernelDriver- , attachKernelDriver- , withDetachedKernelDriver- ) where--import System.USB.Internal- ( Device- , getDevices-- , getBusNumber- , getDeviceAddress- , getMaxPacketSize-- , DeviceHandle- , openDevice- , closeDevice- , withDeviceHandle- , getDevice-- , ConfigValue- , getConfig- , setConfig-- , InterfaceNumber- , claimInterface- , releaseInterface- , withInterface- , InterfaceAltSetting- , setInterfaceAltSetting-- , clearHalt- , resetDevice-- , kernelDriverActive- , detachKernelDriver- , attachKernelDriver- , withDetachedKernelDriver- )-
+ System/USB/Devices.hs view
@@ -0,0 +1,92 @@+--------------------------------------------------------------------------------+-- |+-- Module : System.USB.Devices+-- Copyright : (c) 2009 Bas van Dijk+-- License : BSD3 (see the file LICENSE)+-- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>+--+-- The functionality documented in this module is designed to help with the+-- following operations:+--+-- * Enumerating the USB devices currently attached to the system.+--+-- * Choosing a device to operate from your software.+--+-- * Opening and closing the chosen device.+--+--------------------------------------------------------------------------------++module System.USB.Devices+ ( -- * Enumeration+ Device+ , getDevices++ , getBusNumber+ , getDeviceAddress+ , getMaxPacketSize++ -- * Opening & closing of devices+ , DeviceHandle+ , openDevice+ , closeDevice+ , withDeviceHandle+ , getDevice++ -- * Getting & setting the configuration+ , ConfigValue+ , getConfig+ , setConfig++ -- * Claiming & releasing interfaces+ , InterfaceNumber+ , claimInterface+ , releaseInterface+ , withInterface+ , InterfaceAltSetting+ , setInterfaceAltSetting++ -- * Clearing & Resetting devices+ , clearHalt+ , resetDevice++ -- * USB kernel drivers+ , kernelDriverActive+ , detachKernelDriver+ , attachKernelDriver+ , withDetachedKernelDriver+ ) where++import System.USB.Internal+ ( Device+ , getDevices++ , getBusNumber+ , getDeviceAddress+ , getMaxPacketSize++ , DeviceHandle+ , openDevice+ , closeDevice+ , withDeviceHandle+ , getDevice++ , ConfigValue+ , getConfig+ , setConfig++ , InterfaceNumber+ , claimInterface+ , releaseInterface+ , withInterface+ , InterfaceAltSetting+ , setInterfaceAltSetting++ , clearHalt+ , resetDevice++ , kernelDriverActive+ , detachKernelDriver+ , attachKernelDriver+ , withDetachedKernelDriver+ )+
System/USB/Exceptions.hs view
@@ -1,3 +1,12 @@+--------------------------------------------------------------------------------+-- |+-- Module : System.USB.Exceptions+-- Copyright : (c) 2009 Bas van Dijk+-- License : BSD3 (see the file LICENSE)+-- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>+--+--------------------------------------------------------------------------------+ module System.USB.Exceptions ( USBException(..) ) where@@ -5,4 +14,3 @@ import System.USB.Internal ( USBException(..) )-
System/USB/IO/Synchronous.hs view
@@ -1,3 +1,12 @@+--------------------------------------------------------------------------------+-- |+-- Module : System.USB.IO.Synchronous+-- Copyright : (c) 2009 Bas van Dijk+-- License : BSD3 (see the file LICENSE)+-- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>+--+--------------------------------------------------------------------------------+ module System.USB.IO.Synchronous ( Timeout , Size
System/USB/Initialization.hs view
@@ -1,3 +1,12 @@+--------------------------------------------------------------------------------+-- |+-- Module : System.USB.Init+-- Copyright : (c) 2009 Bas van Dijk+-- License : BSD3 (see the file LICENSE)+-- Maintainer : Bas van Dijk <v.dijk.bas@gmail.com>+--+--------------------------------------------------------------------------------+ module System.USB.Initialization ( Ctx , newCtx
System/USB/Internal.hs view
@@ -59,19 +59,21 @@ -- *** Querying device descriptors , deviceUSBSpecReleaseNumber- , BCD4 , deviceClass , deviceSubClass , deviceProtocol , deviceMaxPacketSize0- , deviceVendorId, VendorId- , deviceProductId, ProductId+ , deviceVendorId+ , deviceProductId , deviceReleaseNumber , deviceManufacturerStrIx , deviceProductStrIx , deviceSerialNumberStrIx , deviceNumConfigs + , BCD4+ , VendorId, ProductId+ -- ** Configuration descriptor , ConfigDesc @@ -82,16 +84,15 @@ -- *** Querying configuration descriptors , configValue , configStrIx- , configAttribs- , ConfigAttribs- , DeviceStatus(..)- , configMaxPower , configNumInterfaces , configInterfaces , configExtra + , ConfigAttribs+ , DeviceStatus(..)+ -- ** Interface descriptor , InterfaceDesc @@ -111,24 +112,24 @@ -- *** Querying endpoint descriptors , endpointAddress+ , endpointAttribs+ , endpointMaxPacketSize+ , endpointInterval+ , endpointRefresh+ , endpointSynchAddress+ , endpointExtra+ , EndpointAddress(..) , TransferDirection(..) - , endpointAttribs , EndpointAttribs , TransferType(..) , Synchronization(..) , Usage(..) - , endpointMaxPacketSize , MaxPacketSize(..) , TransactionOpportunities(..) - , endpointInterval- , endpointRefresh- , endpointSynchAddress- , endpointExtra- -- ** String descriptors , getLanguages , LangId, PrimaryLangId, SubLangId@@ -368,11 +369,11 @@ getMaxPacketSize dev endpoint = withDevice dev $ \devPtr -> do m <- c'libusb_get_max_packet_size devPtr $- marshallEndpointAddress endpoint+ marshalEndpointAddress endpoint case m of n | n == c'LIBUSB_ERROR_NOT_FOUND -> throwIO NotFoundException | n == c'LIBUSB_ERROR_OTHER -> throwIO OtherException- | otherwise -> return . convertMaxPacketSize $ fromIntegral n+ | otherwise -> return . unmarshalMaxPacketSize $ fromIntegral n -- ** Opening & closing of devices ---------------------------------------------@@ -639,7 +640,7 @@ clearHalt devHndl = handleUSBException . c'libusb_clear_halt (devHndlPtr devHndl)- . marshallEndpointAddress+ . marshalEndpointAddress {-| Perform a USB port reset to reinitialize a device. @@ -817,28 +818,26 @@ -- configurations. } deriving (Show, Eq, Data, Typeable) --- | For a database of USB vendors and products see the /usb-id-database/--- package at: <http://hackage.haskell.org/package/usb-id-database> type VendorId = Word16 type ProductId = Word16 convertDeviceDesc :: C'libusb_device_descriptor -> DeviceDesc convertDeviceDesc d = DeviceDesc- { deviceUSBSpecReleaseNumber = convertBCD4 $- libusb_device_descriptor'bcdUSB d- , deviceClass = libusb_device_descriptor'bDeviceClass d- , deviceSubClass = libusb_device_descriptor'bDeviceSubClass d- , deviceProtocol = libusb_device_descriptor'bDeviceProtocol d- , deviceMaxPacketSize0 = libusb_device_descriptor'bMaxPacketSize0 d- , deviceVendorId = libusb_device_descriptor'idVendor d- , deviceProductId = libusb_device_descriptor'idProduct d- , deviceReleaseNumber = convertBCD4 $- libusb_device_descriptor'bcdDevice d- , deviceManufacturerStrIx = libusb_device_descriptor'iManufacturer d- , deviceProductStrIx = libusb_device_descriptor'iProduct d- , deviceSerialNumberStrIx = libusb_device_descriptor'iSerialNumber d- , deviceNumConfigs = libusb_device_descriptor'bNumConfigurations d+ { deviceUSBSpecReleaseNumber = unmarshalBCD4 $+ c'libusb_device_descriptor'bcdUSB d+ , deviceClass = c'libusb_device_descriptor'bDeviceClass d+ , deviceSubClass = c'libusb_device_descriptor'bDeviceSubClass d+ , deviceProtocol = c'libusb_device_descriptor'bDeviceProtocol d+ , deviceMaxPacketSize0 = c'libusb_device_descriptor'bMaxPacketSize0 d+ , deviceVendorId = c'libusb_device_descriptor'idVendor d+ , deviceProductId = c'libusb_device_descriptor'idProduct d+ , deviceReleaseNumber = unmarshalBCD4 $+ c'libusb_device_descriptor'bcdDevice d+ , deviceManufacturerStrIx = c'libusb_device_descriptor'iManufacturer d+ , deviceProductStrIx = c'libusb_device_descriptor'iProduct d+ , deviceSerialNumberStrIx = c'libusb_device_descriptor'iSerialNumber d+ , deviceNumConfigs = c'libusb_device_descriptor'bNumConfigurations d } {-| Get the USB device descriptor for a given device.@@ -910,10 +909,11 @@ -- device is currently self-powered } deriving (Show, Eq, Data, Typeable) -convertConfigAttribs :: Word8 -> ConfigAttribs-convertConfigAttribs a = DeviceStatus { remoteWakeup = testBit a 5- , selfPowered = testBit a 6- }+unmarshalConfigAttribs :: Word8 -> ConfigAttribs+unmarshalConfigAttribs a =+ DeviceStatus { remoteWakeup = testBit a 5+ , selfPowered = testBit a 6+ } -------------------------------------------------------------------------------- @@ -986,23 +986,23 @@ convertConfigDesc :: C'libusb_config_descriptor -> IO ConfigDesc convertConfigDesc c = do- let numInterfaces = libusb_config_descriptor'bNumInterfaces c+ let numInterfaces = c'libusb_config_descriptor'bNumInterfaces c interfaces <- peekArray (fromIntegral numInterfaces)- (libusb_config_descriptor'interface c) >>=+ (c'libusb_config_descriptor'interface c) >>= mapM convertInterface extra <- B.packCStringLen- ( castPtr $ libusb_config_descriptor'extra c- , fromIntegral $ libusb_config_descriptor'extra_length c+ ( castPtr $ c'libusb_config_descriptor'extra c+ , fromIntegral $ c'libusb_config_descriptor'extra_length c ) return ConfigDesc- { configValue = libusb_config_descriptor'bConfigurationValue c- , configStrIx = libusb_config_descriptor'iConfiguration c- , configAttribs = convertConfigAttribs $- libusb_config_descriptor'bmAttributes c- , configMaxPower = libusb_config_descriptor'MaxPower c+ { configValue = c'libusb_config_descriptor'bConfigurationValue c+ , configStrIx = c'libusb_config_descriptor'iConfiguration c+ , configAttribs = unmarshalConfigAttribs $+ c'libusb_config_descriptor'bmAttributes c+ , configMaxPower = c'libusb_config_descriptor'MaxPower c , configNumInterfaces = numInterfaces , configInterfaces = interfaces , configExtra = extra@@ -1010,8 +1010,8 @@ convertInterface:: C'libusb_interface -> IO [InterfaceDesc] convertInterface i =- peekArray (fromIntegral $ libusb_interface'num_altsetting i)- (libusb_interface'altsetting i) >>=+ peekArray (fromIntegral $ c'libusb_interface'num_altsetting i)+ (c'libusb_interface'altsetting i) >>= mapM convertInterfaceDesc @@ -1067,24 +1067,24 @@ convertInterfaceDesc :: C'libusb_interface_descriptor -> IO InterfaceDesc convertInterfaceDesc i = do- let n = libusb_interface_descriptor'bNumEndpoints i+ let n = c'libusb_interface_descriptor'bNumEndpoints i endpoints <- peekArray (fromIntegral n)- (libusb_interface_descriptor'endpoint i) >>=+ (c'libusb_interface_descriptor'endpoint i) >>= mapM convertEndpointDesc extra <- B.packCStringLen- ( castPtr $ libusb_interface_descriptor'extra i- , fromIntegral $ libusb_interface_descriptor'extra_length i+ ( castPtr $ c'libusb_interface_descriptor'extra i+ , fromIntegral $ c'libusb_interface_descriptor'extra_length i ) return InterfaceDesc- { interfaceNumber = libusb_interface_descriptor'bInterfaceNumber i- , interfaceAltSetting = libusb_interface_descriptor'bAlternateSetting i- , interfaceClass = libusb_interface_descriptor'bInterfaceClass i- , interfaceSubClass = libusb_interface_descriptor'bInterfaceSubClass i- , interfaceStrIx = libusb_interface_descriptor'iInterface i- , interfaceProtocol = libusb_interface_descriptor'bInterfaceProtocol i+ { interfaceNumber = c'libusb_interface_descriptor'bInterfaceNumber i+ , interfaceAltSetting = c'libusb_interface_descriptor'bAlternateSetting i+ , interfaceClass = c'libusb_interface_descriptor'bInterfaceClass i+ , interfaceSubClass = c'libusb_interface_descriptor'bInterfaceSubClass i+ , interfaceStrIx = c'libusb_interface_descriptor'iInterface i+ , interfaceProtocol = c'libusb_interface_descriptor'bInterfaceProtocol i , interfaceNumEndpoints = n , interfaceEndpoints = endpoints , interfaceExtra = extra@@ -1134,20 +1134,20 @@ convertEndpointDesc :: C'libusb_endpoint_descriptor -> IO EndpointDesc convertEndpointDesc e = do extra <- B.packCStringLen- ( castPtr $ libusb_endpoint_descriptor'extra e- , fromIntegral $ libusb_endpoint_descriptor'extra_length e+ ( castPtr $ c'libusb_endpoint_descriptor'extra e+ , fromIntegral $ c'libusb_endpoint_descriptor'extra_length e ) return EndpointDesc- { endpointAddress = convertEndpointAddress $- libusb_endpoint_descriptor'bEndpointAddress e- , endpointAttribs = convertEndpointAttribs $- libusb_endpoint_descriptor'bmAttributes e- , endpointMaxPacketSize = convertMaxPacketSize $- libusb_endpoint_descriptor'wMaxPacketSize e- , endpointInterval = libusb_endpoint_descriptor'bInterval e- , endpointRefresh = libusb_endpoint_descriptor'bRefresh e- , endpointSynchAddress = libusb_endpoint_descriptor'bSynchAddress e+ { endpointAddress = unmarshalEndpointAddress $+ c'libusb_endpoint_descriptor'bEndpointAddress e+ , endpointAttribs = unmarshalEndpointAttribs $+ c'libusb_endpoint_descriptor'bmAttributes e+ , endpointMaxPacketSize = unmarshalMaxPacketSize $+ c'libusb_endpoint_descriptor'wMaxPacketSize e+ , endpointInterval = c'libusb_endpoint_descriptor'bInterval e+ , endpointRefresh = c'libusb_endpoint_descriptor'bRefresh e+ , endpointSynchAddress = c'libusb_endpoint_descriptor'bSynchAddress e , endpointExtra = extra } @@ -1158,18 +1158,18 @@ , endpointDirection :: TransferDirection } deriving (Show, Eq, Data, Typeable) -convertEndpointAddress :: Word8 -> EndpointAddress-convertEndpointAddress a = EndpointAddress (fromIntegral $ bits 0 3 a)- (if testBit a 7 then In else Out)+unmarshalEndpointAddress :: Word8 -> EndpointAddress+unmarshalEndpointAddress a = EndpointAddress (fromIntegral $ bits 0 3 a)+ (if testBit a 7 then In else Out) -marshallEndpointAddress :: EndpointAddress -> CUChar-marshallEndpointAddress (EndpointAddress number direction)+marshalEndpointAddress :: EndpointAddress -> CUChar+marshalEndpointAddress (EndpointAddress number direction) | between number 0 15 = let n = fromIntegral number in case direction of Out -> n In -> setBit n 7 | otherwise =- error "marshallEndpointAddress: endpointNumber not >= 0 and <= 15"+ error "marshalEndpointAddress: endpointNumber not >= 0 and <= 15" -- | Direction of data transfer relative to the host. data TransferDirection = Out -- ^ Host to device.@@ -1197,15 +1197,15 @@ | Implicit deriving (Enum, Show, Eq, Data, Typeable) -convertEndpointAttribs :: Word8 -> EndpointAttribs-convertEndpointAttribs a =+unmarshalEndpointAttribs :: Word8 -> EndpointAttribs+unmarshalEndpointAttribs a = case bits 0 1 a of 0 -> Control 1 -> Isochronous (genToEnum $ bits 2 3 a) (genToEnum $ bits 4 5 a) 2 -> Bulk 3 -> Interrupt- _ -> error "convertEndpointAttribs: this can't happen!"+ _ -> error "unmarshalEndpointAttribs: this can't happen!" -------------------------------------------------------------------------------- @@ -1219,8 +1219,8 @@ | TwoAdditionalTransactions deriving (Enum, Show, Eq, Data, Typeable) -convertMaxPacketSize :: Word16 -> MaxPacketSize-convertMaxPacketSize m =+unmarshalMaxPacketSize :: Word16 -> MaxPacketSize+unmarshalMaxPacketSize m = MaxPacketSize { maxPacketSize = fromIntegral $ bits 0 10 m , transactionOpportunities = genToEnum $ bits 11 12 m@@ -1238,7 +1238,7 @@ let maxSize = 255 -- Some devices choke on size > 255 in allocaArray maxSize $ \dataPtr -> do reportedSize <- putStrDesc devHndl 0 0 maxSize dataPtr- fmap (fmap convertLangId) $+ fmap (fmap unmarshalLangId) $ peekArray ((reportedSize - 2) `div` 2) (castPtr $ dataPtr `plusPtr` 2) @@ -1292,11 +1292,11 @@ type PrimaryLangId = Word16 type SubLangId = Word16 -convertLangId :: Word16 -> LangId-convertLangId = bits 0 9 &&& bits 10 15+unmarshalLangId :: Word16 -> LangId+unmarshalLangId = bits 0 9 &&& bits 10 15 -marshallLangId :: LangId -> Word16-marshallLangId (p, s) = p .|. s `shiftL`10+marshalLangId :: LangId -> Word16+marshalLangId (p, s) = p .|. s `shiftL`10 -- | Type of indici of string descriptors. --@@ -1317,7 +1317,7 @@ BI.createAndTrim size $ putStrDesc devHndl strIx- (marshallLangId langId)+ (marshalLangId langId) size . castPtr @@ -1369,8 +1369,8 @@ | ToOther deriving (Enum, Show, Eq, Data, Typeable) -marshallRequestType :: RequestType -> Recipient -> Word8-marshallRequestType t r = genFromEnum t `shiftL` 5 .|. genFromEnum r+marshalRequestType :: RequestType -> Recipient -> Word8+marshalRequestType t r = genFromEnum t `shiftL` 5 .|. genFromEnum r -- ** Control transfers --------------------------------------------------------@@ -1402,7 +1402,7 @@ control devHndl reqType reqRecipient request value index timeout = ignore . checkUSBException $ c'libusb_control_transfer (devHndlPtr devHndl)- (marshallRequestType reqType reqRecipient)+ (marshalRequestType reqType reqRecipient) request value index@@ -1439,7 +1439,7 @@ BI.createAndTrim size $ \dataPtr -> checkUSBException $ c'libusb_control_transfer (devHndlPtr devHndl)- (setBit (marshallRequestType reqType reqRecipient) 7)+ (setBit (marshalRequestType reqType reqRecipient) 7) request value index@@ -1477,7 +1477,7 @@ input `writeWith` \dataPtr size -> checkUSBException $ c'libusb_control_transfer (devHndlPtr devHndl)- (marshallRequestType reqType reqRecipient)+ (marshalRequestType reqType reqRecipient) request value index@@ -1635,7 +1635,7 @@ alloca $ \transferredPtr -> do handleUSBException $ doReadTransfer (devHndlPtr devHndl)- (marshallEndpointAddress endpoint)+ (marshalEndpointAddress endpoint) (castPtr dataPtr) (fromIntegral size) transferredPtr@@ -1653,7 +1653,7 @@ alloca $ \transferredPtr -> do handleUSBException $ doWriteTransfer (devHndlPtr devHndl)- (marshallEndpointAddress endpoint)+ (marshalEndpointAddress endpoint) (castPtr dataPtr) (fromIntegral size) transferredPtr@@ -1737,9 +1737,9 @@ -- | A decoded 16 bits Binary Coded Decimal using 4 bits for each digit. type BCD4 = (Int, Int, Int, Int) -convertBCD4 :: Word16 -> BCD4-convertBCD4 bcd = let [a, b, c, d] = fmap fromIntegral $ decodeBCD 4 bcd- in (a, b, c, d)+unmarshalBCD4 :: Word16 -> BCD4+unmarshalBCD4 bcd = let [a, b, c, d] = fmap fromIntegral $ decodeBCD 4 bcd+ in (a, b, c, d) {-| @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
usb.cabal view
@@ -1,5 +1,5 @@ name: usb-version: 0.1.0.1+version: 0.2 cabal-version: >=1.6 build-type: Simple license: BSD3@@ -24,10 +24,10 @@ build-depends: base >= 4 && < 4.2 , bytestring == 0.9.* , text == 0.4.*- , bindings-libusb == 1.2.*+ , bindings-libusb == 1.3.* exposed-modules: System.USB System.USB.Initialization- System.USB.DeviceHandlingAndEnumeration+ System.USB.Devices System.USB.Descriptors System.USB.IO.Synchronous System.USB.Exceptions