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

📄 usb_prop.c

📁 用 Hitex 工具软件开发 stm32 的例子
💻 C
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name          : usb_prop.c
* Author             : MCD Application Team
* Version            : V1.0
* Date               : 10/08/2007
* Description        : All processings related to Joystick Mouse Demo
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "system.h"
#include "usb_main.h"
#include "usb_lib.h"
#include "usb_conf.h"
#include "usb_prop.h"
#include "usb_desc.h"
#include "usb_pwr.h"
#include "hw_config.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u32 ProtocolValue;

/* -------------------------------------------------------------------------- */
/*  Structures initializations */
/* -------------------------------------------------------------------------- */

DEVICE Device_Table =
{
   EP_NUM,
   1
};

DEVICE_PROP Device_Property =
{
   HID_init,
   HID_Reset,
   HID_Status_In,
   HID_Status_Out,
   HID_Data_Setup,
   HID_NoData_Setup,
   HID_Get_Interface_Setting,
   HID_GetDeviceDescriptor,
   HID_GetConfigDescriptor,
   HID_GetStringDescriptor,
   0,
   0x40 /*MAX PACKET SIZE*/
};
USER_STANDARD_REQUESTS User_Standard_Requests =
{
   HID_GetConfiguration,
   HID_SetConfiguration,
   HID_GetInterface,
   HID_SetInterface,
   HID_GetStatus,
   HID_ClearFeature,
   HID_SetEndPointFeature,
   HID_SetDeviceFeature,
   HID_SetDeviceAddress
};

ONE_DESCRIPTOR Device_Descriptor =
{
   (u8*)HID_DeviceDescriptor,
   HID_SIZ_DEVICE_DESC
};

ONE_DESCRIPTOR Config_Descriptor =
{
   (u8*)HID_ConfigDescriptor,
   HID_SIZ_CONFIG_DESC
};

ONE_DESCRIPTOR HID_Report_Descriptor =
{
   (u8 *)HID_ReportDescriptor,
   HID_SIZ_REPORT_DESC
};

ONE_DESCRIPTOR Mouse_Hid_Descriptor =
{
   (u8*)HID_ConfigDescriptor + HID_OFF_HID_DESC,
   HID_SIZ_HID_DESC
};

ONE_DESCRIPTOR String_Descriptor[4] =
{
   {(u8*)HID_StringLangID, HID_SIZ_STRING_LANGID},
   {(u8*)HID_StringVendor, HID_SIZ_STRING_VENDOR},
   {(u8*)HID_StringProduct, HID_SIZ_STRING_PRODUCT},
   {(u8*)HID_StringSerial, HID_SIZ_STRING_SERIAL}
};

/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Extern function prototypes ------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : HID_init.
* Description    : HID Mouse init routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void HID_init(void)
{
   if (USB_ENUM.process_ready == FALSE)
   {
      pInformation->Current_Configuration = 0;
      /* Connect the device */
      PowerOn();
      /* USB interrupts initialization */
      _SetISTR(0);               /* clear pending interrupts */
      wInterrupt_Mask = IMR_MSK;
      _SetCNTR(wInterrupt_Mask); /* set interrupts mask */
      pInformation->Current_Feature = HID_ConfigDescriptor[7];
      USB_ENUM.process_ready = TRUE;
   }
   /* Wait until device is configured */
   if (pInformation->Current_Configuration != 0)
   {
     bDeviceState = CONFIGURED;
     USB_ENUM.process_ready = FALSE;
     ReEntryProcess = Dummy;
     ReEntry.enabled = FALSE;
   }
   else
   {
     USB_ENUM.process_ready = TRUE;
     ReEntry.enabled = TRUE;
     ReEntryProcess = HID_init;
   }
}

/*******************************************************************************
* Function Name  : HID_Reset.
* Description    : HID Mouse reset routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void HID_Reset(void)
{
   /* Set HID as not configured */
   pInformation->Current_Configuration = 0;
   pInformation->Current_Interface = 0;/*the default Interface*/
   SetBTABLE(BTABLE_ADDRESS);

   /* Initialize Endpoint 0 */
   SetEPType(ENDP0, EP_CONTROL);
   SetEPTxStatus(ENDP0, EP_TX_STALL);
   SetEPRxAddr(ENDP0, ENDP0_RXADDR);
   SetEPTxAddr(ENDP0, ENDP0_TXADDR);
   Clear_Status_Out(ENDP0);
   SetEPRxCount(ENDP0, Device_Property.MaxPacketSize);
   SetEPRxValid(ENDP0);

   /* Initialize Endpoint 1 */
   SetEPType(ENDP1, EP_INTERRUPT);
   SetEPTxAddr(ENDP1, ENDP1_TXADDR);
   SetEPTxCount(ENDP1, 4);
   SetEPRxStatus(ENDP1, EP_RX_DIS);
   SetEPTxStatus(ENDP1, EP_TX_NAK);

   /* Set this device to response on default address */
   SetDeviceAddress(0);
}

