Skip to content

Conversation

rondlh
Copy link

@rondlh rondlh commented Sep 15, 2025

Solves 24 timer rollover bug using ELAPSED and PENDING macros.

Requirements

None

Description

This PR solves 24 timer rollover bugs I found in the code. These bugs can make the TFT behave erratically, but only after a long time. The cause is the 32 bit timer register rollover from 0xFFFFFFFF to 0. When using incorrect timer math the results can be incorrect.
To solve the bugs I use a strategy bored by Marlin, which uses macros to prevent issues.

PENDING(when) with "when" a time in the future.
ELAPSED(starttime, interval) with starttime a time in the past, and the interval the time to check for if it has elapsed since the starttime.

Benefits

  1. No erratic TFT behavior after a long on time.
  2. Set a good example for users who review the code base.
  3. Improved code quality.

Related Issues

#2992

24 rollover bugfixes using ELAPSED and PENDING macros
#define MIN_TO_SEC(t) (t * 60) // minute to seconds
#define MIN_TO_MS(t) (SEC_TO_MS(t) * 60) // minute to milliseconds

// timer rollover safe functions
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move this macros just above // time conversion

Copy link
Author

Choose a reason for hiding this comment

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

I would move this macros just above // time conversion

Done!

Copy link
Author

Choose a reason for hiding this comment

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

Code is final and ready for release.

Moved "timer rollover safe functions" to above "time conversion" as suggested by digant73
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.

2 participants