Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
HardwareSerial::write(const char*, ...) API compatibility to AVR, ESP…
…8266, et al (espressif#3585) * API compatibility to AVR, ESP8266, et al * Add non-blocking HardwareSerial::read(buffer, size) extension (ESP8266 portability) * Refactor for fewer indirect calls.
  • Loading branch information
dok-net authored and me-no-dev committed Jan 20, 2020
commit 0607d36734d52d67be1b88764bf446fac7eb62f3
18 changes: 18 additions & 0 deletions cores/esp32/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion cores/esp32/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ class HardwareSerial: public Stream
int availableForWrite(void);
int peek(void);
int read(void);
size_t read(uint8_t *buffer, size_t size);
inline size_t read(char * buffer, size_t size)
{
return read((uint8_t*) buffer, size);
}
void flush(void);
void flush( bool txOnly);
size_t write(uint8_t);
size_t write(const uint8_t *buffer, size_t size);

inline size_t write(const char * buffer, size_t size)
{
return write((uint8_t*) buffer, size);
}
inline size_t write(const char * s)
{
return write((uint8_t*) s, strlen(s));
Expand Down