diff --git a/keywords.txt b/keywords.txt index f5092e5..7a9038f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -28,6 +28,7 @@ buttonsState KEYWORD2 clear KEYWORD2 collide KEYWORD2 cpuLoad KEYWORD2 +delayShort KEYWORD2 digitalWriteRGB KEYWORD2 display KEYWORD2 displayOff KEYWORD2 diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index 506823b..b96e2d1 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -48,7 +48,7 @@ void Arduboy2Base::begin() // wait for all buttons to be released do { - delay(50); + delayShort(50); } while (buttonsState()); } @@ -77,7 +77,7 @@ void Arduboy2Base::systemButtons() digitalWriteRGB(BLUE_LED, RGB_ON); // turn on blue LED sysCtrlSound(UP_BUTTON + B_BUTTON, GREEN_LED, 0xff); sysCtrlSound(DOWN_BUTTON + B_BUTTON, RED_LED, 0); - delay(200); + delayShort(200); } digitalWriteRGB(BLUE_LED, RGB_OFF); // turn off blue LED @@ -87,10 +87,10 @@ void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal) { if (pressed(buttons)) { digitalWriteRGB(BLUE_LED, RGB_OFF); // turn off blue LED - delay(200); + delayShort(200); digitalWriteRGB(led, RGB_ON); // turn on "acknowledge" LED EEPROM.update(EEPROM_AUDIO_ON_OFF, eeVal); - delay(500); + delayShort(500); digitalWriteRGB(led, RGB_OFF); // turn off "acknowledge" LED while (pressed(buttons)) { } // Wait for button release @@ -161,15 +161,15 @@ void Arduboy2Base::bootLogoShell(void (*drawLogo)(int16_t)) clear(); (*drawLogo)(y); // call the function that actually draws the logo display(); - delay(27); + delayShort(27); // longer delay post boot, we put it inside the loop to // save the flash calling clear/delay again outside the loop if (y==-16) { - delay(250); + delayShort(250); } } - delay(700); + delayShort(700); digitalWriteRGB(BLUE_LED, RGB_OFF); bootLogoExtra(); @@ -1087,15 +1087,15 @@ void Arduboy2::bootLogoText() cursor_y = y; print("ARDUBOY"); display(); - delay(27); + delayShort(27); // longer delay post boot, we put it inside the loop to // save the flash calling clear/delay again outside the loop if (y==-16) { - delay(250); + delayShort(250); } } - delay(750); + delayShort(700); digitalWriteRGB(BLUE_LED, RGB_OFF); textSize = 1; @@ -1127,7 +1127,7 @@ void Arduboy2::bootLogoExtra() while (i < EEPROM_UNIT_NAME + ARDUBOY_UNIT_NAME_LEN); display(); - delay(1000); + delayShort(1000); } } diff --git a/src/Arduboy2Core.cpp b/src/Arduboy2Core.cpp index b9c6a82..44730f8 100644 --- a/src/Arduboy2Core.cpp +++ b/src/Arduboy2Core.cpp @@ -194,9 +194,9 @@ void Arduboy2Core::bootPins() void Arduboy2Core::bootOLED() { // reset the display - delay(5); // reset pin should be low here. let it stay low a while + delayShort(5); // reset pin should be low here. let it stay low a while bitSet(RST_PORT, RST_BIT); // set high to come out of reset - delay(5); // wait a while + delayShort(5); // wait a while // select the display (permanently, since nothing else is using SPI) bitClear(CS_PORT, CS_BIT); @@ -281,7 +281,7 @@ void Arduboy2Core::displayOff() SPItransfer(0xAE); // display off SPItransfer(0x8D); // charge pump: SPItransfer(0x10); // disable - delay(250); + delayShort(250); bitClear(RST_PORT, RST_BIT); // set display reset pin low (reset state) } @@ -469,3 +469,10 @@ uint8_t Arduboy2Core::buttonsState() return buttons; } + +// delay in ms with 16 bit duration +void Arduboy2Core::delayShort(uint16_t ms) +{ + delay((unsigned long) ms); +} + diff --git a/src/Arduboy2Core.h b/src/Arduboy2Core.h index 944c7aa..324ae15 100644 --- a/src/Arduboy2Core.h +++ b/src/Arduboy2Core.h @@ -676,6 +676,19 @@ class Arduboy2Core */ void static safeMode(); + /** \brief + * Delay for the number of milliseconds, specified as a 16 bit value. + * + * \param ms The delay in milliseconds. + * + * \details + * This function works the same as the Arduino `delay()` function except + * the provided value is 16 bits long, so the maximum delay allowed is + * 65535 milliseconds (about 65.5 seconds). Using this function instead + * of Arduino `delay()` will save a few bytes of code. + */ + void static delayShort(uint16_t ms) __attribute__ ((noinline)); + protected: // internals void static setCPUSpeed8MHz();