aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/DisplayApp.cpp
diff options
context:
space:
mode:
authormark9064 <30447455+mark9064@users.noreply.github.com>2024-08-23 11:25:54 +0100
committerJF <JF002@users.noreply.github.com>2024-10-27 16:56:47 +0100
commit771008495edf0144dd528818bafa77bc10096002 (patch)
tree386907838c35945cb9b28cdf41e8fd4577c5d05b /src/displayapp/DisplayApp.cpp
parentf032847ae1108ad19c1a3c447cfd4f255e6ae33b (diff)
Replace rounded div macro
Diffstat (limited to 'src/displayapp/DisplayApp.cpp')
-rw-r--r--src/displayapp/DisplayApp.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 14047571..918dd9f9 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -159,8 +159,11 @@ void DisplayApp::InitHw() {
TickType_t DisplayApp::CalculateSleepTime() {
TickType_t ticksElapsed = xTaskGetTickCount() - alwaysOnStartTime;
// Divide both the numerator and denominator by 8 to increase the number of ticks (frames) before the overflow tick is reached
- TickType_t elapsedTarget = ROUNDED_DIV((configTICK_RATE_HZ / 8) * alwaysOnTickCount * alwaysOnRefreshPeriod, 1000 / 8);
- // ROUNDED_DIV overflows when numerator + (denominator floordiv 2) > uint32 max
+ auto RoundedDiv = [](uint32_t a, uint32_t b) {
+ return ((a + (b / 2)) / b);
+ };
+ TickType_t elapsedTarget = RoundedDiv((configTICK_RATE_HZ / 8) * alwaysOnTickCount * alwaysOnRefreshPeriod, 1000 / 8);
+ // RoundedDiv overflows when numerator + (denominator floordiv 2) > uint32 max
// in this case around 9 hours
constexpr TickType_t overflowTick = (UINT32_MAX - (1000 / 16)) / ((configTICK_RATE_HZ / 8) * alwaysOnRefreshPeriod);