Skip to content

Commit c1c3a79

Browse files
committed
atmel-samd: changed Status to Runtime; instituted runtime singleton
1 parent 60d6ccc commit c1c3a79

8 files changed

Lines changed: 145 additions & 21 deletions

File tree

ports/atmel-samd/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ SRC_COMMON_HAL = \
268268
neopixel_write/__init__.c \
269269
os/__init__.c \
270270
storage/__init__.c \
271-
supervisor/Status.c \
271+
supervisor/__init__.c \
272+
supervisor/Runtime.c \
272273
time/__init__.c \
273274
analogio/__init__.c \
274275
analogio/AnalogIn.c \

ports/atmel-samd/common-hal/supervisor/Status.c renamed to ports/atmel-samd/common-hal/supervisor/Runtime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
#include <stdbool.h>
28-
#include "shared-bindings/supervisor/Status.h"
28+
#include "shared-bindings/supervisor/Runtime.h"
2929
#include "usb.h"
3030

3131
bool common_hal_get_serial_connected(void) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Michael Schroeder
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H
28+
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H
29+
30+
#include "py/obj.h"
31+
32+
typedef struct {
33+
mp_obj_base_t base;
34+
// Stores no state currently.
35+
} super_runtime_obj_t;
36+
37+
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_SUPERVISOR_RUNTIME_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Michael Schroeder
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
28+
#include "py/obj.h"
29+
30+
#include "shared-bindings/supervisor/__init__.h"
31+
#include "shared-bindings/supervisor/Runtime.h"
32+
33+
34+
// The singleton supervisor.Runtime object, bound to supervisor.runtime
35+
// It currently only has properties, and no state.
36+
const super_runtime_obj_t common_hal_supervisor_runtime_obj = {
37+
.base = {
38+
.type = &supervisor_runtime_type,
39+
},
40+
};
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626

2727
#include <stdbool.h>
2828
#include "py/objproperty.h"
29-
#include "shared-bindings/supervisor/Status.h"
29+
#include "shared-bindings/supervisor/Runtime.h"
3030

3131
//TODO: add USB, REPL to description once they're operational
32-
//| .. currentmodule:: status
32+
//| .. currentmodule:: runtime
3333
//|
34-
//| :class:`Status` --- Supervisor Status information
35-
//| -------------------------------------------------
34+
//| :class:`Runtime` --- Supervisor Runtime information
35+
//| ----------------------------------------------------
3636
//|
37-
//| Get current status of the serial connection.
37+
//| Get current status of runtime objects.
3838
//|
3939
//| Usage::
4040
//|
4141
//| import supervisor
42-
//| if supervisor.serial_connected:
42+
//| if supervisor.runtime.serial_connected:
4343
//| print("Hello World!")
4444
//|
4545

46-
//| .. attribute:: serial_connected
46+
//| .. attribute:: runtime.serial_connected
4747
//|
4848
//| Returns the serial communication status (read-only)
4949
//|
@@ -64,14 +64,14 @@ const mp_obj_property_t supervisor_serial_connected_obj = {
6464
(mp_obj_t)&mp_const_none_obj},
6565
};
6666

67-
STATIC const mp_rom_map_elem_t supervisor_status_locals_dict_table[] = {
67+
STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table[] = {
6868
{ MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_serial_connected_obj) },
6969
};
7070

71-
STATIC MP_DEFINE_CONST_DICT(supervisor_status_locals_dict, supervisor_status_locals_dict_table);
71+
STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);
7272

73-
const mp_obj_type_t supervisor_status_type = {
73+
const mp_obj_type_t supervisor_runtime_type = {
7474
.base = { &mp_type_type },
75-
.name = MP_QSTR_Status,
76-
.locals_dict = (mp_obj_t)&supervisor_status_locals_dict,
75+
.name = MP_QSTR_Runtime,
76+
.locals_dict = (mp_obj_t)&supervisor_runtime_locals_dict,
7777
};
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H
28-
#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_RUNTIME_STATUS_H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_RUNTIME_STATUS_H
2929

3030
#include <stdbool.h>
3131
#include "py/obj.h"
3232

33-
//#include "common-hal/supervisor/Status.h"
3433

35-
const mp_obj_type_t supervisor_status_type;
34+
const mp_obj_type_t supervisor_runtime_type;
3635

3736
bool common_hal_get_serial_connected(void);
3837

3938
//TODO: placeholders for future functions
4039
//bool common_hal_get_repl_active(void);
4140
//bool common_hal_get_usb_enumerated(void);
4241

43-
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_STATUS_H
42+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_RUNTIME_H

shared-bindings/supervisor/__init__.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
#include "supervisor/shared/autoreload.h"
2929
#include "supervisor/shared/rgb_led_status.h"
3030

31-
#include "shared-bindings/supervisor/Status.h"
31+
#include "shared-bindings/supervisor/__init__.h"
32+
#include "shared-bindings/supervisor/Runtime.h"
3233
//| :mod:`supervisor` --- Supervisor settings
3334
//| =================================================
3435
//|
@@ -37,6 +38,13 @@
3738
//| :platform: SAMD21
3839
//|
3940

41+
//| .. attribute:: runtime
42+
//|
43+
//| Runtime information, such as `runtime.serial_connected`
44+
//| (USB serial connection status).
45+
//| This object is the sole instance of `supervisor.Runtime`.
46+
//|
47+
4048
//| .. method:: enable_autoreload()
4149
//|
4250
//| Enable autoreload based on USB file write activity.
@@ -79,7 +87,7 @@ STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
7987
{ MP_OBJ_NEW_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
8088
{ MP_OBJ_NEW_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj) },
8189
{ MP_OBJ_NEW_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj) },
82-
{ MP_ROM_QSTR(MP_QSTR_Status), MP_ROM_PTR(&supervisor_status_type) },
90+
{ MP_ROM_QSTR(MP_QSTR_runtime), MP_ROM_PTR(&common_hal_supervisor_runtime_obj) },
8391
};
8492

8593
STATIC MP_DEFINE_CONST_DICT(supervisor_module_globals, supervisor_module_globals_table);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2018 Michael Schroeder
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H
29+
30+
//#include "py/mpconfig.h"
31+
#include "py/obj.h"
32+
33+
#include "common-hal/supervisor/Runtime.h"
34+
35+
extern const super_runtime_obj_t common_hal_supervisor_runtime_obj;
36+
37+
38+
39+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR___INIT___H

0 commit comments

Comments
 (0)