mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Change init order. Unpopulated reader slots will report zero or Error for capacity.
This commit is contained in:
parent
7dc1c97fe0
commit
6b7194bde8
2 changed files with 35 additions and 27 deletions
|
@ -30,8 +30,8 @@ bLastUsbError(0) {
|
||||||
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
||||||
epInfo[i].epAttribs = 0;
|
epInfo[i].epAttribs = 0;
|
||||||
|
|
||||||
if (!i)
|
//if (!i)
|
||||||
epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
|
epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
|
||||||
}
|
}
|
||||||
if (pUsb)
|
if (pUsb)
|
||||||
pUsb->RegisterDeviceClass(this);
|
pUsb->RegisterDeviceClass(this);
|
||||||
|
@ -52,8 +52,8 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
||||||
epInfo[i].epAttribs = 0;
|
epInfo[i].epAttribs = 0;
|
||||||
|
|
||||||
if (!i)
|
//if (!i)
|
||||||
epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
|
epInfo[i].bmNakPower = USB_NAK_MAX_POWER;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddressPool &addrPool = pUsb->GetAddressPool();
|
AddressPool &addrPool = pUsb->GetAddressPool();
|
||||||
|
@ -184,24 +184,6 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
|
|
||||||
MediaCTL(lun, 0x01);
|
MediaCTL(lun, 0x01);
|
||||||
while (rcode = TestUnitReady(lun)) {
|
|
||||||
if (rcode == MASS_ERR_NO_MEDIA)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (rcode == MASS_ERR_DEVICE_DISCONNECTED)
|
|
||||||
goto Fail;
|
|
||||||
|
|
||||||
if (!count)
|
|
||||||
Notify(PSTR("Not ready...\r\n"), 0x80);
|
|
||||||
|
|
||||||
if (count == 0xff)
|
|
||||||
break;
|
|
||||||
|
|
||||||
delay(100);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
if (count == 0xff)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
rcode = 0;
|
rcode = 0;
|
||||||
InquiryResponse response;
|
InquiryResponse response;
|
||||||
|
@ -226,6 +208,24 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
rcode = 255;
|
rcode = 255;
|
||||||
goto FailInvalidSectorSize;
|
goto FailInvalidSectorSize;
|
||||||
}
|
}
|
||||||
|
while (rcode = TestUnitReady(lun)) {
|
||||||
|
if (rcode == MASS_ERR_NO_MEDIA)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (rcode == MASS_ERR_DEVICE_DISCONNECTED)
|
||||||
|
goto Fail;
|
||||||
|
|
||||||
|
if (!count)
|
||||||
|
Notify(PSTR("Not ready...\r\n"), 0x80);
|
||||||
|
|
||||||
|
if (count == 0xff)
|
||||||
|
break;
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if (count == 0xff)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rcode = 0;
|
rcode = 0;
|
||||||
|
@ -260,14 +260,14 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
|
||||||
}
|
}
|
||||||
Notify(PSTR("==========\r\n"), 0x80);
|
Notify(PSTR("==========\r\n"), 0x80);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if (TestUnitReady(bTheLUN)) {
|
if (TestUnitReady(bTheLUN)) {
|
||||||
Notify(PSTR("Unit not ready\r\n"), 0x80);
|
Notify(PSTR("Unit not ready\r\n"), 0x80);
|
||||||
|
|
||||||
rcode = MASS_ERR_UNIT_NOT_READY;
|
rcode = MASS_ERR_UNIT_NOT_READY;
|
||||||
//goto FailOnInit;
|
//goto FailOnInit;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
rcode = OnInit();
|
rcode = OnInit();
|
||||||
|
|
||||||
if (rcode)
|
if (rcode)
|
||||||
|
@ -492,7 +492,7 @@ uint8_t BulkOnly::Inquiry(uint8_t lun, uint16_t bsize, uint8_t *buf) {
|
||||||
Notify(PSTR("---------\r\n"), 0x80);
|
Notify(PSTR("---------\r\n"), 0x80);
|
||||||
|
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
SetCurLUN(lun);
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
cbw.dCBWTag = ++dCBWTag;
|
cbw.dCBWTag = ++dCBWTag;
|
||||||
cbw.dCBWDataTransferLength = bsize;
|
cbw.dCBWDataTransferLength = bsize;
|
||||||
|
@ -514,6 +514,7 @@ uint8_t BulkOnly::RequestSense(uint8_t lun, uint16_t size, uint8_t *buf) {
|
||||||
Notify(PSTR("----------------\r\n"), 0x80);
|
Notify(PSTR("----------------\r\n"), 0x80);
|
||||||
|
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
SetCurLUN(lun);
|
||||||
|
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
cbw.dCBWTag = ++dCBWTag;
|
cbw.dCBWTag = ++dCBWTag;
|
||||||
|
@ -528,7 +529,7 @@ uint8_t BulkOnly::RequestSense(uint8_t lun, uint16_t size, uint8_t *buf) {
|
||||||
cbw.CBWCB[0] = SCSI_CMD_REQUEST_SENSE;
|
cbw.CBWCB[0] = SCSI_CMD_REQUEST_SENSE;
|
||||||
cbw.CBWCB[4] = size;
|
cbw.CBWCB[4] = size;
|
||||||
|
|
||||||
return HandleSCSIError(Transaction(&cbw, size, buf, 0));
|
return Transaction(&cbw, size, buf, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BulkOnly::ReadCapacity(uint8_t lun, uint16_t bsize, uint8_t *buf) {
|
uint8_t BulkOnly::ReadCapacity(uint8_t lun, uint16_t bsize, uint8_t *buf) {
|
||||||
|
@ -537,6 +538,7 @@ uint8_t BulkOnly::ReadCapacity(uint8_t lun, uint16_t bsize, uint8_t *buf) {
|
||||||
|
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
|
||||||
|
SetCurLUN(lun);
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
cbw.dCBWTag = ++dCBWTag;
|
cbw.dCBWTag = ++dCBWTag;
|
||||||
cbw.dCBWDataTransferLength = bsize;
|
cbw.dCBWDataTransferLength = bsize;
|
||||||
|
@ -554,6 +556,7 @@ uint8_t BulkOnly::ReadCapacity(uint8_t lun, uint16_t bsize, uint8_t *buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t BulkOnly::TestUnitReady(uint8_t lun) {
|
uint8_t BulkOnly::TestUnitReady(uint8_t lun) {
|
||||||
|
SetCurLUN(lun);
|
||||||
if (!bAddress) // || !bPollEnable)
|
if (!bAddress) // || !bPollEnable)
|
||||||
return MASS_ERR_UNIT_NOT_READY;
|
return MASS_ERR_UNIT_NOT_READY;
|
||||||
|
|
||||||
|
@ -579,6 +582,7 @@ uint8_t BulkOnly::TestUnitReady(uint8_t lun) {
|
||||||
|
|
||||||
/* Media control: 0x00 Stop Motor, 0x01 Start Motor, 0x02 Eject Media, 0x03 Load Media */
|
/* Media control: 0x00 Stop Motor, 0x01 Start Motor, 0x02 Eject Media, 0x03 Load Media */
|
||||||
uint8_t BulkOnly::MediaCTL(uint8_t lun, uint8_t ctl) {
|
uint8_t BulkOnly::MediaCTL(uint8_t lun, uint8_t ctl) {
|
||||||
|
SetCurLUN(lun);
|
||||||
uint8_t rcode = MASS_ERR_UNIT_NOT_READY;
|
uint8_t rcode = MASS_ERR_UNIT_NOT_READY;
|
||||||
if (bAddress) {
|
if (bAddress) {
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
@ -605,6 +609,7 @@ uint8_t BulkOnly::Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t block
|
||||||
Notify(PSTR("\r\nRead\r\n"), 0x80);
|
Notify(PSTR("\r\nRead\r\n"), 0x80);
|
||||||
Notify(PSTR("---------\r\n"), 0x80);
|
Notify(PSTR("---------\r\n"), 0x80);
|
||||||
|
|
||||||
|
SetCurLUN(lun);
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
|
@ -662,6 +667,7 @@ uint8_t BulkOnly::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t bloc
|
||||||
//MediaCTL(lun, 0x01);
|
//MediaCTL(lun, 0x01);
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
|
||||||
|
SetCurLUN(lun);
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
cbw.dCBWTag = ++dCBWTag;
|
cbw.dCBWTag = ++dCBWTag;
|
||||||
cbw.dCBWDataTransferLength = ((uint32_t)bsize * blocks);
|
cbw.dCBWDataTransferLength = ((uint32_t)bsize * blocks);
|
||||||
|
@ -687,6 +693,7 @@ uint8_t BulkOnly::ModeSense(uint8_t lun, uint8_t pc, uint8_t page, uint8_t subpa
|
||||||
Notify(PSTR("------------\r\n"), 0x80);
|
Notify(PSTR("------------\r\n"), 0x80);
|
||||||
|
|
||||||
CommandBlockWrapper cbw;
|
CommandBlockWrapper cbw;
|
||||||
|
SetCurLUN(lun);
|
||||||
|
|
||||||
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
cbw.dCBWSignature = MASS_CBW_SIGNATURE;
|
||||||
cbw.dCBWTag = ++dCBWTag;
|
cbw.dCBWTag = ++dCBWTag;
|
||||||
|
|
|
@ -207,7 +207,8 @@ protected:
|
||||||
uint8_t bLastUsbError; // Last USB error
|
uint8_t bLastUsbError; // Last USB error
|
||||||
uint8_t bMaxLUN; // Max LUN
|
uint8_t bMaxLUN; // Max LUN
|
||||||
uint8_t bTheLUN; // Active LUN
|
uint8_t bTheLUN; // Active LUN
|
||||||
|
// TO-ADD:
|
||||||
|
// uint32_t CurrentCapacity; // use this to check for media changes.
|
||||||
protected:
|
protected:
|
||||||
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue