In this use case, the USB host and USB device are enabled, it is the dual role.
Note: On the Atmel boards, the switch of USB role is managed automatically by the USB stack thank to a USB OTG connector and its USB ID pin. For a dual role management without OTG connector, please refer to "AVR4950 section 6.1 Dual roles".
Setup Steps
Prior to implement this use case, be sure to have already apply the UDI module "basic use case".
Usage Steps
Example Code
Content of conf_usb_host.h:
#define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
extern void my_callback_mode_change(bool b_host_mode);
Add to application C-file:
{
}
bool my_host_mode;
void my_callback_mode_change(bool b_host_mode)
{
my_host_mode = b_host_mode;
}
void my_usb_task(void)
{
if (my_host_mode) {
} else {
}
}
Workflow
- In case of USB dual roles (Device and Host), the USB stack must be enabled by uhc_start() and the udc_start() must not be called.
- In dual role, to known the current USB mode, the callback to notify the mode changes can be used.
- Ensure that conf_usb_host.h contains the following parameters.
#define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
extern void my_callback_mode_change(bool b_host_mode);
- Ensure that application contains the following code:
bool my_host_mode;
void my_callback_mode_change(bool b_host_mode)
{
my_host_mode = b_host_mode;
}
void my_usb_task(void)
{
if (my_host_mode) {
} else {
}
}
In this use case, the USB host and USB device are enabled, it is the dual role.
- Note
- On the Atmel boards, the switch of USB role is managed automatically by the USB stack thank to a USB On-The-Go (OTG) connector and its USB ID pin. Refer to section "Dual roles" for further information in the application note:
Setup Steps
Prior to implement this use case, be sure to have already applied the UHI module "basic use case".
Usage Steps
Example Code
Content of conf_usb_host.h:
#define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
extern void my_callback_mode_change(bool b_host_mode);
Add to application C-file:
{
}
bool my_host_mode;
void my_callback_mode_change(bool b_host_mode)
{
my_host_mode = b_host_mode;
}
void my_usb_task(void)
{
if (my_host_mode) {
} else {
}
}
Workflow
- In case of USB dual roles (Device and Host), the USB stack must be enabled by uhc_start() and the udc_start() must not be called.
- In dual role, to know the current USB mode, the callback to notify the mode changes can be used.
- Ensure that conf_usb_host.h contains the following parameters:
#define UHC_MODE_CHANGE(b_host_mode) my_callback_mode_change(b_host_mode)
extern void my_callback_mode_change(bool b_host_mode);
- Ensure that application contains the following code:
bool my_host_mode;
void my_callback_mode_change(bool b_host_mode)
{
my_host_mode = b_host_mode;
}
void my_usb_task(void)
{
if (my_host_mode) {
} else {
}
}