Class Uart

Class Documentation

class Uart

Class that wraps modm’s Uart implementation.

Currently only wraps the uart ports that we are generating modm code for. If additional UartPort’s are added, they must be added to this wrapper class here.

Public Types

enum UartPort

Values:

enumerator Uart1
enumerator Uart3
enumerator Uart6
using Parity = modm::platform::UartBase::Parity

Public Functions

Uart() = default
mockable ~Uart() = default
template<UartPort port, modm::baudrate_t baudrate, Parity parity = Parity::Disabled>
inline void init()

Initializes a particular Uart with the pins particular to the board.

See also

Parity.

Note

follow covention in the functino when adding a UartPort.

Template Parameters:
  • port – the particular port to initialize.

  • baudrate – desired baud rate in Hz.

  • parity

mockable bool read (UartPort port, uint8_t *data)

Read a single byte.

Parameters:
  • port[in] the port to read from.

  • data[out] Byte read, if any.

Returns:

true if a byte was received, false otherwise.

mockable std::size_t read (UartPort port, uint8_t *data, std::size_t length)

Read a block of bytes.

Parameters:
  • port[in] the port to read from.

  • data[out] pointer to a buffer big enough to store length bytes

  • length[in] number of bytes to be read.

Returns:

number of bytes which could be read, maximal length.

mockable std::size_t discardReceiveBuffer (UartPort port)

Empty the receive FIFO queue and hardware buffer.

Parameters:

port[in] the port’s buffer to discard.

Returns:

the size of the deleted FIFO queue.

mockable bool write (UartPort port, uint8_t data)

Pushes a single byte into the buffer.

Note

this writing is buffered.

Parameters:

port[in] the port to write to.

Returns:

true if data has been successfully sent, false if buffer is full.

mockable std::size_t write (UartPort port, const uint8_t *data, std::size_t length)

Pushes a block of bytes into the buffer.

Note

this writing may be buffered.

Parameters:
  • port[in] the port to write to.

  • data[in] pointer to a buffer big enough to store length bytes.

  • length[in] number of bytes to be written.

Returns:

the number of bytes that have been written.

mockable bool isWriteFinished (UartPort port) const

Because the data is buffered, check here to see if the buffer is empty (implying everything has been written).

Parameters:

port[in] the port to see if writing is finished.

Returns:

true if the buffer is empty and the last byte has been sent.

mockable void flushWriteBuffer (UartPort port)