diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-11-15 14:44:14 -0800 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-11-16 09:04:17 -0800 |
| commit | ecc47d5258acfd903d3aba03b336e248e85ff5c2 (patch) | |
| tree | c481ee18cc7333b3e64fa8c8b66a27418b26a075 | |
| parent | 2d34450872d40cf308981ffda6b1736528b1fba7 (diff) | |
Create supervisor module.
It can control autoreload and the rgb status led.
| -rw-r--r-- | main.c | 8 | ||||
| -rw-r--r-- | ports/atmel-samd/Makefile | 2 | ||||
| -rw-r--r-- | ports/atmel-samd/mpconfigport.h | 4 | ||||
| -rw-r--r-- | shared-bindings/index.rst | 1 | ||||
| -rw-r--r-- | shared-bindings/supervisor/__init__.c (renamed from ports/atmel-samd/bindings/samd/__init__.c) | 36 | ||||
| -rw-r--r-- | supervisor/shared/autoreload.c | 12 | ||||
| -rw-r--r-- | supervisor/shared/autoreload.h | 4 |
7 files changed, 39 insertions, 28 deletions
@@ -290,18 +290,14 @@ int __attribute__((used)) main(void) { bool first_run = true; for (;;) { if (!skip_repl) { - // The REPL mode can change, or it can request a reload. - bool autoreload_on = autoreload_is_enabled(); - autoreload_disable(); + autoreload_suspend(); new_status_color(REPL_RUNNING); if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { exit_code = pyexec_raw_repl(); } else { exit_code = pyexec_friendly_repl(); } - if (autoreload_on) { - autoreload_enable(); - } + autoreload_resume(); reset_port(); reset_board(); reset_mp(); diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index ccf029a7f..916bc559f 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -221,7 +221,6 @@ SRC_C = \ tick.c \ usb.c \ usb_mass_storage.c \ - bindings/samd/__init__.c \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ lib/oofatfs/ff.c \ @@ -314,6 +313,7 @@ SRC_BINDINGS_ENUMS = \ digitalio/Pull.c \ help.c \ math/__init__.c \ + supervisor/__init__.c \ util.c SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 0728a643b..1db2d5a67 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -168,7 +168,7 @@ extern const struct _mp_obj_module_t cpy_nvm_module; extern const struct _mp_obj_module_t neopixel_write_module; extern const struct _mp_obj_module_t uheap_module; extern const struct _mp_obj_module_t ustack_module; -extern const struct _mp_obj_module_t samd_module; +extern const struct _mp_obj_module_t supervisor_module; extern const struct _mp_obj_module_t gamepad_module; extern const struct _mp_obj_module_t touchio_module; extern const struct _mp_obj_module_t usb_hid_module; @@ -216,7 +216,6 @@ extern const struct _mp_obj_module_t usb_hid_module; // { MP_OBJ_NEW_QSTR(MP_QSTR_gamepad),(mp_obj_t)&gamepad_module }, // { MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module }, // { MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, -// { MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module }, #define MICROPY_PORT_BUILTIN_MODULES \ @@ -228,6 +227,7 @@ extern const struct _mp_obj_module_t usb_hid_module; { MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&struct_module }, \ + { MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, EXTRA_BUILTIN_MODULES diff --git a/shared-bindings/index.rst b/shared-bindings/index.rst index 229ae38d4..6dced5026 100644 --- a/shared-bindings/index.rst +++ b/shared-bindings/index.rst @@ -32,6 +32,7 @@ Module / Port SAMD21 SAMD21 Express ESP8266 `random` **Yes** **Yes** **Yes** `storage` **Yes** **Yes** **Yes** `struct` **Yes** **Yes** **Yes** +`supervisor` **Yes** **Yes** No `time` **Yes** **Yes** **Yes** `touchio` **Yes** **Yes** No `uheap` Debug Debug Debug diff --git a/ports/atmel-samd/bindings/samd/__init__.c b/shared-bindings/supervisor/__init__.c index d2bc0e0c0..cbb138beb 100644 --- a/ports/atmel-samd/bindings/samd/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2016 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2016-2017 Scott Shawcroft for Adafruit Industries * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -28,11 +28,11 @@ #include "supervisor/shared/autoreload.h" #include "supervisor/shared/rgb_led_status.h" -//| :mod:`samd` --- SAMD implementation settings +//| :mod:`supervisor` --- Supervisor settings //| ================================================= //| -//| .. module:: samd -//| :synopsis: SAMD implementation settings +//| .. module:: supervisor +//| :synopsis: Supervisor settings //| :platform: SAMD21 //| @@ -40,29 +40,29 @@ //| //| Enable autoreload based on USB file write activity. //| -STATIC mp_obj_t samd_enable_autoreload(void) { +STATIC mp_obj_t supervisor_enable_autoreload(void) { autoreload_enable(); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_0(samd_enable_autoreload_obj, samd_enable_autoreload); +MP_DEFINE_CONST_FUN_OBJ_0(supervisor_enable_autoreload_obj, supervisor_enable_autoreload); //| .. method:: disable_autoreload() //| //| Disable autoreload based on USB file write activity until //| `enable_autoreload` is called. //| -STATIC mp_obj_t samd_disable_autoreload(void) { +STATIC mp_obj_t supervisor_disable_autoreload(void) { autoreload_disable(); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_0(samd_disable_autoreload_obj, samd_disable_autoreload); +MP_DEFINE_CONST_FUN_OBJ_0(supervisor_disable_autoreload_obj, supervisor_disable_autoreload); //| .. method:: set_rgb_status_brightness() //| //| Set brightness of status neopixel from 0-255 //| `set_rgb_status_brightness` is called. //| -STATIC mp_obj_t samd_set_rgb_status_brightness(mp_obj_t lvl){ +STATIC mp_obj_t supervisor_set_rgb_status_brightness(mp_obj_t lvl){ // This must be int. If cast to uint8_t first, will never raise a ValueError. int brightness_int = mp_obj_get_int(lvl); if(brightness_int < 0 || brightness_int > 255){ @@ -71,18 +71,18 @@ STATIC mp_obj_t samd_set_rgb_status_brightness(mp_obj_t lvl){ set_rgb_status_brightness((uint8_t)brightness_int); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(samd_set_rgb_status_brightness_obj, samd_set_rgb_status_brightness); +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_rgb_status_brightness_obj, supervisor_set_rgb_status_brightness); -STATIC const mp_rom_map_elem_t samd_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_samd) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&samd_enable_autoreload_obj)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&samd_disable_autoreload_obj)}, - { MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&samd_set_rgb_status_brightness_obj)}, +STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj)}, + { MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(samd_module_globals, samd_module_globals_table); +STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table); -const mp_obj_module_t samd_module = { +const mp_obj_module_t supervisor_module = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&samd_module_globals, + .globals = (mp_obj_dict_t*)&supervisor_module_globals, }; diff --git a/supervisor/shared/autoreload.c b/supervisor/shared/autoreload.c index b1d0f05a9..39c33c05e 100644 --- a/supervisor/shared/autoreload.c +++ b/supervisor/shared/autoreload.c @@ -31,13 +31,15 @@ volatile uint32_t autoreload_delay_ms = 0; bool autoreload_enabled = false; +static bool autoreload_suspended = false; volatile bool reload_next_character = false; inline void autoreload_tick() { if (autoreload_delay_ms == 0) { return; } - if (autoreload_delay_ms == 1 && autoreload_enabled && !reload_next_character) { + if (autoreload_delay_ms == 1 && autoreload_enabled && + !autoreload_suspended && !reload_next_character) { mp_keyboard_interrupt(); reload_next_character = true; } @@ -53,6 +55,14 @@ void autoreload_disable() { autoreload_enabled = false; } +void autoreload_suspend() { + autoreload_suspended = true; +} + +void autoreload_resume() { + autoreload_suspended = false; +} + inline bool autoreload_is_enabled() { return autoreload_enabled; } diff --git a/supervisor/shared/autoreload.h b/supervisor/shared/autoreload.h index bc3c6d21d..62f9fe073 100644 --- a/supervisor/shared/autoreload.h +++ b/supervisor/shared/autoreload.h @@ -39,4 +39,8 @@ void autoreload_enable(void); void autoreload_disable(void); bool autoreload_is_enabled(void); +// Temporarily turn it off. Used during the REPL. +void autoreload_suspend(void); +void autoreload_resume(void); + #endif // MICROPY_INCLUDED_SUPERVISOR_AUTORELOAD_H |
