Skip to content

Commit c9c60d2

Browse files
authored
add wait_cpuclock() macro for AVR and CPU_CLOCK macro (#12755)
1 parent c4dbf4b commit c9c60d2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tmk_core/common/avr/_wait.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@
3737
} \
3838
} \
3939
} while (0)
40+
#define wait_cpuclock(n) __builtin_avr_delay_cycles(n)
41+
#define CPU_CLOCK F_CPU
4042

4143
/* The AVR series GPIOs have a one clock read delay for changes in the digital input signal.
4244
* But here's more margin to make it two clocks. */
4345
#ifndef GPIO_INPUT_PIN_DELAY
4446
# define GPIO_INPUT_PIN_DELAY 2
4547
#endif
4648

47-
#define waitInputPinDelay() __builtin_avr_delay_cycles(GPIO_INPUT_PIN_DELAY)
49+
#define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)

tmk_core/common/chibios/_wait.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ void wait_us(uint16_t duration);
4141
} while (0)
4242
#endif
4343

44+
#include "_wait.c"
45+
46+
#define CPU_CLOCK STM32_SYSCLK
47+
4448
/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
4549
* to which the GPIO is connected.
4650
* The connected buses differ depending on the various series of MCUs.
@@ -51,11 +55,8 @@ void wait_us(uint16_t duration);
5155
* If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used.
5256
* (A fairly large value of 0.25 microseconds is set.)
5357
*/
54-
55-
#include "_wait.c"
56-
5758
#ifndef GPIO_INPUT_PIN_DELAY
58-
# define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4)
59+
# define GPIO_INPUT_PIN_DELAY (CPU_CLOCK / 1000000L / 4)
5960
#endif
6061

6162
#define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)

0 commit comments

Comments
 (0)