mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Set next state expected time on per element basis (#13706) * Set next state expected time on per element basis * Rename osdNextElement to be clearer Co-authored-by: Steve Evans <SteveCEvans@users.noreply.github.com>
This commit is contained in:
parent
591c64ddc1
commit
cffe79e387
1 changed files with 20 additions and 37 deletions
|
@ -202,12 +202,9 @@ const osd_stats_e osdStatsDisplayOrder[OSD_STAT_COUNT] = {
|
||||||
OSD_STAT_AVG_THROTTLE,
|
OSD_STAT_AVG_THROTTLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Group elements in a number of groups to reduce task scheduling overhead
|
|
||||||
#define OSD_GROUP_COUNT OSD_ITEM_COUNT
|
|
||||||
// Aim to render a group of elements within a target time
|
|
||||||
#define OSD_ELEMENT_RENDER_TARGET 30
|
|
||||||
|
|
||||||
#define OSD_TASK_MARGIN 1
|
#define OSD_TASK_MARGIN 1
|
||||||
|
#define OSD_ELEMENT_MARGIN 1
|
||||||
|
|
||||||
// Decay the estimated max task duration by 1/(1 << OSD_EXEC_TIME_SHIFT) on every invocation
|
// Decay the estimated max task duration by 1/(1 << OSD_EXEC_TIME_SHIFT) on every invocation
|
||||||
#define OSD_EXEC_TIME_SHIFT 8
|
#define OSD_EXEC_TIME_SHIFT 8
|
||||||
|
|
||||||
|
@ -1375,7 +1372,6 @@ void osdUpdate(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
static uint16_t osdStateDurationFractionUs[OSD_STATE_COUNT] = { 0 };
|
static uint16_t osdStateDurationFractionUs[OSD_STATE_COUNT] = { 0 };
|
||||||
static uint32_t osdElementDurationFractionUs[OSD_ITEM_COUNT] = { 0 };
|
static uint32_t osdElementDurationFractionUs[OSD_ITEM_COUNT] = { 0 };
|
||||||
static bool firstPass = true;
|
|
||||||
timeUs_t executeTimeUs;
|
timeUs_t executeTimeUs;
|
||||||
osdState_e osdCurrentState = osdState;
|
osdState_e osdCurrentState = osdState;
|
||||||
|
|
||||||
|
@ -1506,29 +1502,20 @@ void osdUpdate(timeUs_t currentTimeUs)
|
||||||
{
|
{
|
||||||
bool moreElements = true;
|
bool moreElements = true;
|
||||||
|
|
||||||
for (int rendered = 0; moreElements; rendered++) {
|
uint8_t osdElement = osdGetActiveElement();
|
||||||
uint8_t osdCurrentElement = osdGetActiveElement();
|
|
||||||
|
|
||||||
timeUs_t startElementTime = micros();
|
timeUs_t startElementTime = micros();
|
||||||
|
|
||||||
timeUs_t anticipatedEndUs = startElementTime + (osdElementDurationFractionUs[osdCurrentElement] >> OSD_EXEC_TIME_SHIFT);
|
moreElements = osdDrawNextActiveElement(osdDisplayPort, startElementTime);
|
||||||
|
|
||||||
if ((rendered > 0) && cmpTimeUs(anticipatedEndUs, currentTimeUs) > OSD_ELEMENT_RENDER_TARGET) {
|
executeTimeUs = micros() - startElementTime;
|
||||||
// There isn't time to render the next element
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
moreElements = osdDrawNextActiveElement(osdDisplayPort, currentTimeUs);
|
if (executeTimeUs > (osdElementDurationFractionUs[osdElement] >> OSD_EXEC_TIME_SHIFT)) {
|
||||||
|
osdElementDurationFractionUs[osdElement] = executeTimeUs << OSD_EXEC_TIME_SHIFT;
|
||||||
executeTimeUs = micros() - startElementTime;
|
} else if (osdElementDurationFractionUs[osdElement] > 0) {
|
||||||
|
// Slowly decay the max time
|
||||||
if (executeTimeUs > (osdElementDurationFractionUs[osdCurrentElement] >> OSD_EXEC_TIME_SHIFT)) {
|
osdElementDurationFractionUs[osdElement]--;
|
||||||
osdElementDurationFractionUs[osdCurrentElement] = executeTimeUs << OSD_EXEC_TIME_SHIFT;
|
}
|
||||||
} else if (osdElementDurationFractionUs[osdCurrentElement] > 0) {
|
|
||||||
// Slowly decay the max time
|
|
||||||
osdElementDurationFractionUs[osdCurrentElement]--;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (moreElements) {
|
if (moreElements) {
|
||||||
// There are more elements to draw
|
// There are more elements to draw
|
||||||
|
@ -1577,7 +1564,6 @@ void osdUpdate(timeUs_t currentTimeUs)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
firstPass = false;
|
|
||||||
osdState = OSD_STATE_IDLE;
|
osdState = OSD_STATE_IDLE;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -1591,21 +1577,18 @@ void osdUpdate(timeUs_t currentTimeUs)
|
||||||
if (!schedulerGetIgnoreTaskExecTime()) {
|
if (!schedulerGetIgnoreTaskExecTime()) {
|
||||||
executeTimeUs = micros() - currentTimeUs;
|
executeTimeUs = micros() - currentTimeUs;
|
||||||
|
|
||||||
|
if (executeTimeUs > (osdStateDurationFractionUs[osdCurrentState] >> OSD_EXEC_TIME_SHIFT)) {
|
||||||
// On the first pass no element groups will have been formed, so all elements will have been
|
osdStateDurationFractionUs[osdCurrentState] = executeTimeUs << OSD_EXEC_TIME_SHIFT;
|
||||||
// rendered which is unrepresentative, so ignore
|
} else if (osdStateDurationFractionUs[osdCurrentState] > 0) {
|
||||||
if (!firstPass) {
|
// Slowly decay the max time
|
||||||
if (executeTimeUs > (osdStateDurationFractionUs[osdCurrentState] >> OSD_EXEC_TIME_SHIFT)) {
|
osdStateDurationFractionUs[osdCurrentState]--;
|
||||||
osdStateDurationFractionUs[osdCurrentState] = executeTimeUs << OSD_EXEC_TIME_SHIFT;
|
|
||||||
} else if (osdStateDurationFractionUs[osdCurrentState] > 0) {
|
|
||||||
// Slowly decay the max time
|
|
||||||
osdStateDurationFractionUs[osdCurrentState]--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (osdState == OSD_STATE_IDLE) {
|
if (osdState == OSD_STATE_IDLE) {
|
||||||
schedulerSetNextStateTime((osdStateDurationFractionUs[OSD_STATE_CHECK] >> OSD_EXEC_TIME_SHIFT) + OSD_TASK_MARGIN);
|
schedulerSetNextStateTime((osdStateDurationFractionUs[OSD_STATE_CHECK] >> OSD_EXEC_TIME_SHIFT));
|
||||||
|
} else if (osdState == OSD_STATE_UPDATE_ELEMENTS) {
|
||||||
|
schedulerSetNextStateTime((osdElementDurationFractionUs[osdGetActiveElement()] >> OSD_EXEC_TIME_SHIFT) + OSD_ELEMENT_MARGIN);
|
||||||
} else {
|
} else {
|
||||||
schedulerSetNextStateTime((osdStateDurationFractionUs[osdState] >> OSD_EXEC_TIME_SHIFT) + OSD_TASK_MARGIN);
|
schedulerSetNextStateTime((osdStateDurationFractionUs[osdState] >> OSD_EXEC_TIME_SHIFT) + OSD_TASK_MARGIN);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue