diff options
| author | Damien George | 2014-03-25 14:18:18 +0000 |
|---|---|---|
| committer | Damien George | 2014-03-25 14:18:18 +0000 |
| commit | caac542b235003f7b79d7aa23eaebe8f2c772508 (patch) | |
| tree | f70b42312f091b10c9e3d871fe1a70d573e7cba4 /stmhal | |
| parent | 1dfde891e3e26543da6d42215da6a23c32b0a8bc (diff) | |
Proper support for registering builtin modules in ROM.
Comes with some refactoring of code and renaming of files. All modules
are now named mod*.[ch].
Diffstat (limited to 'stmhal')
| -rw-r--r-- | stmhal/Makefile | 6 | ||||
| -rw-r--r-- | stmhal/main.c | 13 | ||||
| -rw-r--r-- | stmhal/modos.c (renamed from stmhal/osmodule.c) | 2 | ||||
| -rw-r--r-- | stmhal/modos.h (renamed from stmhal/osmodule.h) | 0 | ||||
| -rw-r--r-- | stmhal/modpyb.c (renamed from stmhal/pybmodule.c) | 2 | ||||
| -rw-r--r-- | stmhal/modpyb.h (renamed from stmhal/pybmodule.h) | 0 | ||||
| -rw-r--r-- | stmhal/modtime.c (renamed from stmhal/timemodule.c) | 2 | ||||
| -rw-r--r-- | stmhal/modtime.h (renamed from stmhal/timemodule.h) | 0 | ||||
| -rw-r--r-- | stmhal/mpconfigport.h | 9 |
9 files changed, 16 insertions, 18 deletions
diff --git a/stmhal/Makefile b/stmhal/Makefile index 7896849c6..1c9ea5531 100644 --- a/stmhal/Makefile +++ b/stmhal/Makefile @@ -74,9 +74,9 @@ SRC_C = \ pyexec.c \ help.c \ input.c \ - pybmodule.c \ - osmodule.c \ - timemodule.c \ + modpyb.c \ + modos.c \ + modtime.c \ import.c \ lexerfatfs.c \ gpio.c \ diff --git a/stmhal/main.c b/stmhal/main.c index a231ca250..ab96dcdef 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -21,9 +21,6 @@ #include "gc.h" #include "gccollect.h" #include "pyexec.h" -#include "pybmodule.h" -#include "osmodule.h" -#include "timemodule.h" #include "usart.h" #include "led.h" #include "exti.h" @@ -110,6 +107,7 @@ static const char fresh_boot_py[] = "# boot.py -- run on boot-up\n" "# can run arbitrary Python, but best to keep it minimal\n" "\n" +"import pyb\n" "pyb.source_dir('/src')\n" "pyb.main('main.py')\n" "#pyb.usb_usr('VCP')\n" @@ -246,15 +244,6 @@ soft_reset: pin_map_init(); - // we pre-import the pyb module - // 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 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; #if MICROPY_HW_HAS_SWITCH diff --git a/stmhal/osmodule.c b/stmhal/modos.c index 7f32fe674..0ec9fcbb9 100644 --- a/stmhal/osmodule.c +++ b/stmhal/modos.c @@ -10,7 +10,7 @@ #include "rng.h" #include "storage.h" #include "ff.h" -#include "osmodule.h" +#include "modos.h" #if _USE_LFN static char lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ diff --git a/stmhal/osmodule.h b/stmhal/modos.h index e3c13f756..e3c13f756 100644 --- a/stmhal/osmodule.h +++ b/stmhal/modos.h diff --git a/stmhal/pybmodule.c b/stmhal/modpyb.c index 5e735903e..c7bab3666 100644 --- a/stmhal/pybmodule.c +++ b/stmhal/modpyb.c @@ -30,7 +30,7 @@ #include "usb.h" #include "i2c.h" #endif -#include "pybmodule.h" +#include "modpyb.h" #include "ff.h" // get lots of info about the board diff --git a/stmhal/pybmodule.h b/stmhal/modpyb.h index 955aaefe3..955aaefe3 100644 --- a/stmhal/pybmodule.h +++ b/stmhal/modpyb.h diff --git a/stmhal/timemodule.c b/stmhal/modtime.c index b2dac6a54..4786c85c7 100644 --- a/stmhal/timemodule.c +++ b/stmhal/modtime.c @@ -6,7 +6,7 @@ #include "qstr.h" #include "obj.h" #include "map.h" -#include "timemodule.h" +#include "modtime.h" STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { #if MICROPY_ENABLE_FLOAT diff --git a/stmhal/timemodule.h b/stmhal/modtime.h index 70e35b1fd..70e35b1fd 100644 --- a/stmhal/timemodule.h +++ b/stmhal/modtime.h diff --git a/stmhal/mpconfigport.h b/stmhal/mpconfigport.h index edaee6315..b187c43bb 100644 --- a/stmhal/mpconfigport.h +++ b/stmhal/mpconfigport.h @@ -27,6 +27,15 @@ extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; { MP_QSTR_input, (mp_obj_t)&mp_builtin_input_obj }, \ { MP_QSTR_open, (mp_obj_t)&mp_builtin_open_obj }, +// extra built in modules to add to the list of known ones +extern const struct _mp_obj_module_t os_module; +extern const struct _mp_obj_module_t pyb_module; +extern const struct _mp_obj_module_t time_module; +#define MICROPY_EXTRA_BUILTIN_MODULES \ + { MP_QSTR_os, (mp_obj_t)&os_module }, \ + { MP_QSTR_pyb, (mp_obj_t)&pyb_module }, \ + { MP_QSTR_time, (mp_obj_t)&time_module }, \ + // type definitions for the specific machine #define BYTES_PER_WORD (4) |
