[code] time module

This commit is contained in:
Damien Nicolet
2018-11-03 16:07:01 +01:00
parent 940270e78a
commit 79bfc7f112
14 changed files with 227 additions and 8 deletions

View File

@@ -24,6 +24,16 @@ Q(draw_string)
Q(get_pixel)
Q(set_pixel)
// utime QSTRs
Q(time)
Q(sleep)
Q(sleep_ms)
Q(sleep_us)
Q(ticks_ms)
Q(ticks_us)
Q(ticks_add)
Q(ticks_diff)
// MicroPython QSTRs
Q()
Q(*)

View File

@@ -4,16 +4,17 @@ extern "C" {
#include "mphalport.h"
}
void micropython_port_should_interrupt() {
bool micropython_port_should_interrupt() {
static int c = 0;
c++;
if (c%20000 != 0) {
return;
return false;
}
c = 0;
Ion::Keyboard::State scan = Ion::Keyboard::scan();
if (scan.keyDown((Ion::Keyboard::Key)mp_interrupt_char)) {
mp_keyboard_interrupt();
return true;
}
return false;
}

View File

@@ -4,10 +4,11 @@
#ifdef __cplusplus
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_should_interrupt();
bool micropython_port_should_interrupt();
#ifdef __cplusplus
}

View File

@@ -107,6 +107,8 @@ typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
extern const struct _mp_obj_module_t kandinsky_module;
extern const struct _mp_obj_module_t mp_module_utime;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_ROM_QSTR(MP_QSTR_kandinsky), MP_ROM_PTR(&kandinsky_module) }
{ MP_ROM_QSTR(MP_QSTR_kandinsky), MP_ROM_PTR(&kandinsky_module) }, \
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&mp_module_utime) },