3333#include "shared-bindings/supervisor/RunReason.h"
3434#include "shared-bindings/supervisor/Runtime.h"
3535
36+ #include "tusb.h"
37+
3638STATIC supervisor_run_reason_t _run_reason ;
3739
38- // TODO: add USB, REPL to description once they're operational
40+ // TODO: add REPL to description once it is operational
41+
3942//| class Runtime:
4043//| """Current status of runtime objects.
4144//|
@@ -52,6 +55,21 @@ STATIC supervisor_run_reason_t _run_reason;
5255//| ...
5356//|
5457
58+ //| usb_connected: bool
59+ //| """Returns the USB enumeration status (read-only)."""
60+ //|
61+ STATIC mp_obj_t supervisor_runtime_get_usb_connected (mp_obj_t self ) {
62+ return mp_obj_new_bool (tud_ready ());
63+ }
64+ MP_DEFINE_CONST_FUN_OBJ_1 (supervisor_runtime_get_usb_connected_obj , supervisor_runtime_get_usb_connected );
65+
66+ const mp_obj_property_t supervisor_runtime_usb_connected_obj = {
67+ .base .type = & mp_type_property ,
68+ .proxy = {(mp_obj_t )& supervisor_runtime_get_usb_connected_obj ,
69+ (mp_obj_t )& mp_const_none_obj ,
70+ (mp_obj_t )& mp_const_none_obj },
71+ };
72+
5573//| serial_connected: bool
5674//| """Returns the USB serial communication status (read-only)."""
5775//|
@@ -104,6 +122,7 @@ void supervisor_set_run_reason(supervisor_run_reason_t run_reason) {
104122}
105123
106124STATIC const mp_rom_map_elem_t supervisor_runtime_locals_dict_table [] = {
125+ { MP_ROM_QSTR (MP_QSTR_usb_connected ), MP_ROM_PTR (& supervisor_runtime_usb_connected_obj ) },
107126 { MP_ROM_QSTR (MP_QSTR_serial_connected ), MP_ROM_PTR (& supervisor_runtime_serial_connected_obj ) },
108127 { MP_ROM_QSTR (MP_QSTR_serial_bytes_available ), MP_ROM_PTR (& supervisor_runtime_serial_bytes_available_obj ) },
109128 { MP_ROM_QSTR (MP_QSTR_run_reason ), MP_ROM_PTR (& supervisor_runtime_run_reason_obj ) },
0 commit comments