pwr_switch.h 1.8 KB

1234567891011121314151617181920212223242526272829
  1. // pwr_switch.h -- GPIO trigger emulating a momentary press of the HOST motherboard's power switch.
  2. //
  3. // Optional feature (build with -DOPK_PWR_SWITCH=1, see config.h): fires ONE momentary pulse on
  4. // PWR_SWITCH_PIN when the paired Steam Controller's STEAM button gets a short press (down+up
  5. // within 1s -- the same gesture rf_link.cpp already recognizes for USB remote wakeup) WHILE the
  6. // host is OFF: USB has never enumerated / has stopped enumerating (USBDevice.mounted() == false),
  7. // sustained for HOST_OFF_DEBOUNCE_MS so a brief re-enumeration blip can't false-fire. Assumes the
  8. // USB port keeps standby power while the host is off (so this firmware keeps running and
  9. // listening) and the controller is already bonded -- there is no pairing UI here.
  10. //
  11. // Hardware note: PWR_SWITCH_PIN must drive an ISOLATING stage (relay / optocoupler / transistor)
  12. // wired across the motherboard's front-panel power-switch header -- never short the header
  13. // directly to the nRF's GPIO. This module only knows how to drive one pin; the isolation is on you.
  14. #pragma once
  15. #ifndef PWR_SWITCH_PIN
  16. // Arduino pin number for physical P0.17 ("017" on this SuperMini clone's silkscreen) under the
  17. // Adafruit Feather core this builds against (variants/feather_nrf52840_express/variant.cpp:
  18. // g_ADigitalPinMap[29] == 17) -- confirmed on real hardware with a standalone blink sketch. The
  19. // silkscreen number is NOT the Arduino pin number; don't assume identity on a different board.
  20. #define PWR_SWITCH_PIN 29
  21. #endif
  22. #ifndef PWR_SWITCH_ACTIVE
  23. #define PWR_SWITCH_ACTIVE \
  24. HIGH // level that closes the switch; set LOW if your driver is active-low
  25. #endif
  26. void pwrSwitchInit(); // call once from setup(): pin to output, released (inactive) level
  27. void pwrSwitchTask(); // call every loop(): edge-detect the Steam short press, gate, pulse, release