Merge pull request #3624 from dhalbert/usb-serial-detect-2
improve USB CDC disconnect/reconnect checking
This commit is contained in:
commit
bbed1b0354
@ -47,5 +47,4 @@ char serial_read(void);
|
|||||||
bool serial_bytes_available(void);
|
bool serial_bytes_available(void);
|
||||||
bool serial_connected(void);
|
bool serial_connected(void);
|
||||||
|
|
||||||
extern volatile bool _serial_connected;
|
|
||||||
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
|
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H
|
||||||
|
@ -47,8 +47,6 @@ busio_uart_obj_t debug_uart;
|
|||||||
byte buf_array[64];
|
byte buf_array[64];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
volatile bool _serial_connected;
|
|
||||||
|
|
||||||
void serial_early_init(void) {
|
void serial_early_init(void) {
|
||||||
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
||||||
debug_uart.base.type = &busio_uart_type;
|
debug_uart.base.type = &busio_uart_type;
|
||||||
@ -71,7 +69,9 @@ bool serial_connected(void) {
|
|||||||
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return _serial_connected;
|
// True if DTR is asserted, and the USB connection is up.
|
||||||
|
// tud_cdc_get_line_state(): bit 0 is DTR, bit 1 is RTS
|
||||||
|
return (tud_cdc_get_line_state() & 1) && tud_ready();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,6 @@ void tud_umount_cb(void) {
|
|||||||
// remote_wakeup_en : if host allows us to perform remote wakeup
|
// remote_wakeup_en : if host allows us to perform remote wakeup
|
||||||
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
|
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
|
||||||
void tud_suspend_cb(bool remote_wakeup_en) {
|
void tud_suspend_cb(bool remote_wakeup_en) {
|
||||||
_serial_connected = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoked when usb bus is resumed
|
// Invoked when usb bus is resumed
|
||||||
@ -128,8 +127,6 @@ void tud_resume_cb(void) {
|
|||||||
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
|
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
|
||||||
(void) itf; // interface ID, not used
|
(void) itf; // interface ID, not used
|
||||||
|
|
||||||
_serial_connected = dtr;
|
|
||||||
|
|
||||||
// DTR = false is counted as disconnected
|
// DTR = false is counted as disconnected
|
||||||
if ( !dtr )
|
if ( !dtr )
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user