Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
tap::communication::serial::Uart Class Reference

#include <uart.hpp>

Public Types

enum  UartPort { Uart1 , Uart3 , Uart6 }
 
using Parity = modm::platform::UartBase::Parity
 

Public Member Functions

 Uart ()=default
 
mockable ~Uart ()=default
 
template<UartPort port, modm::baudrate_t baudrate, Parity parity = Parity::Disabled>
void init ()
 
mockable bool read (UartPort port, uint8_t *data)
 
mockable std::size_t read (UartPort port, uint8_t *data, std::size_t length)
 
mockable std::size_t discardReceiveBuffer (UartPort port)
 
mockable bool write (UartPort port, uint8_t data)
 
mockable std::size_t write (UartPort port, const uint8_t *data, std::size_t length)
 
mockable bool isWriteFinished (UartPort port) const
 
mockable void flushWriteBuffer (UartPort port)
 

Detailed Description

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.

Member Typedef Documentation

◆ Parity

using tap::communication::serial::Uart::Parity = modm::platform::UartBase::Parity

Member Enumeration Documentation

◆ UartPort

Enumerator
Uart1 
Uart3 
Uart6 

Constructor & Destructor Documentation

◆ Uart()

tap::communication::serial::Uart::Uart ( )
default

◆ ~Uart()

mockable tap::communication::serial::Uart::~Uart ( )
default

Member Function Documentation

◆ discardReceiveBuffer()

std::size_t tap::communication::serial::Uart::discardReceiveBuffer ( UartPort  port)

Empty the receive FIFO queue and hardware buffer.

Parameters
[in]portthe port's buffer to discard.
Returns
the size of the deleted FIFO queue.

◆ flushWriteBuffer()

void tap::communication::serial::Uart::flushWriteBuffer ( UartPort  port)

◆ init()

template<UartPort port, modm::baudrate_t baudrate, Parity parity = Parity::Disabled>
void tap::communication::serial::Uart::init ( )
inline

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

Note
follow covention in the functino when adding a UartPort.
Template Parameters
portthe particular port to initialize.
baudratedesired baud rate in Hz.
parity
See also
Parity.

◆ isWriteFinished()

bool tap::communication::serial::Uart::isWriteFinished ( UartPort  port) const

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

Parameters
[in]portthe port to see if writing is finished.
Returns
true if the buffer is empty and the last byte has been sent.

◆ read() [1/2]

bool tap::communication::serial::Uart::read ( UartPort  port,
uint8_t *  data 
)

Read a single byte.

Parameters
[in]portthe port to read from.
[out]dataByte read, if any.
Returns
true if a byte was received, false otherwise.

◆ read() [2/2]

std::size_t tap::communication::serial::Uart::read ( UartPort  port,
uint8_t *  data,
std::size_t  length 
)

Read a block of bytes.

Parameters
[in]portthe port to read from.
[out]datapointer to a buffer big enough to store length bytes
[in]lengthnumber of bytes to be read.
Returns
number of bytes which could be read, maximal length.

◆ write() [1/2]

std::size_t tap::communication::serial::Uart::write ( UartPort  port,
const uint8_t *  data,
std::size_t  length 
)

Pushes a block of bytes into the buffer.

Parameters
[in]portthe port to write to.
[in]datapointer to a buffer big enough to store length bytes.
[in]lengthnumber of bytes to be written.
Returns
the number of bytes that have been written.
Note
this writing may be buffered.

◆ write() [2/2]

bool tap::communication::serial::Uart::write ( UartPort  port,
uint8_t  data 
)

Pushes a single byte into the buffer.

Parameters
[in]portthe port to write to.
Returns
true if data has been successfully sent, false if buffer is full.
Note
this writing is buffered.

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