View Source usb (usb v0.2.1)
Erlang interface for interacting with USB devices.
Summary
Types
Reference to a USB device attached to the host system.
A map representing the standard USB device descriptor. This descriptor is documented in section 9.6.1 of the USB 3.0 specification.
A referenced to an open USB device. This handle is used to perform I/O and other operations. When finished with a device handle, you should call close_device/1
.
Indicates the speed at which the device is operating.
Functions
Claim an interface on a given device handle. You must claim the interface you wish to use before you can perform I/O on any of its endpoints.
Clear the halt/stall condition for an endpoint.
Close a device handle.
Stop listening for hotplug events.
Get the number of the bus that a device is connected to.
Get a USB configuration descriptor based on its index.
Get the address of the device on the bus it is connected to.
Get the USB device descriptor for a given device.
Returns a list of USB devices currently attached to the system.
Get the negotiated connection speed for a device.
Get the number of the port that a device is connected to.
Get the list of all port numbers from root for the specified device.
Equivalent to monitor_hotplug([]).
start listening for hotplug events. The owner process will start receiving the following hotplug events
Open a device and obtain a device handle. A handle allows you to perform I/O on the device in question.
Release an interface previously claimed with claim_interface/2
.
Types
-type alt_setting() :: #{interface_number := non_neg_integer(), setting_number := non_neg_integer(), class_code := non_neg_integer(), sub_class_code := non_neg_integer(), protocol_code := non_neg_integer(), description_string_index := non_neg_integer(), endpoints := [endpoint()], extra := binary()}.
-opaque device()
Reference to a USB device attached to the host system.
-type device_descriptor() :: #{usb_version := 0..65535, class_code := byte(), sub_class_code := byte(), protocol_code := byte(), max_packet_size0 := byte(), vendor_id := 0..65535, product_id := 0..65535, device_version := 0..65535, manufacturer_string_index := byte(), product_string_index := byte(), serial_number_string_index := byte(), num_configurations := byte()}.
A map representing the standard USB device descriptor. This descriptor is documented in section 9.6.1 of the USB 3.0 specification.
-opaque device_handle()
A referenced to an open USB device. This handle is used to perform I/O and other operations. When finished with a device handle, you should call close_device/1
.
-type device_speed() :: unknown | low | full | high | super | super_plus.
Indicates the speed at which the device is operating.
unknown
- The OS doesn't report or know the device speed.
low
- The device is operating at low speed (1.5MBit/s).
full
- The device is operating at full speed (12MBit/s).
high
- The device is operating at high speed (480MBit/s).
super
- The device is operating at super speed (5000MBit/s).
super_plus
- The device is operating at super speed plus (10000MBit/s).
-type endpoint() :: #{address := non_neg_integer(), attributes := non_neg_integer(), max_packet_size := non_neg_integer(), interval := non_neg_integer(), refresh := non_neg_integer(), synch_address := non_neg_integer(), extra := binary()}.
-opaque hotplug_monitor()
-type interface_descriptor() :: #{alt_settings := [alt_setting()]}.
-type monitor_hotplug_flag() :: enumerate.
Functions
-spec attach_kernel_driver(device_handle(), integer()) -> ok | {error, term()}.
-spec claim_interface(device_handle(), non_neg_integer()) -> ok | {error, term()}.
Claim an interface on a given device handle. You must claim the interface you wish to use before you can perform I/O on any of its endpoints.
It is legal to attempt to claim an already-claimed interface, in which case this function just returns ok
without doing anything.
Claiming of interfaces is a purely logical operation; it does not cause any requests to be sent over the bus. Interface claiming is used to instruct the underlying operating system that your application wishes to take ownership of the interface.
-spec clear_halt(device_handle(), byte()) -> ok | {error, term()}.
Clear the halt/stall condition for an endpoint.
Endpoints with halt status are unable to receive or transmit data until the halt condition is stalled.
You should cancel all pending transfers before attempting to clear the halt condition.
-spec close_device(device_handle()) -> ok | {error, term()}.
Close a device handle.
-spec demonitor_hotplug(hotplug_monitor()) -> ok | {error, term()}.
Stop listening for hotplug events.
-spec detach_kernel_driver(device_handle(), integer()) -> ok | {error, term()}.
Get the number of the bus that a device is connected to.
-spec get_config_descriptor(device(), byte()) -> {ok, config_descriptor()} | {error, term()}.
Get a USB configuration descriptor based on its index.
Get the address of the device on the bus it is connected to.
-spec get_device_descriptor(device()) -> {ok, device_descriptor()} | {error, term()}.
Get the USB device descriptor for a given device.
Returns a list of USB devices currently attached to the system.
-spec get_device_speed(device()) -> {ok, device_speed()} | {error, term()}.
Get the negotiated connection speed for a device.
Get the number of the port that a device is connected to.
Get the list of all port numbers from root for the specified device.
-spec monitor_hotplug() -> {ok, hotplug_monitor()} | {error, term()}.
Equivalent to monitor_hotplug([]).
start listening for hotplug events.
-spec monitor_hotplug([monitor_hotplug_flag()]) -> {ok, hotplug_monitor()} | {error, term()}.
start listening for hotplug events. The owner process will start receiving the following hotplug events:
{usb, device_arrived, Device}
and {usb, device_left, Device}
.
If the enumerate
flag is provided, the owner process will received device_arrived
events for all devices already plugged into the host.
-spec open_device(device()) -> {ok, device_handle()} | {error, term()}.
Open a device and obtain a device handle. A handle allows you to perform I/O on the device in question.
-spec read_control(device_handle(), byte(), byte(), non_neg_integer(), non_neg_integer(), non_neg_integer(), timeout()) -> {ok, binary()} | {error, term()}.
-spec release_interface(device_handle(), non_neg_integer()) -> ok | {error, term()}.
Release an interface previously claimed with claim_interface/2
.
You should release all claimed interfaces before closing a device handle.
-spec set_configuration(device_handle(), integer()) -> ok | {error, term()}.
-spec write_bulk(device_handle(), byte(), binary(), timeout()) -> {ok, integer()} | {error, timeout, non_neg_integer()} | {error, term()}.
-spec write_control(device_handle(), byte(), byte(), non_neg_integer(), non_neg_integer(), binary(), timeout()) -> {ok, integer()} | {error, term()}.
-spec write_interrupt(device_handle(), byte(), binary(), timeout()) -> {ok, integer()} | {error, timeout, non_neg_integer()} | {error, term()}.