summaryrefslogtreecommitdiff
path: root/tmk_core/common/chibios/_wait.h
diff options
context:
space:
mode:
authorSimon Arlott <70171+nomis@users.noreply.github.com>2021-08-20 00:31:23 +0100
committerGitHub <noreply@github.com>2021-08-20 00:31:23 +0100
commit0a1bf7f6aa6e44557041e03f6e58df5a180c6d79 (patch)
treec2883c302bd9f0d49b4f086763386399ef58b3d2 /tmk_core/common/chibios/_wait.h
parent462e7f075a14175be08f32561d5ba783e725ab7c (diff)
Support using a timer for wait_us() on ChibiOS-based boards (#12211)
* Support using a timer for wait_us() on ChibiOS-based boards (#12198) There are spare GPT timers that can be used to get a more accurate wait_ms() time. This is required for the matrix scan unselect delay (30µs) to be shorter than the system tick rate of 100µs. This is limited to the maximum GPT duration of 65535 so values above that will automatically use the previous implementation based on the system tick. Using a specific timer means it can't be shared by another thread at the same time so when wait_us() is called from anything other than the main thread it will use the system tick implementation too. * Update tmk_core/common/chibios/wait.c * Update tmk_core/common/chibios/wait.c Co-authored-by: Joel Challis <git@zvecr.com>
Diffstat (limited to 'tmk_core/common/chibios/_wait.h')
-rw-r--r--tmk_core/common/chibios/_wait.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/tmk_core/common/chibios/_wait.h b/tmk_core/common/chibios/_wait.h
index 5bface53e1..4a5172536b 100644
--- a/tmk_core/common/chibios/_wait.h
+++ b/tmk_core/common/chibios/_wait.h
@@ -16,6 +16,7 @@
#pragma once
#include <ch.h>
+#include <hal.h>
/* chThdSleepX of zero maps to infinite - so we map to a tiny delay to still yield */
#define wait_ms(ms) \
@@ -26,14 +27,19 @@
chThdSleepMicroseconds(1); \
} \
} while (0)
-#define wait_us(us) \
- do { \
- if (us != 0) { \
- chThdSleepMicroseconds(us); \
- } else { \
- chThdSleepMicroseconds(1); \
- } \
- } while (0)
+
+#ifdef WAIT_US_TIMER
+void wait_us(uint16_t duration);
+#else
+# define wait_us(us) \
+ do { \
+ if (us != 0) { \
+ chThdSleepMicroseconds(us); \
+ } else { \
+ chThdSleepMicroseconds(1); \
+ } \
+ } while (0)
+#endif
/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
* to which the GPIO is connected.
@@ -46,7 +52,7 @@
* (A fairly large value of 0.25 microseconds is set.)
*/
-#include "wait.c"
+#include "_wait.c"
#ifndef GPIO_INPUT_PIN_DELAY
# define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4)