Skip to content

Commit

Permalink
Fixes to the delay function.
Browse files Browse the repository at this point in the history
  • Loading branch information
slav-at-attachix committed Oct 25, 2017
1 parent e54234c commit 4a99e23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 12 additions & 3 deletions Sming/SmingCore/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@ void delay(uint32_t time)
int quotient = time / MAX_SAFE_DELAY;
int remainder = time % MAX_SAFE_DELAY;
for(int i=0, max = quotient + 1; i < max ; i++) {
int microseconds = MAX_SAFE_DELAY * 1000;
if(i == quotient) {
os_delay_us((uint16_t)(remainder * 1000));
microseconds = remainder * 1000;
}
else {
os_delay_us((uint16_t)(MAX_SAFE_DELAY * 1000));

int q = microseconds / 0xFFFF;
int r = microseconds % 0xFFFF;
for(int j=0, m=q + 1; j < m; j++ ) {
if(j == q) {
os_delay_us(r);
}
else {
os_delay_us(0xFFFF);
}
}

system_soft_wdt_feed ();
Expand Down
4 changes: 2 additions & 2 deletions samples/LED_WS2812/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ void init()
while (true) {
char buffer1[] = "\x40\x00\x00\x00\x40\x00\x00\x00\x40";
ws2812_writergb(LED_PIN, buffer1, sizeof(buffer1));
os_delay_us(500000);
delay(50);

//We need to feed WDT.
WDT.alive();

char buffer2[] = "\x00\x40\x40\x40\x00\x40\x40\x40\x00";
ws2812_writergb(LED_PIN, buffer2, sizeof(buffer2));
os_delay_us(500000);
delay(50);
}
}

0 comments on commit 4a99e23

Please sign in to comment.