|
Tizen Native API
10.0
|
This API is used to handle USB device configuration.
This module provides an interface for inspecting an USB device configuration.
Overview
Data structures and operations described here are related to USB configuration.
Related Features
This API is related with the following features:
- http://tizen.org/feature/usb.host
It is recommended to design feature related codes in your application for reliability.
You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.
To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.
More details on featuring your application can be found from Feature List.
Functions | |
| int | usb_host_config_get_num_interfaces (usb_host_config_h config, int *num_interfaces) |
| Gets number of interfaces for given configuration. | |
| int | usb_host_config_is_self_powered (usb_host_config_h config, bool *self_powered) |
| Checks if the device is self-powered in given configuration. | |
| int | usb_host_config_support_remote_wakeup (usb_host_config_h config, bool *remote_wakeup) |
| Checks if the device supports remote wakeup in given configuration. | |
| int | usb_host_config_get_max_power (usb_host_config_h config, int *max_power) |
| Gets maximum power in given USB configuration. | |
| int | usb_host_device_get_config_str (usb_host_config_h config, int *length, unsigned char *data) |
| Gets a string describing a USB configuration into given buffer. | |
| int | usb_host_config_get_interface (usb_host_config_h config, int interface_index, usb_host_interface_h *interface) |
| Gets a USB interface from given USB configuration. | |
| int | usb_host_config_destroy (usb_host_config_h config) |
| Frees a configuration struct and its associated data. | |
Typedefs | |
| typedef struct usb_host_config_s * | usb_host_config_h |
| An opaque handle representing a USB device configuration. | |
Typedef Documentation
| typedef struct usb_host_config_s* usb_host_config_h |
An opaque handle representing a USB device configuration.
This type represents USB device configuration. Device can have multiple configurations, a configuration can have multiple interfaces. This handle can be obtained by usb_host_device_get_config().
- Since :
- 3.0
Function Documentation
| int usb_host_config_destroy | ( | usb_host_config_h | config | ) |
Frees a configuration struct and its associated data.
Frees configuration obtained from usb_host_device_get_config().
- Since :
- 3.0
- Parameters:
-
[in] config Configuration to free
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed
- Precondition:
- config must be obtained by usb_host_device_get_config().
#include <usb_host.h> void select_configuration(usb_host_device_h dev) { int ret, num_configurations; usb_host_config_h config; ret = usb_host_device_get_num_configurations(dev, &num_configurations); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); for (int i = 0; i < num_configurations; ++i) { ret = usb_host_device_get_config(dev, i, &config); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); if (interesting(config)) { ret = usb_host_set_config(config); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); } ret = usb_host_config_destroy(config); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); } }
| int usb_host_config_get_interface | ( | usb_host_config_h | config, |
| int | interface_index, | ||
| usb_host_interface_h * | interface | ||
| ) |
Gets a USB interface from given USB configuration.
Gets a USB interface from configuration by its index.
- Since :
- 3.0
- Parameters:
-
[in] config Configuration handle [in] interface_index index of interface to retrieve (counting from 0) [out] interface Interface handle
- Remarks:
- There is no need to destroy the interface handle. It is no longer valid when config is destroyed.
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_NOT_FOUND Configuration does not exist USB_HOST_ERROR_NOT_SUPPORTED Not supported USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed
#include <usb_host.h> #define INTERFACE_INDEX 3 usb_host_interface_h get_interface(usb_host_config_h config) { int ret; usb_host_interface_h interface; ret = usb_host_config_get_interface(config, INTERFACE_INDEX, &interface); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); return ret; }
| int usb_host_config_get_max_power | ( | usb_host_config_h | config, |
| int * | max_power | ||
| ) |
Gets maximum power in given USB configuration.
Returns the maximum power drawn by the device in the provided USB configuration, in mA.
- Since :
- 3.0
- Parameters:
-
[in] config A configuration [out] max_power Maximum power, in mA
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_NOT_SUPPORTED Not supported USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed
#include <usb_host.h> #include <stdio.h> void print_remote_wakeup(usb_host_config_h config) { int ret, max_power; ret = usb_host_config_get_max_power(dev, &max_power); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); printf("Max power: %d mA\n", max_power); }
| int usb_host_config_get_num_interfaces | ( | usb_host_config_h | config, |
| int * | num_interfaces | ||
| ) |
Gets number of interfaces for given configuration.
Gets the number of interfaces supported by the provided configuration.
- Since :
- 3.0
- Parameters:
-
[in] config A configuration [out] num_interfaces Number of interfaces
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_NOT_SUPPORTED Not supported USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed
#include <usb_host.h> #include <stdio.h> void print_num_interfaces(usb_host_interface_h interface) { int ret, num_interfaces; ret = usb_host_interface_get_num_interfaces(inteface, &num_interfaces); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); printf("Number of interfaces: %d\n", num_interfaces); }
| int usb_host_config_is_self_powered | ( | usb_host_config_h | config, |
| bool * | self_powered | ||
| ) |
Checks if the device is self-powered in given configuration.
Checks if the device in provided configuration is self-powered.
- Since :
- 3.0
- Parameters:
-
[in] config A configuration [out] self_powered True if device is self-powered in given configuration, false otherwise
- Returns:
- 0 on success, negative error code otherwise
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed USB_HOST_ERROR_NOT_SUPPORTED Not supported
#include <usb_host.h> #include <stdio.h> void print_self_powered(usb_host_config_h config) { int ret; bool self_powered; ret = usb_host_config_is_self_powered(dev, &self_powered); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); printf("Configuration is %sself-powered\n", self_powered ? "" : "not "); }
| int usb_host_config_support_remote_wakeup | ( | usb_host_config_h | config, |
| bool * | remote_wakeup | ||
| ) |
Checks if the device supports remote wakeup in given configuration.
Checks if the device in provided configuration supports remote wakeup.
- Since :
- 3.0
- Parameters:
-
[in] config A configuration [out] remote_wakeup True if device supports remote wakeup in given configuration, false otherwise
- Returns:
- 0 on success, negative error code otherwise
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed USB_HOST_ERROR_NOT_SUPPORTED Not supported
#include <usb_host.h> #include <stdio.h> void print_remote_wakeup(usb_host_config_h config) { int ret; bool remote_wakeup; ret = usb_host_config_support_remote_wakeup(dev, &remote_wakeup); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); printf("Configuration %s remote wakeup\n", self_powered ? "supports" : "does not support"); }
| int usb_host_device_get_config_str | ( | usb_host_config_h | config, |
| int * | length, | ||
| unsigned char * | data | ||
| ) |
Gets a string describing a USB configuration into given buffer.
Puts a string representation of the USB configuration into the given buffer.
- Since :
- 3.0
- Parameters:
-
[in] config A configuration [in,out] length Pointer to a variable containing the current size of the buffer, which will be modified to actual usage [out] data Buffer to store string
- Returns:
- 0 on success, otherwise a negative error value
- Return values:
-
USB_HOST_ERROR_NONE Successful USB_HOST_ERROR_NOT_SUPPORTED Not supported USB_HOST_ERROR_OVERFLOW There was no space in buffer USB_HOST_ERROR_OUT_OF_MEMORY Out of memory USB_HOST_ERROR_INVALID_PARAMETER Invalid parameter was passed
- Precondition:
- config must be configuration of device opened by usb_host_device_open() or usb_host_device_open_with_vid_pid()
#include <usb_host.h> #include <stdio.h> #define BUFFER_SIZE 128 void print_config_str(usb_host_config_h config) { int ret, length = BUFFER_SIZE - 1; unsigned char data[BUFFER_SIZE]; ret = usb_host_device_get_config_str(dev, &length, data); if (ret != USB_HOST_ERROR_NONE) handle_error(ret); data[length] = '\0'; printf("Configuration description: %s\n", data); }