summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2022-04-17 00:46:31 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2022-04-17 00:46:31 +0200
commit2e31f5e437645bb6c21ace8c4fe9c435ff88bdec (patch)
tree262faea4ae05ce603f3cded938cbe43e85b70980
parentb1df70e6d0d119f7970931c1565db4da705677fc (diff)
stm32_uart: Use constraints to make helper functions compatible with all versions.
-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;