Commit d3116556 authored by Damien George's avatar Damien George
Browse files

stmhal: Add time module with sleep function.

parent ad7b84a7
......@@ -74,6 +74,7 @@ SRC_C = \
pyexec.c \
pybmodule.c \
osmodule.c \
timemodule.c \
import.c \
lexerfatfs.c \
gpio.c \
......
......@@ -23,6 +23,7 @@
#include "pyexec.h"
#include "pybmodule.h"
#include "osmodule.h"
#include "timemodule.h"
#include "usart.h"
#include "led.h"
#include "exti.h"
......@@ -276,9 +277,10 @@ soft_reset:
// probably shouldn't do this, so we are compatible with CPython
rt_store_name(MP_QSTR_pyb, (mp_obj_t)&pyb_module);
// pre-import the os module
// pre-import the os and time modules
// TODO don't do this! (need a way of registering builtin modules...)
rt_store_name(MP_QSTR_os, (mp_obj_t)&os_module);
rt_store_name(MP_QSTR_time, (mp_obj_t)&time_module);
// check if user switch held (initiates reset of filesystem)
bool reset_filesystem = false;
......
......@@ -66,3 +66,7 @@ Q(rmdir)
Q(unlink)
Q(sep)
Q(urandom)
// for time module
Q(time)
Q(sleep)
#include <stm32f4xx_hal.h>
#include "nlr.h"
#include "misc.h"
#include "mpconfig.h"
#include "qstr.h"
#include "obj.h"
#include "map.h"
#include "timemodule.h"
STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) {
#if MICROPY_ENABLE_FLOAT
if (MP_OBJ_IS_INT(seconds_o)) {
#endif
HAL_Delay(1000 * mp_obj_get_int(seconds_o));
#if MICROPY_ENABLE_FLOAT
} else {
HAL_Delay((uint32_t)(1000 * mp_obj_get_float(seconds_o)));
}
#endif
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep);
STATIC const mp_map_elem_t time_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_time) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sleep), (mp_obj_t)&time_sleep_obj },
};
STATIC const mp_map_t time_module_globals = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(time_module_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(time_module_globals_table) / sizeof(mp_map_elem_t),
.table = (mp_map_elem_t*)time_module_globals_table,
};
const mp_obj_module_t time_module = {
.base = { &mp_type_module },
.name = MP_QSTR_time,
.globals = (mp_map_t*)&time_module_globals,
};
extern const mp_obj_module_t time_module;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment