File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -74,6 +74,7 @@ SRC_C = \
7474 pyexec.c \
7575 pybmodule.c \
7676 osmodule.c \
77+ timemodule.c \
7778 import.c \
7879 lexerfatfs.c \
7980 gpio.c \
Original file line number Diff line number Diff line change 2323#include "pyexec.h"
2424#include "pybmodule.h"
2525#include "osmodule.h"
26+ #include "timemodule.h"
2627#include "usart.h"
2728#include "led.h"
2829#include "exti.h"
@@ -276,9 +277,10 @@ int main(void) {
276277 // probably shouldn't do this, so we are compatible with CPython
277278 rt_store_name (MP_QSTR_pyb , (mp_obj_t )& pyb_module );
278279
279- // pre-import the os module
280+ // pre-import the os and time modules
280281 // TODO don't do this! (need a way of registering builtin modules...)
281282 rt_store_name (MP_QSTR_os , (mp_obj_t )& os_module );
283+ rt_store_name (MP_QSTR_time , (mp_obj_t )& time_module );
282284
283285 // check if user switch held (initiates reset of filesystem)
284286 bool reset_filesystem = false;
Original file line number Diff line number Diff line change @@ -66,3 +66,7 @@ Q(rmdir)
6666Q (unlink )
6767Q (sep )
6868Q (urandom )
69+
70+ // for time module
71+ Q (time )
72+ Q (sleep )
Original file line number Diff line number Diff line change 1+ #include <stm32f4xx_hal.h>
2+
3+ #include "nlr.h"
4+ #include "misc.h"
5+ #include "mpconfig.h"
6+ #include "qstr.h"
7+ #include "obj.h"
8+ #include "map.h"
9+ #include "timemodule.h"
10+
11+ STATIC mp_obj_t time_sleep (mp_obj_t seconds_o ) {
12+ #if MICROPY_ENABLE_FLOAT
13+ if (MP_OBJ_IS_INT (seconds_o )) {
14+ #endif
15+ HAL_Delay (1000 * mp_obj_get_int (seconds_o ));
16+ #if MICROPY_ENABLE_FLOAT
17+ } else {
18+ HAL_Delay ((uint32_t )(1000 * mp_obj_get_float (seconds_o )));
19+ }
20+ #endif
21+ return mp_const_none ;
22+ }
23+
24+ MP_DEFINE_CONST_FUN_OBJ_1 (time_sleep_obj , time_sleep );
25+
26+ STATIC const mp_map_elem_t time_module_globals_table [] = {
27+ { MP_OBJ_NEW_QSTR (MP_QSTR___name__ ), MP_OBJ_NEW_QSTR (MP_QSTR_time ) },
28+
29+ { MP_OBJ_NEW_QSTR (MP_QSTR_sleep ), (mp_obj_t )& time_sleep_obj },
30+ };
31+
32+ STATIC const mp_map_t time_module_globals = {
33+ .all_keys_are_qstrs = 1 ,
34+ .table_is_fixed_array = 1 ,
35+ .used = sizeof (time_module_globals_table ) / sizeof (mp_map_elem_t ),
36+ .alloc = sizeof (time_module_globals_table ) / sizeof (mp_map_elem_t ),
37+ .table = (mp_map_elem_t * )time_module_globals_table ,
38+ };
39+
40+ const mp_obj_module_t time_module = {
41+ .base = { & mp_type_module },
42+ .name = MP_QSTR_time ,
43+ .globals = (mp_map_t * )& time_module_globals ,
44+ };
Original file line number Diff line number Diff line change 1+ extern const mp_obj_module_t time_module ;
You can’t perform that action at this time.
0 commit comments