[ion] fix sleep functions in emscripten build

This commit is contained in:
Damien Nicolet
2018-11-09 01:27:47 +01:00
parent f93bf97182
commit 9b818bd963
16 changed files with 38 additions and 28 deletions

View File

@@ -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);

View File

@@ -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=)]'

View File

@@ -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
}

View File

@@ -1,5 +1,5 @@
#include <stdint.h>
#include <ion.h>
void Ion::msleep(long ms) {
void Ion::mssleep(long ms) {
}

View File

@@ -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; i<n; i++) {
GPIOC.ODR()->set(6, false);
usleep(20);
ussleep(20);
GPIOC.ODR()->set(6, true);
usleep(20);
ussleep(20);
}
}

View File

@@ -12,7 +12,7 @@ void Suspend(const char * input) {
return;
}
reply(sOK);
Ion::msleep(100);
Ion::mssleep(100);
Ion::Power::suspend();
}

View File

@@ -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);

View File

@@ -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");
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -2,6 +2,7 @@
#include "display.h"
#include "events_keyboard.h"
#include "../../../apps/global_preferences.h"
#include <emscripten.h>
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);
}

View File

@@ -104,7 +104,7 @@ Ion::Events::Event Ion::Events::getEvent(int * timeout) {
#include <chrono>
void Ion::msleep(long ms) {
void Ion::mssleep(long ms) {
auto start = std::chrono::high_resolution_clock::now();
while (true) {
sDisplay->redraw();

View File

@@ -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);
}
}

View File

@@ -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
}