CANTram Framework 1.0.1
Dieses Framework ermöglicht die Nutzung der CANTram Hardware, einer Mikrocontroller basierten mdoularen Steuerung.
Loading...
Searching...
No Matches
UARTCore Class Referenceabstract

Base class for platform-specific UART implementations. More...

#include <UARTCore.h>

Inheritance diagram for UARTCore:
Collaboration diagram for UARTCore:

Public Types

enum  DataBits { UART_DATA_5_BITS = 0 , UART_DATA_6_BITS = 1 , UART_DATA_7_BITS = 2 , UART_DATA_8_BITS = 3 }
 Possible data bit widths for UART communication. More...
enum  Parity { UART_PARITY_NONE = 0 , UART_PARITY_EVEN = 1 , UART_PARITY_ODD = 2 }
 Parity configuration options. More...
enum  StopBits { UART_STOP_BITS_1 = 1 , UART_STOP_BITS_1_5 = 2 , UART_STOP_BITS_2 = 3 }
 Stop bit configuration options. More...
Public Types inherited from HardwareResource
enum  Type {
  UART , SPI , I2C , PWM ,
  CAN
}
 Enumeration of hardware resource types. More...

Public Member Functions

virtual bool install (int uart_num, uint8_t tx_pin, uint8_t rx_pin, uint16_t bufferSize)=0
 Install and initialize the UART driver and resources.
virtual bool reset () override
 Reset the UART core and release/clear resources.
virtual bool config (uint32_t baudrate, DataBits dataBits, Parity parity, StopBits stopBits)
 Configure UART communication parameters.
virtual bool setBaudrate (uint32_t baudrate)
virtual bool setDataBits (DataBits dataBits)
virtual bool setParity (Parity parity)
virtual bool setStopBits (StopBits stopBits)
virtual bool send (const char buffer[], size_t size)
 Send a buffer of bytes over UART.
virtual size_t read (char buffer[])
 Read available bytes from the UART into the provided buffer.
virtual size_t available ()=0
 Get the number of bytes currently available for reading.
virtual void flush ()=0
 Flush the UART transmit buffer.
HardwareResource::Type getType () override
 Get the HardwareResource type for this core.
virtual bool setPins (uint8_t tx_pin, uint8_t rx_pin)
Public Member Functions inherited from HardwareResource
bool requestUsage ()
 Request a usage slot for this resource.
uint8_t getUsages ()
 Get the current number of usages of this resource.
bool isUsed ()
 Check if the resource is currently used.
virtual uint8_t getRemainingUsages ()
 Get remaining usage capacity for this resource.

Protected Attributes

int8_t _rxPin = DEFAULT_REF
int8_t _txPin = DEFAULT_REF
bool pinsConfigured = false
uint32_t _baudrate = 0
StopBits _stopBits = UART_STOP_BITS_1
Parity _parity = UART_PARITY_NONE
DataBits _dataBits = UART_DATA_8_BITS
Protected Attributes inherited from HardwareResource
uint8_t usages =0
 Current usage counter.

Additional Inherited Members

Protected Member Functions inherited from HardwareResource
 HardwareResource ()=default
 Default constructor.
virtual uint8_t getMaxUsages ()
 Get the maximum simultaneous usages allowed for this resource.

Detailed Description

Base class for platform-specific UART implementations.

Derive from UARTCore when implementing UART support for a specific microcontroller or platform. The class integrates with the HardwareResource lifecycle provided by CANTramCore.

Member Enumeration Documentation

◆ DataBits

Possible data bit widths for UART communication.

Enum values map to typical UART data length settings.

◆ Parity

Parity configuration options.

Select no parity, even parity or odd parity for UART frames.

◆ StopBits

Stop bit configuration options.

Specifies 1, 1.5 or 2 stop bits for UART frames.

Member Function Documentation

◆ available()

virtual size_t UARTCore::available ( )
pure virtual

Get the number of bytes currently available for reading.

Query the UART driver's RX buffer to determine how many bytes can be read without blocking.

Returns
size_t Number of bytes available to read.

Implemented in ESP32_UART.

◆ config()

virtual bool UARTCore::config ( uint32_t baudrate,
DataBits dataBits,
Parity parity,
StopBits stopBits )
inlinevirtual

Configure UART communication parameters.

Set baudrate, data bits, parity and stop bits for the UART peripheral.

Parameters
baudrateDesired baud rate (e.g., 115200).
dataBitsData bit selection from DataBits enum.
parityParity selection from Parity enum.
stopBitsStop bit selection from StopBits enum.
Returns
true if configuration succeeded, false otherwise.

◆ flush()

virtual void UARTCore::flush ( )
pure virtual

Flush the UART transmit buffer.

Ensure that any queued transmit data is sent. Implementation should block until transmit is complete if required.

Returns
void

Implemented in ESP32_UART.

◆ getType()

HardwareResource::Type UARTCore::getType ( )
inlineoverridevirtual

Get the HardwareResource type for this core.

Overrides HardwareResource::getType() to return HardwareResource::Type::UART.

Returns
HardwareResource::Type The enum value Type::UART.

Implements HardwareResource.

◆ install()

virtual bool UARTCore::install ( int uart_num,
uint8_t tx_pin,
uint8_t rx_pin,
uint16_t bufferSize )
pure virtual

Install and initialize the UART driver and resources.

Prepare the underlying hardware driver and allocate required memory/buffers for UART operation. This method should be called once before attempting to use the UART for I/O.

Parameters
uart_numIdentifier of the UART peripheral to install (platform-specific).
tx_pinGPIO pin used for UART TX.
rx_pinGPIO pin used for UART RX.
bufferSizeSize in bytes of the RX buffer to allocate.
Returns
true if installation and allocation succeeded, false on failure.

Implemented in ESP32_UART.

◆ read()

virtual size_t UARTCore::read ( char buffer[])
inlinevirtual

Read available bytes from the UART into the provided buffer.

Attempt to read up to the size of the provided buffer. The concrete implementation should return the actual number of bytes read.

Parameters
bufferDestination buffer to receive bytes.
Returns
size_t Number of bytes read into the buffer (0 if none available).

Reimplemented in ESP32_UART.

Here is the caller graph for this function:

◆ reset()

virtual bool UARTCore::reset ( )
inlineoverridevirtual

Reset the UART core and release/clear resources.

Default implementation logs the reset and delegates to HardwareResource::reset() to clear usage counters. Override if additional platform-specific teardown is required.

Returns
true if reset succeeded, false otherwise.

Reimplemented from HardwareResource.

Reimplemented in ESP32_UART.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

virtual bool UARTCore::send ( const char buffer[],
size_t size )
inlinevirtual

Send a buffer of bytes over UART.

Write the provided buffer to the UART transmit queue or driver. Default implementation logs and returns false.

Parameters
bufferCharacter buffer containing bytes to send.
sizeNumber of bytes to send from the buffer.
Returns
true if the data was successfully queued/sent, false otherwise.

Reimplemented in ESP32_UART.

Here is the caller graph for this function:

The documentation for this class was generated from the following file:
  • C:/Users/leowa/Documents/PlatformIO/Projects/CANTramFrameworkUsage/lib/CANTramFramework/include/UARTCore.h