add Chapter11
This commit is contained in:
20
Chapter11/compile_time/hal/uart/inc/uart.hpp
Normal file
20
Chapter11/compile_time/hal/uart/inc/uart.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <span>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
class uart
|
||||
{
|
||||
public:
|
||||
virtual void init(std::uint32_t baudrate) = 0;
|
||||
virtual void write_array(const char * ptr, std::size_t len) = 0;
|
||||
|
||||
virtual void write(std::span<const char> data)
|
||||
{
|
||||
write_array(data.data(), data.size());
|
||||
}
|
||||
};
|
||||
}; // namespace hal
|
||||
29
Chapter11/compile_time/hal/uart/inc/uart_stm32.hpp
Normal file
29
Chapter11/compile_time/hal/uart/inc/uart_stm32.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <uart.hpp>
|
||||
|
||||
#include <stm32f0xx_hal.h>
|
||||
#include <stm32f072xb.h>
|
||||
|
||||
namespace hal
|
||||
{
|
||||
class uart_stm32 : public uart
|
||||
{
|
||||
public:
|
||||
uart_stm32(USART_TypeDef *inst);
|
||||
|
||||
void init(std::uint32_t baudrate = c_baudrate_default) override;
|
||||
|
||||
void write_array(const char * ptr, std::size_t len) override;
|
||||
|
||||
private:
|
||||
UART_HandleTypeDef huart_;
|
||||
USART_TypeDef *instance_;
|
||||
std::uint32_t baudrate_;
|
||||
static constexpr std::uint32_t c_baudrate_default = 115200;
|
||||
};
|
||||
}; // namespace hal
|
||||
Reference in New Issue
Block a user