diff options
Diffstat (limited to 'platforms/avr/_wait.h')
-rw-r--r-- | platforms/avr/_wait.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/platforms/avr/_wait.h b/platforms/avr/_wait.h new file mode 100644 index 000000000..683db6ae5 --- /dev/null +++ b/platforms/avr/_wait.h | |||
@@ -0,0 +1,49 @@ | |||
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 <util/delay.h> | ||
19 | |||
20 | #define wait_ms(ms) \ | ||
21 | do { \ | ||
22 | if (__builtin_constant_p(ms)) { \ | ||
23 | _delay_ms(ms); \ | ||
24 | } else { \ | ||
25 | for (uint16_t i = ms; i > 0; i--) { \ | ||
26 | _delay_ms(1); \ | ||
27 | } \ | ||
28 | } \ | ||
29 | } while (0) | ||
30 | #define wait_us(us) \ | ||
31 | do { \ | ||
32 | if (__builtin_constant_p(us)) { \ | ||
33 | _delay_us(us); \ | ||
34 | } else { \ | ||
35 | for (uint16_t i = us; i > 0; i--) { \ | ||
36 | _delay_us(1); \ | ||
37 | } \ | ||
38 | } \ | ||
39 | } while (0) | ||
40 | #define wait_cpuclock(n) __builtin_avr_delay_cycles(n) | ||
41 | #define CPU_CLOCK F_CPU | ||
42 | |||
43 | /* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. | ||
44 | * But here's more margin to make it two clocks. */ | ||
45 | #ifndef GPIO_INPUT_PIN_DELAY | ||
46 | # define GPIO_INPUT_PIN_DELAY 2 | ||
47 | #endif | ||
48 | |||
49 | #define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) | ||