core-avr-io

AvrStream

class AvrStream

Abstracts the method of reading/writing bytes.

Subclassed by EEPROMStream, MemoryStream

Public Functions

virtual char read() = 0

Reads a single byte from the stream and advances the index.

Return
Returns the byte read.

virtual int read(char *const buffer, const int offset, const int count) = 0

Reads a block of bytes into the input buffer.

Return
The number of bytes actually read. -1 if there was an error.
Parameters
  • buffer: The buffer to read values into.
  • offset: The starting index.
  • count: The maximum number of bytes to read.

virtual bool write(const char value) = 0

Writes a single byte to the stream and advances the index.

Return
Returns true if the byte could be successfully written.
Parameters
  • value: The value to write.

virtual int write(char *const buffer, const int offset, const int count) = 0

Writes a block of bytes to the stream.

Return
Returns how many bytes were successfully written.
Parameters
  • buffer: The buffer to copy values from.
  • offset: The starting byte offset.
  • count: The number of bytes to write from buffer.

virtual int set(const char value, const int offset, const int count) = 0

Sets a block of bytes to a specific value. Effectively, memset.

Return
Returns how many bytes were successfully set.
Parameters
  • value: The value to fill with.
  • offset: The starting byte offset.
  • count: The number of bytes to set.

virtual int seek(const int offset, const int origin) = 0

Moves the index to a specific place. This is used when reading and writing single values.

Return
The current absolute index.
Parameters
  • offset: The offset to count from.
  • origin: The number of bytes to add to the offset.

Stream Implementations

class MemoryStream

Stream implementation completely in memory.

Inherits from AvrStream

class EEPROMStream

Abstracts SPI + EEPROM paging into working with a single block of contiguous bytes. All calls are blocking.

Inherits from AvrStream