mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-08-02 09:21:54 +00:00
Add HAL UART implementation
This commit is contained in:
parent
03ca528d91
commit
221b455e43
53
include/sta/hal/uart.hpp
Normal file
53
include/sta/hal/uart.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @brief Implementation for UART using HAL.
|
||||
*
|
||||
* Define STA_HAL_UART_ENABLE in <sta/config.hpp> to enable.
|
||||
*
|
||||
* To enable the global DebugSerial instance (example using UART1) define:
|
||||
* #define STA_HAL_UART_DEBUG huart1
|
||||
*/
|
||||
#ifndef STA_HAL_UART_HPP
|
||||
#define STA_HAL_UART_HPP
|
||||
|
||||
#include <sta/config.hpp>
|
||||
#ifdef STA_HAL_UART_ENABLE
|
||||
|
||||
#include <sta/uart.hpp>
|
||||
|
||||
#include <main.h>
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
/**
|
||||
* @brief Implementation of UART for HAL.
|
||||
*/
|
||||
class HalUART : public UART
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @param handle UART handle
|
||||
*/
|
||||
HalUART(UART_HandleTypeDef * handle);
|
||||
|
||||
using UART::print;
|
||||
|
||||
void write(const uint8_t * buffer, size_t size) override;
|
||||
|
||||
private:
|
||||
UART_HandleTypeDef * handle_; /**< UART handle */
|
||||
};
|
||||
|
||||
|
||||
#ifdef STA_HAL_UART_DEBUG
|
||||
/**
|
||||
* @brief Global UART instance for debug output.
|
||||
*/
|
||||
extern HalUART DebugSerial;
|
||||
#endif // STA_HAL_UART_DEBUG
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#endif // STA_HAL_UART_ENABLE
|
||||
|
||||
#endif // STA_HAL_UART_HPP
|
32
src/hal/uart.cpp
Normal file
32
src/hal/uart.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <sta/hal/uart.hpp>
|
||||
|
||||
#ifdef STA_HAL_UART_ENABLE
|
||||
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalUART::HalUART(UART_HandleTypeDef * handle)
|
||||
: handle_{handle}
|
||||
{}
|
||||
|
||||
|
||||
void HalUART::write(const uint8_t * buffer, size_t size)
|
||||
{
|
||||
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
|
||||
}
|
||||
} // namespace sta
|
||||
|
||||
|
||||
#ifdef STA_HAL_UART_DEBUG
|
||||
|
||||
#include <usart.h>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
HalUART DebugSerial(&STA_HAL_UART_DEBUG);
|
||||
} // namespace sta
|
||||
|
||||
#endif // STA_HAL_UART_DEBUG
|
||||
|
||||
|
||||
#endif // STA_HAL_UART_ENABLE
|
Loading…
x
Reference in New Issue
Block a user