Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
USB Host Controller (UHC)

The UHC provides a high-level abstraction of the usb host.

You can use these functions to control the main host state (start/suspend/resume/...).

All USB Host Interface (UHI) in USB Host Stack is based on UHC to support USB enumeration.

For more details for Atmel Software Framework (ASF) USB Host Stack, refer to following application note:

This documentation describes common USB Host usage based on UHC, as follow:

API Overview

Data Structures

struct  uhc_device_t
 Structure to store device information. More...
 

Enumerations

enum  uhc_enum_status_t {
  UHC_ENUM_SUCCESS = 0,
  UHC_ENUM_UNSUPPORTED,
  UHC_ENUM_OVERCURRENT,
  UHC_ENUM_FAIL,
  UHC_ENUM_HARDWARE_LIMIT,
  UHC_ENUM_SOFTWARE_LIMIT,
  UHC_ENUM_MEMORY_LIMIT,
  UHC_ENUM_DISCONNECT
}
 Enumeration status Used in UHC_ENUM_EVENT() callback when a USB device enumeration is completed. More...
 

Functions to Control the USB Host Stack

void uhc_start (void)
 Starts the host mode. More...
 
void uhc_stop (bool b_id_stop)
 Stops the host mode. More...
 
void uhc_suspend (bool b_remotewakeup)
 Suspends a USB line. More...
 
bool uhc_is_suspend (void)
 Test if the suspend state is enabled on the USB line. More...
 
void uhc_resume (void)
 Resumes the USB line. More...
 
bool uhc_suspend_lpm (bool b_remotewakeup, uint8_t hird)
 Suspends a USB line through LPM feature(SAM D21). More...
 

User Functions to Manage a Device

uint8_t uhc_get_device_number (void)
 Returns the number of connected devices. More...
 
char * uhc_dev_get_string_manufacturer (uhc_device_t *dev)
 Gets the USB string manufacturer from a USB device. More...
 
char * uhc_dev_get_string_product (uhc_device_t *dev)
 Gets the USB string product from a USB device. More...
 
char * uhc_dev_get_string_serial (uhc_device_t *dev)
 Gets the USB string serial from a USB device. More...
 
char * uhc_dev_get_string (uhc_device_t *dev, uint8_t str_id)
 Gets a USB string from a USB device. More...
 
uint16_t uhc_dev_get_power (uhc_device_t *dev)
 Gets the maximum consumption of a device (mA). More...
 
uhd_speed_t uhc_dev_get_speed (uhc_device_t *dev)
 Returns the current device speed. More...
 
bool uhc_dev_is_high_speed_support (uhc_device_t *dev)
 Tests if the device supports the USB high speed. More...
 

Enumeration status Used in UHC_ENUM_EVENT() callback when a USB device enumeration is completed.

Enumerator
UHC_ENUM_SUCCESS 

Device is enumerated.

The supported USB device interfaces has been enabled.

UHC_ENUM_UNSUPPORTED 

None of the interfaces are supported by the UHIs.

UHC_ENUM_OVERCURRENT 

Device power is not supported.

UHC_ENUM_FAIL 

A problem occurred during USB enumeration.

UHC_ENUM_HARDWARE_LIMIT 

USB hardware can not support it.

Not enough free pipes.

UHC_ENUM_SOFTWARE_LIMIT 

USB software can not support it.

Implementation limit.

UHC_ENUM_MEMORY_LIMIT 

USB software can not support it.

Not enough memory.

UHC_ENUM_DISCONNECT 

The device has been disconnected during USB enumeration.

uint16_t uhc_dev_get_power ( uhc_device_t dev)

Gets the maximum consumption of a device (mA).

Parameters
[in]devDevice to request.
Returns
Maximum consumption of the device (mA).
uhd_speed_t uhc_dev_get_speed ( uhc_device_t dev)

Returns the current device speed.

Parameters
[in]devDevice to request.
Returns
Device speed.
char* uhc_dev_get_string ( uhc_device_t dev,
uint8_t  str_id 
)

Gets a USB string from a USB device.

This function waits the end of setup requests and the timing can be long (3ms to 15s). Thus, do not call it in an interrupt routine. This function allocates a buffer which must be free by user application.

Parameters
[in]devDevice to request.
[in]str_idString ID requested.
Returns
Pointer on unicode string, or NULL if function fails.
char* uhc_dev_get_string_manufacturer ( uhc_device_t dev)

Gets the USB string manufacturer from a USB device.

This function waits the end of setup requests and the timing can be long (3ms to 15s). Thus, do not call it in an interrupt routine. This function allocates a buffer which must be free by user application.

Parameters
[in]devDevice to request.
Returns
Pointer on unicode string, or NULL if function fails.
char* uhc_dev_get_string_product ( uhc_device_t dev)

Gets the USB string product from a USB device.

This function waits the end of setup requests and the timing can be long (3ms to 15s). Thus, do not call it in an interrupt routine. This function allocates a buffer which must be free by user application.

Parameters
[in]devDevice to request.
Returns
Pointer on unicode string, or NULL if function fails.
char* uhc_dev_get_string_serial ( uhc_device_t dev)

Gets the USB string serial from a USB device.

This function waits the end of setup requests and the timing can be long (3ms to 15s). Thus, do not call it in an interrupt routine. This function allocates a buffer which must be free by user application.

Parameters
[in]devDevice to request.
Returns
Pointer on unicode string, or NULL if function fails.
bool uhc_dev_is_high_speed_support ( uhc_device_t dev)

Tests if the device supports the USB high speed.

This function can wait the end of a setup request and the timing can be long (1ms to 5s). Thus, do not call it in an interrupt routine.

Parameters
[in]devDevice to request.
Returns
True, if high speed is supported.
uint8_t uhc_get_device_number ( void  )

Returns the number of connected devices.

Returns
Number of device connected on USB tree.
bool uhc_is_suspend ( void  )

Test if the suspend state is enabled on the USB line.

Returns
USB line in SUSPEND state or device not connected, if true.
void uhc_resume ( void  )

Resumes the USB line.

void uhc_start ( void  )

Starts the host mode.

void uhc_stop ( bool  b_id_stop)

Stops the host mode.

Parameters
[in]b_id_stopStop USB ID pin management, if true.
void uhc_suspend ( bool  b_remotewakeup)

Suspends a USB line.

Parameters
[in]b_remotewakeupAuthorize the remote wakeup features, if true.
bool uhc_suspend_lpm ( bool  b_remotewakeup,
uint8_t  hird 
)

Suspends a USB line through LPM feature(SAM D21).

Parameters
[in]b_remotewakeupAuthorize the remote wakeup features, if true.
[in]hirdHost Initiated Resume Duration.
Returns
False if the LPM is not supported by USB Device.