Skip to content

Commit

Permalink
atmel-samd: Enable -Os for SAMD51 and update neopixel accordingly.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannewt committed Nov 7, 2017
1 parent e2867eb commit a8ee001
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CFLAGS = -Os -DNDEBUG
endif

ifeq ($(CHIP_FAMILY), samd51)
CFLAGS = -O2 -DNDEBUG
CFLAGS = -Os -DNDEBUG
endif

#Debugging/Optimization
Expand Down
31 changes: 15 additions & 16 deletions ports/atmel-samd/common-hal/neopixel_write/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@
#include "tick.h"

#ifdef SAMD51
static inline void delay_cycles(uint8_t cycles) {
uint32_t start = SysTick->VAL;
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) {}
// This magical macro makes sure the delay isn't optimized out and is the
// minimal three instructions.
#define delay_cycles(cycles) \
{ \
uint32_t t; \
asm volatile ( \
"movs %[t], %[c]\n\t" \
"loop%=:\n\t" \
"subs %[t], #1\n\t" \
"bne.n loop%=" : [t] "=r"(t) : [c] "I" (cycles)); \
}
}
#endif

uint64_t next_start_tick_ms = 0;
Expand Down Expand Up @@ -88,7 +87,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(18);
delay_cycles(3);
#endif
if(p & bitMask) {
// This is the high delay unique to a one bit.
Expand All @@ -97,7 +96,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop; nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(25);
delay_cycles(11);
#endif
*clr = pinMask;
} else {
Expand All @@ -108,7 +107,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(25);
delay_cycles(3);
#endif
}
if((bitMask >>= 1) != 0) {
Expand All @@ -119,7 +118,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
asm("nop; nop; nop; nop; nop;");
#endif
#ifdef SAMD51
delay_cycles(44);
delay_cycles(20);
#endif
} else {
if(ptr >= end) break;
Expand All @@ -130,7 +129,7 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout,
// above operations take.
// For the SK6812 its 0.6us +- 0.15us
#ifdef SAMD51
delay_cycles(50);
delay_cycles(15);
#endif
}
}
Expand Down

0 comments on commit a8ee001

Please sign in to comment.