avr-classes
Public Member Functions | List of all members
NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE > Class Template Reference

#include <notifyingbufferedusart.h>

Inheritance diagram for NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >:
BufferedUsart< RXQUEUESIZE, TXQUEUESIZE > SimpleUsart Usart::InterruptHandler

Public Member Functions

 NotifyingBufferedUsart (Usart *usart, EventReceiver *receiver, const Event &readableEvent, const Event &writableEvent)
 
bool read (uint8_t *byte)
 
bool write (uint8_t byte)
 
virtual void onDataRegisterEmpty (void) override
 
virtual void onRxComplete (void) override
 
- Public Member Functions inherited from BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >
 BufferedUsart (Usart *usart)
 
void enable (bool state)
 
bool read (uint8_t *byte)
 
bool write (uint8_t byte)
 
- Public Member Functions inherited from SimpleUsart
 SimpleUsart (Usart *usart)
 
void enable (bool state)
 
uint8_t read (void)
 
void write (uint8_t byte)
 

Additional Inherited Members

- Protected Attributes inherited from SimpleUsart
Usart *const m_usart
 

Detailed Description

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
class NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >

Extension of the BufferedUsart that sends notifications using the event system when data becomes ready for reading or when there is new capacaity for writing data. The notifications are sent only once the trigger occurs, until the user re-enables them by reading data (for the readable notification) or writing data (for the writable notification).

Note
Keep in mind that sending of events happens in ISR context. When using an EventDispatcher with autoDispatch set to true as receiver, all its subscribers will also be notified within ISR context!

Constructor & Destructor Documentation

◆ NotifyingBufferedUsart()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::NotifyingBufferedUsart ( Usart usart,
EventReceiver receiver,
const Event readableEvent,
const Event writableEvent 
)
inline

Constructor.

Parameters
usartPointer to USART device to be used.
receiverPointer to EventReceiver instance to receive notifications.
readableEventEvent to be sent when data was added to the incoming buffer (device is readable).
writableEventEvent to be sent when data was removed from the outgoing buffer (device is writable).
Note
You can pass INVALID_EVENT_ID for events that should not be sent.

Member Function Documentation

◆ onDataRegisterEmpty()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
virtual void NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::onDataRegisterEmpty ( void  )
inlineoverridevirtual

Calls base class implementation and sends writeable notification, if not already done.

Reimplemented from BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >.

◆ onRxComplete()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
virtual void NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::onRxComplete ( void  )
inlineoverridevirtual

Calls base class implementation and sends readable notification, if not already done.

Reimplemented from BufferedUsart< RXQUEUESIZE, TXQUEUESIZE >.

◆ read()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
bool NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::read ( uint8_t *  byte)
inline

Re-enables readable notification and gets a byte from the buffer, if available.

Parameters
bytePointer to buffer that receives the data byte.
Returns
True if a data byte was read, false otherwise.

◆ write()

template<uint8_t RXQUEUESIZE, uint8_t TXQUEUESIZE>
bool NotifyingBufferedUsart< RXQUEUESIZE, TXQUEUESIZE >::write ( uint8_t  byte)
inline

Re-enables writable notification and puts a byte into the buffer, if possible.

Parameters
byteData byte to send.
Returns
True if data was enqueued, false otherwise.