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

📄 f32x_usb_standard_requests.c

📁 利用C8051F320的USB传输实例
💻 C
📖 第 1 页 / 共 2 页
字号:
         bEpState = SetConfiguration(gEp0Command.wValue.c[1]);
   }
   gEp0Status.bEpState = bEpState;
}


//-----------------------------------------------------------------------------
// SetInterfaceRequest
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
//-----------------------------------------------------------------------------
void SetInterfaceRequest()
{
   /*
   // Length field must be zero
   if ((gEp0Command.wLength.i) || (gDeviceStatus.bDevState != DEV_CONFIG))
      bEpState = EP_ERROR;

   else
   {
      // Check that target interface exists for this configuration
      if(gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
         bEpState = EP_ERROR;

      else
      {
         // Get pointer to interface status structure
         pIfStatus = (PIF_STATUS)&gDeviceStatus.IfStatus;

         // Check that alternate setting exists for the interface
         if (gEp0Command.wValue.i > pIfStatus->bNumAlts)
            bEpState = EP_ERROR;

         // Assign alternate setting
         else
         {
            pIfStatus->bCurrentAlt = gEp0Command.wValue.i;
            bEpState = SetInterface(pIfStatus);
         }
      }
   }
   gEp0Status.bEpState = bEpState;
   */
}

//-----------------------------------------------------------------------------
// GetStatusRequest
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
//-----------------------------------------------------------------------------
void GetStatusRequest ()
{
   // Value field must be zero; Length field must be 2
   if ((gEp0Command.wValue.i != 0) || (gEp0Command.wLength.i != 0x02) ||
   (gDeviceStatus.bDevState == DEV_DEFAULT) ||
   (gDeviceStatus.bDevState == DEV_ADDRESS && gEp0Command.wIndex.i != 0))
   {
      bEpState = EP_ERROR;
   }

   else
   {
      // Check for desired status (device, interface, endpoint)
      switch (gEp0Command.bmRequestType & CMD_MASK_RECIP)
      {
         // Device
         case CMD_RECIP_DEV:
            // Index must be zero for a Device status request
            if (gEp0Command.wIndex.i != 0)
               bEpState = EP_ERROR;
            else
            {
               // Prepare data_out for transmission
               gEp0Status.wData.c[1] = 0;
               gEp0Status.wData.c[0] = gDeviceStatus.bRemoteWakeupStatus;
               gEp0Status.wData.c[0] |= gDeviceStatus.bSelfPoweredStatus;
            }
            break;

         // Interface
         case CMD_RECIP_IF:
            // Prepare data_out for transmission
            gEp0Status.wData.i = 0;
            break;

         // Endpoint
         case CMD_RECIP_EP:
            // Prepare data_out for transmission
            gEp0Status.wData.i = 0;
            if (GetEpStatus(gEp0Command.wIndex.i) == EP_HALTED)
               gEp0Status.wData.c[0] |= 0x01;
            break;

         // Other cases unsupported
         default:
            bEpState = EP_ERROR;
            break;
      }

      // Endpoint0 state assignment
      bEpState = EP_TX;

      // Point ep0 data pointer to transmit data_out
      gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
      gEp0Status.uNumBytes = 2;
   }
   gEp0Status.bEpState = bEpState;
}

//-----------------------------------------------------------------------------
// GetDescriptorRequest
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
//-----------------------------------------------------------------------------
void GetDescriptorRequest ()
{
   WORD wTempInt;

   // This request is valid in all device states
   // Switch on requested descriptor (Value field)
   switch (gEp0Command.wValue.c[0])
   {
      // Device Descriptor Request
      case DSC_DEVICE:
         // Get size of the requested descriptor
         uNumBytes = STD_DSC_SIZE;
         // Prep to send the requested length
         if (uNumBytes > gEp0Command.wLength.i)
         {
            uNumBytes = gEp0Command.wLength.i;
         }
         // Point data pointer to the requested descriptor
         gEp0Status.pData = (void*)&gDescriptorMap.bStdDevDsc;
         bEpState = EP_TX;
         break;

      // Configuration Descriptor Request
      case DSC_CONFIG:
         // Make sure requested descriptor exists
         if (gEp0Command.wValue.c[1] >
         gDescriptorMap.bStdDevDsc[std_bNumConfigurations])
         {
            bEpState = EP_ERROR;
         }
         else
         {
            // Get total length of this configuration descriptor
            // (includes all associated interface and endpoints)
            wTempInt.c[1] = gDescriptorMap.bCfg1[cfg_wTotalLength_lsb];
            wTempInt.c[0] = gDescriptorMap.bCfg1[cfg_wTotalLength_msb];
            uNumBytes = wTempInt.i;

            // Prep to transmit the requested length
            if (uNumBytes > gEp0Command.wLength.i)
            {
               uNumBytes = gEp0Command.wLength.i;
            }
            // Point data pointer to requested descriptor
            gEp0Status.pData = &gDescriptorMap.bCfg1;
            bEpState = EP_TX;
         }
         break;
   }
   gEp0Status.uNumBytes = uNumBytes;
   gEp0Status.bEpState = bEpState;
}

//-----------------------------------------------------------------------------
// GetConfigurationRequest
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
//-----------------------------------------------------------------------------
void GetConfigurationRequest ()
{
   // Length field must be 1; Index field must be 0;
   // Value field must be 0
   if ((gEp0Command.wLength.i != 1) || (gEp0Command.wIndex.i) ||
   (gEp0Command.wValue.i) || (gDeviceStatus.bDevState == DEV_DEFAULT))
   {
      bEpState = EP_ERROR;
   }

   else if (gDeviceStatus.bDevState == DEV_ADDRESS)
   {
      // Prepare data_out for transmission
      gEp0Status.wData.i = 0;
      // Point ep0 data pointer to transmit data_out
      gEp0Status.pData = (BYTE *)&gEp0Status.wData.i;
      // ep0 state assignment
      bEpState = EP_TX;
   }

   else
   {
      // Index to desired field
      gEp0Status.pData = (void *)&gDescriptorMap.bCfg1[cfg_bConfigurationValue];

      // ep0 state assignment
      bEpState = EP_TX;
   }
   gEp0Status.uNumBytes = 1;
   gEp0Status.bEpState = bEpState;
}

//-----------------------------------------------------------------------------
// GetInterfaceRequest
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
//-----------------------------------------------------------------------------
void GetInterfaceRequest ()
{
   // Value field must be 0; Length field must be 1
   if ((gEp0Command.wValue.i) || (gEp0Command.wLength.i != 1) ||
   (gDeviceStatus.bDevState != DEV_CONFIG))
   {
      bEpState = EP_ERROR;
   }

   else
   {
      // Make sure requested interface exists
      if (gEp0Command.wIndex.i > gDeviceStatus.bNumInterf - 1)
         bEpState = EP_ERROR;
      else
      {
         // Get current interface setting
         gEp0Status.pData = (void *)(&gDeviceStatus.IfStatus)->bCurrentAlt;

         // Length must be 1
         gEp0Status.uNumBytes = 1;
         bEpState = EP_TX;
      }
   }
   gEp0Status.bEpState = bEpState;
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -