diff options
Diffstat (limited to 'platforms/chibios/_wait.h')
| -rw-r--r-- | platforms/chibios/_wait.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/platforms/chibios/_wait.h b/platforms/chibios/_wait.h new file mode 100644 index 000000000..2f36c64a2 --- /dev/null +++ b/platforms/chibios/_wait.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | /* Copyright 2021 QMK | ||
| 2 | * | ||
| 3 | * This program is free software: you can redistribute it and/or modify | ||
| 4 | * it under the terms of the GNU General Public License as published by | ||
| 5 | * the Free Software Foundation, either version 3 of the License, or | ||
| 6 | * (at your option) any later version. | ||
| 7 | * | ||
| 8 | * This program is distributed in the hope that it will be useful, | ||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 11 | * GNU General Public License for more details. | ||
| 12 | * | ||
| 13 | * You should have received a copy of the GNU General Public License | ||
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 15 | */ | ||
| 16 | #pragma once | ||
| 17 | |||
| 18 | #include <ch.h> | ||
| 19 | #include <hal.h> | ||
| 20 | |||
| 21 | /* chThdSleepX of zero maps to infinite - so we map to a tiny delay to still yield */ | ||
| 22 | #define wait_ms(ms) \ | ||
| 23 | do { \ | ||
| 24 | if (ms != 0) { \ | ||
| 25 | chThdSleepMilliseconds(ms); \ | ||
| 26 | } else { \ | ||
| 27 | chThdSleepMicroseconds(1); \ | ||
| 28 | } \ | ||
| 29 | } while (0) | ||
| 30 | |||
| 31 | #ifdef WAIT_US_TIMER | ||
| 32 | void wait_us(uint16_t duration); | ||
| 33 | #else | ||
| 34 | # define wait_us(us) \ | ||
| 35 | do { \ | ||
| 36 | if (us != 0) { \ | ||
| 37 | chThdSleepMicroseconds(us); \ | ||
| 38 | } else { \ | ||
| 39 | chThdSleepMicroseconds(1); \ | ||
| 40 | } \ | ||
| 41 | } while (0) | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #include "_wait.c" | ||
| 45 | |||
| 46 | /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus | ||
| 47 | * to which the GPIO is connected. | ||
| 48 | * The connected buses differ depending on the various series of MCUs. | ||
| 49 | * And since the instruction execution clock of the CPU and the bus clock of GPIO are different, | ||
| 50 | * there is a delay of several clocks to read the change of the input signal. | ||
| 51 | * | ||
| 52 | * Define this delay with the GPIO_INPUT_PIN_DELAY macro. | ||
| 53 | * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used. | ||
| 54 | * (A fairly large value of 0.25 microseconds is set.) | ||
| 55 | */ | ||
| 56 | #ifndef GPIO_INPUT_PIN_DELAY | ||
| 57 | # define GPIO_INPUT_PIN_DELAY (CPU_CLOCK / 1000000L / 4) | ||
| 58 | #endif | ||
| 59 | |||
| 60 | #define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) | ||
