aboutsummaryrefslogtreecommitdiff
path: root/02-usart/include/common.h
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2020-11-18 22:46:11 -0700
committerJosh Rahm <joshuarahm@gmail.com>2020-11-18 22:46:11 -0700
commit75f8523f3a70558788186f8f2d7ca5a6f9f71194 (patch)
treeccadcf76b602c91d840eb287d8d6fb423c8f19e8 /02-usart/include/common.h
parentc1405b06d98b9b227fa7ff53c158f31d745eb505 (diff)
downloadstm32l4-75f8523f3a70558788186f8f2d7ca5a6f9f71194.tar.gz
stm32l4-75f8523f3a70558788186f8f2d7ca5a6f9f71194.tar.bz2
stm32l4-75f8523f3a70558788186f8f2d7ca5a6f9f71194.zip
Change dma.h over to a regset() strategy.
Apparently people really don't like bitfields in practice, so I have devised a compromise to retain some readability while using bitmasks instead by writing a regset() macro.
Diffstat (limited to '02-usart/include/common.h')
-rw-r--r--02-usart/include/common.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/02-usart/include/common.h b/02-usart/include/common.h
index f9cbe06..394dc62 100644
--- a/02-usart/include/common.h
+++ b/02-usart/include/common.h
@@ -17,6 +17,8 @@
#define __IO volatile
#endif
+#define CTZ(n) __builtin_ctz(n)
+
#define bool int
#ifndef __cplusplus
#define true 1
@@ -39,4 +41,7 @@
typedef __IO uint32_t bits_t;
+#define regset(reg, mask, val) \
+ (reg = (reg & ~mask) | (val << CTZ(mask)))
+
#endif /* COMMON_H */