summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings')
-rwxr-xr-xshared-bindings/supervisor/Runtime.c111
-rwxr-xr-xshared-bindings/supervisor/Runtime.h8
2 files changed, 87 insertions, 32 deletions
diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c
index 8e0259a3b..cfda620bc 100755
--- a/shared-bindings/supervisor/Runtime.c
+++ b/shared-bindings/supervisor/Runtime.c
@@ -55,43 +55,96 @@ STATIC supervisor_run_reason_t _run_reason;
//| serial_connected: bool
//| """Returns the USB serial communication status (read-only)."""
//|
+STATIC mp_obj_t supervisor_runtime_get_serial_connected(mp_obj_t self){
+ return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial_connected());
+}
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial_connected_obj, supervisor_runtime_get_serial_connected);
-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;
- }
+//| serial2: io.BytesIO
+//| """Returns the USB secondary serial communication channel.
+//| Raises `NotImplementedError` if it does not exist.
+//| """
+//|
+STATIC mp_obj_t supervisor_runtime_get_serial2(mp_obj_t self){
+#if CIRCUITPY_USB_SERIAL2
+ return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2());
+#else
+ mp_raise_NotImplementedError(translate("serial2 not available"));
+#endif
}
-MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_connected_obj, supervisor_get_serial_connected);
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_obj, supervisor_runtime_get_serial2);
+
+const mp_obj_property_t supervisor_runtime_serial2_connected_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_connected_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
-const mp_obj_property_t supervisor_serial_connected_obj = {
+const mp_obj_property_t supervisor_runtime_serial_connected_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&supervisor_get_serial_connected_obj,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_serial_connected_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
+//| serial2_connected: bool
+//| """Returns the USB secondary serial communication status (read-only).
+//| Raises `NotImplementedError` if there is no secondary serial channel.
+//| """
+//|
+STATIC mp_obj_t supervisor_runtime_get_serial2_connected(mp_obj_t self){
+#if CIRCUITPY_USB_SERIAL2
+ return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2_connected());
+#else
+ mp_raise_NotImplementedError(translate("serial2 not available"));
+#endif
+}
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_connected_obj, supervisor_runtime_get_serial2_connected);
+
+const mp_obj_property_t supervisor_runtime_serial2_connected_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_connected_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
//| serial_bytes_available: int
//| """Returns the whether any bytes are available to read
//| on the USB serial input. Allows for polling to see whether
//| to call the built-in input() or wait. (read-only)"""
//|
-STATIC mp_obj_t supervisor_get_serial_bytes_available(mp_obj_t self){
- if (!common_hal_get_serial_bytes_available()) {
- return mp_const_false;
- }
- else {
- return mp_const_true;
- }
+STATIC mp_obj_t supervisor_runtime_get_serial_bytes_available(mp_obj_t self){
+ return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial_bytes_available());
+}
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial_bytes_available_obj, supervisor_runtime_get_serial_bytes_available);
+
+const mp_obj_property_t supervisor_runtime_serial_bytes_available_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_serial_bytes_available_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
+
+//| serial2_bytes_available: int
+//| """Returns the whether any bytes are available to read
+//| on the secondary USB serial input (read-only).
+//| Raises `NotImplementedError` if there is no secondary serial input.
+//| """
+//|
+STATIC mp_obj_t supervisor_runtime_get_serial2_bytes_available(mp_obj_t self){
+#if CIRCUITPY_USB_SERIAL2
+ return mp_obj_new_bool(common_hal_supervisor_runtime_get_serial2_bytes_available());
+#else
+ mp_raise_NotImplementedError(translate("serial2 not available"));
+#endif
}
-MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_serial_bytes_available_obj, supervisor_get_serial_bytes_available);
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_serial2_bytes_available_obj, supervisor_runtime_get_serial2_bytes_available);
-const mp_obj_property_t supervisor_serial_bytes_available_obj = {
+const mp_obj_property_t supervisor_runtime_serial2_bytes_available_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&supervisor_get_serial_bytes_available_obj,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_serial2_bytes_available_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
@@ -100,26 +153,28 @@ const mp_obj_property_t supervisor_serial_bytes_available_obj = {
//| run_reason: RunReason
//| """Returns why CircuitPython started running this particular time."""
//|
-STATIC mp_obj_t supervisor_get_run_reason(mp_obj_t self) {
+STATIC mp_obj_t supervisor_runtime_get_run_reason(mp_obj_t self) {
return cp_enum_find(&supervisor_run_reason_type, _run_reason);
}
-MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_run_reason_obj, supervisor_get_run_reason);
+MP_DEFINE_CONST_FUN_OBJ_1(supervisor_runtime_get_run_reason_obj, supervisor_runtime_get_run_reason);
-const mp_obj_property_t supervisor_run_reason_obj = {
+const mp_obj_property_t supervisor_runtime_run_reason_obj = {
.base.type = &mp_type_property,
- .proxy = {(mp_obj_t)&supervisor_get_run_reason_obj,
+ .proxy = {(mp_obj_t)&supervisor_runtime_get_run_reason_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj},
};
-void supervisor_set_run_reason(supervisor_run_reason_t run_reason) {
+void supervisor_runtime_set_run_reason(supervisor_runtime_run_reason_t run_reason) {
_run_reason = run_reason;
}
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) },
- { MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_serial_bytes_available_obj) },
- { MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_run_reason_obj) },
+ { MP_ROM_QSTR(MP_QSTR_serial_connected), MP_ROM_PTR(&supervisor_runtime_serial_connected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_serial2_connected), MP_ROM_PTR(&supervisor_runtime_serial2_connected_obj) },
+ { MP_ROM_QSTR(MP_QSTR_serial_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial_bytes_available_obj) },
+ { MP_ROM_QSTR(MP_QSTR_serial2_bytes_available), MP_ROM_PTR(&supervisor_runtime_serial2_bytes_available_obj) },
+ { MP_ROM_QSTR(MP_QSTR_run_reason), MP_ROM_PTR(&supervisor_runtime_run_reason_obj) },
};
STATIC MP_DEFINE_CONST_DICT(supervisor_runtime_locals_dict, supervisor_runtime_locals_dict_table);
diff --git a/shared-bindings/supervisor/Runtime.h b/shared-bindings/supervisor/Runtime.h
index 51ed7604d..6874ac744 100755
--- a/shared-bindings/supervisor/Runtime.h
+++ b/shared-bindings/supervisor/Runtime.h
@@ -36,12 +36,12 @@ extern const mp_obj_type_t supervisor_runtime_type;
void supervisor_set_run_reason(supervisor_run_reason_t run_reason);
-bool common_hal_get_serial_connected(void);
+bool common_hal_supervisor_runtime_get_serial_connected(void);
-bool common_hal_get_serial_bytes_available(void);
+bool common_hal_supervisor_runtime_get_serial_bytes_available(void);
//TODO: placeholders for future functions
-//bool common_hal_get_repl_active(void);
-//bool common_hal_get_usb_enumerated(void);
+//bool common_hal_get_supervisor_runtime_repl_active(void);
+//bool common_hal_get_supervisor_runtime_usb_enumerated(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SUPERVISOR_RUNTIME_H