AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
|
Provides a high-end interface to serial communications using USART0. More...
#include <USART0.h>
Public Types | |
enum | IntegerOutputBase { kBin = 2, kOct = 8, kDec = 10, kHex = 16 } |
An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters. More... | |
Public Member Functions | |
void | start (unsigned long baudRate, UsartSerialConfiguration config=kSerial_8N1) |
Configure the hardware for two-way serial communications, including turning on associated interrupts. You must call this function before reading from or writing to Serial0 on USART0. More... | |
void | stop () |
Stops buffered serial communications using Serial0 on USART0 by deconfiguring the hardware and turning off interrupts. More... | |
virtual size_t | write (char c) |
Write a single character to the output stream. This implements the pure virtual function Writer::write( char c ). More... | |
virtual size_t | write (const char *str) |
Write a null-terminated string to the output stream. This implements the pure virtual function Writer::write( char* str ). More... | |
virtual size_t | write (const char *buffer, size_t size) |
Write a given number of characters from a buffer to the output stream. This implements the pure virtual function Writer::write( const char* buffer, size_t size ). More... | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
Write a given number of bytes from a buffer to the output stream. This implements the pure virtual function Writer::write( const uint8_t* buffer, size_t size ). More... | |
virtual void | flush () |
Flush the output stream. When this function returns, all previously written data will have been transmitted through the underlying output stream. This implements the pure virtual function Writer::flush(). | |
virtual int | read () |
Read and remove the next byte from the input stream. This implements the pure virtual function Reader::read(). More... | |
virtual int | peek () |
Examine the next byte from the input stream, without removing it. This implements the pure virtual function Reader::peek(). More... | |
virtual bool | available () |
Determine if data is available in the input stream. This implements the pure virtual function Reader::available(). More... | |
size_t | print (const char *str, bool addLn=false) |
Print a null-terminated string to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (const uint8_t *buf, size_t size, bool addLn=false) |
Print a number of bytes to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (char c, bool addLn=false) |
Print a single character to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (int8_t n, int base=kDec, bool addLn=false) |
Print an 8-bit integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (uint8_t n, int base=kDec, bool addLn=false) |
Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (int n, int base=kDec, bool addLn=false) |
Print an integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (unsigned int n, int base=kDec, bool addLn=false) |
Print an unsigned integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (long n, int base=kDec, bool addLn=false) |
Print a long integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (unsigned long n, int base=kDec, bool addLn=false) |
Print an unsigned long integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (double d, int digits=2, bool addLn=false) |
Print a floating point number to the output stream, with or without adding a new line character at the end. More... | |
size_t | println (const char *str) |
Print a null-terminated string to the output stream, adding a new line character at the end. More... | |
size_t | println (const uint8_t *buf, size_t size) |
Print a number of bytes to the output stream, adding a new line character at the end. More... | |
size_t | println (char c) |
Print a single character to the output stream, adding a new line character at the end. More... | |
size_t | println (int8_t n, int base=kDec) |
Print an 8-bit integer to the output stream, adding a new line character at the end. More... | |
size_t | println (uint8_t n, int base=kDec) |
Print an 8-bit unsigned integer to the output stream, adding a new line character at the end. More... | |
size_t | println (int n, int base=kDec) |
Print an integer to the output stream, adding a new line character at the end. More... | |
size_t | println (unsigned int n, int base=kDec) |
Print an unsigned integer to the output stream, adding a new line character at the end. More... | |
size_t | println (long n, int base=kDec) |
Print a long integer to the output stream, adding a new line character at the end. More... | |
size_t | println (unsigned long n, int base=kDec) |
Print an unsigned long integer to the output stream, adding a new line character at the end. More... | |
size_t | println (double d, int digits=2) |
Print a floating point number to the output stream, adding a new line character at the end. More... | |
size_t | println () |
Print a new line to the output stream. | |
void | setTimeout (unsigned long milliseconds) |
Sets maximum milliseconds to wait for stream data, default is 1 second. More... | |
bool | find (const char *target) |
Read data from the input stream until the target string is found. More... | |
bool | find (const char *target, size_t length) |
Read data from the stream until the target string of given length is found. More... | |
bool | findUntil (const char *target, const char *terminator) |
Read data from the stream until the target string is found, or the terminator string is found, or the function times out. More... | |
bool | findUntil (const char *target, size_t targetLen, const char *terminate, size_t termLen) |
Read data from the stream until the target string of given length is found, or the terminator string of given length is found, or the function times out. More... | |
bool | readLong (long *result) |
Return the first valid long integer value from the stream. More... | |
bool | readLong (long *result, char skipChar) |
Return the first valid long integer value from the stream, ignoring selected characters. More... | |
bool | readFloat (float *result) |
Return the first valid float value from the stream. More... | |
bool | readFloat (float *result, char skipChar) |
Return the first valid float value from the stream, ignoring selected characters. More... | |
size_t | readBytes (char *buffer, size_t length) |
Read characters from the input stream into a buffer, terminating if length characters have been read or the function times out. The result is NOT null-termimated. More... | |
size_t | readBytes (uint8_t *buffer, size_t length) |
Read bytes (uint8_t) from the input stream into a buffer, terminating if length bytes have been read or the function times out. More... | |
size_t | readBytesUntil (char terminator, char *buffer, size_t length) |
Read characters from the input stream into a buffer, terminating when the terminator charactor is encountered, or if length characters have been read, or if the function times out. The result is NOT null-terminated. More... | |
size_t | readBytesUntil (uint8_t terminator, uint8_t *buffer, size_t length) |
Read bytes (uint8_t) from the input stream into a buffer, terminating when the terminator byte is encountered, or if length bytes have been read, or if the function times out. More... | |
size_t | readLine (char *buffer, size_t length) |
Read characters from the input stream into a buffer, until it reaches EOL, or if length characters have been read, or if it times out. The result IS null-termimated. More... | |
void | consumeWhiteSpace () |
Consumes whitespace characters until the first non-whitespace character is encountered or the function times out. | |
Provides a high-end interface to serial communications using USART0.
The functions in this class are buffered for both input and output and operate using interrupts associated with USART0. This means the write functions return immediately after queuing data in the output buffer for transmission and the transmission happens asynchronously, using dedicated USART0 hardware. Similarly, data is received asynchronously and placed into the read buffer.
The read and write buffers are both ring buffers. If you try to queue more data than the transmit buffer can hold, the write functions will block until there is room in the buffer (as a result of data being transmitted). The read buffer, however, will overwrite if it gets full. You must clear the read buffer by actually reading the data regularly when receiving significant amounts of data.
|
inherited |
An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters.
|
virtual |
Determine if data is available in the input stream. This implements the pure virtual function Reader::available().
Implements Reader.
|
inlineinherited |
Read data from the input stream until the target string is found.
target
is the string the function seeks in the input stream.
|
inlineinherited |
Read data from the stream until the target string of given length is found.
target
is a string, the first length bytes of which the function seeks in the input stream. length
is the number of bytes of the string to use for comparison.
|
inherited |
Read data from the stream until the target string is found, or the terminator string is found, or the function times out.
This function is like find() but the search ends if the terminator string is found first.
target
is the string the function seeks in the input stream. terminator
is the string that stops the search.
|
inherited |
Read data from the stream until the target string of given length is found, or the terminator string of given length is found, or the function times out.
This function is like find() but the search ends if the terminator string is found first.
target
is the string the function seeks in the input stream. targetLen
is the number of bytes in target that the function seeks in the input stream. terminator
is the string that stops the search. termLen
is the number of bytes in the terminator that
|
virtual |
Examine the next byte from the input stream, without removing it. This implements the pure virtual function Reader::peek().
Implements Reader.
|
inherited |
Print a null-terminated string to the output stream, with or without adding a new line character at the end.
str
is the null-terminated string to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a number of bytes to the output stream, with or without adding a new line character at the end.
buf
is the buffer containing bytes to output. size
is the number of bytes from the buffer to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a single character to the output stream, with or without adding a new line character at the end.
c
is the character to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an 8-bit integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print an unsigned integer to the output stream, with or without adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a long integer to the output stream, with or without adding a new line character at the end.
n
is the long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an unsigned long integer to the output stream, with or without adding a new line character at the end.
n
is the unsigned long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a floating point number to the output stream, with or without adding a new line character at the end.
d
is the floating point number to output. digits
is the number of decimal digits to output; the default is 2. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print a null-terminated string to the output stream, adding a new line character at the end.
str
is the null-terminated string to output.
|
inlineinherited |
Print a number of bytes to the output stream, adding a new line character at the end.
buf
is the buffer containing bytes to output. size
is the number of bytes from the buffer to output.
|
inlineinherited |
Print a single character to the output stream, adding a new line character at the end.
c
is the character to output.
|
inlineinherited |
Print an 8-bit integer to the output stream, adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an 8-bit unsigned integer to the output stream, adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an integer to the output stream, adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an unsigned integer to the output stream, adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print a long integer to the output stream, adding a new line character at the end.
n
is the long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an unsigned long integer to the output stream, adding a new line character at the end.
n
is the unsigned long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print a floating point number to the output stream, adding a new line character at the end.
d
is the flaoting point number to output. digits
is the number of decimal digits to output; the default is 2.
|
virtual |
Read and remove the next byte from the input stream. This implements the pure virtual function Reader::read().
Implements Reader.
|
inherited |
Read characters from the input stream into a buffer, terminating if length characters have been read or the function times out. The result is NOT null-termimated.
buffer
a pointer to where the characters read will be stored. length
the maximum number of characters to read.
|
inlineinherited |
Read bytes (uint8_t) from the input stream into a buffer, terminating if length bytes have been read or the function times out.
buffer
a pointer to where the bytes read will be stored. length
the maximum number of bytes to read.
|
inherited |
Read characters from the input stream into a buffer, terminating when the terminator charactor is encountered, or if length characters have been read, or if the function times out. The result is NOT null-terminated.
terminator
a character that when encountered causes the function to return. buffer
a pointer to where the characters read will be stored. length
the maximum number of characters to read.
|
inlineinherited |
Read bytes (uint8_t) from the input stream into a buffer, terminating when the terminator byte is encountered, or if length bytes have been read, or if the function times out.
terminator
a byte that when encountered causes the function to return. buffer
a pointer to where the bytes read will be stored. length
the maximum number of bytes to read.
|
inherited |
Return the first valid float value from the stream.
Initial characters that are not digits (or the minus sign) are skipped; the float is terminated by the first character that is not a digit.
result
is a pointer to where the float will be stored.
|
inherited |
Return the first valid float value from the stream, ignoring selected characters.
Initial characters that are not digits (or the minus sign) are skipped; the float is terminated by the first character that is not a digit and is not one of the skip characters. This allows format characters (typically commas) to be ignored on input.
result
is a pointer to where the float will be stored. skipChar
is a character that will be ignored on input.
|
inherited |
Read characters from the input stream into a buffer, until it reaches EOL, or if length characters have been read, or if it times out. The result IS null-termimated.
buffer
a pointer to where the characters read will be stored. length
the maximum number of characters to read.
|
inherited |
Return the first valid long integer value from the stream.
Initial characters that are not digits (or the minus sign) are skipped; the integer is terminated by the first character that is not a digit.
result
is a pointer to where the long integer will be stored.
|
inherited |
Return the first valid long integer value from the stream, ignoring selected characters.
Initial characters that are not digits (or the minus sign) are skipped; the integer is terminated by the first character that is not a digit and is not one of the skip characters. This allows format characters (typically commas) to be ignored on input.
result
is a pointer to where the long integer will be stored. skipChar
is a character that will be ignored on input.
|
inlineinherited |
Sets maximum milliseconds to wait for stream data, default is 1 second.
milliseconds
the length of the timeout period in milliseconds.
|
inline |
Configure the hardware for two-way serial communications, including turning on associated interrupts. You must call this function before reading from or writing to Serial0 on USART0.
baudRate
the baud rate for the communications, usually one of the following values: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200 (although other values below can be specified).config
sets the configuration in term of data bits, parity, and stop bits. If omitted, the default is 8 data bits, no parity, and 1 stop bit.
|
inline |
Stops buffered serial communications using Serial0 on USART0 by deconfiguring the hardware and turning off interrupts.
After calling this function, Arduino pins 0 and 1 are released and available for use as ordinary digital pins.
If you want to use Serial0 again for communications, you must call start() again.
|
virtual |
Write a single character to the output stream. This implements the pure virtual function Writer::write( char c ).
the
character to be written.Implements Writer.
|
virtual |
Write a null-terminated string to the output stream. This implements the pure virtual function Writer::write( char* str ).
str
the string to be written.Implements Writer.
|
virtual |
Write a given number of characters from a buffer to the output stream. This implements the pure virtual function Writer::write( const char* buffer, size_t size ).
buffer
the buffer of characters to write. size
the number of characters to writeImplements Writer.
|
virtual |
Write a given number of bytes from a buffer to the output stream. This implements the pure virtual function Writer::write( const uint8_t* buffer, size_t size ).
buffer
the buffer of bytes to write. size
the number of bytes to writeImplements Writer.