summaryrefslogtreecommitdiff
path: root/uart/stm32_uart.h
diff options
context:
space:
mode:
Diffstat (limited to 'uart/stm32_uart.h')
-rw-r--r--uart/stm32_uart.h14
1 files changed, 13 insertions, 1 deletions
diff --git a/uart/stm32_uart.h b/uart/stm32_uart.h
index c4ba582..6db8305 100644
--- a/uart/stm32_uart.h
+++ b/uart/stm32_uart.h
@@ -2,6 +2,8 @@
#include <mmio/mmio.h>
+#include <type_traits>
+
struct STM32_UART_reg_v1_t {
volatile uint32_t SR;
volatile uint32_t DR;
@@ -42,10 +44,20 @@ struct STM32_UART_reg_lpv1_t {
template <typename T>
class STM32_UART_t : public mmio_ptr<T> {
+ static constexpr auto is_v1 = std::is_same_v<T, STM32_UART_reg_v1_t>;
+ static constexpr auto is_v2 = std::is_same_v<T, STM32_UART_reg_v2_t>;
+ static constexpr auto is_lpv1 = std::is_same_v<T, STM32_UART_reg_lpv1_t>;
+
public:
using mmio_ptr<T>::ptr;
- void write_blocking(uint8_t data) const {
+ void write_blocking(uint8_t data) const requires is_v1 {
+ // wait for TXE/TXFNF
+ while (!(ptr()->SR & (1<<7)));
+ ptr()->DR = data;
+ }
+
+ void write_blocking(uint8_t data) const requires is_v2 || is_lpv1 {
// wait for TXE/TXFNF
while (!(ptr()->ISR & (1<<7)));
ptr()->TDR = data;