📄 upsdusb.c
字号:
static void OnClearFeature()
/******************************************************************************
Function : static void OnClearFeature()
Parameters : none
Description: Handler for CLEAR_FEATURE control requests.
******************************************************************************/
{
if((setupPacket.wValue.lo == 0x00) & (setupPacket.wIndex.lo == 0x81)){
ep1State = US_EP1DEFAULT;
}
else{
STALL_EP0(); // No features currently implemented, so stall EP0
}
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E ;mask, keep RX,TX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E+uSTALL0+uTSEQ0+uTX0E;
UCON0 |= uTSEQ0+uTX0E;
}
//the following function changed on April 30, 2004
static void OnSetFeature()
/******************************************************************************
Function : static void OnSetFeature()
Parameters : none
Description: Handler for Set_FEATURE control requests.
******************************************************************************/
{
if((setupPacket.wValue.lo == 0x00) & (setupPacket.wIndex.lo == 0x81)){
ep1State = US_EP1STALL;
}
else{
STALL_EP0(); // No features currently implemented, so stall EP0
}
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E ;mask, keep RX,TX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E+uSTALL0+uTSEQ0+uTX0E;
UCON0 |= uTSEQ0+uTX0E;
}
static void OnSetAddress()
/******************************************************************************
Function : static void OnSetAddress()
Parameters : none
Description: Handler for SET_ADDRESS SETUP packets
******************************************************************************/
{
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E+uSTALL0+uTSEQ0+uTX0E ;mask, keep RX,TX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E+uSTALL0+uTSEQ0+uTX0E;
UCON0 |= uTSEQ0+uTX0E;
}
static void OnGetConfiguration()
/******************************************************************************
Function : static void OnGetConfiguration()
Parameters : none
Description: Handler for GET_CONFIGURATION SETUP requests.
******************************************************************************/
{
/*#pragma asm // send one byte length packet
orl UCON0,#uTSEQ0 ;set TSEQ bit
anl UCON0,#uTSEQ0+uRX0E ;mask, keep RX flag
orl UCON0,#1 ;set FIFO size
#pragma endasm*///08-02-2004
UCON0 |= uTSEQ0;
UCON0 &= uTSEQ0+uRX0E;
UCON0 |= 1;
if (usbState == US_CONFIGURED)
{
UDT0 = 1; //non-zero bConfigurationValue when device is configured
}
else
{
UDT0 = 0; //The value zero shall be returned in address state
}
/*#pragma asm
orl UCON0,#uTX0E ;enable transmit
#pragma endasm*///08-02-2004
UCON0 |= uTX0E;
}
static void OnSetConfiguration()
/******************************************************************************
Function : static void OnSetConfiguration()
Parameters : none
Description: Handler for SET_CONFIGURATION SETUP requests.
******************************************************************************/
{
if (setupPacket.wValue.lo == 0)
{
if (usbState == US_CONFIGURED )
{
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E ;mask, keep RX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E;
UCON0 |= uTSEQ0+uTX0E;
}
usbState = US_ADDRESSED;
}
else
if (setupPacket.wValue.lo == 1)
{
usbState = US_CONFIGURED;
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E ;mask, keep RX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E;
UCON0 |= uTSEQ0+uTX0E;
OnDeviceConfigured();
}
else
{
STALL_EP0(); // stall EP0
}
}
static void OnGetInterface()
/******************************************************************************
Function : static void OnGetInterface()
Parameters : none
Description: Handler for OnGetInterface() control requests.
******************************************************************************/
{
/*#pragma asm // Send back 0 length DATA1 packet
anl UCON0,#uRX0E+uSTALL0 ;mask, keep RX flag
orl UCON0,#uTSEQ0+uTX0E ;set TSEQ bit+enable endpoint
#pragma endasm*///08-02-2004
UCON0 &= uRX0E+uSTALL0;
UCON0 |= uTSEQ0+uTX0E;
}
static void OnSetInterface()
/******************************************************************************
Function : static void OnSetInterface()
Parameters : none
Description: Handler for SET_INTERFACE() control requests.
******************************************************************************/
{
STALL_EP0(); // No features currently implemented, so stall EP0
}
static void OnGetDescriptor()
/******************************************************************************
Function : static void OnGetDescriptor()
Parameters : none
Description: Handler for GET_DESCRIPTOR() control requests
******************************************************************************/
{
data unsigned int bytesRequested;
switch (setupPacket.wValue.hi)
{
case
DT_DEVICE:
pTransmitBufferEP0 = (uchar*) &deviceDesc;
bytesToTransmitEP0 = sizeof(deviceDesc);
break;
case
DT_CONFIGURATION:
pTransmitBufferEP0 = (uchar*) &configDesc;
bytesToTransmitEP0 = configDesc.wTotalLength.lo;
break;
case
DT_STRING:
pTransmitBufferEP0 = (uchar*) stringDescTable[setupPacket.wValue.lo<4?setupPacket.wValue.lo:4];
bytesToTransmitEP0 = *pTransmitBufferEP0;// choose requested string
break;
#if HID_DEVICE
case
DT_HID_CLASS:
pTransmitBufferEP0 = (uchar*) &hidClassDesc;
bytesToTransmitEP0 = hidClassDescSize;
break;
case
DT_HID_REPORT:
pTransmitBufferEP0 = (uchar*) &reportDesc;
bytesToTransmitEP0 = reportDescSize;
break;
case
DT_HID_PHYSICALD:
pTransmitBufferEP0 = (uchar*) &PhysicalReportDesc;
bytesToTransmitEP0 = PhysicalReportDescSize;
break;
#endif
default:
STALL_EP0(); // Unrecognized descriptor, so stall EP0
return;
}
bytesRequested = (setupPacket.wLength.hi << 8) | setupPacket.wLength.lo;
shortTransfer = (bytesToTransmitEP0 < bytesRequested);
if (bytesToTransmitEP0 > bytesRequested)
{
bytesToTransmitEP0 = bytesRequested;
}
UCON0 &= ~uTSEQ0; // TransmitDataEP0 will toggle sequence bit to DATA1
TransmitBufferEP0();
}
static void OnSetDescriptor()
/******************************************************************************
Function : static void OnSetDescriptor()
Parameters : none
Description: Handler for SET_DESCRIPTOR() control requests
******************************************************************************/
{
STALL_EP0(); // No features currently implemented, so stall EP0
}
void OnSetupPacket()
/******************************************************************************
Function : void OnSetupPacket()
Parameters : none
Description: Basic handler for SETUP packets received on EP0.
******************************************************************************/
{
pTransmitBufferEP0 = NULL;
bytesToTransmitEP0 = 0;
// If it's a standard request...
if ((setupPacket.bmRequestType & 0x60) == 0)
{
switch (setupPacket.bRequest) // Handle the request
{
case GET_STATUS: OnGetStatus(); return;
case CLEAR_FEATURE: OnClearFeature(); return;
case SET_FEATURE: OnSetFeature(); return;
case SET_ADDRESS: OnSetAddress(); return;
case GET_DESCRIPTOR: OnGetDescriptor(); return;
case SET_DESCRIPTOR: OnSetDescriptor(); return;
case GET_CONFIGURATION: OnGetConfiguration(); return;
case SET_CONFIGURATION: OnSetConfiguration(); return;
case GET_INTERFACE: OnGetInterface(); return;
case SET_INTERFACE: OnSetInterface(); return;
default:
break;
}
}
STALL_EP0(); // It's not a request we handle, so stall endpoint
}
void BaseEp0TxHandler()
/******************************************************************************
Function : void BaseEp0TxHandler()
Parameters : none
Description: Handler for successful data transmission on control endpoint (EP0).
Use it only for control transfers !!!
******************************************************************************/
{
if (!TransmitBufferEP0()) // Send next chunk of data in transaction
{
// The current request has finished
if (setupPacket.bRequest == SET_ADDRESS) // The current request has finished
{
UADR = setupPacket.wValue.lo | uUSBEN;
if (setupPacket.wValue.lo != 0)
usbState = US_ADDRESSED;
else
usbState = US_DEFAULT;
}
setupPacket.bRequest = REQUEST_COMPLETE;
}
}
/* *************************************************************************
*** ***
** *** End of File *** **
*** ***
************************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -