stm32f103
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
uart.h
Go to the documentation of this file.
1 #ifndef STM32F103_CORE_UART_H_
2 #define STM32F103_CORE_UART_H_
3 
4 #include <functional>
5 #include <memory>
6 
7 #include <stm32f10x_usart.h>
8 
9 #include "gpio.h"
10 #include "util.h"
11 
15 class UART {
16  public:
20  struct Config {
24  USART_TypeDef* usart;
28  uint32_t rcc;
40  uint32_t tx_periph;
44  uint32_t rx_periph;
48  IRQn irq;
49 
53  uint32_t baud_rate;
54  };
55 
61  explicit UART(const Config& config);
62 
66  void EnableInterrupt();
67 
73  void TxByte(const uint8_t byte);
80  void Tx(const char* data, ...);
86  void Tx(const std::string& str);
87 
88  protected:
94  void Init(uint32_t baud_rate);
95 
96  private:
97  USART_TypeDef* usart_;
98  uint32_t rcc_;
99  std::unique_ptr<GPIO> tx_ = nullptr;
100  std::unique_ptr<GPIO> rx_ = nullptr;
101  uint32_t tx_periph_;
102  uint32_t rx_periph_;
103  IRQn irq_;
104 };
105 
106 #endif // STM32F103_CORE_UART_H_
uint32_t rx_periph
RX Peripheral Clock.
Definition: uart.h:44
void Init(uint32_t baud_rate)
Performs initialization for this UART interface.
Definition: uart.cpp:38
uint32_t rcc
RCC: Reset & Clock Control.
Definition: uart.h:28
std::pair< GPIO_TypeDef *, uint16_t > Pin
Type definition for a single pin.
Definition: util.h:16
Configuration for individual UART interfaces.
Definition: uart.h:20
void EnableInterrupt()
Enables interrupt for UART RX.
Definition: uart.cpp:60
void TxByte(const uint8_t byte)
Transmits one byte.
Definition: uart.cpp:75
Implements an abstraction layer for UART interface.
Definition: uart.h:15
IRQn irq
Interrupt Handler.
Definition: uart.h:48
Pin tx
TX Pin.
Definition: uart.h:32
USART_TypeDef * usart
UART/USART.
Definition: uart.h:24
void Tx(const char *data,...)
Transmits a formatted string.
Definition: uart.cpp:80
uint32_t baud_rate
Baud Rate.
Definition: uart.h:53
Pin rx
RX Pin.
Definition: uart.h:36
UART(const Config &config)
Constructor for UART.
Definition: uart.cpp:9
uint32_t tx_periph
TX Peripheral Clock.
Definition: uart.h:40