add Chapter04 bare example
This commit is contained in:
28
Chapter04/bare/hal/uart/inc/uart.hpp
Normal file
28
Chapter04/bare/hal/uart/inc/uart.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
class uart
|
||||
{
|
||||
public:
|
||||
virtual void init() = 0;
|
||||
|
||||
virtual void putchar(char c) = 0;
|
||||
|
||||
void puts(const char *str)
|
||||
{
|
||||
std::size_t ind = 0;
|
||||
|
||||
if(str != nullptr)
|
||||
{
|
||||
while(str[ind] != '\0')
|
||||
{
|
||||
putchar(str[ind]);
|
||||
ind++;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}; // namespace hal
|
||||
25
Chapter04/bare/hal/uart/inc/uart_stm32.hpp
Normal file
25
Chapter04/bare/hal/uart/inc/uart_stm32.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <uart.hpp>
|
||||
|
||||
#include <stm32f0xx_hal.h>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
class uart_stm32 : public uart
|
||||
{
|
||||
public:
|
||||
uart_stm32(USART_TypeDef *inst, std::uint32_t baud = 115200);
|
||||
|
||||
void init() override;
|
||||
|
||||
void putchar(char c) override;
|
||||
|
||||
private:
|
||||
UART_HandleTypeDef huart;
|
||||
USART_TypeDef *instance;
|
||||
std::uint32_t baudrate;
|
||||
};
|
||||
}; // namespace hal
|
||||
Reference in New Issue
Block a user