diff options
Diffstat (limited to 'stmhal/main.c')
-rw-r--r-- | stmhal/main.c | 107 |
1 files changed, 45 insertions, 62 deletions
diff --git a/stmhal/main.c b/stmhal/main.c index 9d88206978..1da7a9a649 100644 --- a/stmhal/main.c +++ b/stmhal/main.c @@ -21,22 +21,21 @@ #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" #include "usrsw.h" #include "usb.h" -#include "rng.h" #include "rtc.h" #include "storage.h" #include "sdcard.h" #include "ff.h" #include "lcd.h" +#include "rng.h" +#include "i2c.h" #include "accel.h" #include "servo.h" +#include "dac.h" #include "pin.h" #if 0 #include "timer.h" @@ -109,6 +108,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" @@ -121,34 +121,6 @@ static const char fresh_main_py[] = "# main.py -- put your code here!\n" ; -static const char *help_text = -"Welcome to Micro Python!\n\n" -"This is a *very* early version of Micro Python and has minimal functionality.\n\n" -"Specific commands for the board:\n" -" pyb.info() -- print some general information\n" -" pyb.gc() -- run the garbage collector\n" -" pyb.repl_info(<val>) -- enable/disable printing of info after each command\n" -" pyb.delay(<n>) -- wait for n milliseconds\n" -" pyb.udelay(<n>) -- wait for n microseconds\n" -" pyb.Led(<n>) -- create Led object for LED n (n=1,2)\n" -" Led methods: on(), off()\n" -" pyb.Servo(<n>) -- create Servo object for servo n (n=1,2,3,4)\n" -" Servo methods: angle(<x>)\n" -" pyb.switch() -- return True/False if switch pressed or not\n" -" pyb.accel() -- get accelerometer values\n" -" pyb.rand() -- get a 16-bit random number\n" -" pyb.gpio(<port>) -- get port value (port='A4' for example)\n" -" pyb.gpio(<port>, <val>) -- set port value, True or False, 1 or 0\n" -" pyb.ADC(<port>) -- make an analog port object (port='C0' for example)\n" -" ADC methods: read()\n" -; - -// get some help about available functions -static mp_obj_t pyb_help(void) { - printf("%s", help_text); - return mp_const_none; -} - int main(void) { // TODO disable JTAG @@ -249,37 +221,8 @@ soft_reset: lcd_init(); #endif -#if MICROPY_HW_ENABLE_RNG - // RNG - rng_init(); -#endif - -#if MICROPY_HW_ENABLE_SERVO - // servo - servo_init(); -#endif - -#if 0 -#if MICROPY_HW_ENABLE_TIMER - // timer - timer_init(); -#endif -#endif - pin_map_init(); - // add some functions to the builtin Python namespace - rt_store_name(MP_QSTR_help, rt_make_function_n(0, pyb_help)); - - // 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 @@ -398,6 +341,9 @@ soft_reset: } } } +#else + // Get rid of compiler warning if no SDCARD is configured. + (void)first_soft_reset; #endif #if defined(USE_HOST_MODE) @@ -408,11 +354,36 @@ soft_reset: pyb_usb_dev_init(USBD_DEVICE_CDC_MSC, usbd_medium_kind); #endif +#if MICROPY_HW_ENABLE_RNG + // RNG + rng_init(); +#endif + + // I2C + i2c_init(); + #if MICROPY_HW_HAS_MMA7660 // MMA accel: init and reset accel_init(); #endif +#if MICROPY_HW_ENABLE_SERVO + // servo + servo_init(); +#endif + +#if 0 +#if MICROPY_HW_ENABLE_TIMER + // timer + timer_init(); +#endif +#endif + +#if MICROPY_HW_ENABLE_DAC + // DAC + dac_init(); +#endif + // run main script { vstr_t *vstr = vstr_new(); @@ -477,7 +448,19 @@ soft_reset: #endif #endif - pyexec_repl(); + // enter REPL + // REPL mode can change, or it can request a soft reset + for (;;) { + if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { + if (pyexec_raw_repl() != 0) { + break; + } + } else { + if (pyexec_friendly_repl() != 0) { + break; + } + } + } printf("PYB: sync filesystems\n"); storage_flush(); |