void USB_EndPoint0 (uint32_t event) { switch (event) { case USB_EVT_SETUP: USB_SetupStage(); USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir); EP0Data.Count = SetupPacket.wLength; /* Number of bytes to transfer */ switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: switch (SetupPacket.bRequest) { case USB_REQUEST_GET_STATUS: if (!USB_ReqGetStatus()) { goto stall_i; } USB_DataInStage(); break; case USB_REQUEST_CLEAR_FEATURE: if (!USB_ReqSetClrFeature(0)) { goto stall_i; } USB_StatusInStage(); #if USB_FEATURE_EVENT USB_Feature_Event(); #endif break; case USB_REQUEST_SET_FEATURE: if (!USB_ReqSetClrFeature(1)) { goto stall_i; } USB_StatusInStage(); #if USB_FEATURE_EVENT USB_Feature_Event(); #endif break; case USB_REQUEST_SET_ADDRESS: if (!USB_ReqSetAddress()) { goto stall_i; } USB_StatusInStage(); break; case USB_REQUEST_GET_DESCRIPTOR: if (!USB_ReqGetDescriptor()) { goto stall_i; } USB_DataInStage(); break; case USB_REQUEST_SET_DESCRIPTOR: /*stall_o:*/ USB_SetStallEP(0x00); /* not supported */ EP0Data.Count = 0; break; case USB_REQUEST_GET_CONFIGURATION: if (!USB_ReqGetConfiguration()) { goto stall_i; } USB_DataInStage(); break; case USB_REQUEST_SET_CONFIGURATION: if (!USB_ReqSetConfiguration()) { goto stall_i; } USB_StatusInStage(); #if USB_CONFIGURE_EVENT USB_Configure_Event(); #endif break; case USB_REQUEST_GET_INTERFACE: if (!USB_ReqGetInterface()) { goto stall_i; } USB_DataInStage(); break; case USB_REQUEST_SET_INTERFACE: if (!USB_ReqSetInterface()) { goto stall_i; } USB_StatusInStage(); #if USB_INTERFACE_EVENT USB_Interface_Event(); #endif break; default: goto stall_i; } break; /* end case REQUEST_STANDARD */ #if USB_CLASS case REQUEST_CLASS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: goto stall_i; /* not supported */ case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ switch (SetupPacket.bRequest) { case HID_REQUEST_GET_REPORT: if (HID_GetReport()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case HID_REQUEST_SET_REPORT: EP0Data.pData = EP0Buf; /* data to be received */ goto setup_class_ok; case HID_REQUEST_GET_IDLE: if (HID_GetIdle()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case HID_REQUEST_SET_IDLE: if (HID_SetIdle()) { USB_StatusInStage(); /* send Acknowledge */ goto setup_class_ok; } break; case HID_REQUEST_GET_PROTOCOL: if (HID_GetProtocol()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case HID_REQUEST_SET_PROTOCOL: if (HID_SetProtocol()) { USB_StatusInStage(); /* send Acknowledge */ goto setup_class_ok; } break; } } #endif /* USB_HID */ #if USB_MSC if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) { /* IF number correct? */ switch (SetupPacket.bRequest) { case MSC_REQUEST_RESET: if ((SetupPacket.wValue.W == 0) && /* RESET with invalid parameters -> STALL */ (SetupPacket.wLength == 0)) { if (MSC_Reset()) { USB_StatusInStage(); goto setup_class_ok; } } break; case MSC_REQUEST_GET_MAX_LUN: if ((SetupPacket.wValue.W == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */ (SetupPacket.wLength == 1)) { if (MSC_GetMaxLUN()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto setup_class_ok; } } break; } } #endif /* USB_MSC */ #if USB_AUDIO if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { switch (SetupPacket.bRequest) { case AUDIO_REQUEST_GET_CUR: case AUDIO_REQUEST_GET_MIN: case AUDIO_REQUEST_GET_MAX: case AUDIO_REQUEST_GET_RES: if (ADC_IF_GetRequest()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case AUDIO_REQUEST_SET_CUR: // case AUDIO_REQUEST_SET_MIN: // case AUDIO_REQUEST_SET_MAX: // case AUDIO_REQUEST_SET_RES: EP0Data.pData = EP0Buf; /* data to be received */ goto setup_class_ok; } } #endif /* USB_AUDIO */ #if USB_CDC if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { switch (SetupPacket.bRequest) { case CDC_SEND_ENCAPSULATED_COMMAND: EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ goto setup_class_ok; case CDC_GET_ENCAPSULATED_RESPONSE: if (CDC_GetEncapsulatedResponse()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case CDC_SET_COMM_FEATURE: EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ goto setup_class_ok; case CDC_GET_COMM_FEATURE: if (CDC_GetCommFeature(SetupPacket.wValue.W)) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case CDC_CLEAR_COMM_FEATURE: if (CDC_ClearCommFeature(SetupPacket.wValue.W)) { USB_StatusInStage(); /* send Acknowledge */ goto setup_class_ok; } break; case CDC_SET_LINE_CODING: EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ goto setup_class_ok; case CDC_GET_LINE_CODING: if (CDC_GetLineCoding()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case CDC_SET_CONTROL_LINE_STATE: if (CDC_SetControlLineState(SetupPacket.wValue.W)) { USB_StatusInStage(); /* send Acknowledge */ goto setup_class_ok; } break; case CDC_SEND_BREAK: if (CDC_SendBreak(SetupPacket.wValue.W)) { USB_StatusInStage(); /* send Acknowledge */ goto setup_class_ok; } break; } } #endif /* USB_CDC */ #if USB_UVC if ((SetupPacket.wIndex.WB.L == USB_UVC_VCIF_NUM) || (SetupPacket.wIndex.WB.L == USB_UVC_VSIF_NUM)) { switch (SetupPacket.bRequest) { case SET_CUR: EP0Data.pData = EP0Buf; /* data to be stored, see USB_EVT_OUT */ goto setup_class_ok; break; case GET_CUR: if (UVC_GetCur()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_MIN: if (UVC_GetMin()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_MAX: if (UVC_GetMax()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_RES: if (UVC_GetRes()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_LEN: if (UVC_GetLen()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_INFO: if (UVC_GetInfo()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; case GET_DEF: if (UVC_GetDef()) { EP0Data.pData = EP0Buf; /* data to be sent */ USB_DataInStage(); /* send data */ goto setup_class_ok; } break; } } #endif /* USB_UVC */ goto stall_i; /* not supported */ /* end case REQUEST_TO_INTERFACE */ case REQUEST_TO_ENDPOINT: #if USB_AUDIO switch (SetupPacket.bRequest) { case AUDIO_REQUEST_GET_CUR: case AUDIO_REQUEST_GET_MIN: case AUDIO_REQUEST_GET_MAX: case AUDIO_REQUEST_GET_RES: if (ADC_EP_GetRequest()) { EP0Data.pData = EP0Buf; /* point to data to be sent */ USB_DataInStage(); /* send requested data */ goto setup_class_ok; } break; case AUDIO_REQUEST_SET_CUR: // case AUDIO_REQUEST_SET_MIN: // case AUDIO_REQUEST_SET_MAX: // case AUDIO_REQUEST_SET_RES: EP0Data.pData = EP0Buf; /* data to be received */ goto setup_class_ok; } #endif /* USB_AUDIO */ goto stall_i; /* end case REQUEST_TO_ENDPOINT */ default: goto stall_i; } setup_class_ok: /* request finished successfully */ break; /* end case REQUEST_CLASS */ #endif /* USB_CLASS */ #if USB_VENDOR case REQUEST_VENDOR: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: if (!USB_ReqVendorDev(TRUE)) { goto stall_i; /* not supported */ } break; case REQUEST_TO_INTERFACE: if (!USB_ReqVendorIF(TRUE)) { goto stall_i; /* not supported */ } break; case REQUEST_TO_ENDPOINT: if (!USB_ReqVendorEP(TRUE)) { goto stall_i; /* not supported */ } break; default: goto stall_i; } if (SetupPacket.wLength) { if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { USB_DataInStage(); } } else { USB_StatusInStage(); } break; /* end case REQUEST_VENDOR */ #endif /* USB_VENDOR */ default: stall_i: USB_SetStallEP(0x80); EP0Data.Count = 0; break; } break; /* end case USB_EVT_SETUP */ case USB_EVT_OUT: if (SetupPacket.bmRequestType.BM.Dir == REQUEST_HOST_TO_DEVICE) { if (EP0Data.Count) { /* still data to receive ? */ USB_DataOutStage(); /* receive data */ if (EP0Data.Count == 0) { /* data complete ? */ switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: goto stall_i; /* not supported */ #if (USB_CLASS) case REQUEST_CLASS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: goto stall_i; /* not supported */ case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ switch (SetupPacket.bRequest) { case HID_REQUEST_SET_REPORT: if (HID_SetReport()) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; } } #endif /* USB_HID */ #if USB_AUDIO if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { switch (SetupPacket.bRequest) { case AUDIO_REQUEST_SET_CUR: // case AUDIO_REQUEST_SET_MIN: // case AUDIO_REQUEST_SET_MAX: // case AUDIO_REQUEST_SET_RES: if (ADC_IF_SetRequest()) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; } } #endif /* USB_AUDIO */ #if USB_CDC if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { switch (SetupPacket.bRequest) { case CDC_SEND_ENCAPSULATED_COMMAND: if (CDC_SendEncapsulatedCommand()) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; case CDC_SET_COMM_FEATURE: if (CDC_SetCommFeature(SetupPacket.wValue.W)) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; case CDC_SET_LINE_CODING: if (CDC_SetLineCoding()) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; } } #endif /* USB_CDC */ #if USB_UVC if ((SetupPacket.wIndex.WB.L == USB_UVC_VCIF_NUM) || (SetupPacket.wIndex.WB.L == USB_UVC_VSIF_NUM)) { switch (SetupPacket.bRequest) { case SET_CUR: if (!UVC_SetCur()) { goto stall_i; } break; } /* end switch (SetupPacket.bRequest) */ break; } #endif /* USB_UVC */ goto stall_i; /* end case REQUEST_TO_INTERFACE */ case REQUEST_TO_ENDPOINT: #if USB_AUDIO switch (SetupPacket.bRequest) { case AUDIO_REQUEST_SET_CUR: // case AUDIO_REQUEST_SET_MIN: // case AUDIO_REQUEST_SET_MAX: // case AUDIO_REQUEST_SET_RES: if (ADC_EP_SetRequest()) { USB_StatusInStage(); /* send Acknowledge */ goto out_class_ok; } break; } #endif /* USB_AUDIO */ goto stall_i; /* end case REQUEST_TO_ENDPOINT */ default: goto stall_i; } out_class_ok: /* request finished successfully */ break; /* end case REQUEST_CLASS */ #endif /* USB_CLASS */ #if USB_VENDOR case REQUEST_VENDOR: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: if (!USB_ReqVendorDev(FALSE)) { goto stall_i; /* not supported */ } break; case REQUEST_TO_INTERFACE: if (!USB_ReqVendorIF(FALSE)) { goto stall_i; /* not supported */ } break; case REQUEST_TO_ENDPOINT: if (!USB_ReqVendorEP(FALSE)) { goto stall_i; /* not supported */ } break; default: goto stall_i; } USB_StatusInStage(); break; /* end case REQUEST_VENDOR */ #endif /* USB_VENDOR */ default: goto stall_i; } } } } else { USB_StatusOutStage(); /* receive Acknowledge */ } break; /* end case USB_EVT_OUT */ case USB_EVT_IN : if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { USB_DataInStage(); /* send data */ } else { if (USB_DeviceAddress & 0x80) { USB_DeviceAddress &= 0x7F; USB_SetAddress(USB_DeviceAddress); } } break; /* end case USB_EVT_IN */ case USB_EVT_OUT_STALL: USB_ClrStallEP(0x00); break; case USB_EVT_IN_STALL: USB_ClrStallEP(0x80); break; } }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : hidInterface0Callback * Returned Value : * Comments : * Handles hid class and vendor specific requests * *END*--------------------------------------------------------------------*/ static bool hidInterface0Callback ( /* USB handle */ void * usb_handle, /* The setup packet void * */ void * setup_pkt, /* Callback state */ uint8_t state ) { /* Body */ bool found = false; SETUP_STRUCT_PTR_t setup_ptr = (SETUP_STRUCT_PTR_t) setup_pkt; _usb_device_handle handle = usb_handle; switch (state) { case USB_CLASS_REQUEST_CALLBACK: switch (setup_ptr->REQUEST) { case HID_GET_REPORT_REQUEST: HID_GetReport(handle); found = true; break; case HID_GET_IDLE_REQUEST: HID_GetIdle(); break; case HID_GET_PROTOCOL_REQUEST: HID_GetProtocol(handle); /* data to be received, see USB_EVT_OUT */ break; case HID_SET_REPORT_REQUEST: HID_SetReport(handle); found = true; break; case HID_SET_IDLE_REQUEST: HID_SetIdle(); break; case HID_SET_PROTOCOL: HID_SetProtocol(); break; default: break; } /* EndSwitch */ break; case USB_VENDOR_REQUEST_CALLBACK: break; default: // Ignore break; } return(found); } /* Endbody */
void USB_EndPoint0 (uint32_t event) { switch (event) { case USB_EVT_SETUP: USB_SetupStage(); EP0Data.Count = SetupPacket.wLength; switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: switch (SetupPacket.bRequest) { case USB_REQUEST_SET_ADDRESS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: USB_DeviceAddress = SetupPacket.wValue.WB.L;//0x80 | SetupPacket.wValue.WB.L; USB_StatusInStage(); USB_SetAddress(USB_DeviceAddress); break; default: break; } break; case USB_REQUEST_GET_DESCRIPTOR: USB_GetDescriptor(); break; /* case USB_REQUEST_GET_CONFIGURATION: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: EP0Data.pData = &USB_Configuration; USB_DataInStage(); break; default: break; } break; */ case USB_REQUEST_SET_CONFIGURATION: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: if (!USB_SetConfiguration()) { USB_SetStallEP(0x80); EP0Data.Count = 0; break; } USB_StatusInStage(); #if USB_CONFIGURE_EVENT USB_Configure_Event(); #endif break; default: break; } break; default: break; } break; case REQUEST_CLASS: #if USB_CLASS switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { switch (SetupPacket.bRequest) { case HID_REQUEST_GET_REPORT: if (HID_GetReport()) { EP0Data.pData = EP0Buf; USB_DataInStage(); } break; case HID_REQUEST_SET_REPORT: EP0Data.pData = EP0Buf; break; case HID_REQUEST_GET_IDLE: if (HID_GetIdle()) { EP0Data.pData = EP0Buf; USB_DataInStage(); } break; case HID_REQUEST_SET_IDLE: if (HID_SetIdle()) { USB_StatusInStage(); } break; case HID_REQUEST_GET_PROTOCOL: if (HID_GetProtocol()) { EP0Data.pData = EP0Buf; USB_DataInStage(); } break; case HID_REQUEST_SET_PROTOCOL: if (HID_SetProtocol()) { USB_StatusInStage(); } break; default: break; } } #endif /* USB_HID */ default: break; } break; #else #endif /* USB_CLASS */ case REQUEST_VENDOR: break; default: USB_SetStallEP(0x80); EP0Data.Count = 0; break; } break; case USB_EVT_OUT: if (SetupPacket.bmRequestType.BM.Dir == 0) { if (EP0Data.Count) { USB_DataOutStage(); if (EP0Data.Count == 0) { switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: USB_SetStallEP(0x80); //EP0Data.Count = 0; break; #if (USB_CLASS) case REQUEST_CLASS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { if (!HID_SetReport()) { USB_SetStallEP(0x80); //EP0Data.Count = 0; //break; } break; //HID_SetReport(); } #endif USB_SetStallEP(0x80); //EP0Data.Count = 0; break; case REQUEST_TO_ENDPOINT: USB_SetStallEP(0x80); //EP0Data.Count = 0; break; default: USB_SetStallEP(0x80); //EP0Data.Count = 0; break; } break; #endif default: USB_SetStallEP(0x80); //EP0Data.Count = 0; break; } USB_StatusInStage(); } } } else { ;//USB_StatusOutStage(); } break; case USB_EVT_IN: if (SetupPacket.bmRequestType.BM.Dir == 1) { if(EP0Data.Count > 0) // ysq add USB_DataInStage(); } //else //{ // if (USB_DeviceAddress & 0x80) // { // USB_DeviceAddress &= 0x7F; // USB_SetAddress(USB_DeviceAddress); // } //} break; case USB_EVT_IN_STALL: USB_ClrStallEP(0x80); break; case USB_EVT_OUT_STALL: USB_ClrStallEP(0x00); break; } }
void USB_EndPoint0 (uint32_t event) { switch (event) { case USB_EVT_SETUP: USB_SetupStage(); USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir); EP0Data.Count = SetupPacket.wLength; switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: switch (SetupPacket.bRequest) { case USB_REQUEST_GET_STATUS: if (!USB_GetStatus()) { goto stall_i; } break; case USB_REQUEST_CLEAR_FEATURE: if (!USB_SetClrFeature(0)) { goto stall_i; } USB_StatusInStage(); #if USB_FEATURE_EVENT USB_Feature_Event(); #endif break; case USB_REQUEST_SET_FEATURE: if (!USB_SetClrFeature(1)) { goto stall_i; } USB_StatusInStage(); #if USB_FEATURE_EVENT USB_Feature_Event(); #endif break; case USB_REQUEST_SET_ADDRESS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L; USB_StatusInStage(); break; default: goto stall_i; } break; case USB_REQUEST_GET_DESCRIPTOR: if (!USB_GetDescriptor()) { goto stall_i; } break; case USB_REQUEST_SET_DESCRIPTOR: /*stall_o:*/ USB_SetStallEP(0x00); EP0Data.Count = 0; break; case USB_REQUEST_GET_CONFIGURATION: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: EP0Data.pData = &USB_Configuration; USB_DataInStage(); break; default: goto stall_i; } break; case USB_REQUEST_SET_CONFIGURATION: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_DEVICE: if (!USB_SetConfiguration()) { goto stall_i; } USB_StatusInStage(); #if USB_CONFIGURE_EVENT USB_Configure_Event(); #endif break; default: goto stall_i; } break; case USB_REQUEST_GET_INTERFACE: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) { EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L; USB_DataInStage(); } else { goto stall_i; } break; default: goto stall_i; } break; case USB_REQUEST_SET_INTERFACE: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: if (!USB_SetInterface()) { goto stall_i; } USB_StatusInStage(); #if USB_INTERFACE_EVENT USB_Interface_Event(); #endif break; default: goto stall_i; } break; default: goto stall_i; } break; case REQUEST_CLASS: #if USB_CLASS switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { switch (SetupPacket.bRequest) { case HID_REQUEST_GET_REPORT: if (HID_GetReport()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } break; case HID_REQUEST_SET_REPORT: EP0Data.pData = EP0Buf; goto class_ok; case HID_REQUEST_GET_IDLE: if (HID_GetIdle()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } break; case HID_REQUEST_SET_IDLE: if (HID_SetIdle()) { USB_StatusInStage(); goto class_ok; } break; case HID_REQUEST_GET_PROTOCOL: if (HID_GetProtocol()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } break; case HID_REQUEST_SET_PROTOCOL: if (HID_SetProtocol()) { USB_StatusInStage(); goto class_ok; } break; } } #endif /* USB_HID */ #if USB_MSC if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) { switch (SetupPacket.bRequest) { case MSC_REQUEST_RESET: if (MSC_Reset()) { USB_StatusInStage(); goto class_ok; } break; case MSC_REQUEST_GET_MAX_LUN: if (MSC_GetMaxLUN()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } break; } } #endif /* USB_MSC */ #if USB_AUDIO if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { if (SetupPacket.bmRequestType.BM.Dir) { if (ADC_IF_GetRequest()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } } else { EP0Data.pData = EP0Buf; goto class_ok; } } #endif /* USB_AUDIO */ goto stall_i; #if USB_AUDIO case REQUEST_TO_ENDPOINT: if (SetupPacket.bmRequestType.BM.Dir) { if (ADC_EP_GetRequest()) { EP0Data.pData = EP0Buf; USB_DataInStage(); goto class_ok; } } else { EP0Data.pData = EP0Buf; goto class_ok; } goto stall_i; #endif /* USB_AUDIO */ default: goto stall_i; } class_ok: break; #else goto stall_i; #endif /* USB_CLASS */ case REQUEST_VENDOR: goto stall_i; default: stall_i: USB_SetStallEP(0x80); EP0Data.Count = 0; break; } break; case USB_EVT_OUT: if (SetupPacket.bmRequestType.BM.Dir == 0) { if (EP0Data.Count) { USB_DataOutStage(); if (EP0Data.Count == 0) { switch (SetupPacket.bmRequestType.BM.Type) { case REQUEST_STANDARD: goto stall_i; #if (USB_CLASS) case REQUEST_CLASS: switch (SetupPacket.bmRequestType.BM.Recipient) { case REQUEST_TO_INTERFACE: #if USB_HID if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { if (!HID_SetReport()) { goto stall_i; } break; } #endif #if USB_AUDIO if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { if (!ADC_IF_SetRequest()) { goto stall_i; } break; } #endif goto stall_i; case REQUEST_TO_ENDPOINT: #if USB_AUDIO if (ADC_EP_SetRequest()) break; #endif goto stall_i; default: goto stall_i; } break; #endif default: goto stall_i; } USB_StatusInStage(); } } } else { USB_StatusOutStage(); } break; case USB_EVT_IN: if (SetupPacket.bmRequestType.BM.Dir == 1) { USB_DataInStage(); } else { if (USB_DeviceAddress & 0x80) { USB_DeviceAddress &= 0x7F; USB_SetAddress(USB_DeviceAddress); } } break; case USB_EVT_IN_STALL: USB_ClrStallEP(0x80); break; case USB_EVT_OUT_STALL: USB_ClrStallEP(0x00); break; } }