From fca9c66c27533ac00117137ee3e3850f632f26eb Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 19 Feb 2018 20:40:17 +0000 Subject: [PATCH 01/11] added Status submodule to shared-bindings/supervisor; issue #544 --- shared-bindings/supervisor/Status.c | 77 +++++++++++++++++++++++++++ shared-bindings/supervisor/Status.h | 43 +++++++++++++++ shared-bindings/supervisor/__init__.c | 10 ++-- 3 files changed, 126 insertions(+), 4 deletions(-) create mode 100755 shared-bindings/supervisor/Status.c create mode 100755 shared-bindings/supervisor/Status.h diff --git a/shared-bindings/supervisor/Status.c b/shared-bindings/supervisor/Status.c new file mode 100755 index 0000000000000..5d34b91f37376 --- /dev/null +++ b/shared-bindings/supervisor/Status.c @@ -0,0 +1,77 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "py/objproperty.h" +#include "shared-bindings/supervisor/Status.h" + +//TODO: add USB, REPL to description once they're operational +//| .. currentmodule:: status +//| +//| :class:`Status` --- Supervisor Status information +//| ------------------------------------------------- +//| +//| Get current status of the serial connection. +//| +//| Usage:: +//| +//| import supervisor +//| if supervisor.serial_connected: +//| print("Hello World!") +//| + +//| .. attribute:: serial_connected +//| +//| Returns the serial communication status (read-only) +//| +STATIC mp_obj_t supervisor_get_serial_connected(mp_obj_t self){ + if (!common_hal_get_serial_connected()) { + return mp_const_false; + } + else { + return mp_const_true; + } +} +MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_connected_obj, supervisor_get_serial_connected); + +const mp_obj_property_t supervisor_serial_connected_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&supervisor_get_serial_connected_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t supervisor_status_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(supervisor_status_locals_dict, supervisor_status_locals_dict_table); + +const mp_obj_type_t supervisor_status_type = { + .base = { &mp_type_type }, + .name = MP_QSTR_Status, + .locals_dict = (mp_obj_t)&supervisor_status_locals_dict, +}; diff --git a/shared-bindings/supervisor/Status.h b/shared-bindings/supervisor/Status.h new file mode 100755 index 0000000000000..43888bcf8e48f --- /dev/null +++ b/shared-bindings/supervisor/Status.h @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H + +#include +#include "py/obj.h" + +//#include "common-hal/supervisor/Status.h" + +const mp_obj_type_t supervisor_status_type; + +bool common_hal_get_serial_connected(void); + +//TODO: placeholders for future functions +//bool common_hal_get_repl_active(void); +//bool common_hal_get_usb_enumerated(void); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index cbb138beb2186..46b69da46e48b 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -27,7 +27,8 @@ #include "py/runtime.h" #include "supervisor/shared/autoreload.h" #include "supervisor/shared/rgb_led_status.h" - + + #include "shared-bindings/supervisor/Status.h" //| :mod:`supervisor` --- Supervisor settings //| ================================================= //| @@ -75,9 +76,10 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_rgb_status_brightness_obj, supervisor_s 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)}, + { 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) }, + { MP_ROM_QSTR(MP_QSTR_Status), MP_ROM_PTR(&supervisor_status_type) }, }; STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table); From 9ee4d137562f1c601b4b225bb6313b013447ece5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 19 Feb 2018 20:49:18 +0000 Subject: [PATCH 02/11] added Status submodule to ports/atmel-samd/common-hal/supervisor; issue #544 --- ports/atmel-samd/Makefile | 1 + .../atmel-samd/common-hal/supervisor/Status.c | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 ports/atmel-samd/common-hal/supervisor/Status.c diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 041f1d1ad7550..be85399084028 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -268,6 +268,7 @@ SRC_COMMON_HAL = \ neopixel_write/__init__.c \ os/__init__.c \ storage/__init__.c \ + supervisor/Status.c \ time/__init__.c \ analogio/__init__.c \ analogio/AnalogIn.c \ diff --git a/ports/atmel-samd/common-hal/supervisor/Status.c b/ports/atmel-samd/common-hal/supervisor/Status.c new file mode 100755 index 0000000000000..b7f95a54e208e --- /dev/null +++ b/ports/atmel-samd/common-hal/supervisor/Status.c @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "shared-bindings/supervisor/Status.h" +#include "usb.h" + +bool common_hal_get_serial_connected(void) { + return (bool) usb_connected(); +} + From 5de8df7997b05bc0ed4aa47fca01096303fb719e Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 19 Feb 2018 22:27:16 +0000 Subject: [PATCH 03/11] added Status submodule to ports/nrf/common-hal/supervisor; issue #544 --- ports/nrf/Makefile | 1 + ports/nrf/common-hal/supervisor/Status.c | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 ports/nrf/common-hal/supervisor/Status.c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index c1bef467234ff..bc282c961a174 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -207,6 +207,7 @@ SRC_COMMON_HAL += \ pulseio/PulseOut.c \ pulseio/PWMOut.c \ storage/__init__.c \ + supervisor/Status.c \ # These don't have corresponding files in each port but are still located in # shared-bindings to make it clear what the contents of the modules are. diff --git a/ports/nrf/common-hal/supervisor/Status.c b/ports/nrf/common-hal/supervisor/Status.c new file mode 100755 index 0000000000000..8c36e8740ee12 --- /dev/null +++ b/ports/nrf/common-hal/supervisor/Status.c @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "shared-bindings/supervisor/Status.h" +#include "supervisor/serial.h" + +bool common_hal_get_serial_connected(void) { + return (bool) serial_connected(); +} + From 60d6ccc73192892d7fe1acba1cafc37e25421cad Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 20 Feb 2018 03:44:45 +0000 Subject: [PATCH 04/11] changed spaced supervisor/Status.c line to tabbed --- ports/atmel-samd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index be85399084028..a58d499268781 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -268,7 +268,7 @@ SRC_COMMON_HAL = \ neopixel_write/__init__.c \ os/__init__.c \ storage/__init__.c \ - supervisor/Status.c \ + supervisor/Status.c \ time/__init__.c \ analogio/__init__.c \ analogio/AnalogIn.c \ From c1c3a79ec4aa5215b6d5debe8bc7a710c40e82a4 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 9 Mar 2018 02:19:51 +0000 Subject: [PATCH 05/11] atmel-samd: changed Status to Runtime; instituted runtime singleton --- ports/atmel-samd/Makefile | 3 +- .../supervisor/{Status.c => Runtime.c} | 2 +- .../common-hal/supervisor/Runtime.h | 37 +++++++++++++++++ .../common-hal/supervisor/__init__.c | 40 +++++++++++++++++++ .../supervisor/{Status.c => Runtime.c} | 24 +++++------ .../supervisor/{Status.h => Runtime.h} | 9 ++--- shared-bindings/supervisor/__init__.c | 12 +++++- shared-bindings/supervisor/__init__.h | 39 ++++++++++++++++++ 8 files changed, 145 insertions(+), 21 deletions(-) rename ports/atmel-samd/common-hal/supervisor/{Status.c => Runtime.c} (96%) create mode 100755 ports/atmel-samd/common-hal/supervisor/Runtime.h create mode 100755 ports/atmel-samd/common-hal/supervisor/__init__.c rename shared-bindings/supervisor/{Status.c => Runtime.c} (77%) rename shared-bindings/supervisor/{Status.h => Runtime.h} (84%) create mode 100755 shared-bindings/supervisor/__init__.h diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index a58d499268781..7347dcdbe9994 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -268,7 +268,8 @@ SRC_COMMON_HAL = \ neopixel_write/__init__.c \ os/__init__.c \ storage/__init__.c \ - supervisor/Status.c \ + supervisor/__init__.c \ + supervisor/Runtime.c \ time/__init__.c \ analogio/__init__.c \ analogio/AnalogIn.c \ diff --git a/ports/atmel-samd/common-hal/supervisor/Status.c b/ports/atmel-samd/common-hal/supervisor/Runtime.c similarity index 96% rename from ports/atmel-samd/common-hal/supervisor/Status.c rename to ports/atmel-samd/common-hal/supervisor/Runtime.c index b7f95a54e208e..8efe7cb78d9a2 100755 --- a/ports/atmel-samd/common-hal/supervisor/Status.c +++ b/ports/atmel-samd/common-hal/supervisor/Runtime.c @@ -25,7 +25,7 @@ */ #include -#include "shared-bindings/supervisor/Status.h" +#include "shared-bindings/supervisor/Runtime.h" #include "usb.h" bool common_hal_get_serial_connected(void) { diff --git a/ports/atmel-samd/common-hal/supervisor/Runtime.h b/ports/atmel-samd/common-hal/supervisor/Runtime.h new file mode 100755 index 0000000000000..f3d76d1b68002 --- /dev/null +++ b/ports/atmel-samd/common-hal/supervisor/Runtime.h @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + // Stores no state currently. +} super_runtime_obj_t; + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H diff --git a/ports/atmel-samd/common-hal/supervisor/__init__.c b/ports/atmel-samd/common-hal/supervisor/__init__.c new file mode 100755 index 0000000000000..ac88556b45da4 --- /dev/null +++ b/ports/atmel-samd/common-hal/supervisor/__init__.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "py/obj.h" + +#include "shared-bindings/supervisor/__init__.h" +#include "shared-bindings/supervisor/Runtime.h" + + +// The singleton supervisor.Runtime object, bound to supervisor.runtime +// It currently only has properties, and no state. +const super_runtime_obj_t common_hal_supervisor_runtime_obj = { + .base = { + .type = &supervisor_runtime_type, + }, +}; \ No newline at end of file diff --git a/shared-bindings/supervisor/Status.c b/shared-bindings/supervisor/Runtime.c similarity index 77% rename from shared-bindings/supervisor/Status.c rename to shared-bindings/supervisor/Runtime.c index 5d34b91f37376..b112cdde24823 100755 --- a/shared-bindings/supervisor/Status.c +++ b/shared-bindings/supervisor/Runtime.c @@ -26,24 +26,24 @@ #include #include "py/objproperty.h" -#include "shared-bindings/supervisor/Status.h" +#include "shared-bindings/supervisor/Runtime.h" //TODO: add USB, REPL to description once they're operational -//| .. currentmodule:: status +//| .. currentmodule:: runtime //| -//| :class:`Status` --- Supervisor Status information -//| ------------------------------------------------- +//| :class:`Runtime` --- Supervisor Runtime information +//| ---------------------------------------------------- //| -//| Get current status of the serial connection. +//| Get current status of runtime objects. //| //| Usage:: //| //| import supervisor -//| if supervisor.serial_connected: +//| if supervisor.runtime.serial_connected: //| print("Hello World!") //| -//| .. attribute:: serial_connected +//| .. attribute:: runtime.serial_connected //| //| Returns the serial communication status (read-only) //| @@ -64,14 +64,14 @@ const mp_obj_property_t supervisor_serial_connected_obj = { (mp_obj_t)&mp_const_none_obj}, }; -STATIC const mp_rom_map_elem_t supervisor_status_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(supervisor_status_locals_dict, supervisor_status_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table); -const mp_obj_type_t supervisor_status_type = { +const mp_obj_type_t supervisor_runtime_type = { .base = { &mp_type_type }, - .name = MP_QSTR_Status, - .locals_dict = (mp_obj_t)&supervisor_status_locals_dict, + .name = MP_QSTR_Runtime, + .locals_dict = (mp_obj_t)&supervisor_runtime_locals_dict, }; diff --git a/shared-bindings/supervisor/Status.h b/shared-bindings/supervisor/Runtime.h similarity index 84% rename from shared-bindings/supervisor/Status.h rename to shared-bindings/supervisor/Runtime.h index 43888bcf8e48f..4a67925ecea0a 100755 --- a/shared-bindings/supervisor/Status.h +++ b/shared-bindings/supervisor/Runtime.h @@ -24,15 +24,14 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_RUNTIME_STATUS_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_RUNTIME_STATUS_H #include #include "py/obj.h" -//#include "common-hal/supervisor/Status.h" -const mp_obj_type_t supervisor_status_type; +const mp_obj_type_t supervisor_runtime_type; bool common_hal_get_serial_connected(void); @@ -40,4 +39,4 @@ bool common_hal_get_serial_connected(void); //bool common_hal_get_repl_active(void); //bool common_hal_get_usb_enumerated(void); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_RUNTIME_H diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 46b69da46e48b..12a41d4334702 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -28,7 +28,8 @@ #include "supervisor/shared/autoreload.h" #include "supervisor/shared/rgb_led_status.h" - #include "shared-bindings/supervisor/Status.h" + #include "shared-bindings/supervisor/__init__.h" + #include "shared-bindings/supervisor/Runtime.h" //| :mod:`supervisor` --- Supervisor settings //| ================================================= //| @@ -37,6 +38,13 @@ //| :platform: SAMD21 //| +//| .. attribute:: runtime +//| +//| Runtime information, such as `runtime.serial_connected` +//| (USB serial connection status). +//| This object is the sole instance of `supervisor.Runtime`. +//| + //| .. method:: enable_autoreload() //| //| Enable autoreload based on USB file write activity. @@ -79,7 +87,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = { { 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) }, - { MP_ROM_QSTR(MP_QSTR_Status), MP_ROM_PTR(&supervisor_status_type) }, + { MP_ROM_QSTR(MP_QSTR_runtime), MP_ROM_PTR(&common_hal_supervisor_runtime_obj) }, }; STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table); diff --git a/shared-bindings/supervisor/__init__.h b/shared-bindings/supervisor/__init__.h new file mode 100755 index 0000000000000..d2e5689452dca --- /dev/null +++ b/shared-bindings/supervisor/__init__.h @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H + +//#include "py/mpconfig.h" +#include "py/obj.h" + +#include "common-hal/supervisor/Runtime.h" + +extern const super_runtime_obj_t common_hal_supervisor_runtime_obj; + + + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H \ No newline at end of file From 01471e1e22eb57bf5295ea489e73f97a3e03b5d5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 9 Mar 2018 03:22:00 +0000 Subject: [PATCH 06/11] sphinx fix; added toctree to include 'runtime' --- shared-bindings/supervisor/__init__.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 12a41d4334702..ec145ce128566 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -37,6 +37,15 @@ //| :synopsis: Supervisor settings //| :platform: SAMD21 //| +//| The `supervisor` module. (TODO: expand description) +//| +//| Libraries +//| +//| .. toctree:: +//| :maxdepth: 3 +//| +//| Runtime +//| //| .. attribute:: runtime //| From f21038b91315589d716058416de6a10b82d5f9f5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 9 Mar 2018 20:24:07 +0000 Subject: [PATCH 07/11] sphinx fix; incorrect currentmodule ref --- shared-bindings/supervisor/Runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index b112cdde24823..c6dff8f281bf3 100755 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -29,7 +29,7 @@ #include "shared-bindings/supervisor/Runtime.h" //TODO: add USB, REPL to description once they're operational -//| .. currentmodule:: runtime +//| .. currentmodule:: supervisor //| //| :class:`Runtime` --- Supervisor Runtime information //| ---------------------------------------------------- From 2569b33c84e59476d1cb5451b04c340a19f01d91 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 9 Mar 2018 21:00:15 +0000 Subject: [PATCH 08/11] 1 more sphinx fix; added '.. class::' constructor --- shared-bindings/supervisor/Runtime.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index c6dff8f281bf3..9d39c40edaea9 100755 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -43,6 +43,12 @@ //| print("Hello World!") //| +//| .. class:: Runtime() +//| +//| You cannot create an instance of `supervisor.Runtime`. +//| Use `supervisor.runtime` to access the sole instance available. +//| + //| .. attribute:: runtime.serial_connected //| //| Returns the serial communication status (read-only) From 8c9cc6b7c0fead1a0dad938465596197856adaa5 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 10 Mar 2018 01:07:17 +0000 Subject: [PATCH 09/11] nrf: changed Status to Runtime; instituted runtime singleton --- ports/nrf/Makefile | 4 +- .../supervisor/{Status.c => Runtime.c} | 2 +- ports/nrf/common-hal/supervisor/Runtime.h | 37 +++++++++++++++++ ports/nrf/common-hal/supervisor/__init__.c | 40 +++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) rename ports/nrf/common-hal/supervisor/{Status.c => Runtime.c} (96%) create mode 100755 ports/nrf/common-hal/supervisor/Runtime.h create mode 100755 ports/nrf/common-hal/supervisor/__init__.c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index bc282c961a174..b2c3533b17a6c 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -207,7 +207,8 @@ SRC_COMMON_HAL += \ pulseio/PulseOut.c \ pulseio/PWMOut.c \ storage/__init__.c \ - supervisor/Status.c \ + supervisor/__init__.c \ + supervisor/Runtime.c \ # These don't have corresponding files in each port but are still located in # shared-bindings to make it clear what the contents of the modules are. @@ -218,7 +219,6 @@ SRC_BINDINGS_ENUMS = \ microcontroller/RunMode.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/nrf/common-hal/supervisor/Status.c b/ports/nrf/common-hal/supervisor/Runtime.c similarity index 96% rename from ports/nrf/common-hal/supervisor/Status.c rename to ports/nrf/common-hal/supervisor/Runtime.c index 8c36e8740ee12..b73a94a1ba79e 100755 --- a/ports/nrf/common-hal/supervisor/Status.c +++ b/ports/nrf/common-hal/supervisor/Runtime.c @@ -25,7 +25,7 @@ */ #include -#include "shared-bindings/supervisor/Status.h" +#include "shared-bindings/supervisor/Runtime.h" #include "supervisor/serial.h" bool common_hal_get_serial_connected(void) { diff --git a/ports/nrf/common-hal/supervisor/Runtime.h b/ports/nrf/common-hal/supervisor/Runtime.h new file mode 100755 index 0000000000000..dbff22e4c9245 --- /dev/null +++ b/ports/nrf/common-hal/supervisor/Runtime.h @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_SUPERVISOR_RUNTIME_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_SUPERVISOR_RUNTIME_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + // Stores no state currently. +} super_runtime_obj_t; + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_SUPERVISOR_RUNTIME_H diff --git a/ports/nrf/common-hal/supervisor/__init__.c b/ports/nrf/common-hal/supervisor/__init__.c new file mode 100755 index 0000000000000..ac88556b45da4 --- /dev/null +++ b/ports/nrf/common-hal/supervisor/__init__.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Michael Schroeder + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + +#include "py/obj.h" + +#include "shared-bindings/supervisor/__init__.h" +#include "shared-bindings/supervisor/Runtime.h" + + +// The singleton supervisor.Runtime object, bound to supervisor.runtime +// It currently only has properties, and no state. +const super_runtime_obj_t common_hal_supervisor_runtime_obj = { + .base = { + .type = &supervisor_runtime_type, + }, +}; \ No newline at end of file From 6205ed9a0cf97ab8c0bf873d6cb1d7da4fd8accf Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Mar 2018 03:42:58 +0000 Subject: [PATCH 10/11] updated cdc_enabled; now more dynamic status return --- ports/atmel-samd/usb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ports/atmel-samd/usb.c b/ports/atmel-samd/usb.c index 740486aa1ebf9..6ce8aeea7eac1 100644 --- a/ports/atmel-samd/usb.c +++ b/ports/atmel-samd/usb.c @@ -227,17 +227,17 @@ void init_usb(void) { } static bool cdc_enabled(void) { - if (mp_cdc_enabled) { - return true; - } if (!cdcdf_acm_is_enabled()) { + mp_cdc_enabled = false; return false; } - cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)read_complete); - cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)write_complete); - cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c); - cdcdf_acm_register_callback(CDCDF_ACM_CB_LINE_CODING_C, (FUNC_PTR)usb_device_cb_line_coding_c); - mp_cdc_enabled = true; + if (!mp_cdc_enabled) { + cdcdf_acm_register_callback(CDCDF_ACM_CB_READ, (FUNC_PTR)read_complete); + cdcdf_acm_register_callback(CDCDF_ACM_CB_WRITE, (FUNC_PTR)write_complete); + cdcdf_acm_register_callback(CDCDF_ACM_CB_STATE_C, (FUNC_PTR)usb_device_cb_state_c); + cdcdf_acm_register_callback(CDCDF_ACM_CB_LINE_CODING_C, (FUNC_PTR)usb_device_cb_line_coding_c); + mp_cdc_enabled = true; + } return true; } From d1974e0038f18ed2ffc59f0f198d998070f4c618 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 6 Apr 2018 01:56:51 +0000 Subject: [PATCH 11/11] supervisor/Runtime: updated documentation for 'no disconnect' --- shared-bindings/supervisor/Runtime.c | 24 +++++++++++++++++------- shared-bindings/supervisor/__init__.c | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 9d39c40edaea9..b061595cf84d1 100755 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -30,7 +30,7 @@ //TODO: add USB, REPL to description once they're operational //| .. currentmodule:: supervisor -//| +//| //| :class:`Runtime` --- Supervisor Runtime information //| ---------------------------------------------------- //| @@ -40,7 +40,7 @@ //| //| import supervisor //| if supervisor.runtime.serial_connected: -//| print("Hello World!") +//| print("Hello World!") //| //| .. class:: Runtime() @@ -49,17 +49,27 @@ //| Use `supervisor.runtime` to access the sole instance available. //| -//| .. attribute:: runtime.serial_connected +//| .. attribute:: runtime.serial_connected +//| +//| Returns the USB serial communication status (read-only). +//| +//| .. note:: //| -//| Returns the serial communication status (read-only) +//| SAMD: Will return ``True`` if the USB serial connection +//| has been established at any point. Will not reset if +//| USB is disconnected but power remains (e.g. battery connected) //| +//| Feather52 (nRF52832): Currently returns ``True`` regardless +//| of USB connection status. +//| + STATIC mp_obj_t supervisor_get_serial_connected(mp_obj_t self){ if (!common_hal_get_serial_connected()) { return mp_const_false; - } + } else { return mp_const_true; - } + } } MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_connected_obj, supervisor_get_serial_connected); @@ -67,7 +77,7 @@ const mp_obj_property_t supervisor_serial_connected_obj = { .base.type = &mp_type_property, .proxy = {(mp_obj_t)&supervisor_get_serial_connected_obj, (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, + (mp_obj_t)&mp_const_none_obj}, }; STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = { diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index ec145ce128566..a82459ad789ee 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -35,7 +35,7 @@ //| //| .. module:: supervisor //| :synopsis: Supervisor settings -//| :platform: SAMD21 +//| :platform: SAMD21/51 (All), nRF (Runtime only) //| //| The `supervisor` module. (TODO: expand description) //|