static void SideShow_GetApplicationOrder(SideShow_PacketHeader_t* PacketHeader) { uint8_t TotalApplications = 0; Endpoint_ClearOUT(); for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) { if (InstalledApplications[App].InUse) TotalApplications++; } PacketHeader->Length = sizeof(SideShow_PacketHeader_t) + sizeof(uint32_t) + (TotalApplications * sizeof(GUID_t)); Endpoint_SelectEndpoint(SIDESHOW_IN_EPNUM); Endpoint_Write_Stream_LE(PacketHeader, sizeof(SideShow_PacketHeader_t)); Endpoint_Write_DWord_LE(TotalApplications); for (uint8_t App = 0; App < MAX_APPLICATIONS; App++) { if (InstalledApplications[App].InUse) Endpoint_Write_Stream_LE(&InstalledApplications[App].ApplicationID, sizeof(GUID_t)); } Endpoint_ClearIN(); }
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to * the device from the USB host before passing along unhandled control requests to the library for processing * internally. */ void EVENT_USB_Device_ControlRequest(void) { uint8_t TMCRequestStatus = TMC_STATUS_SUCCESS; /* Process TMC specific control requests */ switch (USB_ControlRequest.bRequest) { case Req_InitiateAbortBulkOut: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) { /* Check that no split transaction is already in progress and the data transfer tag is valid */ if (RequestInProgress != 0) { TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS; } else if (USB_ControlRequest.wValue != CurrentTransferTag) { TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS; } else { /* Indicate that all in-progress/pending data OUT requests should be aborted */ IsTMCBulkOUTReset = true; /* Save the split request for later checking when a new request is received */ RequestInProgress = Req_InitiateAbortBulkOut; } Endpoint_ClearSETUP(); /* Write the request response byte */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_CheckAbortBulkOutStatus: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) { /* Check that an ABORT BULK OUT transaction has been requested and that the request has completed */ if (RequestInProgress != Req_InitiateAbortBulkOut) TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; else if (IsTMCBulkOUTReset) TMCRequestStatus = TMC_STATUS_PENDING; else RequestInProgress = 0; Endpoint_ClearSETUP(); /* Write the request response bytes */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_Write_Word_LE(0); Endpoint_Write_DWord_LE(LastTransferLength); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_InitiateAbortBulkIn: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) { /* Check that no split transaction is already in progress and the data transfer tag is valid */ if (RequestInProgress != 0) { TMCRequestStatus = TMC_STATUS_SPLIT_IN_PROGRESS; } else if (USB_ControlRequest.wValue != CurrentTransferTag) { TMCRequestStatus = TMC_STATUS_TRANSFER_NOT_IN_PROGRESS; } else { /* Indicate that all in-progress/pending data IN requests should be aborted */ IsTMCBulkINReset = true; /* Save the split request for later checking when a new request is received */ RequestInProgress = Req_InitiateAbortBulkIn; } Endpoint_ClearSETUP(); /* Write the request response bytes */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_Write_Byte(CurrentTransferTag); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_CheckAbortBulkInStatus: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_ENDPOINT)) { /* Check that an ABORT BULK IN transaction has been requested and that the request has completed */ if (RequestInProgress != Req_InitiateAbortBulkIn) TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; else if (IsTMCBulkINReset) TMCRequestStatus = TMC_STATUS_PENDING; else RequestInProgress = 0; Endpoint_ClearSETUP(); /* Write the request response bytes */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_Write_Word_LE(0); Endpoint_Write_DWord_LE(LastTransferLength); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_InitiateClear: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { /* Check that no split transaction is already in progress */ if (RequestInProgress != 0) { Endpoint_Write_Byte(TMC_STATUS_SPLIT_IN_PROGRESS); } else { /* Indicate that all in-progress/pending data IN and OUT requests should be aborted */ IsTMCBulkINReset = true; IsTMCBulkOUTReset = true; /* Save the split request for later checking when a new request is received */ RequestInProgress = Req_InitiateClear; } Endpoint_ClearSETUP(); /* Write the request response byte */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_CheckClearStatus: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { /* Check that a CLEAR transaction has been requested and that the request has completed */ if (RequestInProgress != Req_InitiateClear) TMCRequestStatus = TMC_STATUS_SPLIT_NOT_IN_PROGRESS; else if (IsTMCBulkINReset || IsTMCBulkOUTReset) TMCRequestStatus = TMC_STATUS_PENDING; else RequestInProgress = 0; Endpoint_ClearSETUP(); /* Write the request response bytes */ Endpoint_Write_Byte(TMCRequestStatus); Endpoint_Write_Byte(0); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); } break; case Req_GetCapabilities: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { Endpoint_ClearSETUP(); /* Write the device capabilities to the control endpoint */ Endpoint_Write_Control_Stream_LE(&Capabilities, sizeof(TMC_Capabilities_t)); Endpoint_ClearOUT(); } break; } }