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.
- data DeviceDesc = DeviceDesc {
- deviceUSBSpecReleaseNumber :: BCD4
- deviceClass :: Word8
- deviceSubClass :: Word8
- deviceProtocol :: Word8
- deviceMaxPacketSize0 :: Word8
- deviceVendorId :: VendorId
- deviceProductId :: ProductId
- deviceReleaseNumber :: BCD4
- deviceManufacturerStrIx :: StrIx
- deviceProductStrIx :: StrIx
- deviceSerialNumberStrIx :: StrIx
- deviceNumConfigs :: Word8
- deviceConfigs :: [ConfigDesc]
- type BCD4 = (Int, Int, Int, Int)
- type VendorId = Word16
- type ProductId = Word16
- data ConfigDesc = ConfigDesc {}
- type Interface = [InterfaceDesc]
- type ConfigAttribs = DeviceStatus
- data DeviceStatus = DeviceStatus {
- remoteWakeup :: Bool
- selfPowered :: Bool
- data InterfaceDesc = InterfaceDesc {}
- data EndpointDesc = EndpointDesc {}
- data EndpointAddress = EndpointAddress {}
- data TransferDirection
- type EndpointAttribs = TransferType
- data TransferType
- = Control
- | Isochronous Synchronization Usage
- | Bulk
- | Interrupt
- data Synchronization
- data Usage
- data MaxPacketSize = MaxPacketSize {}
- data TransactionOpportunities
- getLanguages :: DeviceHandle -> IO [LangId]
- type LangId = (PrimaryLangId, SubLangId)
- type PrimaryLangId = Word16
- type SubLangId = Word16
- type StrIx = Word8
- getStrDesc :: DeviceHandle -> StrIx -> LangId -> Size -> IO String
- getStrDescFirstLang :: DeviceHandle -> StrIx -> Size -> IO String
Device descriptor
data DeviceDesc Source
A structure representing the standard USB device descriptor.
This descriptor is documented in section 9.6.1 of the USB 2.0 specification.
This structure can be retrieved by deviceDesc
.
DeviceDesc | |
|
type BCD4 = (Int, Int, Int, Int)Source
A decoded 16 bits Binary Coded Decimal using 4 bits for each digit.
For a database of USB vendors and products see the usb-id-database
package at: http://hackage.haskell.org/package/usb-id-database
Configuration descriptor
data ConfigDesc Source
A structure representing the standard USB configuration descriptor.
This descriptor is documented in section 9.6.3 of the USB 2.0 specification.
This structure can be retrieved by deviceConfigs
.
ConfigDesc | |
|
type Interface = [InterfaceDesc]Source
An interface is represented as a list of alternate interface settings.
Configuration attributes
type ConfigAttribs = DeviceStatusSource
The USB 2.0 specification specifices that the configuration attributes only describe the device status.
data DeviceStatus Source
DeviceStatus | |
|
Interface descriptor
data InterfaceDesc Source
A structure representing the standard USB interface descriptor.
This descriptor is documented in section 9.6.5 of the USB 2.0 specification.
This structure can be retrieved using configInterfaces
.
InterfaceDesc | |
|
Endpoint descriptor
data EndpointDesc Source
A structure representing the standard USB endpoint descriptor.
This descriptor is documented in section 9.6.3 of the USB 2.0 specification. All multiple-byte fields are represented in host-endian format.
EndpointDesc | |
|
Endpoint address
data EndpointAddress Source
The address of an endpoint.
EndpointAddress | |
|
data TransferDirection Source
The direction of data transfer relative to the host.
Endpoint attributes
type EndpointAttribs = TransferTypeSource
The USB 2.0 specification specifies that the endpoint attributes only describe the endpoint transfer type.
data TransferType Source
Describes what types of transfers are allowed on the endpoint.
Control | Control transfers are typically used for command and status operations. |
Isochronous Synchronization Usage | Isochronous transfers occur continuously and periodically. |
Bulk | Bulk transfers can be used for large bursty data. |
Interrupt | Interrupt transfers are typically non-periodic, small device "initiated" communication requiring bounded latency. |
Isochronous transfer attributes
data Synchronization Source
Endpoint max packet size
data MaxPacketSize Source
data TransactionOpportunities Source
Number of additional transactions.
String descriptors
getLanguages :: DeviceHandle -> IO [LangId]Source
Retrieve a list of supported languages.
This function may throw USBException
s.
type LangId = (PrimaryLangId, SubLangId)Source
The language ID consists of the primary language identifier and the sublanguage identififier as described in:
http://www.usb.org/developers/docs/USB_LANGIDs.pdf
For a mapping between IDs and languages see the usb-id-database
package at:
http://hackage.haskell.org/package/usb-id-database
To see which LangId
s are supported by a device see getLanguages
.
type PrimaryLangId = Word16Source
Type of indici of string descriptors.
Can be retrieved by all the *StrIx functions.
getStrDesc :: DeviceHandle -> StrIx -> LangId -> Size -> IO StringSource
Retrieve a string descriptor from a device.
This is a convenience function which formulates the appropriate control message to retrieve the descriptor. The string returned is Unicode, as detailed in the USB specifications.
This function may throw USBException
s.
getStrDescFirstLang :: DeviceHandle -> StrIx -> Size -> IO StringSource
Retrieve a string descriptor from a device using the first supported language.
This is a convenience function which formulates the appropriate control message to retrieve the descriptor. The string returned is Unicode, as detailed in the USB specifications.
This function may throw USBException
s.