I know this is not a common use case that I disconnect teensy from PC but suppose teensy is powered by a battery thus disconnecting it from PC won't shut it off. I want to know how to detect disconnection. I was looking at void usb_isr(void) in usb.c but there's no mention of disconnection or maybe detached state. There's reset state which can happen without disconnection. I checked the USB_nUSBSTS field descriptions. There is no disconnected interrupt.
I looked into the manual and found a bit in the PHY that detects disconnection in device mode on USBPHYx_CTRLn:
5
DEVPLUGIN_POLARITY
For device mode, if this bit is cleared to 0, then it trips the interrupt if the device is plugged in. If
set to 1, then it trips the interrupt if the device is unplugged.
Or is it in USB_ANALOG_USB1_VBUS_DETECT_STAT such as the following?
2
AVALID
Indicates VBus is valid for a A-peripheral. This bit is a read only version of the state of the analog signal. It
can not be overritten by software.
I looked into the manual and found a bit in the PHY that detects disconnection in device mode on USBPHYx_CTRLn:
5
DEVPLUGIN_POLARITY
For device mode, if this bit is cleared to 0, then it trips the interrupt if the device is plugged in. If
set to 1, then it trips the interrupt if the device is unplugged.
Or is it in USB_ANALOG_USB1_VBUS_DETECT_STAT such as the following?
2
AVALID
Indicates VBus is valid for a A-peripheral. This bit is a read only version of the state of the analog signal. It
can not be overritten by software.