update tinyusb

This commit is contained in:
hathach 2018-07-31 13:53:55 +07:00
parent c273b82883
commit 10c124315d
2 changed files with 33 additions and 29 deletions

@ -1 +1 @@
Subproject commit e362f5fd64d257e3ad70962be59fc8593a0f5d95 Subproject commit 191b73b58c5ad6a098c652f31459ef39078a484b

View File

@ -71,59 +71,61 @@ void msc_uf2_umount(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// tinyusb callbacks // tinyusb callbacks
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Callback invoked when received an SCSI command not in built-in list below
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
// - READ10 and WRITE10 has their own callbacks
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
{ {
// read10 & write10 has their own callback and MUST not be handled here void const* response = NULL;
uint16_t resplen = 0;
void const* ptr = NULL;
uint16_t len = 0;
// most scsi handled is input
bool in_xfer = true;
switch ( scsi_cmd[0] ) switch ( scsi_cmd[0] )
{ {
case SCSI_CMD_TEST_UNIT_READY: case SCSI_CMD_TEST_UNIT_READY:
// Command that host uses to check our readiness before sending other commands // Command that host uses to check our readiness before sending other commands
len = 0; resplen = 0;
break; break;
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL: case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
// Host is about to read/write etc ... better not to disconnect disk // Host is about to read/write etc ... better not to disconnect disk
len = 0; resplen = 0;
break; break;
case SCSI_CMD_START_STOP_UNIT: case SCSI_CMD_START_STOP_UNIT:
// Host try to eject/safe remove/powerof us. We could safely disconnect with disk storage, or go into lower power // Host try to eject/safe remove/poweroff us. We could safely disconnect with disk storage, or go into lower power
// scsi_start_stop_unit_t const * cmd_start_stop = (scsi_start_stop_unit_t const *) scsi_cmd /* scsi_start_stop_unit_t const * start_stop = (scsi_start_stop_unit_t const *) scsi_cmd;
len = 0; // Start bit = 0 : low power mode, if load_eject = 1 : unmount disk storage as well
// Start bit = 1 : Ready mode, if load_eject = 1 : mount disk storage
start_stop->start;
start_stop->load_eject;
*/
resplen = 0;
break; break;
default: default:
// negative is error -> Data stage is STALL, status = failed // Set Sense = Invalid Command Operation
return -1; tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
// negative means error -> tinyusb could stall and/or response with failed status
resplen = -1;
break;
} }
// return len must not larger than bufsize // return len must not larger than bufsize
TU_ASSERT( bufsize >= len ); if ( resplen > bufsize ) resplen = bufsize;
if ( ptr && len ) // copy response to stack's buffer if any
if ( response && resplen )
{ {
if(in_xfer) memcpy(buffer, response, resplen);
{
memcpy(buffer, ptr, len);
}else
{
// SCSI output
}
} }
return len; return resplen;
} }
/*------------------------------------------------------------------*/ // Callback invoked when received READ10 command.
/* Tinyusb Flash READ10 & WRITE10 // Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
*------------------------------------------------------------------*/
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{ {
(void) lun; (void) lun;
@ -145,6 +147,8 @@ int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buf
return count; return count;
} }
// Callback invoked when received WRITE10 command.
// Process data in buffer to disk's storage and return number of written bytes
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
{ {
(void) lun; (void) lun;