Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: callback / function to check for (PC) USB host suspending Port #685

Open
FeuerSturm opened this issue Feb 10, 2023 · 1 comment

Comments

@FeuerSturm
Copy link

FeuerSturm commented Feb 10, 2023

@PaulStoffregen

I have ported my project from using TinyUSB stack and FastLED on a generic Raspberry Pi Pico to
a Teensy 4.X with using your amazing OctoWS2811 library, I've got almost everything to work perfect,
but there's one thing that nags me: the lack of being able to reliably detect the PC suspending the USB ports

Using TinyUSB allowed me to simply check for the state of the USB port with bool portSuspended = TinyUSBDevice.suspended();
and I desperatly need such a feature.
I asked for help on the forums already and receivedd a reply with a possible solution reading the suspend flag in the PORTSC1,
unfortunately that's not really working for me at all, using this test sketch showed that it seems to be totally random when the
onboard led turns on or off:

unsigned long lastCheck;

void setup()
{
	pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
	unsigned long currentMillis = millis();
	if(currentMillis - lastCheck >= 1000)
	{
		lastCheck = currentMillis;
		if(!bitRead(USB1_PORTSC1,7))
		{
			digitalWrite(LED_BUILTIN, HIGH);
		} 
		else
		{
			digitalWrite(LED_BUILTIN, LOW);
		}
	}
}

I have then checked the i.MX RT1060 Processor Reference Manual, Rev. 2, 12/2019 and tried everything that I could find searching for "suspend" inside it, no success at all.

I'd really love to see a callback or function to reliably check if the PC the Teensy is connected to is on or off (port suspended or not).

Thanks!

@zahndy
Copy link

zahndy commented May 7, 2024

I was also trying to detect PC suspend but this works for me just fine:

void loop() {

  if(bitRead(USB1_PORTSC1,7) != 0){

Though if it were randomly triggering Its also possible its flashing so fast I cant see it.
Maybe try a different pin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants