COSA
An Object-Oriented Platform for Arduino Programming
Soft::UART Class Reference

#include <UART.hh>

Inheritance diagram for Soft::UART:
Inheritance graph
Collaboration diagram for Soft::UART:
Collaboration graph

Classes

class  RXPinChangeInterrupt
 

Public Types

enum  {
  DATA5 = 0, DATA6 = _BV(UCSZ00), DATA7 = _BV(UCSZ01), DATA8 = _BV(UCSZ01) | _BV(UCSZ00),
  NO_PARITY = 0, EVEN_PARITY = _BV(UPM01), ODD_PARITY = _BV(UPM01) | _BV(UPM00), STOP1 = 0,
  STOP2 = _BV(USBS0)
}
 

Public Member Functions

 UART (Board::DigitalPin tx, Board::InterruptPin rx, IOStream::Device *ibuf)
 
virtual int available ()
 
virtual int peekchar ()
 
virtual int peekchar (char c)
 
virtual int getchar ()
 
virtual void empty ()
 
virtual bool begin (uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)
 
virtual bool end ()
 
virtual int putchar (char c)
 
virtual void powerup ()
 
virtual void powerdown ()
 
void non_blocking ()
 
void blocking ()
 
bool is_blocking () const
 
void eol (Mode mode)
 
Mode eol () const
 
virtual int room ()
 
virtual int puts (const char *s)
 
virtual int puts (str_P s)
 
virtual int write (const void *buf, size_t size)
 
virtual int write (const iovec_t *vec)
 
virtual int write_P (const void *buf, size_t size)
 
virtual char * gets (char *s, size_t count)
 
virtual int read (void *buf, size_t size)
 
virtual int read (iovec_t *vec)
 
virtual int flush ()
 

Static Public Attributes

static const uint8_t RX_BUFFER_MAX = COSA_SOFT_UART_RX_BUFFER_MAX
 
static const uint8_t TX_BUFFER_MAX = COSA_SOFT_UART_TX_BUFFER_MAX
 
static const uint32_t DEFAULT_BAUDRATE = 9600L
 
static const uint8_t DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2
 

Protected Attributes

RXPinChangeInterrupt m_rx
 
IOStream::Devicem_ibuf
 
OutputPin m_tx
 
uint8_t m_stops
 
uint8_t m_bits
 
uint16_t m_count
 
bool m_blocking
 
Mode m_eol
 

Friends

class RXPinChangeInterrupt
 

Detailed Description

Soft UART using serial write and input sampling. The Output serial write method is used for transmission and a pin change interrupt for detecting start condition and receiving data.

Definition at line 94 of file UART.hh.

Member Enumeration Documentation

anonymous enum
inherited

Serial formats; DATA + PARITY + STOP.

Enumerator
DATA5 
DATA6 
DATA7 
DATA8 
NO_PARITY 
EVEN_PARITY 
ODD_PARITY 
STOP1 
STOP2 

Definition at line 46 of file Serial.hh.

Constructor & Destructor Documentation

UART::UART ( Board::DigitalPin  tx,
Board::InterruptPin  rx,
IOStream::Device ibuf 
)

Construct Soft UART with transmitter on given output pin and receiver on given pin change interrupt pin. Received data is captured by an interrupt service routine and put into given buffer (i.e. io-stream).

Parameters
[in]txtransmitter pin.
[in]rxreceiver pin.
[in]ibufinput buffer.

Definition at line 25 of file SOFT_UART.cpp.

Member Function Documentation

virtual int Soft::UART::available ( )
inlinevirtual

Number of bytes available in input buffer.

Returns
bytes.

Reimplemented from IOStream::Device.

Definition at line 116 of file UART.hh.

bool UART::begin ( uint32_t  baudrate = DEFAULT_BAUDRATE,
uint8_t  format = DEFAULT_FORMAT 
)
virtual

Start Soft UART device driver.

Parameters
[in]baudrateserial bitrate (default 9600).
[in]formatserial frame format (default DATA8, NO PARITY, STOP2).
Returns
true(1) if successful otherwise false(0)

Reimplemented from Soft::UAT.

Definition at line 33 of file SOFT_UART.cpp.

void IOStream::Device::blocking ( )
inlineinherited

Set blocking mode.

Definition at line 85 of file IOStream.hh.

virtual void Soft::UART::empty ( )
inlinevirtual

Empty internal device buffers.

Reimplemented from IOStream::Device.

Definition at line 160 of file UART.hh.

virtual bool Soft::UART::end ( )
inlinevirtual

Stop Soft UART device driver.

Returns
true(1) if successful otherwise false(0)

Reimplemented from Serial.

Definition at line 180 of file UART.hh.

void IOStream::Device::eol ( Mode  mode)
inlineinherited

Set end of line mode.

Parameters
[in]modefor end of line.

Definition at line 103 of file IOStream.hh.

Mode IOStream::Device::eol ( ) const
inlineinherited

Get end of line mode.

Returns
mode.

Definition at line 112 of file IOStream.hh.

int IOStream::Device::flush ( )
virtualinherited

Flush internal device buffers. Wait for device to become idle.

Returns
zero(0) or negative error code.

Reimplemented in W5200::Driver, W5500::Driver, W5100::Driver, UART, IOBuffer< SIZE >, CC3000::Driver, and WIO.

Definition at line 169 of file IOStream_Device.cpp.

virtual int Soft::UART::getchar ( )
inlinevirtual

Read character from serial port input buffer. Returns character if successful otherwise on error or buffer empty returns EOF(-1),

Returns
character or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 151 of file UART.hh.

char * IOStream::Device::gets ( char *  s,
size_t  count 
)
virtualinherited

Read string terminated by new-line or until size into given string buffer. Returns pointer to string or NULL if empty line.

Parameters
[in]sstring buffer to read into.
[in]countmax number of bytes to read.
Returns
string pointer or NULL.

Definition at line 118 of file IOStream_Device.cpp.

bool IOStream::Device::is_blocking ( ) const
inlineinherited

Is blocking mode?

Returns
bool.

Definition at line 94 of file IOStream.hh.

void IOStream::Device::non_blocking ( )
inlineinherited

Set non-blocking mode.

Definition at line 77 of file IOStream.hh.

virtual int Soft::UART::peekchar ( )
inlinevirtual

Peek next character from serial port input buffer. Returns character if successful otherwise on error or buffer empty returns EOF(-1),

Returns
character or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 128 of file UART.hh.

virtual int Soft::UART::peekchar ( char  c)
inlinevirtual

Peek for given character from serial port input buffer.

Parameters
[in]ccharacter to peek for.
Returns
available or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 139 of file UART.hh.

virtual void Serial::powerdown ( )
inlinevirtualinherited

Powerdown Serial.

Reimplemented in UART.

Definition at line 97 of file Serial.hh.

virtual void Serial::powerup ( )
inlinevirtualinherited

Powerup Serial.

Reimplemented in UART.

Definition at line 91 of file Serial.hh.

int UAT::putchar ( char  c)
virtualinherited

Write character to serial port output buffer. Returns character if successful otherwise on error or buffer full returns EOF(-1),

Parameters
[in]ccharacter to write.
Returns
character written or EOF(-1).

Reimplemented from IOStream::Device.

Definition at line 35 of file SOFT_UAT.cpp.

int IOStream::Device::puts ( const char *  s)
virtualinherited

Write null terminated string to device. Terminating null is not written.

Parameters
[in]sstring to write.
Returns
zero(0) or negative error code.

Definition at line 43 of file IOStream_Device.cpp.

int IOStream::Device::puts ( str_P  s)
virtualinherited

Write null terminated string from program memory to device. Terminating null is not written.

Parameters
[in]sstring in program memory to write.
Returns
zero(0) or negative error code.

Definition at line 54 of file IOStream_Device.cpp.

int IOStream::Device::read ( void *  buf,
size_t  size 
)
virtualinherited

Read data to given buffer with given size from device.

Parameters
[in]bufbuffer to read into.
[in]sizenumber of bytes to read.
Returns
number of bytes read or EOF(-1).

Reimplemented in FAT16::File, W5200::Driver, W5500::Driver, W5100::Driver, CFFS::File, Socket, and CC3000::Driver.

Definition at line 144 of file IOStream_Device.cpp.

int IOStream::Device::read ( iovec_t vec)
virtualinherited

Read data to given buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to read into.
Returns
number of bytes read or EOF(-1).

Definition at line 157 of file IOStream_Device.cpp.

int IOStream::Device::room ( )
virtualinherited

Number of bytes room (write without blocking).

Returns
bytes.

Reimplemented in W5200::Driver, W5500::Driver, W5100::Driver, UART, IOBuffer< SIZE >, CC3000::Driver, and WIO.

Definition at line 30 of file IOStream_Device.cpp.

int IOStream::Device::write ( const void *  buf,
size_t  size 
)
virtualinherited

Write data from buffer with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented in FAT16::File, HD44780, CFFS::File, VLCD, Socket, and CC3000::Driver.

Definition at line 65 of file IOStream_Device.cpp.

int IOStream::Device::write ( const iovec_t vec)
virtualinherited

Write data from buffers in null terminated io vector.

Parameters
[in]vecio vector with buffers to write.
Returns
number of bytes written or EOF(-1).

Definition at line 87 of file IOStream_Device.cpp.

int IOStream::Device::write_P ( const void *  buf,
size_t  size 
)
virtualinherited

Write data from buffer in program memory with given size to device.

Parameters
[in]bufbuffer to write.
[in]sizenumber of bytes to write.
Returns
number of bytes written or EOF(-1).

Reimplemented in CFFS::File, Socket, and CC3000::Driver.

Definition at line 76 of file IOStream_Device.cpp.

Friends And Related Function Documentation

friend class RXPinChangeInterrupt
friend

Definition at line 197 of file UART.hh.

Member Data Documentation

const uint32_t Serial::DEFAULT_BAUDRATE = 9600L
staticinherited

Default baudrate.

Definition at line 43 of file Serial.hh.

const uint8_t Serial::DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2
staticinherited

Default serial format.

Definition at line 59 of file Serial.hh.

uint8_t Soft::UAT::m_bits
protectedinherited

Definition at line 85 of file UART.hh.

bool IOStream::Device::m_blocking
protectedinherited

Blocking state

Definition at line 248 of file IOStream.hh.

uint16_t Soft::UAT::m_count
protectedinherited

Definition at line 86 of file UART.hh.

Mode IOStream::Device::m_eol
protectedinherited

End of line mode

Definition at line 251 of file IOStream.hh.

IOStream::Device* Soft::UART::m_ibuf
protected

Definition at line 196 of file UART.hh.

RXPinChangeInterrupt Soft::UART::m_rx
protected

Definition at line 195 of file UART.hh.

uint8_t Soft::UAT::m_stops
protectedinherited

Definition at line 84 of file UART.hh.

OutputPin Soft::UAT::m_tx
protectedinherited

Definition at line 83 of file UART.hh.

const uint8_t Soft::UART::RX_BUFFER_MAX = COSA_SOFT_UART_RX_BUFFER_MAX
static

Default buffer size.

Definition at line 97 of file UART.hh.

const uint8_t Soft::UART::TX_BUFFER_MAX = COSA_SOFT_UART_TX_BUFFER_MAX
static

Definition at line 98 of file UART.hh.


The documentation for this class was generated from the following files: