From 9afeeb7215403b470759f9fcbc8f4ef9ce88ca9a Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 25 Nov 2017 09:23:09 +0100 Subject: [PATCH] Add USBDevice.isSuspended() Based on code originally by Rob van der Veer , this adds USBDevice.isSuspended(), so user sketches can run custom code in their `loop` methods after checking if the device is suspended or not. Signed-off-by: Gergely Nagy --- hardware/arduino/avr/cores/arduino/USBAPI.h | 2 ++ hardware/arduino/avr/cores/arduino/USBCore.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/hardware/arduino/avr/cores/arduino/USBAPI.h b/hardware/arduino/avr/cores/arduino/USBAPI.h index 479ced9c84c..701a14f786c 100644 --- a/hardware/arduino/avr/cores/arduino/USBAPI.h +++ b/hardware/arduino/avr/cores/arduino/USBAPI.h @@ -65,6 +65,8 @@ class USBDevice_ void detach(); // Serial port goes down too... void poll(); bool wakeupHost(); // returns false, when wakeup cannot be processed + + bool isSuspended(); }; extern USBDevice_ USBDevice; diff --git a/hardware/arduino/avr/cores/arduino/USBCore.cpp b/hardware/arduino/avr/cores/arduino/USBCore.cpp index e00fb028e22..4f0867246fc 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.cpp +++ b/hardware/arduino/avr/cores/arduino/USBCore.cpp @@ -862,4 +862,10 @@ bool USBDevice_::wakeupHost() return false; } +bool USBDevice_::isSuspended() +{ + return (_usbSuspendState & (1 << SUSPI)); +} + + #endif /* if defined(USBCON) */