/*******************************************************************************
* Function Name  : HID_Status_In.
* Description    : HID status IN routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void HID_Status_In(void)
{
}

/*******************************************************************************
* Function Name  : HID_Status_Out
* Description    : HID status OUT routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void HID_Status_Out (void)
{
}

/*******************************************************************************
* Function Name  : HID_Data_Setup
* Description    : Handle the data class specific requests.
* Input          : Request Nb.
* Output         : None.
* Return         : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT HID_Data_Setup(u8 RequestNo)
{
   u8 *(*CopyRoutine)(u16);

   CopyRoutine = NULL;

   if ((RequestNo == GET_DESCRIPTOR)
      && (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
      && (pInformation->USBwIndex0 == 0))
   {

      if (pInformation->USBwValue1 == REPORT_DESCRIPTOR)
      {
         CopyRoutine = HID_GetReportDescriptor;
      }
      else if (pInformation->USBwValue1 == HID_DESCRIPTOR_TYPE)
      {
         CopyRoutine = HID_GetHIDDescriptor;
      }

   } /* End of GET_DESCRIPTOR */

  /*** GET_PROTOCOL ***/
   else if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
             && RequestNo == GET_PROTOCOL)
   {
      CopyRoutine = HID_GetProtocolValue;
   }

   if (CopyRoutine == NULL)
   {
      return USB_UNSUPPORT;
   }

   pInformation->Ctrl_Info.CopyData = CopyRoutine;
   pInformation->Ctrl_Info.Usb_wOffset = 0;
   (*CopyRoutine)(0);
   return USB_SUCCESS;
}

/*******************************************************************************
* Function Name  : HID_NoData_Setup
* Description    : handle the no data class specific requests
* Input          : Request Nb.
* Output         : None.
* Return         : USB_UNSUPPORT or USB_SUCCESS.
*******************************************************************************/
RESULT HID_NoData_Setup(u8 RequestNo)
{
   if ((Type_Recipient == (CLASS_REQUEST | INTERFACE_RECIPIENT))
         && (RequestNo == SET_PROTOCOL))
   {
      return HID_SetProtocol();
   }

   else
   {
      return USB_UNSUPPORT;
   }
}

/*******************************************************************************
* Function Name  : HID_GetDeviceDescriptor.
* Description    : Gets the device descriptor.
* Input          : Length
* Output         : None.
* Return         : The address of the device descriptor.
*******************************************************************************/
u8 *HID_GetDeviceDescriptor(u16 Length)
{
   return Standard_GetDescriptorData(Length, &Device_Descriptor);
}

/*******************************************************************************
* Function Name  : HID_GetConfigDescriptor.
* Description    : Gets the configuration descriptor.
* Input          : Length
* Output         : None.
* Return         : The address of the configuration descriptor.
*******************************************************************************/
u8 *HID_GetConfigDescriptor(u16 Length)
{
   return Standard_GetDescriptorData(Length, &Config_Descriptor);
}

/*******************************************************************************
* Function Name  : HID_GetStringDescriptor
* Description    : Gets the string descriptors according to the needed index
* Input          : Length
* Output         : None.
* Return         : The address of the string descriptors.
*******************************************************************************/
u8 *HID_GetStringDescriptor(u16 Length)
{
   u8 wValue0 = pInformation->USBwValue0;
   return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
}

/*******************************************************************************
* Function Name  : HID_GetReportDescriptor.
* Description    : Gets the HID report descriptor.
* Input          : Length
* Output         : None.
* Return         : The address of the configuration descriptor.
*******************************************************************************/
u8 *HID_GetReportDescriptor(u16 Length)
{
   return Standard_GetDescriptorData(Length, &HID_Report_Descriptor);
}

/*******************************************************************************
* Function Name  : HID_GetHIDDescriptor.
* Description    : Gets the HID descriptor.
* Input          : Length
* Output         : None.
* Return         : The address of the configuration descriptor.
*******************************************************************************/
u8 *HID_GetHIDDescriptor(u16 Length)
{
   return Standard_GetDescriptorData(Length, &Mouse_Hid_Descriptor);
}

/*******************************************************************************
* Function Name  : HID_Get_Interface_Setting.
* Description    : tests the interface and the alternate setting according to the
*                  supported one.
* Input          : - Interface : interface number.
*                  - AlternateSetting : Alternate Setting number.
* Output         : None.
* Return         : USB_SUCCESS or USB_UNSUPPORT.
*******************************************************************************/
RESULT HID_Get_Interface_Setting(u8 Interface, u8 AlternateSetting)
{
   if (AlternateSetting > 0)
   {
      return USB_UNSUPPORT;
   }
   else if (Interface > 0)
   {
      return USB_UNSUPPORT;
   }
   return USB_SUCCESS;
}

/*******************************************************************************
* Function Name  : HID_SetProtocol
* Description    : HID Set Protocol request routine.
* Input          : None.
* Output         : None.
* Return         : USB SUCCESS.
*******************************************************************************/
RESULT HID_SetProtocol(void)
{
   u8 wValue0 = pInformation->USBwValue0;
   ProtocolValue = wValue0;
   return USB_SUCCESS;
}

/*******************************************************************************
* Function Name  : HID_GetProtocolValue
* Description    : get the protocol value
* Input          : Length.
* Output         : None.
* Return         : address of the protcol value.
*******************************************************************************/
u8 *HID_GetProtocolValue(u16 Length)
{
   if (Length == 0)
   {
      pInformation->Ctrl_Info.Usb_wLength = 1;
      return NULL;
   }
   else
   {
      return (u8 *)(&ProtocolValue);
   }
}

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

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