33
33
#include "shared-bindings/supervisor/RunReason.h"
34
34
#include "shared-bindings/supervisor/Runtime.h"
35
35
36
+ #include "tusb.h"
37
+
36
38
STATIC supervisor_run_reason_t _run_reason ;
37
39
38
- // TODO: add USB, REPL to description once they're operational
40
+ // TODO: add REPL to description once it is operational
41
+
39
42
//| class Runtime:
40
43
//| """Current status of runtime objects.
41
44
//|
@@ -52,6 +55,21 @@ STATIC supervisor_run_reason_t _run_reason;
52
55
//| ...
53
56
//|
54
57
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
+
55
73
//| serial_connected: bool
56
74
//| """Returns the USB serial communication status (read-only)."""
57
75
//|
@@ -104,6 +122,7 @@ void supervisor_set_run_reason(supervisor_run_reason_t run_reason) {
104
122
}
105
123
106
124
STATIC 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 ) },
107
126
{ MP_ROM_QSTR (MP_QSTR_serial_connected ), MP_ROM_PTR (& supervisor_runtime_serial_connected_obj ) },
108
127
{ MP_ROM_QSTR (MP_QSTR_serial_bytes_available ), MP_ROM_PTR (& supervisor_runtime_serial_bytes_available_obj ) },
109
128
{ MP_ROM_QSTR (MP_QSTR_run_reason ), MP_ROM_PTR (& supervisor_runtime_run_reason_obj ) },
0 commit comments