?? usb_class_requests.c
字號:
// 0x0000: stop break
//
//-----------------------------------------------------------------------------
void CS_Send_Break(void)
{
if ( (Setup.bmRequestType == OUT_CL_INTERFACE)
&& (Setup.wLength.i == 0) )
{
Send_Break( Setup.wValue.i );
setup_handled = TRUE;
}
}
//-----------------------------------------------------------------------------
// swap_endian_long
//-----------------------------------------------------------------------------
// swap endian for long varialbe
//-----------------------------------------------------------------------------
#if defined BIG_ENDIAN
void swap_endian_long( ULONG idata *lptr )
{
BYTE tmp[4];
BYTE idata * ptr = (BYTE idata *)lptr;
tmp[3] = ptr[0];
tmp[2] = ptr[1];
tmp[1] = ptr[2];
tmp[0] = ptr[3];
ptr[0] = tmp[0];
ptr[1] = tmp[1];
ptr[2] = tmp[2];
ptr[3] = tmp[3];
}
#endif // end of BIG_ENDIAN
//-----------------------------------------------------------------------------
// HID class request handlers
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Get_Report
//-----------------------------------------------------------------------------
//
// mandatory to HID class
// Send report to host via control pipe
// Input and feature report are supported
//
//-----------------------------------------------------------------------------
static void Get_Report( void )
{
if ( (Setup.bmRequestType == IN_CL_INTERFACE)
&& (Setup.wValue.c[LSB] == 0) ) // Report ID
{
switch ( Setup.wValue.c[MSB] )
{
case HID_REPORT_TYPE_INPUT: // Input report
DataPtr = (BYTE *)HID_InOut_Packet;
DataSize = HID_IN_REPORT_SIZE;
setup_handled = TRUE;
break;
/*
case HID_REPORT_TYPE_FEATURE: // Feature report
DataPtr = (BYTE *)cs_temp_buffer;
DataSize = CS_TEMP_BUF_SIZE;
setup_handled = TRUE;
break;
*/
default:
break;
}
}
if ( setup_handled )
{
// Set serviced Setup Packet, Endpoint 0 intransmit mode,
Ep_Status0 = EP_TX;
if ( DataSize > Setup.wLength.i )
DataSize = Setup.wLength.i; // Send only requested amount of data
}
}
/*
//-----------------------------------------------------------------------------
// Set_Report
//-----------------------------------------------------------------------------
//
// Receive report from host via control pipe
// Output and feature report are supported
//
//-----------------------------------------------------------------------------
static void Set_Report( void )
{
if ( (Setup.bmRequestType == OUT_CL_INTERFACE)
&& (Setup.wValue.c[LSB] == 0) ) // Report ID
{
switch ( Setup.wValue.c[MSB] )
{
case HID_REPORT_TYPE_OUTPUT: // Output report
DataPtr = (BYTE *)cs_temp_buffer;
setup_handled = TRUE;
break;
case HID_REPORT_TYPE_FEATURE: // Feature report
DataPtr = (BYTE *)cs_temp_buffer;
setup_handled = TRUE;
break;
default:
break;
}
}
if ( setup_handled )
{
// Set serviced Setup Packet, Endpoint 0 intransmit mode,
Ep_Status0 = EP_RX;
DataSize = CS_TEMP_BUF_SIZE;
if ( DataSize > Setup.wLength.i )
DataSize = Setup.wLength.i; // Send only requested amount of data
}
}
//-----------------------------------------------------------------------------
// Get_Idle
//-----------------------------------------------------------------------------
//
// return current idle rate for a specified input report over interrupt IN pipe
//
//-----------------------------------------------------------------------------
static void Get_Idle( void )
{
if ( (Setup.bmRequestType == IN_CL_INTERFACE)
&& (Setup.wValue.c[MSB] == 0) // must be 0
&& (Setup.wLength.i == 1) ) // request size is always 1
{
switch ( Setup.wValue.c[LSB] ) // Report ID
{
case 1:
cs_temp_buffer[0] = IDLE_RATE_1;
DataPtr = (BYTE *)cs_temp_buffer;
setup_handled = TRUE;
break;
default:
break;
}
if ( setup_handled )
{
// Set serviced Setup Packet, Endpoint 0 intransmit mode,
Ep_Status0 = EP_TX;
DataSize = 1;
}
}
//-----------------------------------------------------------------------------
// Set_Idle
//-----------------------------------------------------------------------------
//
// Set idle rate to specified duration
// When duration equals to zero, stop the report
//
//-----------------------------------------------------------------------------
static void Set_Idle( void )
{
if ( (Setup.bmRequestType == OUT_CL_INTERFACE)
&& (Setup.wLength.i == 0) ) // Length must be 0
{
switch ( Setup.wValue.c[LSB] ) // Report ID
{
case 0:
IDLE_RATE_1 = Setup.wValue.c[MSB]; // set Duration to all report ID
IDLE_RATE_2 = IDLE_RATE_1;
setup_handled = TRUE;
break;
case 1:
IDLE_RATE_1 = Setup.wValue.c[MSB]; // set Duration to specified report ID
setup_handled = TRUE;
break;
default:
break;
}
}
}
//-----------------------------------------------------------------------------
// Get_Protocol
//-----------------------------------------------------------------------------
//
// Just for boot device (mouse/keyboard)
// return active protocol, either boot or report
//
//-----------------------------------------------------------------------------
bit cs_boot_protocol = HID_PROTOCOL_REPORT;
static uchar code cs_zero[1] = { 0 };
static uchar code cs_one[1] = { 1 };
static void Get_Protocol( void )
{
if ( (Setup.bmRequestType == IN_CL_INTERFACE)
&& (Setup.wValue.i == 0) // must be 0
&& (Setup.wLength.i == 1) ) // request size is always 1
{
if ( cs_boot_protocol == HID_PROTOCOL_BOOT )
DataPtr = (BYTE *)cs_zero;
else
DataPtr = (BYTE *)cs_one;
DataSize = 1;
Ep_Status0 = EP_TX;
setup_handled = TRUE;
}
}
//-----------------------------------------------------------------------------
// Set_Protocol
//-----------------------------------------------------------------------------
//
// Just for boot device
// Switch active protocol
//
//-----------------------------------------------------------------------------
static void Set_Protocol( void )
{
if ( (Setup.bmRequestType == OUT_CL_INTERFACE)
&& (Setup.wValue.c[MSB] == 0) // upper byte of protocol selector
&& (Setup.wLength.i == 0) ) // Length must be 0
{
switch ( Setup.wValue.c[LSB] ) //
{
case HID_PROTOCOL_BOOT:
cs_boot_protocol = HID_PROTOCOL_BOOT;
setup_handled = TRUE;
break;
case HID_PROTOCOL_REPORT:
cs_boot_protocol = HID_PROTOCOL_REPORT;
setup_handled = TRUE;
break;
default:
break;
}
}
}
*/
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -