STM32模拟USB多点触控屏

STM32模拟USB多点触控屏

开发准备

  • STM32的USB官方例程库JoyStickMouse
  • STM32F103RC
  • Windows7

代码修改
1.usb_pwr.c

RESULT PowerOn(void)
{
  u16 wRegVal;                     
  //USB_Cable_Config(ENABLE);//这里由于硬件问题用不到,注释

  /*** CNTR_PWDN = 0 ***/
  wRegVal = CNTR_FRES;
  _SetCNTR(wRegVal);     

  /*** CNTR_FRES = 0 ***/
  wInterrupt_Mask = 0;
  _SetCNTR(wInterrupt_Mask);

  /*** Clear pending interrupts ***/
  _SetISTR(0);

  /*** Set interrupt mask ***/
  wInterrupt_Mask = CNTR_RESETM | CNTR_SUSPM | CNTR_WKUPM;
  _SetCNTR(wInterrupt_Mask);     
  return USB_SUCCESS;
}

2.usb_proc.c

void Joystick_Reset(void)
{
  /* Set Joystick_DEVICE as not configured */
  pInformation->Current_Configuration = 0;
  pInformation->Current_Interface = 0;/* the default Interface */

  /* Current Feature initialization */
  pInformation->Current_Feature = Joystick_ConfigDescriptor[7];

  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 In 1 */
  SetEPType(ENDP1, EP_INTERRUPT); //初始化为中断端点类型
  SetEPTxAddr(ENDP1, ENDP1_TXADDR); //设置发送数据的地址
  SetEPTxCount(ENDP1, 14); //设置发送的长度,这里由于使用的两点触控的触控屏需要发送的数据为14Bytes一次
  SetEPTxStatus(ENDP1, EP_TX_NAK); //设置端点处于忙状态

  /* Initialize Endpoint Out 1 */
  SetEPRxAddr(ENDP1, ENDP1_RXADDR); //设置接收数据的地址
  SetEPRxCount(ENDP1, 2);  //设置接收长度
  SetEPRxStatus(ENDP1, EP_RX_VALID); //设置端点有效,可以接收数据

  bDeviceState = ATTACHED;

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

由于需要枚举的是多点触控屏,需要处理Get_Report和Set_Report,虽然有些人说Set_Report不需要处理,但是我还是顺手处理掉了。

/*******************************************************************************
添加上获取HID描述符和报告描述符函数
*******************************************************************************/
ONE_DESCRIPTOR Test_Hid_Descriptor =                                
  {                                                                 
    (u8*)Joystick_ConfigDescriptor + Test_OFF_HID_DESC,             
    JOYSTICK_SIZ_HID_DESC                                           
  };

ONE_DESCRIPTOR Test_Report_Descriptor =                             
  {                                                                 
    (u8 *)TestReportDescriptor,                                     
    Test_ReportDescriptor_Size                                      
  };    

u8 *Test_GetHIDDescriptor(u16 Length)
{
    return Standard_GetDescriptorData(Length, &Test_Hid_Descriptor);
}

u8 *Test_GetReportDescriptor(u16 Length)
{
    return Standard_GetDescriptorData(Length, &Test_Report_Descriptor);
}

/*******************************************************************************
这里用来处理Get_Report Set_Report
*******************************************************************************/
u8 Report_Buffer[2] = {0x02, 0x02}; //Report_Buffer[0]为FeatureID,
                                    //Report_Buffer[1]为最大触控点数

u8 *Joystick_GetReport(u16 Length)  //处理Get_Report
{
    if(Length == 0)
    {
   
        pInformation->Ctrl_Info.Usb_wLength = 2;
        return NULL;
    }
    return  &Report_Buffer[pInformation->Ctrl_Info.Usb_wOffset];
}

u8 *Joystick_SetReport(u16 Length)//处理Set_Report
{
    if(Length == 0)
    {
   
        pInformation->Ctrl_Info.Usb_wLength = 2;
        return NULL;
    }
    return &Report_Buffer[pInformation->Ctrl_Info.Usb_wOffset];
}

RESULT Joystick_Dat
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值