2026-04-30 08:23:12 +00:00
|
|
|
|
/********************************************************************************
|
|
|
|
|
|
* Copyright (c) 2012, Beijing Tongfang Microelectroics Co., Ltd.
|
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
|
* Module: USB
|
|
|
|
|
|
* Author: Yang Song
|
|
|
|
|
|
* Version: V1.0
|
|
|
|
|
|
* History:
|
|
|
|
|
|
* 2012-09-24 Original version
|
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
|
|
|
u8 g_bUsbDevType; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ֧<D2AA>֣<EFBFBD><D6A3><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ͣ<EFBFBD><CDA3>ϵ<EFBFBD><CFB5><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> USBDEVTYPE_VSP
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
* Function: usbReqHandle
|
|
|
|
|
|
* Description: USB standard request process
|
|
|
|
|
|
* Input: NULL
|
|
|
|
|
|
* Output: NULL
|
|
|
|
|
|
* Return: NULL
|
|
|
|
|
|
* Other: NULL
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
void usbReqHandle(void)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(st_usbDeviceRequest.bStdRqstFlag) // Standard
|
|
|
|
|
|
{
|
|
|
|
|
|
usbStdReq[st_usbDeviceRequest.bRequest]();
|
|
|
|
|
|
st_usbDeviceRequest.bStdRqstFlag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(st_usbDeviceRequest.bClsRqstFlag) // Class
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((g_bUsbDevType == USBDEVTYPE_HIDPOS) || (g_bUsbDevType == USBDEVTYPE_HIDKBD))
|
|
|
|
|
|
{
|
|
|
|
|
|
hidReportRequest(st_usbDeviceRequest.bRequest);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(g_bUsbDevType == USBDEVTYPE_VSP)
|
|
|
|
|
|
{
|
|
|
|
|
|
vspClassRequest(st_usbDeviceRequest.bRequest);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
st_usbDeviceRequest.bClsRqstFlag = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
* Function: AppUSBSendData
|
|
|
|
|
|
* Description: usb<EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* Input: buf <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
|
|
|
|
|
|
* Input: len <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* Output: NULL
|
|
|
|
|
|
* Return: NULL
|
|
|
|
|
|
* Other: NULL
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
void AppUSBSendData(u8* buf, u32 len)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint8_t flag = 0;
|
|
|
|
|
|
uint8_t numssendflag = FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
if (len == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-07 15:06:17 +00:00
|
|
|
|
|
2026-04-30 08:23:12 +00:00
|
|
|
|
if(g_bUsbDevType == USBDEVTYPE_HIDPOS)
|
|
|
|
|
|
{
|
|
|
|
|
|
//check if suspend
|
|
|
|
|
|
TimerHSIClockCount(TIM3, START_TIMER);
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((USBPHYDAT&0x03) != 0x01)
|
|
|
|
|
|
{
|
|
|
|
|
|
flag = 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(TimerHSIClockCount(TIM3, GET_TIMER) > 36000) //3ms
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
TimerHSIClockCount(TIM3, STOP_TIMER);
|
|
|
|
|
|
|
|
|
|
|
|
if(flag == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
USBDCON |= Bit28_En;
|
|
|
|
|
|
TimerDelay(TIM2, 15); //ms
|
|
|
|
|
|
USBDCON &= Bit28_Dis;
|
|
|
|
|
|
}
|
|
|
|
|
|
usbHidPosSendChars(buf, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(g_bUsbDevType == USBDEVTYPE_HIDKBD)
|
|
|
|
|
|
{
|
|
|
|
|
|
//check if suspend
|
|
|
|
|
|
TimerHSIClockCount(TIM3, START_TIMER);
|
|
|
|
|
|
while(1)
|
|
|
|
|
|
{
|
|
|
|
|
|
if((USBPHYDAT&0x03) != 0x01)
|
|
|
|
|
|
{
|
|
|
|
|
|
flag = 1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(TimerHSIClockCount(TIM3, GET_TIMER) > 36000) //3ms
|
|
|
|
|
|
{
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
TimerHSIClockCount(TIM3, STOP_TIMER);
|
|
|
|
|
|
|
|
|
|
|
|
if(flag == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
USBDCON |= Bit28_En;
|
|
|
|
|
|
TimerDelay(TIM2, 15); //ms
|
|
|
|
|
|
USBDCON &= Bit28_Dis;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(gConfgBuf.outputCodeType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case GBK:
|
|
|
|
|
|
//<2F><>ֹû<D6B9>д<EFBFBD><D0B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD>̲<EFBFBD><CCB2><EFBFBD>Ӱ<EFBFBD><D3B0>
|
|
|
|
|
|
if(g_bNumLock == NUMLOCKOFF)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendNumLock();
|
|
|
|
|
|
numssendflag = TRUE;
|
|
|
|
|
|
}
|
|
|
|
|
|
usbHidKbdSendCharsGBK(buf, len);
|
|
|
|
|
|
if(numssendflag)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendNumLock();
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UNICODE:
|
|
|
|
|
|
usbHidKbdSendCharsUNICODE(buf, len);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case UTF8:
|
|
|
|
|
|
usbHidKbdSendCharsUTF8(buf, len);
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
|
|
|
usbHidKbdSendCharsGBK(buf, len);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//usbHidKbdSendChars(buf, len);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(g_bUsbDevType == USBDEVTYPE_VSP)
|
|
|
|
|
|
{
|
|
|
|
|
|
usbVspSendChars(buf, len);
|
|
|
|
|
|
}
|
2026-05-07 15:06:17 +00:00
|
|
|
|
|
|
|
|
|
|
// usbVspSendChars(buf, len);
|
2026-04-30 08:23:12 +00:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
* Function: AppUSBReceiveData
|
|
|
|
|
|
* Description: usb Init
|
|
|
|
|
|
* Input: <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>buf
|
|
|
|
|
|
* Input: bufSize buf<EFBFBD>Ĵ<EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹԽ<EFBFBD><EFBFBD>
|
|
|
|
|
|
* Output: <EFBFBD>յ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
* Return: NULL
|
|
|
|
|
|
* Other: NULL
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
u32 AppUSBReceiveData(u8 *buf, u32 bufSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
u32 len = 0;
|
2026-05-07 15:06:17 +00:00
|
|
|
|
|
2026-04-30 08:23:12 +00:00
|
|
|
|
if(g_bUsbDevType == USBDEVTYPE_HIDPOS)
|
|
|
|
|
|
{
|
|
|
|
|
|
len = usbHidPosRecvChars(buf, bufSize);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(g_bUsbDevType == USBDEVTYPE_HIDKBD)
|
|
|
|
|
|
{
|
|
|
|
|
|
//keyboard Ŀǰû<C7B0>н<EFBFBD><D0BD><EFBFBD>
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(g_bUsbDevType == USBDEVTYPE_VSP)
|
|
|
|
|
|
{
|
|
|
|
|
|
len = usbVspRecvChars(buf, bufSize);
|
|
|
|
|
|
}
|
2026-05-07 15:06:17 +00:00
|
|
|
|
|
|
|
|
|
|
// len = usbVspRecvChars(buf, bufSize);
|
2026-04-30 08:23:12 +00:00
|
|
|
|
|
|
|
|
|
|
return len;
|
|
|
|
|
|
}
|
|
|
|
|
|
|