Merge pull request #394 from tannewt/neopixel_delay_fix

atmel-samd: Fix the neopixel delay method so it handles overflow better.
This commit is contained in:
Dan Halbert 2017-11-01 15:31:46 -04:00 committed by GitHub
commit dcede575ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -37,8 +37,12 @@ static inline void delay_cycles(uint8_t cycles) {
uint32_t stop = start - cycles; uint32_t stop = start - cycles;
if (start < cycles) { if (start < cycles) {
stop = 0xffffff + start - cycles; stop = 0xffffff + start - cycles;
while (SysTick->VAL < start || SysTick->VAL > stop) {}
} else {
// Make sure the systick value is between start and stop in case it
// wraps around before we read its value less than stop.
while (SysTick->VAL > stop && SysTick->VAL <= start) {}
} }
while (SysTick->VAL > stop) {}
} }
#endif #endif