File tree Expand file tree Collapse file tree
shared-bindings/supervisor Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4646//|
4747
4848//| 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)."""
5650//|
5751
5852STATIC 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);
4747bool serial_bytes_available (void );
4848bool serial_connected (void );
4949
50+ extern volatile bool _serial_connected ;
5051#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;
4747byte buf_array [64 ];
4848#endif
4949
50+ volatile bool _serial_connected ;
51+
5052void serial_early_init (void ) {
5153#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
5254 debug_uart .base .type = & busio_uart_type ;
@@ -69,7 +71,7 @@ bool serial_connected(void) {
6971#if defined(DEBUG_UART_TX ) && defined(DEBUG_UART_RX )
7072 return true;
7173#else
72- return tud_cdc_connected () ;
74+ return _serial_connected ;
7375#endif
7476}
7577
Original file line number Diff line number Diff line change 2929#include "shared-module/usb_midi/__init__.h"
3030#include "supervisor/background_callback.h"
3131#include "supervisor/port.h"
32+ #include "supervisor/serial.h"
3233#include "supervisor/usb.h"
3334#include "lib/utils/interrupt_char.h"
3435#include "lib/mp-readline/readline.h"
@@ -115,6 +116,7 @@ void tud_umount_cb(void) {
115116// remote_wakeup_en : if host allows us to perform remote wakeup
116117// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
117118void tud_suspend_cb (bool remote_wakeup_en ) {
119+ _serial_connected = false;
118120}
119121
120122// Invoked when usb bus is resumed
@@ -126,6 +128,8 @@ void tud_resume_cb(void) {
126128void tud_cdc_line_state_cb (uint8_t itf , bool dtr , bool rts ) {
127129 (void ) itf ; // interface ID, not used
128130
131+ _serial_connected = dtr ;
132+
129133 // DTR = false is counted as disconnected
130134 if ( !dtr )
131135 {
You can’t perform that action at this time.
0 commit comments