clean up HostPowerManagement

Remove the effectively unused `initial_suspend_` variable. It wasn't
doing  anything useful, because it was set to false on the first round
through the event loop. Also remove the unused reference to the internal
AVR USB core variable `_usbSuspendState`.

Saves 18 bytes of flash on AVR, and 32 on GD32.

Signed-off-by: Taylor Yu <tlyu@mit.edu>
master
Taylor Yu 2 years ago
parent 18d0292d64
commit e233e96be7

@ -26,15 +26,10 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
// This is a terrible hack until Arduino#6964 gets implemented.
// It makes the `_usbSuspendState` symbol available to us.
extern uint8_t _usbSuspendState;
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true;
bool HostPowerManagement::isSuspended() { bool HostPowerManagement::isSuspended() {
#if defined(__AVR__) #if defined(__AVR__)
@ -48,17 +43,13 @@ bool HostPowerManagement::isSuspended() {
EventHandlerResult HostPowerManagement::beforeEachCycle() { EventHandlerResult HostPowerManagement::beforeEachCycle() {
if (isSuspended()) { if (isSuspended()) {
if (!initial_suspend_) { if (!was_suspended_) {
if (!was_suspended_) { was_suspended_ = true;
was_suspended_ = true; hostPowerManagementEventHandler(Suspend);
hostPowerManagementEventHandler(Suspend); } else {
} else { hostPowerManagementEventHandler(Sleep);
hostPowerManagementEventHandler(Sleep);
}
} }
} else { } else {
if (initial_suspend_)
initial_suspend_ = false;
if (was_suspended_) { if (was_suspended_) {
was_suspended_ = false; was_suspended_ = false;
hostPowerManagementEventHandler(Resume); hostPowerManagementEventHandler(Resume);

@ -34,7 +34,6 @@ class HostPowerManagement : public kaleidoscope::Plugin {
private: private:
static bool was_suspended_; static bool was_suspended_;
static bool initial_suspend_;
bool isSuspended(); bool isSuspended();
}; };

Loading…
Cancel
Save