Skip to content
Snippets Groups Projects
Commit 4691ef4b authored by Cristian Maglie's avatar Cristian Maglie
Browse files

USB: Added optimized Stream::readBytes for EP OUT handler

This bypass the generic (but inefficient) implementation of Stream::readBytes
and uses an optimized version of readBytes than can do efficient multi-byte reads.
parent 3127d1dc
Branches
Tags
No related merge requests found
......@@ -184,6 +184,20 @@ int Serial_::read(void)
return usb.recv(CDC_ENDPOINT_OUT);
}
size_t Serial_::readBytes(char *buffer, size_t length)
{
size_t count = 0;
_startMillis = millis();
while (count < length)
{
uint32_t n = usb.recv(CDC_ENDPOINT_OUT, buffer+count, length-count);
if (n == 0 && (millis() - _startMillis) >= _timeout)
break;
count += n;
}
return count;
}
void Serial_::flush(void)
{
usb.flush(CDC_ENDPOINT_IN);
......
......@@ -127,6 +127,8 @@ public:
using Print::write; // pull in write(str) from Print
operator bool();
size_t readBytes(char *buffer, size_t length);
// This method allows processing "SEND_BREAK" requests sent by
// the USB host. Those requests indicate that the host wants to
// send a BREAK signal and are accompanied by a single uint16_t
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment