From 2e31f5e437645bb6c21ace8c4fe9c435ff88bdec Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 17 Apr 2022 00:46:31 +0200 Subject: stm32_uart: Use constraints to make helper functions compatible with all versions. --- uart/stm32_uart.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 +#include + 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 class STM32_UART_t : public mmio_ptr { + static constexpr auto is_v1 = std::is_same_v; + static constexpr auto is_v2 = std::is_same_v; + static constexpr auto is_lpv1 = std::is_same_v; + public: using mmio_ptr::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; -- cgit v1.2.3