Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/SoftwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ int SoftwareSerial::read() {
return val;
}

size_t SoftwareSerial::read(uint8_t* buffer, size_t size) {

streamInt SoftwareSerial::read(uint8_t* buffer, size_t size) {
if (!m_rxValid) { return 0; }
size_t avail;
streamInt avail;
if (0 == (avail = m_buffer->pop_n(buffer, size))) {
rxBits();
avail = m_buffer->pop_n(buffer, size);
Expand Down
10 changes: 8 additions & 2 deletions src/SoftwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ enum SoftwareSerialConfig {
SWSERIAL_8S2,
};

#if STREAM_READ_RETURNS_INT // stream:to*()
using streamInt = int;
#else
using streamInt = size_t;
#endif

/// This class is compatible with the corresponding AVR one, however,
/// the constructor takes no arguments, for compatibility with the
/// HardwareSerial class.
Expand Down Expand Up @@ -156,9 +162,9 @@ class SoftwareSerial : public Stream {
return (0x9669 >> byte) & 1;
}
/// The read(buffer, size) functions are non-blocking, the same as readBytes but without timeout
size_t read(uint8_t* buffer, size_t size);
streamInt read(uint8_t* buffer, size_t size);
/// The read(buffer, size) functions are non-blocking, the same as readBytes but without timeout
size_t read(char* buffer, size_t size) {
streamInt read(char* buffer, size_t size) {
return read(reinterpret_cast<uint8_t*>(buffer), size);
}
/// @returns The number of bytes read into buffer, up to size. Times out if the limit set through
Expand Down