Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beken-72xx] Fix duration rollover in deep sleep #253

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
11 changes: 5 additions & 6 deletions cores/beken-72xx/base/api/lt_sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ void lt_deep_sleep_unset_gpio(uint32_t gpio_index_map) {
deep_sleep_param.gpio_index_map &= (~gpio_index_map);
}

void lt_deep_sleep_config_timer(uint32_t sleep_duration) {
void lt_deep_sleep_config_timer(uint32_t sleep_duration_ms) {
deep_sleep_param.wake_up_way |= PS_DEEP_WAKEUP_RTC;
uint64_t duration_math = 32768 * sleep_duration;
if (duration_math / 1000 > 0xFFFFFFFF) {
// Sleep forever
deep_sleep_param.sleep_time = 0xFFFFFFFF;
uint64_t sleep_ticks = 32.768 * sleep_duration_ms;
if (sleep_ticks >= 0xFFFFFFFF) {
Copy link
Collaborator

@Cossid Cossid Feb 21, 2024

Choose a reason for hiding this comment

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

I think this should still be > instead of >= in case some actually does want to sleep forever (like rely fully on GPIO wakeup).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! Just fix the rollover.

Copy link
Member

Choose a reason for hiding this comment

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

No, if someone wants it to sleep forever, they won't call lt_deep_sleep_config_timer() in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about it more it wouldn't make sense to call lt_deep_sleep_config_timer() if you want to wait forever for another wake reason. My ESPHome deep_sleep changes only call the lt_deep_sleep_config_timer() function if a sleep_duration is defined in the YAML.

deep_sleep_param.sleep_time = 0xFFFFFFFE;
} else {
deep_sleep_param.sleep_time = (duration_math / 1000) & 0xFFFFFFFF;
deep_sleep_param.sleep_time = sleep_ticks & 0xFFFFFFFF;
}
}

Expand Down
Loading