usb-0.4: Communicate with USB devices

MaintainerBas van Dijk <v.dijk.bas@gmail.com>

System.USB.IO.Synchronous

Contents

Description

This module provides functionality for performing control, bulk and interrupt transfers.

Synopsis

Documentation

type ReadAction = Size -> Timeout -> IO (ByteString, Bool)Source

Handy type synonym for read transfers.

A ReadAction is a function which takes a Size which defines how many bytes to read and a Timeout. The function returns an IO action which, when executed, performs the actual read and returns the ByteString that was read paired with a flag which indicates whether a transfer timed out.

type WriteAction = ByteString -> Timeout -> IO (Size, Bool)Source

Handy type synonym for write transfers.

A WriteAction is a function which takes a ByteString to write and a Timeout. The function returns an IO action which, when exectued, returns the number of bytes that were actually written paired with an flag which indicates whether a transfer timed out.

type Timeout = IntSource

A timeout in milliseconds. A timeout defines how long a transfer should wait before giving up due to no response being received. For no timeout, use value 0.

type Size = IntSource

Number of bytes transferred.

Control transfers

type ControlAction α = RequestType -> Recipient -> Request -> Value -> Index -> αSource

Handy type synonym that names the parameters of a control transfer.

type Value = Word16Source

(Host-endian)

type Index = Word16Source

(Host-endian)

control :: DeviceHandle -> ControlAction (Timeout -> IO ())Source

Perform a USB control request that does not transfer data.

Exceptions:

readControl :: DeviceHandle -> ControlAction ReadActionSource

Perform a USB control read.

Exceptions:

writeControl :: DeviceHandle -> ControlAction WriteActionSource

Perform a USB control write.

Exceptions:

Standard Device Requests

setHalt :: DeviceHandle -> EndpointAddress -> Timeout -> IO ()Source

See: USB 2.0 Spec. section 9.4.9

clearRemoteWakeup :: DeviceHandle -> Timeout -> IO ()Source

See: USB 2.0 Spec. section 9.4.1

setRemoteWakeup :: DeviceHandle -> Timeout -> IO ()Source

See: USB 2.0 Spec. section 9.4.9

setStandardTestMode :: DeviceHandle -> TestMode -> Timeout -> IO ()Source

See: USB 2.0 Spec. section 9.4.9 TODO: What about vendor-specific test modes?

getDeviceStatus :: DeviceHandle -> Timeout -> IO DeviceStatusSource

See: USB 2.0 Spec. section 9.4.5

getEndpointStatus :: DeviceHandle -> EndpointAddress -> Timeout -> IO BoolSource

See: USB 2.0 Spec. section 9.4.5

setDeviceAddress :: DeviceHandle -> Word16 -> Timeout -> IO ()Source

See: USB 2.0 Spec. section 9.4.6

synchFrame :: DeviceHandle -> EndpointAddress -> Timeout -> IO IntSource

See: USB 2.0 Spec. section 9.4.11

Bulk transfers

readBulkSource

Arguments

:: DeviceHandle

A handle for the device to communicate with.

-> EndpointAddress

The address of a valid In and Bulk endpoint to communicate with. Make sure the endpoint belongs to the current alternate setting of a claimed interface which belongs to the device.

-> ReadAction 

Perform a USB bulk read.

Exceptions:

writeBulkSource

Arguments

:: DeviceHandle

A handle for the device to communicate with.

-> EndpointAddress

The address of a valid Out and Bulk endpoint to communicate with. Make sure the endpoint belongs to the current alternate setting of a claimed interface which belongs to the device.

-> WriteAction 

Perform a USB bulk write.

Exceptions:

Interrupt transfers

readInterruptSource

Arguments

:: DeviceHandle

A handle for the device to communicate with.

-> EndpointAddress

The address of a valid In and Interrupt endpoint to communicate with. Make sure the endpoint belongs to the current alternate setting of a claimed interface which belongs to the device.

-> ReadAction 

Perform a USB interrupt read.

Exceptions:

writeInterruptSource

Arguments

:: DeviceHandle

A handle for the device to communicate with.

-> EndpointAddress

The address of a valid Out and Interrupt endpoint to communicate with. Make sure the endpoint belongs to the current alternate setting of a claimed interface which belongs to the device.

-> WriteAction 

Perform a USB interrupt write.

Exceptions: