forked from mfulz_github/qmk_firmware
Cleanups to the MassStorage Device demos, and the MassStorage Device Class driver.
This commit is contained in:
parent
588886878e
commit
21cc9c9e19
|
@ -239,8 +239,6 @@ static void SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* MSInterfaceI
|
||||||
|
|
||||||
/* Succeed the command and update the bytes transferred counter */
|
/* Succeed the command and update the bytes transferred counter */
|
||||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
MSInterfaceInfo->State.CommandBlock.DataTransferLength = 0;
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address
|
/** Command processing for an issued SCSI READ (10) or WRITE (10) command. This command reads in the block start address
|
||||||
|
@ -255,15 +253,11 @@ static void SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo
|
||||||
uint32_t BlockAddress;
|
uint32_t BlockAddress;
|
||||||
uint16_t TotalBlocks;
|
uint16_t TotalBlocks;
|
||||||
|
|
||||||
/* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */
|
/* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */
|
||||||
((uint8_t*)&BlockAddress)[3] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[2];
|
BlockAddress = SwapEndian_32(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[2]);
|
||||||
((uint8_t*)&BlockAddress)[2] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[3];
|
|
||||||
((uint8_t*)&BlockAddress)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
|
|
||||||
((uint8_t*)&BlockAddress)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[5];
|
|
||||||
|
|
||||||
/* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */
|
/* Load in the 16-bit total blocks (SCSI uses big-endian, so have to reverse the byte order) */
|
||||||
((uint8_t*)&TotalBlocks)[1] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[7];
|
TotalBlocks = SwapEndian_16(*(uint32_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[7]);
|
||||||
((uint8_t*)&TotalBlocks)[0] = MSInterfaceInfo->State.CommandBlock.SCSICommandData[8];
|
|
||||||
|
|
||||||
/* Check if the block address is outside the maximum allowable value for the LUN */
|
/* Check if the block address is outside the maximum allowable value for the LUN */
|
||||||
if (BlockAddress >= LUN_MEDIA_BLOCKS)
|
if (BlockAddress >= LUN_MEDIA_BLOCKS)
|
||||||
|
@ -289,6 +283,4 @@ static void SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* MSInterfaceInfo
|
||||||
|
|
||||||
/* Update the bytes transferred counter and succeed the command */
|
/* Update the bytes transferred counter and succeed the command */
|
||||||
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
|
MSInterfaceInfo->State.CommandBlock.DataTransferLength -= ((uint32_t)TotalBlocks * VIRTUAL_MEMORY_BLOCK_SIZE);
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
||||||
Endpoint_ClearSETUP();
|
Endpoint_ClearSETUP();
|
||||||
|
|
||||||
/* Indicate that the current transfer should be aborted */
|
/* Indicate that the current transfer should be aborted */
|
||||||
IsMassStoreReset = true;
|
IsMassStoreReset = true;
|
||||||
|
|
||||||
Endpoint_ClearStatusStage();
|
Endpoint_ClearStatusStage();
|
||||||
}
|
}
|
||||||
|
@ -204,19 +204,6 @@ void MassStorage_Task(void)
|
||||||
|
|
||||||
/* Return command status block to the host */
|
/* Return command status block to the host */
|
||||||
ReturnCommandStatus();
|
ReturnCommandStatus();
|
||||||
|
|
||||||
/* Check if a Mass Storage Reset occurred */
|
|
||||||
if (IsMassStoreReset)
|
|
||||||
{
|
|
||||||
/* Reset the data endpoint banks */
|
|
||||||
Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);
|
|
||||||
Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);
|
|
||||||
|
|
||||||
Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
|
|
||||||
Endpoint_ClearStall();
|
|
||||||
Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
|
|
||||||
Endpoint_ClearStall();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Indicate ready */
|
/* Indicate ready */
|
||||||
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
LEDs_SetAllLEDs(LEDMASK_USB_READY);
|
||||||
|
@ -228,8 +215,23 @@ void MassStorage_Task(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the abort transfer flag */
|
/* Check if a Mass Storage Reset occurred */
|
||||||
IsMassStoreReset = false;
|
if (IsMassStoreReset)
|
||||||
|
{
|
||||||
|
/* Reset the data endpoint banks */
|
||||||
|
Endpoint_ResetFIFO(MASS_STORAGE_OUT_EPNUM);
|
||||||
|
Endpoint_ResetFIFO(MASS_STORAGE_IN_EPNUM);
|
||||||
|
|
||||||
|
Endpoint_SelectEndpoint(MASS_STORAGE_OUT_EPNUM);
|
||||||
|
Endpoint_ClearStall();
|
||||||
|
Endpoint_ResetDataToggle();
|
||||||
|
Endpoint_SelectEndpoint(MASS_STORAGE_IN_EPNUM);
|
||||||
|
Endpoint_ClearStall();
|
||||||
|
Endpoint_ResetDataToggle();
|
||||||
|
|
||||||
|
/* Clear the abort transfer flag */
|
||||||
|
IsMassStoreReset = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Function to read in a command block from the host, via the bulk data OUT endpoint. This function reads in the next command block
|
/** Function to read in a command block from the host, via the bulk data OUT endpoint. This function reads in the next command block
|
||||||
|
|
|
@ -165,12 +165,12 @@ void ReadNextReport(void)
|
||||||
*
|
*
|
||||||
* \param[in] ReportOUTData Buffer containing the report to send to the device
|
* \param[in] ReportOUTData Buffer containing the report to send to the device
|
||||||
* \param[in] ReportIndex Index of the report in the device (zero if the device does not use multiple reports)
|
* \param[in] ReportIndex Index of the report in the device (zero if the device does not use multiple reports)
|
||||||
* \param[in] ReportType Type of report to send, either HID_REPORTTYPE_OUTPUT or HID_REPORTTYPE_FEATURE
|
* \param[in] ReportType Type of report to send, either REPORT_ITEM_TYPE_Out or REPORT_ITEM_TYPE_Feature
|
||||||
* \param[in] ReportLength Length of the report to send
|
* \param[in] ReportLength Length of the report to send
|
||||||
*/
|
*/
|
||||||
void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t ReportType, uint16_t ReportLength)
|
void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t ReportType, uint16_t ReportLength)
|
||||||
{
|
{
|
||||||
/* Select and unfreeze HID data OUT pipe */
|
/* Select the HID data OUT pipe */
|
||||||
Pipe_SelectPipe(HID_DATA_OUT_PIPE);
|
Pipe_SelectPipe(HID_DATA_OUT_PIPE);
|
||||||
|
|
||||||
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the
|
/* Not all HID devices have an OUT endpoint (some require OUT reports to be sent over the
|
||||||
|
|
|
@ -61,12 +61,6 @@
|
||||||
|
|
||||||
/** HID Class specific request to send a HID report to the device. */
|
/** HID Class specific request to send a HID report to the device. */
|
||||||
#define REQ_SetReport 0x09
|
#define REQ_SetReport 0x09
|
||||||
|
|
||||||
/** HID Report type specifier, for output reports to a device */
|
|
||||||
#define HID_REPORTTYPE_OUTPUT 0x02
|
|
||||||
|
|
||||||
/** HID Report type specifier, for feature reports to a device */
|
|
||||||
#define HID_REPORTTYPE_FEATURE 0x03
|
|
||||||
|
|
||||||
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
/** LED mask for the library LED driver, to indicate that the USB interface is not ready. */
|
||||||
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
#define LEDMASK_USB_NOTREADY LEDS_LED1
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#define INCLUDE_FROM_MS_CLASS_DEVICE_C
|
#define INCLUDE_FROM_MS_CLASS_DEVICE_C
|
||||||
#include "MassStorage.h"
|
#include "MassStorage.h"
|
||||||
|
|
||||||
static USB_ClassInfo_MS_Device_t* CallbackMSInterfaceInfo;
|
static volatile bool* CallbackIsResetSource;
|
||||||
|
|
||||||
void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||||
{
|
{
|
||||||
|
@ -130,8 +130,10 @@ void MS_Device_USBTask(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||||
|
|
||||||
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
|
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
|
||||||
Endpoint_ClearStall();
|
Endpoint_ClearStall();
|
||||||
|
Endpoint_ResetDataToggle();
|
||||||
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
|
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataINEndpointNumber);
|
||||||
Endpoint_ClearStall();
|
Endpoint_ClearStall();
|
||||||
|
Endpoint_ResetDataToggle();
|
||||||
|
|
||||||
MSInterfaceInfo->State.IsMassStoreReset = false;
|
MSInterfaceInfo->State.IsMassStoreReset = false;
|
||||||
}
|
}
|
||||||
|
@ -141,11 +143,14 @@ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInte
|
||||||
{
|
{
|
||||||
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
|
Endpoint_SelectEndpoint(MSInterfaceInfo->Config.DataOUTEndpointNumber);
|
||||||
|
|
||||||
CallbackMSInterfaceInfo = MSInterfaceInfo;
|
CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
|
||||||
Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,
|
if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock,
|
||||||
(sizeof(MS_CommandBlockWrapper_t) - 16),
|
(sizeof(MS_CommandBlockWrapper_t) - 16),
|
||||||
StreamCallback_MS_Device_AbortOnMassStoreReset);
|
StreamCallback_MS_Device_AbortOnMassStoreReset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((MSInterfaceInfo->State.CommandBlock.Signature != MS_CBW_SIGNATURE) ||
|
if ((MSInterfaceInfo->State.CommandBlock.Signature != MS_CBW_SIGNATURE) ||
|
||||||
(MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) ||
|
(MSInterfaceInfo->State.CommandBlock.LUN >= MSInterfaceInfo->Config.TotalLUNs) ||
|
||||||
(MSInterfaceInfo->State.CommandBlock.Flags & 0x1F) ||
|
(MSInterfaceInfo->State.CommandBlock.Flags & 0x1F) ||
|
||||||
|
@ -159,14 +164,17 @@ static bool MS_Device_ReadInCommandBlock(USB_ClassInfo_MS_Device_t* const MSInte
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackMSInterfaceInfo = MSInterfaceInfo;
|
CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
|
||||||
Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,
|
if (Endpoint_Read_Stream_LE(&MSInterfaceInfo->State.CommandBlock.SCSICommandData,
|
||||||
MSInterfaceInfo->State.CommandBlock.SCSICommandLength,
|
MSInterfaceInfo->State.CommandBlock.SCSICommandLength,
|
||||||
StreamCallback_MS_Device_AbortOnMassStoreReset);
|
StreamCallback_MS_Device_AbortOnMassStoreReset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Endpoint_ClearOUT();
|
Endpoint_ClearOUT();
|
||||||
|
|
||||||
return !(MSInterfaceInfo->State.IsMassStoreReset);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
|
||||||
|
@ -175,7 +183,9 @@ static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInt
|
||||||
|
|
||||||
while (Endpoint_IsStalled())
|
while (Endpoint_IsStalled())
|
||||||
{
|
{
|
||||||
|
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||||
USB_USBTask();
|
USB_USBTask();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (MSInterfaceInfo->State.IsMassStoreReset)
|
if (MSInterfaceInfo->State.IsMassStoreReset)
|
||||||
return;
|
return;
|
||||||
|
@ -185,27 +195,31 @@ static void MS_Device_ReturnCommandStatus(USB_ClassInfo_MS_Device_t* const MSInt
|
||||||
|
|
||||||
while (Endpoint_IsStalled())
|
while (Endpoint_IsStalled())
|
||||||
{
|
{
|
||||||
|
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||||
USB_USBTask();
|
USB_USBTask();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (MSInterfaceInfo->State.IsMassStoreReset)
|
if (MSInterfaceInfo->State.IsMassStoreReset)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CallbackMSInterfaceInfo = MSInterfaceInfo;
|
CallbackIsResetSource = &MSInterfaceInfo->State.IsMassStoreReset;
|
||||||
Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(MS_CommandStatusWrapper_t),
|
if (Endpoint_Write_Stream_LE(&MSInterfaceInfo->State.CommandStatus, sizeof(MS_CommandStatusWrapper_t),
|
||||||
StreamCallback_MS_Device_AbortOnMassStoreReset);
|
StreamCallback_MS_Device_AbortOnMassStoreReset))
|
||||||
|
{
|
||||||
Endpoint_ClearIN();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (MSInterfaceInfo->State.IsMassStoreReset)
|
Endpoint_ClearIN();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void)
|
static uint8_t StreamCallback_MS_Device_AbortOnMassStoreReset(void)
|
||||||
{
|
{
|
||||||
MS_Device_USBTask(CallbackMSInterfaceInfo);
|
#if !defined(INTERRUPT_CONTROL_ENDPOINT)
|
||||||
|
USB_USBTask();
|
||||||
|
#endif
|
||||||
|
|
||||||
if (CallbackMSInterfaceInfo->State.IsMassStoreReset)
|
if (*CallbackIsResetSource)
|
||||||
return STREAMCALLBACK_Abort;
|
return STREAMCALLBACK_Abort;
|
||||||
else
|
else
|
||||||
return STREAMCALLBACK_Continue;
|
return STREAMCALLBACK_Continue;
|
||||||
|
|
|
@ -87,9 +87,9 @@
|
||||||
MS_CommandStatusWrapper_t CommandStatus; /**< Mass Storage class command status structure, set elements to indicate
|
MS_CommandStatusWrapper_t CommandStatus; /**< Mass Storage class command status structure, set elements to indicate
|
||||||
* the issued command's success or failure to the host
|
* the issued command's success or failure to the host
|
||||||
*/
|
*/
|
||||||
bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset
|
volatile bool IsMassStoreReset; /**< Flag indicating that the host has requested that the Mass Storage interface be reset
|
||||||
* and that all current Mass Storage operations should immediately abort
|
* and that all current Mass Storage operations should immediately abort
|
||||||
*/
|
*/
|
||||||
} State; /**< State data for the USB class interface within the device. All elements in this section
|
} State; /**< State data for the USB class interface within the device. All elements in this section
|
||||||
* are reset to their defaults when the interface is enumerated.
|
* are reset to their defaults when the interface is enumerated.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue