style: code format
This commit is contained in:
parent
3d22dac649
commit
7af40c37a9
@ -24,8 +24,8 @@ __CODE uint8_t PRODUCTDESC[30];
|
|||||||
__XDATA uint8_t HidFreature[64];
|
__XDATA uint8_t HidFreature[64];
|
||||||
__XDATA uint8_t HidInput[64];
|
__XDATA uint8_t HidInput[64];
|
||||||
__XDATA uint8_t HidOutput[64];
|
__XDATA uint8_t HidOutput[64];
|
||||||
usb_request_t usb_request;
|
USB_Request_t usb_request;
|
||||||
USB_EP0_Stage_t USB_EP0_Stage;
|
USB_EP0_Stage_t usb_ep0_stag;
|
||||||
|
|
||||||
void USB_Init();
|
void USB_Init();
|
||||||
uint8_t CalCheckSum(uint8_t *buf, uint8_t len);
|
uint8_t CalCheckSum(uint8_t *buf, uint8_t len);
|
||||||
@ -63,7 +63,7 @@ void USB_Init()
|
|||||||
USB_WriteReg(INTROUT1E, 0x3f);
|
USB_WriteReg(INTROUT1E, 0x3f);
|
||||||
USB_WriteReg(INTRUSBE, 0x00);
|
USB_WriteReg(INTRUSBE, 0x00);
|
||||||
USB_WriteReg(POWER, 0x01);
|
USB_WriteReg(POWER, 0x01);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
|
|
||||||
EXTI_USB_SetIntState(HAL_State_ON);
|
EXTI_USB_SetIntState(HAL_State_ON);
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
USB_WriteReg(INCSR1, INCLRDT);
|
USB_WriteReg(INCSR1, INCLRDT);
|
||||||
USB_SelectEndPoint(1);
|
USB_SelectEndPoint(1);
|
||||||
USB_WriteReg(OUTCSR1, OUTCLRDT);
|
USB_WriteReg(OUTCSR1, OUTCLRDT);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,7 +102,7 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
if (csr & STSTL) // Sent Stall
|
if (csr & STSTL) // Sent Stall
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, csr & ~STSTL);
|
USB_WriteReg(CSR0, csr & ~STSTL);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (csr & SUEND) // Setup End
|
if (csr & SUEND) // Setup End
|
||||||
@ -110,15 +110,15 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
USB_WriteReg(CSR0, csr | SSUEND);
|
USB_WriteReg(CSR0, csr | SSUEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (USB_EP0_Stage.bStage)
|
switch (usb_ep0_stag.bStage)
|
||||||
{
|
{
|
||||||
case USB_CtrlState_Idle:
|
case USB_CtrlState_Idle:
|
||||||
if (csr & OPRDY) // Out Packet Ready
|
if (csr & OPRDY) // Out Packet Ready
|
||||||
{
|
{
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_SettingUp;
|
usb_ep0_stag.bStage = USB_CtrlState_SettingUp;
|
||||||
USB_ReadFIFO(FIFO0, (uint8_t *)&usb_request);
|
USB_ReadFIFO(FIFO0, (uint8_t *)&usb_request);
|
||||||
((uint8_t *)&USB_EP0_Stage.wResidue)[0] = usb_request.wLength.bb.bh;
|
((uint8_t *)&usb_ep0_stag.wResidue)[0] = usb_request.wLength.bb.bh;
|
||||||
((uint8_t *)&USB_EP0_Stage.wResidue)[1] = usb_request.wLength.bb.bl;
|
((uint8_t *)&usb_ep0_stag.wResidue)[1] = usb_request.wLength.bb.bl;
|
||||||
switch (usb_request.bmRequestType & REQUEST_TYPE_MASK)
|
switch (usb_request.bmRequestType & REQUEST_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_RequestType_Standard:
|
case USB_RequestType_Standard:
|
||||||
@ -139,16 +139,16 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_StdReq_GetDescriptor:
|
case USB_StdReq_GetDescriptor:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataIn;
|
usb_ep0_stag.bStage = USB_CtrlState_DataIn;
|
||||||
switch (usb_request.wValue.bb.bh)
|
switch (usb_request.wValue.bb.bh)
|
||||||
{
|
{
|
||||||
case USB_DescriptorType_Device:
|
case USB_DescriptorType_Device:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)DEVICEDESC;
|
usb_ep0_stag.pData = (uint8_t *)DEVICEDESC;
|
||||||
len = sizeof(DEVICEDESC);
|
len = sizeof(DEVICEDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DescriptorType_Configuration:
|
case USB_DescriptorType_Configuration:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)CONFIGDESC;
|
usb_ep0_stag.pData = (uint8_t *)CONFIGDESC;
|
||||||
len = sizeof(CONFIGDESC);
|
len = sizeof(CONFIGDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -156,43 +156,43 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
switch (usb_request.wValue.bb.bl)
|
switch (usb_request.wValue.bb.bl)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)LANGIDDESC;
|
usb_ep0_stag.pData = (uint8_t *)LANGIDDESC;
|
||||||
len = sizeof(LANGIDDESC);
|
len = sizeof(LANGIDDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)MANUFACTDESC;
|
usb_ep0_stag.pData = (uint8_t *)MANUFACTDESC;
|
||||||
len = sizeof(MANUFACTDESC);
|
len = sizeof(MANUFACTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)PRODUCTDESC;
|
usb_ep0_stag.pData = (uint8_t *)PRODUCTDESC;
|
||||||
len = sizeof(PRODUCTDESC);
|
len = sizeof(PRODUCTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stag.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DescriptorType_Report:
|
case USB_DescriptorType_Report:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)HIDREPORTDESC;
|
usb_ep0_stag.pData = (uint8_t *)HIDREPORTDESC;
|
||||||
len = sizeof(HIDREPORTDESC);
|
len = sizeof(HIDREPORTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stag.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (len < USB_EP0_Stage.wResidue)
|
if (len < usb_ep0_stag.wResidue)
|
||||||
{
|
{
|
||||||
USB_EP0_Stage.wResidue = len;
|
usb_ep0_stag.wResidue = len;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stag.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -201,13 +201,13 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
switch (usb_request.bRequest)
|
switch (usb_request.bRequest)
|
||||||
{
|
{
|
||||||
case USB_HidReq_GetReport:
|
case USB_HidReq_GetReport:
|
||||||
USB_EP0_Stage.pData = HidFreature;
|
usb_ep0_stag.pData = HidFreature;
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataIn;
|
usb_ep0_stag.bStage = USB_CtrlState_DataIn;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_HidReq_SetReport:
|
case USB_HidReq_SetReport:
|
||||||
USB_EP0_Stage.pData = HidFreature;
|
usb_ep0_stag.pData = HidFreature;
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataOut;
|
usb_ep0_stag.bStage = USB_CtrlState_DataOut;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_HidReq_SetIdle:
|
case USB_HidReq_SetIdle:
|
||||||
@ -217,17 +217,17 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
// case USB_HidReq_GetProtocol:
|
// case USB_HidReq_GetProtocol:
|
||||||
// case USB_HidReq_SetProtocol:
|
// case USB_HidReq_SetProtocol:
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stag.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stag.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (USB_EP0_Stage.bStage)
|
switch (usb_ep0_stag.bStage)
|
||||||
{
|
{
|
||||||
case USB_CtrlState_DataIn:
|
case USB_CtrlState_DataIn:
|
||||||
USB_WriteReg(CSR0, SOPRDY);
|
USB_WriteReg(CSR0, SOPRDY);
|
||||||
@ -240,12 +240,12 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
|
|
||||||
case USB_CtrlState_SettingUp:
|
case USB_CtrlState_SettingUp:
|
||||||
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_CtrlState_Stalled:
|
case USB_CtrlState_Stalled:
|
||||||
USB_WriteReg(CSR0, SOPRDY | SDSTL);
|
USB_WriteReg(CSR0, SOPRDY | SDSTL);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -255,14 +255,14 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
if (!(csr & IPRDY))
|
if (!(csr & IPRDY))
|
||||||
{
|
{
|
||||||
L_Ep0SendData:
|
L_Ep0SendData:
|
||||||
cnt = USB_EP0_Stage.wResidue > 64 ? 64 : USB_EP0_Stage.wResidue;
|
cnt = usb_ep0_stag.wResidue > 64 ? 64 : usb_ep0_stag.wResidue;
|
||||||
USB_WriteFIFO(FIFO0, USB_EP0_Stage.pData, cnt);
|
USB_WriteFIFO(FIFO0, usb_ep0_stag.pData, cnt);
|
||||||
USB_EP0_Stage.wResidue -= cnt;
|
usb_ep0_stag.wResidue -= cnt;
|
||||||
USB_EP0_Stage.pData += cnt;
|
usb_ep0_stag.pData += cnt;
|
||||||
if (USB_EP0_Stage.wResidue == 0)
|
if (usb_ep0_stag.wResidue == 0)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, IPRDY | DATEND);
|
USB_WriteReg(CSR0, IPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -274,13 +274,13 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
case USB_CtrlState_DataOut:
|
case USB_CtrlState_DataOut:
|
||||||
if (csr & OPRDY)
|
if (csr & OPRDY)
|
||||||
{
|
{
|
||||||
cnt = USB_ReadFIFO(FIFO0, USB_EP0_Stage.pData);
|
cnt = USB_ReadFIFO(FIFO0, usb_ep0_stag.pData);
|
||||||
USB_EP0_Stage.wResidue -= cnt;
|
usb_ep0_stag.wResidue -= cnt;
|
||||||
USB_EP0_Stage.pData += cnt;
|
usb_ep0_stag.pData += cnt;
|
||||||
if (USB_EP0_Stage.wResidue == 0)
|
if (usb_ep0_stag.wResidue == 0)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stag.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -44,8 +44,8 @@ __CODE uint8_t KeyMap[16];
|
|||||||
__XDATA uint8_t HidFreature[64];
|
__XDATA uint8_t HidFreature[64];
|
||||||
__XDATA uint8_t HidInput[64];
|
__XDATA uint8_t HidInput[64];
|
||||||
__XDATA uint8_t HidOutput[64];
|
__XDATA uint8_t HidOutput[64];
|
||||||
usb_request_t usb_request;
|
USB_Request_t usb_request;
|
||||||
USB_EP0_Stage_t USB_EP0_Stage;
|
USB_EP0_Stage_t usb_ep0_stage;
|
||||||
|
|
||||||
void USB_Init(void);
|
void USB_Init(void);
|
||||||
void KeyScan(void);
|
void KeyScan(void);
|
||||||
@ -105,7 +105,7 @@ void USB_Init()
|
|||||||
USB_WriteReg(INTROUT1E, 0x3f);
|
USB_WriteReg(INTROUT1E, 0x3f);
|
||||||
USB_WriteReg(INTRUSBE, 0x00);
|
USB_WriteReg(INTRUSBE, 0x00);
|
||||||
USB_WriteReg(POWER, 0x01);
|
USB_WriteReg(POWER, 0x01);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
|
|
||||||
EXTI_USB_SetIntState(HAL_State_ON);
|
EXTI_USB_SetIntState(HAL_State_ON);
|
||||||
}
|
}
|
||||||
@ -123,34 +123,34 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
introut = USB_ReadReg(INTROUT1);
|
introut = USB_ReadReg(INTROUT1);
|
||||||
if (intrusb & RSTIF)
|
if (intrusb & RSTIF)
|
||||||
{
|
{
|
||||||
USB_WriteReg(INDEX, 1);
|
USB_SelectEndPoint(1);
|
||||||
USB_WriteReg(INCSR1, INCLRDT);
|
USB_WriteReg(INCSR1, INCLRDT);
|
||||||
USB_WriteReg(INDEX, 1);
|
USB_SelectEndPoint(1);
|
||||||
USB_WriteReg(OUTCSR1, OUTCLRDT);
|
USB_WriteReg(OUTCSR1, OUTCLRDT);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
if (intrin & EP0IF)
|
if (intrin & EP0IF)
|
||||||
{
|
{
|
||||||
USB_WriteReg(INDEX, 0);
|
USB_SelectEndPoint(0);
|
||||||
csr = USB_ReadReg(CSR0);
|
csr = USB_ReadReg(CSR0);
|
||||||
if (csr & STSTL)
|
if (csr & STSTL)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, csr & ~STSTL);
|
USB_WriteReg(CSR0, csr & ~STSTL);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
if (csr & SUEND)
|
if (csr & SUEND)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, csr | SSUEND);
|
USB_WriteReg(CSR0, csr | SSUEND);
|
||||||
}
|
}
|
||||||
switch (USB_EP0_Stage.bStage)
|
switch (usb_ep0_stage.bStage)
|
||||||
{
|
{
|
||||||
case USB_CtrlState_Idle:
|
case USB_CtrlState_Idle:
|
||||||
if (csr & OPRDY)
|
if (csr & OPRDY)
|
||||||
{
|
{
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_SettingUp;
|
usb_ep0_stage.bStage = USB_CtrlState_SettingUp;
|
||||||
USB_ReadFIFO(FIFO0, (uint8_t *)&usb_request);
|
USB_ReadFIFO(FIFO0, (uint8_t *)&usb_request);
|
||||||
((uint8_t *)&USB_EP0_Stage.wResidue)[0] = usb_request.wLength.bb.bh;
|
((uint8_t *)&usb_ep0_stage.wResidue)[0] = usb_request.wLength.bb.bh;
|
||||||
((uint8_t *)&USB_EP0_Stage.wResidue)[1] = usb_request.wLength.bb.bl;
|
((uint8_t *)&usb_ep0_stage.wResidue)[1] = usb_request.wLength.bb.bl;
|
||||||
switch (usb_request.bmRequestType & REQUEST_TYPE_MASK)
|
switch (usb_request.bmRequestType & REQUEST_TYPE_MASK)
|
||||||
{
|
{
|
||||||
case USB_RequestType_Standard:
|
case USB_RequestType_Standard:
|
||||||
@ -171,16 +171,16 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_StdReq_GetDescriptor:
|
case USB_StdReq_GetDescriptor:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataIn;
|
usb_ep0_stage.bStage = USB_CtrlState_DataIn;
|
||||||
switch (usb_request.wValue.bb.bh)
|
switch (usb_request.wValue.bb.bh)
|
||||||
{
|
{
|
||||||
case USB_DescriptorType_Device:
|
case USB_DescriptorType_Device:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)DEVICEDESC;
|
usb_ep0_stage.pData = (uint8_t *)DEVICEDESC;
|
||||||
len = sizeof(DEVICEDESC);
|
len = sizeof(DEVICEDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DescriptorType_Configuration:
|
case USB_DescriptorType_Configuration:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)CONFIGDESC;
|
usb_ep0_stage.pData = (uint8_t *)CONFIGDESC;
|
||||||
len = sizeof(CONFIGDESC);
|
len = sizeof(CONFIGDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -188,43 +188,43 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
switch (usb_request.wValue.bb.bl)
|
switch (usb_request.wValue.bb.bl)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)LANGIDDESC;
|
usb_ep0_stage.pData = (uint8_t *)LANGIDDESC;
|
||||||
len = sizeof(LANGIDDESC);
|
len = sizeof(LANGIDDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)MANUFACTDESC;
|
usb_ep0_stage.pData = (uint8_t *)MANUFACTDESC;
|
||||||
len = sizeof(MANUFACTDESC);
|
len = sizeof(MANUFACTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)PRODUCTDESC;
|
usb_ep0_stage.pData = (uint8_t *)PRODUCTDESC;
|
||||||
len = sizeof(PRODUCTDESC);
|
len = sizeof(PRODUCTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stage.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_DescriptorType_Report:
|
case USB_DescriptorType_Report:
|
||||||
USB_EP0_Stage.pData = (uint8_t *)HIDREPORTDESC;
|
usb_ep0_stage.pData = (uint8_t *)HIDREPORTDESC;
|
||||||
len = sizeof(HIDREPORTDESC);
|
len = sizeof(HIDREPORTDESC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stage.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (len < USB_EP0_Stage.wResidue)
|
if (len < usb_ep0_stage.wResidue)
|
||||||
{
|
{
|
||||||
USB_EP0_Stage.wResidue = len;
|
usb_ep0_stage.wResidue = len;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stage.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -233,13 +233,13 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
switch (usb_request.bRequest)
|
switch (usb_request.bRequest)
|
||||||
{
|
{
|
||||||
case USB_HidReq_GetReport:
|
case USB_HidReq_GetReport:
|
||||||
USB_EP0_Stage.pData = HidFreature;
|
usb_ep0_stage.pData = HidFreature;
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataIn;
|
usb_ep0_stage.bStage = USB_CtrlState_DataIn;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_HidReq_SetReport:
|
case USB_HidReq_SetReport:
|
||||||
USB_EP0_Stage.pData = HidFreature;
|
usb_ep0_stage.pData = HidFreature;
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_DataOut;
|
usb_ep0_stage.bStage = USB_CtrlState_DataOut;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_HidReq_SetIdle:
|
case USB_HidReq_SetIdle:
|
||||||
@ -249,17 +249,17 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
// case USB_HidReq_GetProtocol:
|
// case USB_HidReq_GetProtocol:
|
||||||
// case USB_HidReq_SetProtocol:
|
// case USB_HidReq_SetProtocol:
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stage.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Stalled;
|
usb_ep0_stage.bStage = USB_CtrlState_Stalled;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (USB_EP0_Stage.bStage)
|
switch (usb_ep0_stage.bStage)
|
||||||
{
|
{
|
||||||
case USB_CtrlState_DataIn:
|
case USB_CtrlState_DataIn:
|
||||||
USB_WriteReg(CSR0, SOPRDY);
|
USB_WriteReg(CSR0, SOPRDY);
|
||||||
@ -272,12 +272,12 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
|
|
||||||
case USB_CtrlState_SettingUp:
|
case USB_CtrlState_SettingUp:
|
||||||
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case USB_CtrlState_Stalled:
|
case USB_CtrlState_Stalled:
|
||||||
USB_WriteReg(CSR0, SOPRDY | SDSTL);
|
USB_WriteReg(CSR0, SOPRDY | SDSTL);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,14 +287,14 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
if (!(csr & IPRDY))
|
if (!(csr & IPRDY))
|
||||||
{
|
{
|
||||||
L_Ep0SendData:
|
L_Ep0SendData:
|
||||||
cnt = USB_EP0_Stage.wResidue > 64 ? 64 : USB_EP0_Stage.wResidue;
|
cnt = usb_ep0_stage.wResidue > 64 ? 64 : usb_ep0_stage.wResidue;
|
||||||
USB_WriteFIFO(FIFO0, USB_EP0_Stage.pData, cnt);
|
USB_WriteFIFO(FIFO0, usb_ep0_stage.pData, cnt);
|
||||||
USB_EP0_Stage.wResidue -= cnt;
|
usb_ep0_stage.wResidue -= cnt;
|
||||||
USB_EP0_Stage.pData += cnt;
|
usb_ep0_stage.pData += cnt;
|
||||||
if (USB_EP0_Stage.wResidue == 0)
|
if (usb_ep0_stage.wResidue == 0)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, IPRDY | DATEND);
|
USB_WriteReg(CSR0, IPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -306,13 +306,13 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
case USB_CtrlState_DataOut:
|
case USB_CtrlState_DataOut:
|
||||||
if (csr & OPRDY)
|
if (csr & OPRDY)
|
||||||
{
|
{
|
||||||
cnt = USB_ReadFIFO(FIFO0, USB_EP0_Stage.pData);
|
cnt = USB_ReadFIFO(FIFO0, usb_ep0_stage.pData);
|
||||||
USB_EP0_Stage.wResidue -= cnt;
|
usb_ep0_stage.wResidue -= cnt;
|
||||||
USB_EP0_Stage.pData += cnt;
|
usb_ep0_stage.pData += cnt;
|
||||||
if (USB_EP0_Stage.wResidue == 0)
|
if (usb_ep0_stage.wResidue == 0)
|
||||||
{
|
{
|
||||||
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
USB_WriteReg(CSR0, SOPRDY | DATEND);
|
||||||
USB_EP0_Stage.bStage = USB_CtrlState_Idle;
|
usb_ep0_stage.bStage = USB_CtrlState_Idle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -325,7 +325,7 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
|
|
||||||
if (intrin & EP1INIF)
|
if (intrin & EP1INIF)
|
||||||
{
|
{
|
||||||
USB_WriteReg(INDEX, 1);
|
USB_SelectEndPoint(1);
|
||||||
csr = USB_ReadReg(INCSR1);
|
csr = USB_ReadReg(INCSR1);
|
||||||
if (csr & INSTSTL)
|
if (csr & INSTSTL)
|
||||||
{
|
{
|
||||||
@ -339,7 +339,7 @@ INTERRUPT(USB_Routine, EXTI_VectUSB)
|
|||||||
|
|
||||||
if (introut & EP1OUTIF)
|
if (introut & EP1OUTIF)
|
||||||
{
|
{
|
||||||
USB_WriteReg(INDEX, 1);
|
USB_SelectEndPoint(1);
|
||||||
csr = USB_ReadReg(OUTCSR1);
|
csr = USB_ReadReg(OUTCSR1);
|
||||||
if (csr & OUTSTSTL)
|
if (csr & OUTSTSTL)
|
||||||
{
|
{
|
||||||
@ -431,7 +431,7 @@ void SendKeyStatus(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// return 8 bytes data
|
// return 8 bytes data
|
||||||
USB_WriteReg(INDEX, 1);
|
USB_SelectEndPoint(1);
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
USB_WriteReg(FIFO1, HidInput[i]);
|
USB_WriteReg(FIFO1, HidInput[i]);
|
||||||
|
@ -240,14 +240,14 @@ typedef union
|
|||||||
} bb;
|
} bb;
|
||||||
} uint16_2uint8_t;
|
} uint16_2uint8_t;
|
||||||
|
|
||||||
typedef struct _usb_request_t
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t bmRequestType;
|
uint8_t bmRequestType;
|
||||||
uint8_t bRequest;
|
uint8_t bRequest;
|
||||||
uint16_2uint8_t wValue;
|
uint16_2uint8_t wValue;
|
||||||
uint16_2uint8_t wIndex;
|
uint16_2uint8_t wIndex;
|
||||||
uint16_2uint8_t wLength;
|
uint16_2uint8_t wLength;
|
||||||
} usb_request_t;
|
} USB_Request_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user