Merge branch 'master' into utime_module

This commit is contained in:
Romain Goyet
2018-11-15 14:37:11 +01:00
10 changed files with 61 additions and 20 deletions

View File

@@ -4,17 +4,28 @@ extern "C" {
#include "mphalport.h"
}
bool micropython_port_should_interrupt() {
void micropython_port_vm_hook_loop() {
/* This function is called very frequently by the MicroPython engine. We grab
* this opportunity to interrupt execution and/or refresh the display on
* platforms that need it. */
/* Doing too many things here slows down Python execution quite a lot. So we
* only do things once in a while and return as soon as possible otherwise. */
static int c = 0;
c++;
if (c%20000 != 0) {
return false;
c = (c + 1) % 20000;
if (c != 0) {
return;
}
c = 0;
Ion::Keyboard::State scan = Ion::Keyboard::scan();
if (scan.keyDown((Ion::Keyboard::Key)mp_interrupt_char)) {
/* Check if the user asked for an interruption from the keyboard */
if (micropython_port_should_interrupt()) {
mp_keyboard_interrupt();
return true;
}
return false;
}
bool micropython_port_should_interrupt() {
Ion::Keyboard::State scan = Ion::Keyboard::scan();
Ion::Keyboard::Key interruptKey = static_cast<Ion::Keyboard::Key>(mp_interrupt_char);
return scan.keyDown(interruptKey);
}

View File

@@ -6,8 +6,7 @@ extern "C" {
#endif
#include <stdbool.h>
/* should_interrupt effectively does something once every 20000 calls. It checks
* if a key is down to raise an interruption flag. */
void micropython_port_vm_hook_loop();
bool micropython_port_should_interrupt();
#ifdef __cplusplus

View File

@@ -90,7 +90,7 @@
// (This scheme won't work if we want to mix Thumb and normal ARM code.)
#define MICROPY_MAKE_POINTER_CALLABLE(p) (p)
#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt();
#define MICROPY_VM_HOOK_LOOP micropython_port_vm_hook_loop();
typedef intptr_t mp_int_t; // must be pointer size
typedef uintptr_t mp_uint_t; // must be pointer size