Microchip's Accessory Framework for Android(tm)
14
USB_ApplicationDataEventHandler() and USB_ApplicationEventHandler() for the pre-compiled example. For
the source example the function names are configurable through the usb_config.h ( see page 15) file (see the usb_config.h
see page 15) section for more information). For more detailed information about these functions or the USB library,
please refer to www.microchip.com/mal . This download includes the USB host library code as well as more detailed
documentation about that library.
The data events are consumed by the Android client driver. So the user application data event handler doesn't need to do
anything. It needs to be present for the library to link successfully but it can just return FALSE.
BOOL USB_ApplicationDataEventHandler( BYTE address, USB_EVENT event, void *data, DWORD size
)
{
return FALSE;
}
The regular event handler has a little more work that needs to be done. This handler notifies the user of device attach and
detach events. For Android devices this is covered in the Detecting a Connection/Disconnection to an Android Device ( see
page 18) section. This function also notifies the user about errors that might occur in the USB subsystem. These can be
useful for debugging development issues or logging issue once released in the field. The last important duty that this function
provides is determining if the power required by the attached device is available. This is done through the
EVENT_VBUS_REQUEST_POWER event. Remember in this event that the amount of power requested through the USB bus is
the power required/2, not the power required. Below is full implementation of the USB event handler that will work with a
single attached Android device.
BOOL USB_ApplicationEventHandler( BYTE address, USB_EVENT event, void *data, DWORD size )
{
switch ( event )
{
case EVENT_VBUS_REQUEST_POWER:
// The data pointer points to a byte that represents the amount of power
// requested in mA, divided by two. If the device wants too much power,
// we reject it.
if (((USB_VBUS_POWER_EVENT_DATA*)data)->current <= (MAX_ALLOWED_CURRENT / 2))
{
return TRUE;
}
else
{
DEBUG_ERROR( "Device requires too much current\r\n" );
}
break ;
case
case
case
case
case
case
case
case
EVENT_VBUS_RELEASE_POWER:
EVENT_HUB_ATTACH:
EVENT_UNSUPPORTED_DEVICE:
EVENT_CANNOT_ENUMERATE:
EVENT_CLIENT_INIT_ERROR:
EVENT_OUT_OF_MEMORY:
EVENT_UNSPECIFIED_ERROR:
EVENT_DETACH:
//Fall-through
case EVENT_ANDROID_DETACH:
device_attached = FALSE;
return TRUE;
}
break ;
// Android Specific events
case EVENT_ANDROID_ATTACH:
device_attached = TRUE;
device_handle = data;
return TRUE;
default :
break ;
}
return FALSE;
14
4
相关PDF资料
DM300004-2 BOARD DEMO DSPICDEM.NET 2
DM300014 BOARD DEMO DSPICDEM 1.1 GEN PURP
DM300016 BOARD DEMO DSPICDEM STARTER
DM300017 BOARD DEMO DSPICDEM STARTER
DM300020 BOARD DEV DSPICDEM MC1 MOTORCTRL
DM300021 MODULE PWR DSPICDEM MC1H HV 3PHS
DM300022 MODULE PWR DSPICDEM MC1L LV 3PHS
DM320002 BOARD EXPANSION PIC32 I/O
相关代理商/技术参数
DM2410-0AL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0BL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0CL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0DL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0GL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0HL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-0SL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic
DM2410-1AL1 制造商:未知厂家 制造商全称:未知厂家 功能描述:Optoelectronic