From c1c3a79ec4aa5215b6d5debe8bc7a710c40e82a4 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 9 Mar 2018 02:19:51 +0000 Subject: atmel-samd: changed Status to Runtime; instituted runtime singleton --- shared-bindings/supervisor/Runtime.c | 77 +++++++++++++++++++++++++++++++++++ shared-bindings/supervisor/Runtime.h | 42 +++++++++++++++++++ shared-bindings/supervisor/Status.c | 77 ----------------------------------- shared-bindings/supervisor/Status.h | 43 ------------------- shared-bindings/supervisor/__init__.c | 12 +++++- shared-bindings/supervisor/__init__.h | 39 ++++++++++++++++++ 6 files changed, 168 insertions(+), 122 deletions(-) create mode 100755 shared-bindings/supervisor/Runtime.c create mode 100755 shared-bindings/supervisor/Runtime.h delete mode 100755 shared-bindings/supervisor/Status.c delete mode 100755 shared-bindings/supervisor/Status.h create mode 100755 shared-bindings/supervisor/__init__.h (limited to 'shared-bindings') diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c new file mode 100755 index 000000000..b112cdde2 --- /dev/null +++ b/shared-bindings/supervisor/Runtime.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/Runtime.h" + +//TODO: add USB, REPL to description once they're operational +//| .. currentmodule:: runtime +//| +//| :class:`Runtime` --- Supervisor Runtime information +//| ---------------------------------------------------- +//| +//| Get current status of runtime objects. +//| +//| Usage:: +//| +//| import supervisor +//| if supervisor.runtime.serial_connected: +//| print("Hello World!") +//| + +//| .. attribute:: runtime.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_runtime_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table); + +const mp_obj_type_t supervisor_runtime_type = { + .base = { &mp_type_type }, + .name = MP_QSTR_Runtime, + .locals_dict = (mp_obj_t)&supervisor_runtime_locals_dict, +}; diff --git a/shared-bindings/supervisor/Runtime.h b/shared-bindings/supervisor/Runtime.h new file mode 100755 index 000000000..4a67925ec --- /dev/null +++ b/shared-bindings/supervisor/Runtime.h @@ -0,0 +1,42 @@ +/* + * 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_RUNTIME_STATUS_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_RUNTIME_STATUS_H + +#include +#include "py/obj.h" + + +const mp_obj_type_t supervisor_runtime_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_RUNTIME_H diff --git a/shared-bindings/supervisor/Status.c b/shared-bindings/supervisor/Status.c deleted file mode 100755 index 5d34b91f3..000000000 --- a/shared-bindings/supervisor/Status.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 deleted file mode 100755 index 43888bcf8..000000000 --- a/shared-bindings/supervisor/Status.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 46b69da46..12a41d433 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 000000000..d2e568945 --- /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 -- cgit v1.2.3