diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 368818d0c..162be2380 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -257,7 +257,7 @@ void AppsContainer::displayExamModePopUp(bool activate) { void AppsContainer::shutdownDueToLowBattery() { while (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) { m_emptyBatteryWindow.redraw(true); - Ion::msleep(3000); + Ion::mssleep(3000); Ion::Power::suspend(); } window()->redraw(true); diff --git a/build/toolchain.emscripten.mak b/build/toolchain.emscripten.mak index baabdca9b..de1cc514c 100644 --- a/build/toolchain.emscripten.mak +++ b/build/toolchain.emscripten.mak @@ -58,6 +58,8 @@ __ZThn32_N4Code17ConsoleController9inputTextEPKc \ __ZThn36_N4Code17ConsoleController9inputTextEPKc \ __ZZN4Code14MenuControllerC1EP9ResponderPNS_11ScriptStoreEP19ButtonRowControllerbEN3__08__invokeEPvS8_ \ __ZZN4Code14MenuControllerC1EP9ResponderPNS_11ScriptStoreEP19ButtonRowControllerbENK3__0clEPvS8_ \ +_delay_ms \ +_delay_us \ _do_load \ _do_load_from_lexer \ _fun_bc_call \ @@ -71,7 +73,9 @@ _mp_call_function_n_kw \ _mp_execute_bytecode \ _mp_hal_input \ _mp_import_name \ -_mp_parse_compile_execute +_mp_parse_compile_execute \ +_mssleep \ +_ussleep EMTERPRETIFY_WHITELIST = $(foreach sym,$(EMSCRIPTEN_ASYNC_SYMBOLS),"$(sym)",)END EMFLAGS = -s PRECISE_F32=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s EMTERPRETIFY_WHITELIST='[$(EMTERPRETIFY_WHITELIST:,END=)]' diff --git a/ion/include/ion/timing.h b/ion/include/ion/timing.h index 60d32d782..a6c6565f0 100644 --- a/ion/include/ion/timing.h +++ b/ion/include/ion/timing.h @@ -11,8 +11,8 @@ namespace Ion { EXTERNC uint32_t millis(); EXTERNC uint32_t micros(); -EXTERNC void msleep(long ms); -EXTERNC void usleep(long us); +EXTERNC void mssleep(long ms); +EXTERNC void ussleep(long us); #ifdef __cplusplus } diff --git a/ion/src/blackbox/ion.cpp b/ion/src/blackbox/ion.cpp index d946ac29b..ba42d685a 100644 --- a/ion/src/blackbox/ion.cpp +++ b/ion/src/blackbox/ion.cpp @@ -1,5 +1,5 @@ #include #include -void Ion::msleep(long ms) { +void Ion::mssleep(long ms) { } diff --git a/ion/src/device/backlight.cpp b/ion/src/device/backlight.cpp index ad71b85d1..22bb30d39 100644 --- a/ion/src/device/backlight.cpp +++ b/ion/src/device/backlight.cpp @@ -45,12 +45,12 @@ void shutdown() { void suspend() { GPIOC.ODR()->set(6, false); - msleep(3); // Might not need to be blocking + mssleep(3); // Might not need to be blocking } void resume() { GPIOC.ODR()->set(6, true); - usleep(50); + ussleep(50); uint8_t level = sLevel; sLevel = 0xF; setLevel(level); @@ -74,9 +74,9 @@ uint8_t level() { void sendPulses(int n) { for (int i=0; iset(6, false); - usleep(20); + ussleep(20); GPIOC.ODR()->set(6, true); - usleep(20); + ussleep(20); } } diff --git a/ion/src/device/bench/command/suspend.cpp b/ion/src/device/bench/command/suspend.cpp index 27666921d..63dd53543 100644 --- a/ion/src/device/bench/command/suspend.cpp +++ b/ion/src/device/bench/command/suspend.cpp @@ -12,7 +12,7 @@ void Suspend(const char * input) { return; } reply(sOK); - Ion::msleep(100); + Ion::mssleep(100); Ion::Power::suspend(); } diff --git a/ion/src/device/console.cpp b/ion/src/device/console.cpp index 04d824589..05d48e7e9 100644 --- a/ion/src/device/console.cpp +++ b/ion/src/device/console.cpp @@ -63,7 +63,7 @@ void shutdown() { bool peerConnected() { RxPin.group().PUPDR()->setPull(RxPin.pin(), GPIO::PUPDR::Pull::Down); RxPin.group().MODER()->setMode(RxPin.pin(), GPIO::MODER::Mode::Input); - msleep(1); + mssleep(1); bool result = RxPin.group().IDR()->get(RxPin.pin()); RxPin.group().PUPDR()->setPull(RxPin.pin(), GPIO::PUPDR::Pull::None); RxPin.group().MODER()->setMode(RxPin.pin(), GPIO::MODER::Mode::AlternateFunction); diff --git a/ion/src/device/device.cpp b/ion/src/device/device.cpp index a140a8abc..0ccdca626 100644 --- a/ion/src/device/device.cpp +++ b/ion/src/device/device.cpp @@ -24,16 +24,16 @@ extern "C" { // Public Ion methods -/* TODO: The delay methods 'msleep' and 'usleep' are currently dependent on the +/* TODO: The delay methods 'mssleep' and 'ussleep' are currently dependent on the * optimizations chosen by the compiler. To prevent that and to gain in * precision, we could use the controller cycle counter (Systick). */ -void Ion::msleep(long ms) { +void Ion::mssleep(long ms) { for (volatile long i=0; i<8852*ms; i++) { __asm volatile("nop"); } } -void Ion::usleep(long us) { +void Ion::ussleep(long us) { for (volatile long i=0; i<9*us; i++) { __asm volatile("nop"); } diff --git a/ion/src/device/display.cpp b/ion/src/device/display.cpp index 717231773..65861a604 100644 --- a/ion/src/device/display.cpp +++ b/ion/src/device/display.cpp @@ -162,7 +162,7 @@ void initGPIO() { TearingEffectPin.group().MODER()->setMode(TearingEffectPin.pin(), GPIO::MODER::Mode::Input); TearingEffectPin.group().PUPDR()->setPull(TearingEffectPin.pin(), GPIO::PUPDR::Pull::None); - msleep(120); + mssleep(120); } @@ -247,10 +247,10 @@ void shutdownFSMC() { void initPanel() { send_command(Command::Reset); - msleep(5); + mssleep(5); send_command(Command::SleepOut); - msleep(5); + mssleep(5); send_command(Command::PixelFormatSet, 0x05); send_command(Command::TearingEffectLineOn, 0x00); @@ -262,7 +262,7 @@ void initPanel() { void shutdownPanel() { send_command(Command::DisplayOff); send_command(Command::SleepIn); - msleep(5); + mssleep(5); } void setDrawingArea(KDRect r, Orientation o) { diff --git a/ion/src/device/events.cpp b/ion/src/device/events.cpp index 7f1443566..18a63aab1 100644 --- a/ion/src/device/events.cpp +++ b/ion/src/device/events.cpp @@ -6,11 +6,11 @@ namespace Events { static bool sleepWithTimeout(int duration, int * timeout) { if (*timeout >= duration) { - msleep(duration); + mssleep(duration); *timeout -= duration; return false; } else { - msleep(*timeout); + mssleep(*timeout); *timeout = 0; return true; } diff --git a/ion/src/device/keyboard.h b/ion/src/device/keyboard.h index 9d9aa388a..e4495b8fd 100644 --- a/ion/src/device/keyboard.h +++ b/ion/src/device/keyboard.h @@ -56,7 +56,7 @@ inline void activateRow(uint8_t row) { Device::RowGPIO.ODR()->setBitRange(9, 0, rowState); // TODO: 100 us seems to work, but wasn't really calculated - usleep(100); + ussleep(100); } inline bool columnIsActive(uint8_t column) { diff --git a/ion/src/device/power.cpp b/ion/src/device/power.cpp index 021d75cc6..860b76480 100644 --- a/ion/src/device/power.cpp +++ b/ion/src/device/power.cpp @@ -29,7 +29,7 @@ void Ion::Power::suspend(bool checkIfPowerKeyReleased) { /* Update LEDS * if the standby mode was stopped due to a "stop charging" event, we wait * a while to be sure that the plug state of the USB is up-to-date. */ - msleep(200); + mssleep(200); //Ion::LED::setCharging(Ion::USB::isPlugged(), Ion::Battery::isCharging()); #endif diff --git a/ion/src/emscripten/main.cpp b/ion/src/emscripten/main.cpp index c753d78af..09f840e87 100644 --- a/ion/src/emscripten/main.cpp +++ b/ion/src/emscripten/main.cpp @@ -2,6 +2,7 @@ #include "display.h" #include "events_keyboard.h" #include "../../../apps/global_preferences.h" +#include extern "C" { const char * IonSoftwareVersion(); @@ -19,5 +20,10 @@ int main(int argc, char * argv[]) { return 0; } -void Ion::msleep(long ms) { +void Ion::mssleep(long ms) { + emscripten_sleep(ms); +} + +void Ion::ussleep(long us) { + emscripten_sleep(us/1000); } diff --git a/ion/src/simulator/init.cpp b/ion/src/simulator/init.cpp index d20630b14..61650c045 100644 --- a/ion/src/simulator/init.cpp +++ b/ion/src/simulator/init.cpp @@ -104,7 +104,7 @@ Ion::Events::Event Ion::Events::getEvent(int * timeout) { #include -void Ion::msleep(long ms) { +void Ion::mssleep(long ms) { auto start = std::chrono::high_resolution_clock::now(); while (true) { sDisplay->redraw(); diff --git a/python/src/extmod/modutime.c b/python/src/extmod/modutime.c index 829ba0cd5..254ff3071 100644 --- a/python/src/extmod/modutime.c +++ b/python/src/extmod/modutime.c @@ -35,14 +35,14 @@ void delay_ms(mp_uint_t delay) { uint32_t start = millis(); while (millis() - start < delay && !micropython_port_should_interrupt(true)) { - msleep(1); + mssleep(1); } } void delay_us(mp_uint_t delay) { uint32_t start = micros(); while (micros() - start < delay && !micropython_port_should_interrupt(false)) { - usleep(1); + ussleep(1); } } diff --git a/quiz/src/runner.cpp b/quiz/src/runner.cpp index b3dbd1a32..be0a08c59 100644 --- a/quiz/src/runner.cpp +++ b/quiz/src/runner.cpp @@ -39,7 +39,7 @@ static inline void ion_main_inner() { quiz_print("ALL TESTS FINISHED"); #if !QUIZ_USE_CONSOLE while (1) { - Ion::msleep(1000); + Ion::mssleep(1000); } #endif } @@ -59,7 +59,7 @@ void ion_main(int argc, char * argv[]) { quiz_assert(false); #if !QUIZ_USE_CONSOLE while (1) { - Ion::msleep(1000); + Ion::mssleep(1000); } #endif }