ToughC5: deep sleep wakeup through the PM1 IRQ output, and IO expander access - #297
Merged
Conversation
There was a problem hiding this comment.
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_Classfor 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.
Contributor
Author
|
Applied both suggestions:
Re-verified on ToughC5: RTC alarm wake, touch wake and power button wake all work after the change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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).