circuitpython/shared-bindings/supervisor
Jeff Epler 28043c94b5 supervisor: Improve serial connection detection
These changes remove the caveat from supervisor.runtime.serial_connected.

It appears that _tud_cdc_connected() only tracks explicit changes to the
"DTR" bit, which leads to disconnects not being registered.

Instead:
 * when line state is changed explicitly, track the dtr value in
   _serial_connected
 * when the USB bus is suspended, set _serial_connected to False

Testing performed (using sam e54 xplained):  Run a program to show
the state of `serial_connected` on the LED:
```
import digitalio
import supervisor
import board

led = digitalio.DigitalInOut(board.LED)
while True:
    led.switch_to_output(not supervisor.runtime.serial_connected)
```

Try all the following:
 * open, close serial terminal program
    - LED status tracks whether terminal is open
 * turn on/off data lines using the switchable charge-only cable
    - LED turns off when switch is in "charger" position
    - LED turns back on when switch is in Data position and terminal is
      opened (but doesn't turn back on just because switch position is
      changed)
2020-09-17 18:32:06 -05:00
..
Runtime.c supervisor: Improve serial connection detection 2020-09-17 18:32:06 -05:00
Runtime.h Add externs. GCC10 complains about duplicate defines 2020-07-22 16:26:46 -07:00
__init__.c Modify some Python stubs 2020-08-07 01:01:28 +09:00
__init__.h Fix up end of file and trailing whitespace. 2020-06-03 10:56:35 +01:00