void USBCDCMSC::memoryRead (void) { uint32_t n; n = (length > MAX_PACKET) ? MAX_PACKET : length; if ((addr + n) > MemorySize) { n = MemorySize - addr; stage = ERROR; } // we read an entire block if (!(addr%BlockSize)) disk_read((char *)page, addr/BlockSize); // write data which are in RAM writeNB(MSDBULK_IN, &page[addr%BlockSize], n, MAX_PACKET_SIZE_EPBULK); addr += n; length -= n; csw.DataResidue -= n; if ( !length || (stage != PROCESS_CBW)) { csw.Status = (stage == PROCESS_CBW) ? CSW_PASSED : CSW_FAILED; stage = (stage == PROCESS_CBW) ? SEND_CSW : stage; } }
size_t EthernetClient::write(const uint8_t *buf, size_t size) { int ret; size_t n = 0, res = size; while (n < size) { if ((ret = writeNB(&buf[n], res)) < 0) break; n += ret; res -= ret; } return n; }
bool USBCDCMSC::msd_write (uint8_t * buf, uint16_t size) { if (size >= cbw.DataLength) { size = cbw.DataLength; } stage = SEND_CSW; if (!writeNB(MSDBULK_IN, buf, size, MAX_PACKET_SIZE_EPBULK)) { return false; } csw.DataResidue -= size; csw.Status = CSW_PASSED; return true; }
int EthernetClient::writeNB(uint8_t b) { return writeNB(&b, 1); }
void USBCDCMSC::sendCSW() { csw.Signature = CSW_Signature; writeNB(MSDBULK_IN, (uint8_t *)&csw, sizeof(CSW), MAX_PACKET_SIZE_EPBULK); stage = WAIT_CSW; }
bool USBHID::sendNB(HID_REPORT *report) { return writeNB(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE); }