⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f3xx_usb0_standard_requests.c

📁 用c8051做的usb鼠标(HID类)Firmware works with the Silicon Labs IDE v1.71 or later and the Keil C51 tool cha
💻 C
📖 第 1 页 / 共 2 页
字号:
         {
            if (SETUP.wValue.c[LSB] == IN_EP1)
            {
               DATAPTR = (unsigned char*) &Endpoint1Desc;
               DATASIZE = Endpoint1Desc.bLength;
            }
            else
            {
               DATAPTR = (unsigned char*) &Endpoint2Desc;
               DATASIZE = Endpoint2Desc.bLength;
            }
         }
         else
         {
            Force_Stall();
         }
         break;

	case DSC_HID: // HID Specific (HID class descriptor)
		DATAPTR = (unsigned char*)&HidDesc;
		DATASIZE = HidDesc.bLength;
		break;

	case DSC_HID_REPORT: // HID Specific (HID report descriptor)
		DATAPTR = (unsigned char*)&HIDREPORTDESC;
		DATASIZE = HID_REPORT_DESCRIPTOR_SIZE;
		break;

      default:
         Force_Stall ();               // Send Stall if unsupported request
         break;
   }

   // Verify that the requested descriptor is valid
   if (SETUP.wValue.c[MSB] == DSC_DEVICE ||
   SETUP.wValue.c[MSB] == DSC_CONFIG     ||
   SETUP.wValue.c[MSB] == DSC_STRING     ||
   SETUP.wValue.c[MSB] == DSC_INTERFACE  ||
   SETUP.wValue.c[MSB] == DSC_ENDPOINT)
   {
      if ((SETUP.wLength.c[LSB] < DATASIZE) &&
      (SETUP.wLength.c[MSB] == 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
   // This request must be directed to the device
   if ( (SETUP.bmRequestType != OUT_DEVICE)    ||
   // with value word set to zero
   SETUP.wValue.c[MSB]  || SETUP.wValue.c[LSB]||
   // and index set to zero
   SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB]||
   // and SETUP length set to one
   SETUP.wLength.c[MSB] || (SETUP.wLength.c[LSB] != 1) )
   {
      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
      								   // only supports one configuration
         DATAPTR = (unsigned char*)&ONES_PACKET;
         DATASIZE = 1;
      }
      if (USB0_STATE == DEV_ADDRESS)   // If the device is in address state, it
      {                                // is not configured, so return 0x00
         DATAPTR = (unsigned char*)&ZERO_PACKET;
         DATASIZE = 1;
      }
   }
   if (EP_STATUS[0] != EP_STALL)
   {
	  // Set Serviced Out Packet bit
      POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
      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

   // Device must be addressed before configured
   if ((USB0_STATE == DEV_DEFAULT) ||
   // and request recipient must be the device
   (SETUP.bmRequestType != IN_DEVICE) ||
   // the index and length words must be zero
   SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB]||
   SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB] ||
   SETUP.wValue.c[MSB]  || (SETUP.wValue.c[LSB] > 1))
   // This software only supports config = 0,1
   {
      Force_Stall ();                  // Send stall if SETUP data is invalid
   }

   else
   {
      if (SETUP.wValue.c[LSB] > 0)     // Any positive configuration request
      {                                // results in configuration being set
      								   // to 1
         USB0_STATE = DEV_CONFIGURED;
         EP_STATUS[1] = EP_IDLE;       // Set endpoint status to idle (enabled)

         POLL_WRITE_BYTE (INDEX, 1);   // Change index to endpoint 1
         // Set DIRSEL to indicate endpoint 1 is IN/OUT
         POLL_WRITE_BYTE (EINCSR2, rbInSPLIT);
         POLL_WRITE_BYTE (INDEX, 0);   // Set index back to endpoint 0

         Handle_In1();
      }
      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 device is not configured
   if ((USB0_STATE != DEV_CONFIGURED) ||
   // or recipient is not an interface
   (SETUP.bmRequestType != OUT_INTERFACE) ||
   // or non-zero value or index fields
   SETUP.wValue.c[MSB]  ||SETUP.wValue.c[LSB] ||
   // or data length not equal to one
   SETUP.wIndex.c[MSB]  ||SETUP.wIndex.c[LSB] ||
   SETUP.wLength.c[MSB] ||(SETUP.wLength.c[LSB] != 1))
   {
      Force_Stall ();                  // Then return stall due to invalid
      								   // request
   }

   else
   {
	  // Otherwise, return 0x00 to host
      DATAPTR = (unsigned char*)&ZERO_PACKET;
      DATASIZE = 1;
   }
   if (EP_STATUS[0] != EP_STALL)
   {
	  // Set Serviced SETUP packet, put endpoint in transmit mode and reset
	  // Data sent counter
      POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
      EP_STATUS[0] = EP_TX;
      DATASENT = 0;
   }
}

//-----------------------------------------------------------------------------
// Set_Interface
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Standard request that should not change in custom HID designs.
//
//-----------------------------------------------------------------------------
void Set_Interface (void)
{
   // Make sure request is directed at interface
   if ((SETUP.bmRequestType != IN_INTERFACE)  ||
   // and all other packet values are set to zero
   SETUP.wLength.c[MSB] ||SETUP.wLength.c[LSB]||
   SETUP.wValue.c[MSB]  ||SETUP.wValue.c[LSB] ||
   SETUP.wIndex.c[MSB]  ||SETUP.wIndex.c[LSB])
   {
      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)
   {
      // Set serviced SETUP Packet
      POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
   }

}



//-----------------------------------------------------------------------------
// Get_Report()
//-----------------------------------------------------------------------------
//
// Return Value - None
// Parameters - None
//
// Description: Sends a given report type to the host.
//
//-----------------------------------------------------------------------------
void Get_Report (void)
{
   // call appropriate handler to prepare buffer
   ReportHandler_IN_ISR(SETUP.wValue.c[LSB]);
   // set DATAPTR to buffer used inside Control Endpoint
   DATAPTR = IN_BUFFER.Ptr;
   DATASIZE = IN_BUFFER.Length;

   if (EP_STATUS[0] != EP_STALL)
   {
	  // Set serviced SETUP Packet
      POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
      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)
{
   // prepare buffer for OUT packet
   Setup_OUT_BUFFER ();

   // set DATAPTR to buffer
   DATAPTR = OUT_BUFFER.Ptr;
   DATASIZE = SETUP.wLength.i;

   if (EP_STATUS[0] != EP_STALL)
   {
	  // Set serviced SETUP Packet
      POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
      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 + -