📄 f3xx_usb0_standard_requests.c
字号:
{ // was requested, and set data ptr and
case DSC_DEVICE: // size accordingly
DATAPTR = (uint8_t*)&DEVICEDESC;
DATASIZE = DEVICEDESC.bLength;
break;
case DSC_CONFIG:
DATAPTR = (uint8_t*)&ConfigDesc; // Compiler Specific - The next statement
// reverses the bytes in the configuration
// descriptor for the compiler
DATASIZE = ConfigDesc.wTotalLength.c[cMSB] + 256*ConfigDesc.wTotalLength.c[cLSB];
break;
case DSC_STRING:
if (SETUP.wValue.c[cLSB] < 4)
{
DATAPTR = (uint8_t *) STRINGDESCTABLE[SETUP.wValue.c[cLSB]]; // Can have a maximum of 255 strings
DATASIZE = *DATAPTR;
}
else
{
Force_Stall();
}
break;
case DSC_INTERFACE:
DATAPTR = (uint8_t*)&InterfaceDesc;
DATASIZE = InterfaceDesc.bLength;
break;
case DSC_HID: // HID Specific (HID class descriptor)
DATAPTR = (uint8_t*) &HidDesc;
DATASIZE = HidDesc.bLength;
break;
case DSC_HID_REPORT: // HID Specific (HID report descriptor)
switch(SETUP.wIndex.c[cLSB]) // Determine which descriptor number
{
case 0:
DATAPTR = (uint8_t*) &HID_REPORT_DESC_MOUSE[0];
DATASIZE = HID_REPORT_DESCRIPTOR_SIZE_MOUSE;
break;
case 1:
DATAPTR = (uint8_t*) &HID_REPORT_DESC_KEYB[0];
DATASIZE = HID_REPORT_DESCRIPTOR_SIZE_KEYB;
break;
case 2:
DATAPTR = (uint8_t*) &HID_REPORT_DESC_RC[0];
DATASIZE = HID_REPORT_DESCRIPTOR_SIZE_RC;
break;
default:
break;
}
break;
default:
Force_Stall (); // Send Stall if unsupported request
break;
}
if (SETUP.wValue.c[cMSB] == DSC_DEVICE || // Verify that the requested descriptor is valid
SETUP.wValue.c[cMSB] == DSC_CONFIG ||
SETUP.wValue.c[cMSB] == DSC_STRING ||
SETUP.wValue.c[cMSB] == DSC_INTERFACE ||
SETUP.wValue.c[cMSB] == DSC_ENDPOINT)
{
if((SETUP.wLength.c[cLSB] < DATASIZE)&&(SETUP.wLength.c[cMSB] == 0))
{
DATASIZE = SETUP.wLength.i; // Send only requested amount of data
}
}
if(EP_STATUS[0] != EP_STALL) // Make sure endpoint not in stall mode
{
POLL_WRITE_BYTE (E0CSR, rbSOPRDY); // Service SETUP Packet
EP_STATUS[0] = EP_TX; // Put endpoint in transmit mode
DATASENT = 0; // Reset Data Sent counter
}
}
//-----------------------------------------------------------------------------
// Get_Configuration
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Standard request that should not change in custom HID designs.
//
//-----------------------------------------------------------------------------
void Get_Configuration(void) // This routine returns current configuration value
{
if((SETUP.bmRequestType != OUT_DEVICE) || // This request must be directed to the device
SETUP.wValue.c[cMSB] || SETUP.wValue.c[cLSB] || // with value word set to zero
SETUP.wIndex.c[cMSB] || SETUP.wIndex.c[cLSB] || // and index set to zero
SETUP.wLength.c[cMSB] || (SETUP.wLength.c[cLSB] != 1)) // and SETUP length set to one
{
Force_Stall(); // Otherwise send a stall to host
}
else
{
if (USB0_STATE == DEV_CONFIGURED) // If the device is configured, then return value 0x01 since this software
{
DATAPTR = (uint8_t*)&ONES_PACKET[0]; // only supports one configuration
DATASIZE = 1;
}
if(USB0_STATE == DEV_ADDRESS) // If the device is in address state, it is not configured, so return 0x00
{
DATAPTR = (uint8_t*) &ZERO_PACKET[0];
DATASIZE = 1;
}
}
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, rbSOPRDY); // Set Serviced Out Packet bit
EP_STATUS[0] = EP_TX; // Put endpoint into transmit mode
DATASENT = 0; // Reset Data Sent counter to zero
}
}
//-----------------------------------------------------------------------------
// Set_Configuration
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Standard request that should not change in custom HID designs.
//
//-----------------------------------------------------------------------------
void Set_Configuration(void) // This routine allows host to change current device configuration value
{
int i;
if((USB0_STATE == DEV_DEFAULT) || // Device must be addressed before configured
(SETUP.bmRequestType != IN_DEVICE) || // and request recipient must be the device
SETUP.wIndex.c[cMSB] || SETUP.wIndex.c[cLSB]|| // the index and length words must be zero
SETUP.wLength.c[cMSB] || SETUP.wLength.c[cLSB] ||
SETUP.wValue.c[cMSB] || (SETUP.wValue.c[cLSB] > 1)) // This software only supports config = 0,1
{
Force_Stall (); // Send stall if SETUP data is invalid
}
else
{
if(SETUP.wValue.c[cLSB] > 0) // Any positive configuration request
{ // results in configuration being set to 1
USB0_STATE = DEV_CONFIGURED;
for (i=1; i<=3; i++)
{
EP_STATUS[i] = EP_IDLE; // Set endpoint status to idle (enabled)
POLL_WRITE_BYTE(INDEX, i); // Change index to endpoint 1
POLL_WRITE_BYTE(EINCSR2, rbInSPLIT); // Set DIRSEL to indicate endpoint 1 is IN/OUT
}
POLL_WRITE_BYTE(INDEX, 0); // Set index back to endpoint 0
}
else
{
USB0_STATE = DEV_ADDRESS; // Unconfigures device by setting state
EP_STATUS[1] = EP_HALT; // to address, and changing endpoint 1 and 2
}
}
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE(E0CSR, (rbSOPRDY | rbDATAEND)); // Indicate SETUP packet has been serviced
}
}
//-----------------------------------------------------------------------------
// Get_Interface
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - Non
//
// Standard request that should not change in custom HID designs.
//
//-----------------------------------------------------------------------------
void Get_Interface(void) // This routine returns 0x00, since only one interface is supported by this firmware
{
if ((USB0_STATE != DEV_CONFIGURED) || // If device is not configured
(SETUP.bmRequestType != OUT_INTERFACE) || // or recipient is not an interface
SETUP.wValue.c[cMSB] || SETUP.wValue.c[cLSB] || // or non-zero value or index fields
SETUP.wIndex.c[cMSB] || SETUP.wIndex.c[cLSB] || // or data length not equal to one
SETUP.wLength.c[cMSB] || (SETUP.wLength.c[cLSB] != 1))
{
Force_Stall(); // Then return stall due to invalid request
}
else
{
DATAPTR = (uint8_t*) &ZERO_PACKET[0]; // Otherwise, return 0x00 to host
DATASIZE = 1;
}
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, rbSOPRDY); // Set Serviced SETUP packet, put endpoint in transmit mode and reset
EP_STATUS[0] = EP_TX;
DATASENT = 0; // Data sent counter
}
}
//-----------------------------------------------------------------------------
// Set_Interface
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Standard request that should not change in custom HID designs.
//
//-----------------------------------------------------------------------------
void Set_Interface(void)
{
if((SETUP.bmRequestType != IN_INTERFACE) || // Make sure request is directed at interface
SETUP.wLength.c[cMSB] ||SETUP.wLength.c[cLSB]|| // and all other packet values are set to zero
SETUP.wValue.c[cMSB] ||SETUP.wValue.c[cLSB] ||
SETUP.wIndex.c[cMSB] ||SETUP.wIndex.c[cLSB])
{
Force_Stall(); // Othewise send a stall to host
}
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND)); // Indicate SETUP packet has been serviced
}
}
//-----------------------------------------------------------------------------
// Get_Idle
//-----------------------------------------------------------------------------
// Not supported.
//
//-----------------------------------------------------------------------------
void Get_Idle(void)
{
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Get_Protocol
//-----------------------------------------------------------------------------
// Not supported.
//
//-----------------------------------------------------------------------------
void Get_Protocol(void)
{
}
//-----------------------------------------------------------------------------
// Set_Protocol
//-----------------------------------------------------------------------------
// Not supported.
//
//-----------------------------------------------------------------------------
void Set_Protocol(void)
{
}
//-----------------------------------------------------------------------------
// Set_Idle()
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Description: Sets the idle feature on interrupt in endpoint.
//-----------------------------------------------------------------------------
void Set_Idle(void)
{
if (EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND)); // Set serviced SETUP Packet
}
}
//-----------------------------------------------------------------------------
// Get_Report()
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Description: Sends a given report type to the host.
//
//-----------------------------------------------------------------------------
void Get_Report(void)
{
ReportHandler_IN_ISR(SETUP.wValue.c[cLSB]); // call appropriate handler to prepare buffer
DATAPTR = in_buffer.Ptr; // set DATAPTR to buffer used inside Control Endpoint
DATASIZE = in_buffer.Length;
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, rbSOPRDY); // Set serviced SETUP Packet
EP_STATUS[0] = EP_TX; // Endpoint 0 in transmit mode
DATASENT = 0; // Reset DATASENT counter
}
}
//-----------------------------------------------------------------------------
// Set_Report()
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Description: Receives a report sent from the host.
//
//-----------------------------------------------------------------------------
void Set_Report(void)
{
Setup_OUT_BUFFER (); // prepare buffer for OUT packet
DATAPTR = out_buffer.Ptr; // set DATAPTR to buffer
DATASIZE = SETUP.wLength.i;
if(EP_STATUS[0] != EP_STALL)
{
POLL_WRITE_BYTE (E0CSR, rbSOPRDY); // Set serviced SETUP Packet
EP_STATUS[0] = EP_RX; // Endpoint 0 in transmit mode
DATASENT = 0; // Reset DATASENT counter
}
}
/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -