Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Fixed `PM5 auto-off` - no longer powers the board into a state it can't be woken from (@nemanjan00)
- Fixed `tools/ePassport` - FILES and LOG panes no longer go blank on long content, and picture files now show the picture (@pkilar)
- Fixed `hf xerox view` - now rejects a dump file too small to contain the info blocks instead of reading past it (@munzzyy)
- Changed NG frame layout to align better with 64bytes frames. From 512 -> 624bytes (@iceman1001)
Expand Down
17 changes: 17 additions & 0 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,20 @@ static bool s_autooff_setup = false;
// unplugged at all (and the hw bwmautooff toggle would be unreachable, since setting it
// needs a client/USB). So we require having seen USB present at least once this session
// before an absent reading triggers shutdown.
#ifndef PM5_AUTOOFF_CONFIRMATIONS
// Consecutive absent samples required before powering off (x PM5_AUTOOFF_POLL_MS).
// This is the grace period the comment above has always promised, and it is not only
// glitch rejection: pulling VBUS puts the BWM charger into Battery Discharge Mode, and
// BATFET is only turned fully on as part of that transition. Releasing the power latch
// 250ms in leaves the charger mid-transition and the board will not power on again -
// waiting lets DISCHG settle first.
#define PM5_AUTOOFF_CONFIRMATIONS 20 // 20 x 250ms = 5s
#endif

static void bwm_autooff_check(void) {
static uint32_t last_tick = 0;
static bool usb_was_present = false; // have we seen USB present since boot?
static uint8_t absent = 0; // consecutive USB-absent samples

if (g_autooff_enabled == false) {
return;
Expand All @@ -130,6 +141,7 @@ static void bwm_autooff_check(void) {
// Gpio_VUSB_Read() == true means USB power present.
if (Gpio_VUSB_Read()) {
usb_was_present = true; // latch: USB has been present this session
absent = 0; // present again -> restart the grace period
return;
}

Expand All @@ -139,6 +151,11 @@ static void bwm_autooff_check(void) {
return;
}

// Require the absence to persist before acting on it.
if (++absent < PM5_AUTOOFF_CONFIRMATIONS) {
return;
}

LEDsoff();
Gpio_ARM_Power_ON_Low();
while (1); // wait for hardware power-off (button press powers back on, in hardware)
Expand Down
Loading