File tree Expand file tree Collapse file tree 4 files changed +9
-8
lines changed
shared-bindings/supervisor Expand file tree Collapse file tree 4 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 46
46
//|
47
47
48
48
//| serial_connected: bool
49
- //| """Returns the USB serial communication status (read-only).
50
- //|
51
- //| .. note::
52
- //|
53
- //| SAMD: Will return ``True`` if the USB serial connection
54
- //| has been established at any point. Will not reset if
55
- //| USB is disconnected but power remains (e.g. battery connected)"""
49
+ //| """Returns the USB serial communication status (read-only)."""
56
50
//|
57
51
58
52
STATIC mp_obj_t supervisor_get_serial_connected (mp_obj_t self ){
Original file line number Diff line number Diff line change @@ -47,4 +47,5 @@ char serial_read(void);
47
47
bool serial_bytes_available (void );
48
48
bool serial_connected (void );
49
49
50
+ extern volatile bool _serial_connected ;
50
51
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ busio_uart_obj_t debug_uart;
47
47
byte buf_array [64 ];
48
48
#endif
49
49
50
+ volatile bool _serial_connected ;
51
+
50
52
void serial_early_init (void ) {
51
53
#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
52
54
debug_uart .base .type = & busio_uart_type ;
@@ -69,7 +71,7 @@ bool serial_connected(void) {
69
71
#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
70
72
return true;
71
73
#else
72
- return tud_cdc_connected () ;
74
+ return _serial_connected ;
73
75
#endif
74
76
}
75
77
Original file line number Diff line number Diff line change 29
29
#include "shared-module/usb_midi/__init__.h"
30
30
#include "supervisor/background_callback.h"
31
31
#include "supervisor/port.h"
32
+ #include "supervisor/serial.h"
32
33
#include "supervisor/usb.h"
33
34
#include "lib/utils/interrupt_char.h"
34
35
#include "lib/mp-readline/readline.h"
@@ -115,6 +116,7 @@ void tud_umount_cb(void) {
115
116
// remote_wakeup_en : if host allows us to perform remote wakeup
116
117
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
117
118
void tud_suspend_cb (bool remote_wakeup_en ) {
119
+ _serial_connected = false;
118
120
}
119
121
120
122
// Invoked when usb bus is resumed
@@ -126,6 +128,8 @@ void tud_resume_cb(void) {
126
128
void tud_cdc_line_state_cb (uint8_t itf , bool dtr , bool rts ) {
127
129
(void ) itf ; // interface ID, not used
128
130
131
+ _serial_connected = dtr ;
132
+
129
133
// DTR = false is counted as disconnected
130
134
if ( !dtr )
131
135
{
You can’t perform that action at this time.
0 commit comments