Skip to content

ToughC5: deep sleep wakeup through the PM1 IRQ output, and IO expander access - #297

Merged
lovyan03 merged 2 commits into
m5stack:developfrom
ainyan03:toughc5_wake
Aug 7, 2026
Merged

ToughC5: deep sleep wakeup through the PM1 IRQ output, and IO expander access#297
lovyan03 merged 2 commits into
m5stack:developfrom
ainyan03:toughc5_wake

Conversation

@ainyan03

@ainyan03 ainyan03 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

On ToughC5 neither the RTC nIRQ nor the touch INT reaches the ESP32 directly: they are collected by the PM1 (GPIO3 / GPIO0), and the PM1 IRQ output (GPIO1) is the only line wired to the ESP32 (GPIO4). This PR makes deep sleep wakeup ride on that single active-low line, and exposes the on-board M5IOE1.

Wake ToughC5 from deep sleep through the PM1 IRQ output

  • begin(): configure PM1 GPIO1 as the IRQ output and GPIO3 (RX8130 nIRQ) as an input. Without an IRQ pin the PM1 clears the IRQ status registers (0x40-0x42) by itself, so neither the power button nor the RTC alarm could ever be observed. The line has no external pull-up, so GPIO4 is set up as an input with the internal pull-up.
  • _clearWakeupInterrupt(): clear WAKE_SRC and the IRQ statuses. While WAKE_SRC is left set, the WAKEUP bit of IRQ status 3 keeps reasserting and the IRQ output never releases.
  • _powerOff(): with a timer, arm EXT1 (ANY_LOW), enable the RTC-domain pull-up that stays effective during deep sleep, and wait for the IRQ output to release before sleeping.
  • deepSleep(): include C5 in the wakeup pin handling. The pull policy is the opposite of the boards that have an external pull-up: ToughC5 needs the pull-up, not the pull-down.

Expose the ToughC5 M5IOE1 through getIOExpander

  • Beside the LCD power / reset / backlight, the TF card power (PYG6) and card detect (PYG14) hang off this IO expander, so applications need a way to reach it.

Verified on ToughC5: RTC alarm wake fires at the configured time, touch and the power button wake the device from deep sleep, and the TF card works through the IOE (power on, card detect, mount and directory listing).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates ToughC5 board support so deep sleep wakeup can work through the single PM1 IRQ output line (PM1 GPIO1 → ESP32 GPIO4), and exposes the on-board M5IOE1 IO expander via getIOExpander() for applications that need TF power/card-detect control.

Changes:

  • Configure PM1 GPIO1 as IRQ output and set up the ESP32 wakeup pin (GPIO4) with an internal pull-up for ToughC5.
  • Adjust deep sleep / power-off wakeup handling for ToughC5 so EXT1 ANY_LOW wake works correctly and the PM1 IRQ line can be released by clearing WAKE_SRC / IRQ status.
  • Instantiate and expose M5IOE1_Class for ToughC5 in the IO expander setup path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/utility/Power_Class.cpp Adds ToughC5 PM1 IRQ/wakeup-pin setup and updates deep sleep pull policy and power-off wake handling.
src/M5Unified.cpp Adds ToughC5 IO expander instantiation and clears PM1 wake/IRQ status in _clearWakeupInterrupt().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +235 to +238
/// PM1 GPIO1 は ESP32 の G4 へ配線された IRQ 出力。IRQ ピンを設定して
/// おかないと PM1 が IRQ ステータス (0x40-0x42) を自動クリアしてしまい、
/// 電源ボタンや RTC アラームの IRQ 検出が機能しない。
M5pm1.setGPIOFunction(M5PM1_Class::gpio1, M5PM1_Class::irq);
Comment on lines +1217 to +1221
{ /// RTC の nIRQ は ESP32 に直結されておらず PM1 の IRQ 出力に集約される
/// 構成 (ToughC5 等)。IRQ 出力が解放される (High に戻る) まで待って
/// から眠り、その Low 遷移で deep sleep から復帰できるようにする。
esp_sleep_enable_ext1_wakeup(1ULL << _wakeupPin, ESP_EXT1_WAKEUP_ANY_LOW);
#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED
On ToughC5 neither the RTC nIRQ nor the touch INT reaches the ESP32
directly: they are collected by the PM1 (GPIO3 / GPIO0), and the PM1
IRQ output (GPIO1) is the only line wired to the ESP32 (GPIO4). Waking
from deep sleep therefore has to ride on that single active-low line.

- begin(): configure PM1 GPIO1 as the IRQ output and GPIO3 (RX8130
  nIRQ) as an input. Without an IRQ pin the PM1 clears the IRQ status
  registers (0x40-0x42) by itself, so neither the power button nor the
  RTC alarm could ever be observed. The line has no external pull-up,
  so GPIO4 is set up as an input with the internal pull-up.
- _clearWakeupInterrupt(): clear WAKE_SRC and the IRQ statuses. While
  WAKE_SRC is left set, the WAKEUP bit of IRQ status 3 keeps
  reasserting and the IRQ output never releases.
- _powerOff(): with a timer, arm EXT1 (ANY_LOW), enable the RTC-domain
  pull-up that stays effective during deep sleep, and wait for the IRQ
  output to release before sleeping.
- deepSleep(): include C5 in the wakeup pin handling. The pull policy
  is the opposite of the boards that have an external pull-up: ToughC5
  needs the pull-up, not the pull-down.
Beside the LCD power / reset / backlight, the TF card power (PYG6) and
card detect (PYG14) hang off this IO expander, so applications need a
way to reach it.
@ainyan03

ainyan03 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Applied both suggestions:

  • PM1 GPIO1 is now configured as a push-pull output driven high (mode / drive / pull / level) before switching its function to IRQ, following the same setup used by the existing m5pm1 boards. The released state is now actively driven high instead of relying on the ESP32-side pull-up alone (the internal pull-up is kept as a safety net for deep sleep).
  • The return value of esp_sleep_enable_ext1_wakeup() is now checked, and a warning is logged when the wakeup pin cannot be armed.

Re-verified on ToughC5: RTC alarm wake, touch wake and power button wake all work after the change.

@lovyan03
lovyan03 merged commit 0b76dfc into m5stack:develop Aug 7, 2026
22 of 23 checks passed
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

Successfully merging this pull request may close these issues.

3 participants