libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::UartHandler Class Reference

Detailed Description

Uart Peripheral

Author
shensley
Date
March 2020

#include <uart.h>

Classes

struct  Config
 

Public Types

enum class  Result { OK , ERR }
 
enum class  DmaDirection { RX , TX }
 
typedef void(* StartCallbackFunctionPtr) (void *context)
 
typedef void(* EndCallbackFunctionPtr) (void *context, Result result)
 
typedef void(* CircularRxCallbackFunctionPtr) (uint8_t *data, size_t size, void *context, Result result)
 

Public Member Functions

 UartHandler ()
 
 UartHandler (const UartHandler &other)=default
 
UartHandleroperator= (const UartHandler &other)=default
 
Result Init (const Config &config)
 
const ConfigGetConfig () const
 
Result BlockingTransmit (uint8_t *buff, size_t size, uint32_t timeout=100)
 
Result BlockingReceive (uint8_t *buffer, uint16_t size, uint32_t timeout=100)
 
Result DmaTransmit (uint8_t *buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void *callback_context)
 
Result DmaReceive (uint8_t *buff, size_t size, UartHandler::StartCallbackFunctionPtr start_callback, UartHandler::EndCallbackFunctionPtr end_callback, void *callback_context)
 
Result DmaListenStart (uint8_t *buff, size_t size, CircularRxCallbackFunctionPtr cb, void *callback_context)
 
Result DmaListenStop ()
 
bool IsListening () const
 
int CheckError ()
 
int PollReceive (uint8_t *buff, size_t size, uint32_t timeout)
 
Result PollTx (uint8_t *buff, size_t size)
 

Member Typedef Documentation

◆ CircularRxCallbackFunctionPtr

typedef void(* daisy::UartHandler::CircularRxCallbackFunctionPtr) (uint8_t *data, size_t size, void *context, Result result)

A callback to be executed when using circular/listening mode includes a callback context, as well as the data to be handled This fires either after half of the size of the user-defined buffer has been transferred from peripheral to memory, or after an IDLE frame is detected.

Parameters
databyte-buffer to fill with data
sizesize of the "data" byte buffer
contextuser-defined context variable to pass state to the callback
resultstate of the UART Handler result, should be OK if things are OK.

◆ EndCallbackFunctionPtr

typedef void(* daisy::UartHandler::EndCallbackFunctionPtr) (void *context, Result result)

A callback to be executed after a standard dma transfer is completed.

◆ StartCallbackFunctionPtr

typedef void(* daisy::UartHandler::StartCallbackFunctionPtr) (void *context)

A callback to be executed right before a standard dma transfer is started.

Member Enumeration Documentation

◆ DmaDirection

Enumerator
RX 

&

TX 

&

◆ Result

Return values for Uart functions.

Enumerator
OK 

&

ERR 

&

Constructor & Destructor Documentation

◆ UartHandler() [1/2]

daisy::UartHandler::UartHandler ( )
inline

◆ UartHandler() [2/2]

daisy::UartHandler::UartHandler ( const UartHandler other)
default

Member Function Documentation

◆ BlockingReceive()

Result daisy::UartHandler::BlockingReceive ( uint8_t buffer,
uint16_t  size,
uint32_t  timeout = 100 
)

Polling Receive

Parameters
bufferinput buffer
sizebuffer size
timeoutHow long to timeout for in milliseconds
Returns
Whether the receive was successful or not

◆ BlockingTransmit()

Result daisy::UartHandler::BlockingTransmit ( uint8_t buff,
size_t  size,
uint32_t  timeout = 100 
)

Blocking transmit

Parameters
buffinput buffer
sizebuffer size
timeouthow long in milliseconds the function will wait before returning without successful communication

◆ CheckError()

int daisy::UartHandler::CheckError ( )
Returns
the result of HAL_UART_GetError() to the user.

◆ DmaListenStart()

Result daisy::UartHandler::DmaListenStart ( uint8_t buff,
size_t  size,
CircularRxCallbackFunctionPtr  cb,
void callback_context 
)

Starts the DMA Reception in "Listen" mode. In this mode the DMA is configured for circular behavior, and the IDLE interrupt is enabled.

At TC, HT, and IDLE interrupts data must be processed.

Size must be set so that at maximum bandwidth, the software has time to process N bytes before the next circular IRQ is fired

Parameters
buffbuffer of data accessible by DMA.
sizesize of buffer
cbcallback that happens containing new bytes to process in software
callback_contextpointer to user-defined data accessible from callback

◆ DmaListenStop()

Result daisy::UartHandler::DmaListenStop ( )

Stops the DMA Reception during listen mode

◆ DmaReceive()

Result daisy::UartHandler::DmaReceive ( uint8_t buff,
size_t  size,
UartHandler::StartCallbackFunctionPtr  start_callback,
UartHandler::EndCallbackFunctionPtr  end_callback,
void callback_context 
)

DMA-based receive

Parameters
*buffinput buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
end_callbackA callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the receive was successful or not

◆ DmaTransmit()

Result daisy::UartHandler::DmaTransmit ( uint8_t buff,
size_t  size,
UartHandler::StartCallbackFunctionPtr  start_callback,
UartHandler::EndCallbackFunctionPtr  end_callback,
void callback_context 
)

DMA-based transmit

Parameters
*buffinput buffer
sizebuffer size
start_callbackA callback to execute when the transfer starts, or NULL. The callback is called from an interrupt, so keep it fast.
end_callbackA callback to execute when the transfer finishes, or NULL. The callback is called from an interrupt, so keep it fast.
callback_contextA pointer that will be passed back to you in the callbacks.
Returns
Whether the transmit was successful or not

◆ GetConfig()

const Config & daisy::UartHandler::GetConfig ( ) const

Returns the current config.

◆ Init()

Result daisy::UartHandler::Init ( const Config config)

Initializes the UART Peripheral

◆ IsListening()

bool daisy::UartHandler::IsListening ( ) const

Returns whether listen the DmaListen mode is active or not

◆ operator=()

UartHandler & daisy::UartHandler::operator= ( const UartHandler other)
default

◆ PollReceive()

int daisy::UartHandler::PollReceive ( uint8_t buff,
size_t  size,
uint32_t  timeout 
)

Will be deprecated soon! Wrapper for BlockingTransmit

◆ PollTx()

Result daisy::UartHandler::PollTx ( uint8_t buff,
size_t  size 
)

Will be deprecated soon! Wrapper for BlockingTransmit


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