summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2017-11-01 15:31:46 -0400
committerGitHub <noreply@github.com>2017-11-01 15:31:46 -0400
commitdcede575fffb9c73d2340c64efc05bd898b86923 (patch)
treeb418f8ea2334604a2ec88611451b9a6075b236b2 /ports
parent3b179808224bceaf40ffd1da0a6295c2d0f3e970 (diff)
parenta8dae22ae9373c3d026a6b1bc953dec201c7185d (diff)
Merge pull request #394 from tannewt/neopixel_delay_fix
atmel-samd: Fix the neopixel delay method so it handles overflow better.
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/common-hal/neopixel_write/__init__.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/ports/atmel-samd/common-hal/neopixel_write/__init__.c b/ports/atmel-samd/common-hal/neopixel_write/__init__.c
index fbe7a2ff6..d9f7da6a8 100644
--- a/ports/atmel-samd/common-hal/neopixel_write/__init__.c
+++ b/ports/atmel-samd/common-hal/neopixel_write/__init__.c
@@ -37,8 +37,12 @@ static inline void delay_cycles(uint8_t cycles) {
uint32_t stop = start - cycles;
if (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