Skip to content

Commit

Permalink
Unify behaviour of wait on AVR (qmk#14025)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and nhongooi committed Dec 5, 2021
1 parent 973bae4 commit dab2025
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tmk_core/common/avr/_wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit dab2025

Please sign in to comment.