summaryrefslogtreecommitdiff
path: root/tmk_core/common/avr
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-16 17:28:12 +0100
committerGitHub <noreply@github.com>2021-08-16 17:28:12 +0100
commit2bc8215ce5f5c7473bb75de95cef4ab468d7e837 (patch)
tree3fa646a2a10cacc52f3e5e67d2cc6c1253d7c3a8 /tmk_core/common/avr
parent4818debcd05819de774000bb641fea8baa49b787 (diff)
Unify behaviour of wait on AVR (#14025)
Diffstat (limited to 'tmk_core/common/avr')
-rw-r--r--tmk_core/common/avr/_wait.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/tmk_core/common/avr/_wait.h b/tmk_core/common/avr/_wait.h
index 56eb316faf..ae1a25131a 100644
--- a/tmk_core/common/avr/_wait.h
+++ b/tmk_core/common/avr/_wait.h
@@ -17,8 +17,26 @@
#include <util/delay.h>
-#define wait_ms(ms) _delay_ms(ms)
-#define wait_us(us) _delay_us(us)
+#define wait_ms(ms) \
+ do { \
+ if (__builtin_constant_p(ms)) { \
+ _delay_ms(ms); \
+ } else { \
+ for (uint16_t i = ms; i > 0; i--) { \
+ _delay_ms(1); \
+ } \
+ } \
+ } while (0)
+#define wait_us(us) \
+ do { \
+ if (__builtin_constant_p(us)) { \
+ _delay_us(us); \
+ } else { \
+ for (uint16_t i = us; i > 0; i--) { \
+ _delay_us(1); \
+ } \
+ } \
+ } while (0)
/* The AVR series GPIOs have a one clock read delay for changes in the digital input signal.
* But here's more margin to make it two clocks. */