forked from espressif/arduino-esp32
HardwareSerial::write(const char*, ...) API compatibility to AVR, ESP8266, et al (#3585)
* API compatibility to AVR, ESP8266, et al * Add non-blocking HardwareSerial::read(buffer, size) extension (ESP8266 portability) * Refactor for fewer indirect calls.
This commit is contained in:
@ -131,6 +131,24 @@ int HardwareSerial::read(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// read characters into buffer
|
||||
// terminates if size characters have been read, or no further are pending
|
||||
// returns the number of characters placed in the buffer
|
||||
// the buffer is NOT null terminated.
|
||||
size_t HardwareSerial::read(uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t avail = available();
|
||||
if (size < avail) {
|
||||
avail = size;
|
||||
}
|
||||
size_t count = 0;
|
||||
while(count < avail) {
|
||||
*buffer++ = uartRead(_uart);
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void HardwareSerial::flush(void)
|
||||
{
|
||||
uartFlush(_uart);
|
||||
|
Reference in New Issue
Block a user