8000 Merge pull request #3513 from microDev1/checkUSB · carlossless/circuitpython@e3c54b0 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e3c54b0

Browse files
authored
Merge pull request adafruit#3513 from microDev1/checkUSB
Implement function to check usb connection
2 parents c480047 + bd95914 commit e3c54b0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

shared-bindings/supervisor/Runtime.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333
#include "shared-bindings/supervisor/RunReason.h"
3434
#include "shared-bindings/supervisor/Runtime.h"
3535

36+
#include "tusb.h"
37+
3638
STATIC 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

106124
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) },
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

Comments
 (0)
0