File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,5 +47,4 @@ char serial_read(void);
4747bool serial_bytes_available (void );
4848bool serial_connected (void );
4949
50- extern volatile bool _serial_connected ;
5150#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
Original file line number Diff line number Diff line change @@ -47,8 +47,6 @@ busio_uart_obj_t debug_uart;
4747byte buf_array [64 ];
4848#endif
4949
50- volatile bool _serial_connected ;
51-
5250void serial_early_init (void ) {
5351#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
5452 debug_uart .base .type = & busio_uart_type ;
@@ -71,7 +69,9 @@ bool serial_connected(void) {
7169#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
7270 return true;
7371#else
74- return _serial_connected ;
72+ // True if DTR is asserted, and the USB connection is up.
73+ // tud_cdc_get_line_state(): bit 0 is DTR, bit 1 is RTS
74+ return (tud_cdc_get_line_state () & 1 ) && tud_ready ();
7575#endif
7676}
7777
Original file line number Diff line number Diff line change @@ -116,7 +116,6 @@ void tud_umount_cb(void) {
116116// remote_wakeup_en : if host allows us to perform remote wakeup
117117// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
118118void tud_suspend_cb (bool remote_wakeup_en ) {
119- _serial_connected = false;
120119}
121120
122121// Invoked when usb bus is resumed
@@ -128,8 +127,6 @@ void tud_resume_cb(void) {
128127void tud_cdc_line_state_cb (uint8_t itf , bool dtr , bool rts ) {
129128 (void ) itf ; // interface ID, not used
130129
131- _serial_connected = dtr ;
132-
133130 // DTR = false is counted as disconnected
134131 if ( !dtr )
135132 {
You can’t perform that action at this time.
0 commit comments