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

Reduce flash usage by 3.7K by changing CMS data structures #4380

Merged
merged 3 commits into from
Mar 1, 2019
Merged
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
27 changes: 24 additions & 3 deletions src/main/cms/cms.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ static void cmsUpdateMaxRow(displayPort_t *instance)

for (const OSD_Entry *ptr = pageTop; ptr->type != OME_END; ptr++) {
pageMaxRow++;
if (ptr->type == OME_BACK_AND_END) {
break;
}
}

if (pageMaxRow > MAX_MENU_ITEMS(instance)) {
Expand Down Expand Up @@ -516,6 +519,7 @@ static int cmsDrawMenuEntry(displayPort_t *pDisplay, const OSD_Entry *p, uint8_t
case OME_OSD_Exit:
case OME_END:
case OME_Back:
case OME_BACK_AND_END:
break;

case OME_MENU:
Expand Down Expand Up @@ -592,8 +596,12 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
coloff += cmsElementIsLabel(p->type) ? 1 : 2;
room -= displayWrite(pDisplay, coloff, i + top, p->text);
CLR_PRINTLABEL(p, i);
if (room < 30)
if (room < 30) {
return;
}
}
if (p->type == OME_BACK_AND_END) {
break;
}
}

Expand All @@ -605,16 +613,25 @@ static void cmsDrawMenu(displayPort_t *pDisplay, uint32_t currentTimeUs)
for (i = 0, p = pageTop; i < MAX_MENU_ITEMS(pDisplay) && p->type != OME_END; i++, p++) {
if (IS_PRINTVALUE(p, i)) {
room -= cmsDrawMenuEntry(pDisplay, p, top + i, i);
if (room < 30)
if (room < 30) {
return;
}
}
if (p->type == OME_BACK_AND_END) {
break;
}
}
}

static void cmsMenuCountPage(displayPort_t *pDisplay)
{
const OSD_Entry *p;
for (p = currentCtx.menu->entries; p->type != OME_END; p++);
for (p = currentCtx.menu->entries; p->type != OME_END; p++) {
if (p->type == OME_BACK_AND_END) {
p++;
break;
}
}
pageCount = (p - currentCtx.menu->entries - 1) / MAX_MENU_ITEMS(pDisplay) + 1;
}

Expand Down Expand Up @@ -722,6 +739,9 @@ static void cmsTraverseGlobalExit(const CMS_Menu *pMenu)
if (p->type == OME_Submenu) {
cmsTraverseGlobalExit(p->data);
}
if (p->type == OME_BACK_AND_END) {
break;
}
}

if (pMenu->onGlobalExit) {
Expand Down Expand Up @@ -866,6 +886,7 @@ STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
break;

case OME_Back:
case OME_BACK_AND_END:
cmsMenuBack(pDisplay);
res = BUTTON_PAUSE;
break;
Expand Down
6 changes: 2 additions & 4 deletions src/main/cms/cms_menu_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ static const OSD_Entry menuBattSettingsEntries[]=
OSD_SETTING_ENTRY("CAP WARN", SETTING_BATTERY_CAPACITY_WARNING),
OSD_SETTING_ENTRY("CAP CRIT", SETTING_BATTERY_CAPACITY_CRITICAL),

OSD_BACK_ENTRY,
OSD_END_ENTRY
OSD_BACK_AND_END_ENTRY,
};

static CMS_Menu cmsx_menuBattSettings = {
Expand All @@ -134,8 +133,7 @@ static OSD_Entry menuBatteryEntries[]=
OSD_UINT8_CALLBACK_ENTRY("PROF", cmsx_onBatteryProfileIndexChange, (&(const OSD_UINT8_t){ &battDispProfileIndex, 1, MAX_BATTERY_PROFILE_COUNT, 1})),
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuBattSettings),

OSD_BACK_ENTRY,
OSD_END_ENTRY
OSD_BACK_AND_END_ENTRY,
};

CMS_Menu cmsx_menuBattery = {
Expand Down
3 changes: 1 addition & 2 deletions src/main/cms/cms_menu_blackbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ static const OSD_Entry cmsx_menuBlackboxEntries[] =
OSD_FUNC_CALL_ENTRY("ERASE FLASH", cmsx_EraseFlash),
#endif // USE_FLASHFS

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuBlackbox = {
Expand Down
10 changes: 4 additions & 6 deletions src/main/cms/cms_menu_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ static const OSD_Entry menuInfoEntries[] = {
OSD_STRING_ENTRY("GITREV", infoGitRev),
OSD_STRING_ENTRY("TARGET", infoTargetName),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu menuInfo = {
Expand Down Expand Up @@ -128,8 +127,7 @@ static const OSD_Entry menuFeaturesEntries[] =
OSD_SUBMENU_ENTRY("LED STRIP", &cmsx_menuLedstrip),
#endif // LED_STRIP

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu menuFeatures = {
Expand Down Expand Up @@ -158,8 +156,8 @@ static const OSD_Entry menuMainEntries[] =
OSD_SUBMENU_ENTRY("FC+FW INFO", &menuInfo),
OSD_SUBMENU_ENTRY("MISC", &cmsx_menuMisc),

{"SAVE+REBOOT", OME_OSD_Exit, {.func = cmsMenuExit}, (void*)CMS_EXIT_SAVEREBOOT, 0},
{"EXIT", OME_OSD_Exit, {.func = cmsMenuExit}, (void*)CMS_EXIT, 0},
{"SAVE+REBOOT", {.func = cmsMenuExit}, (void*)CMS_EXIT_SAVEREBOOT, OME_OSD_Exit, 0},
{"EXIT" , {.func = cmsMenuExit}, (void*)CMS_EXIT, OME_OSD_Exit, 0},
#ifdef CMS_MENU_DEBUG
OSD_SUBMENU_ENTRY("ERR SAMPLE", &menuInfoEntries[0]),
#endif
Expand Down
27 changes: 9 additions & 18 deletions src/main/cms/cms_menu_imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ static const OSD_Entry cmsx_menuPidEntries[] =
OSD_UINT8_ENTRY("YAW I", (&(const OSD_UINT8_t){ &cmsx_pidYaw[1], 0, 200, 1 })),
OSD_UINT8_ENTRY("YAW D", (&(const OSD_UINT8_t){ &cmsx_pidYaw[2], 0, 200, 1 })),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuPid = {
Expand Down Expand Up @@ -198,8 +197,7 @@ static const OSD_Entry cmsx_menuPidAltMagEntries[] =

OSD_UINT8_ENTRY("MAG P", (&(const OSD_UINT8_t){ &cmsx_pidHead[0], 0, 255, 1 })),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuPidAltMag = {
Expand Down Expand Up @@ -248,8 +246,7 @@ static const OSD_Entry cmsx_menuPidGpsnavEntries[] =
OSD_UINT8_ENTRY("POSR I", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[1], 0, 255, 1 })),
OSD_UINT8_ENTRY("POSR D", (&(const OSD_UINT8_t){ &cmsx_pidVelXY[2], 0, 255, 1 })),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuPidGpsnav = {
Expand Down Expand Up @@ -277,8 +274,7 @@ static const OSD_Entry cmsx_menuManualRateProfileEntries[] =
OSD_SETTING_ENTRY("MANU RC EXPO", SETTING_MANUAL_RC_EXPO),
OSD_SETTING_ENTRY("MANU RC YAW EXP", SETTING_MANUAL_RC_YAW_EXPO),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuManualRateProfile = {
Expand Down Expand Up @@ -317,8 +313,7 @@ static const OSD_Entry cmsx_menuRateProfileEntries[] =
OSD_SETTING_ENTRY("THRPID ATT", SETTING_TPA_RATE),
OSD_SETTING_ENTRY_STEP("TPA BRKPT", SETTING_TPA_BREAKPOINT, 10),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuRateProfile = {
Expand Down Expand Up @@ -376,8 +371,7 @@ static const OSD_Entry cmsx_menuProfileOtherEntries[] = {
{ "HORZN STR", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonStrength, 0, 200, 1 } , 0 },
{ "HORZN TRS", OME_UINT8, NULL, &(OSD_UINT8_t){ &cmsx_horizonTransition, 0, 200, 1 } , 0 },

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuProfileOther = {
Expand All @@ -404,8 +398,7 @@ static const OSD_Entry cmsx_menuFilterPerProfileEntries[] =
OSD_SETTING_ENTRY("YAW P LIM", SETTING_YAW_P_LIMIT),
OSD_SETTING_ENTRY("YAW LPF", SETTING_YAW_LPF_HZ),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuFilterPerProfile = {
Expand All @@ -426,8 +419,7 @@ static const OSD_Entry cmsx_menuGyroEntries[] =
OSD_SETTING_ENTRY("GYRO SYNC", SETTING_GYRO_SYNC),
OSD_SETTING_ENTRY("GYRO LPF", SETTING_GYRO_HARDWARE_LPF),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuGyro = {
Expand Down Expand Up @@ -466,8 +458,7 @@ static const OSD_Entry cmsx_menuImuEntries[] =
{"FILT GLB", OME_Submenu, cmsMenuChange, &cmsx_menuFilterGlobal, 0},
#endif

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuImu = {
Expand Down
3 changes: 1 addition & 2 deletions src/main/cms/cms_menu_ledstrip.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ static const OSD_Entry cmsx_menuLedstripEntries[] =
OSD_LABEL_ENTRY("-- LED STRIP --"),
OSD_BOOL_FUNC_ENTRY("ENABLED", cmsx_FeatureLedStrip_Enabled),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuLedstrip = {
Expand Down
6 changes: 2 additions & 4 deletions src/main/cms/cms_menu_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ static const OSD_Entry cmsx_menuRcEntries[] =
OSD_INT16_RO_ENTRY("AUX3", &rcData[AUX3]),
OSD_INT16_RO_ENTRY("AUX4", &rcData[AUX4]),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuRcPreview = {
Expand All @@ -94,8 +93,7 @@ static const OSD_Entry menuMiscEntries[]=

OSD_SUBMENU_ENTRY("RC PREV", &cmsx_menuRcPreview),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuMisc = {
Expand Down
12 changes: 4 additions & 8 deletions src/main/cms/cms_menu_navigation.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ static const OSD_Entry cmsx_menuNavSettingsEntries[] =
OSD_SETTING_ENTRY("MID THR FOR AH", SETTING_NAV_USE_MIDTHR_FOR_ALTHOLD),
OSD_SETTING_ENTRY("MC HOVER THR", SETTING_NAV_MC_HOVER_THR),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuNavSettings = {
Expand Down Expand Up @@ -83,8 +82,7 @@ static const CMS_Menu cmsx_menuNavSettings = {
OSD_SETTING_ENTRY("RTH ABORT THRES", SETTING_NAV_RTH_ABORT_THRESHOLD),
OSD_SETTING_ENTRY("EMERG LANDING SPEED", SETTING_NAV_EMERG_LANDING_SPEED),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuRTH = {
Expand All @@ -111,8 +109,7 @@ static const OSD_Entry cmsx_menuFixedWingEntries[] =
OSD_SETTING_ENTRY("PITCH TO THR RATIO", SETTING_NAV_FW_PITCH2THR),
OSD_SETTING_ENTRY("LOITER RADIUS", SETTING_NAV_FW_LOITER_RADIUS),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuFixedWing = {
Expand All @@ -134,8 +131,7 @@ static const OSD_Entry cmsx_menuNavigationEntries[] =
OSD_SUBMENU_ENTRY("RTH", &cmsx_menuRTH),
OSD_SUBMENU_ENTRY("FIXED WING", &cmsx_menuFixedWing),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuNavigation = {
Expand Down
30 changes: 11 additions & 19 deletions src/main/cms/cms_menu_osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include "io/osd.h"

#define OSD_ITEM_ENTRY(label, item_id) ((OSD_Entry){ label, OME_Submenu, {.itemId = item_id}, &cmsx_menuOsdElementActions, 0 })
#define OSD_ITEM_ENTRY(label, item_id) ((OSD_Entry){ label, {.itemId = item_id}, &cmsx_menuOsdElementActions, OME_Submenu, 0 })

static int osdCurrentLayout = -1;
static int osdCurrentItem = -1;
Expand All @@ -57,8 +57,7 @@ static const OSD_Entry cmsx_menuAlarmsEntries[] = {
OSD_SETTING_ENTRY("MAX DIST", SETTING_OSD_DIST_ALARM),
OSD_SETTING_ENTRY("MAX NEG ALT", SETTING_OSD_NEG_ALT_ALARM),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuAlarms = {
Expand Down Expand Up @@ -101,17 +100,15 @@ static const OSD_Entry menuOsdElemActionsEntries[] = {
OSD_UINT8_CALLBACK_ENTRY("COLUMN", cmsx_osdElementOnChange, (&(const OSD_UINT8_t){ &osdCurrentElementColumn, 0, OSD_Y(OSD_POS_MAX), 1 })),
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const OSD_Entry menuOsdFixedElemActionsEntries[] = {

OSD_BOOL_CALLBACK_ENTRY("ENABLED", cmsx_osdElementOnChange, &osdCurrentElementVisible),
OSD_FUNC_CALL_ENTRY("PREVIEW", osdElementPreview),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static CMS_Menu cmsx_menuOsdElementActions = {
Expand Down Expand Up @@ -261,15 +258,14 @@ static const OSD_Entry menuOsdElemsEntries[] =
OSD_ELEMENT_ENTRY("SENSOR 7 TEMP", OSD_TEMP_SENSOR_7_TEMPERATURE),
#endif

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

#if defined(USE_GPS) && defined(USE_BARO) && defined(USE_PITOT) && defined(USE_TEMPERATURE_SENSOR)
// All CMS OSD elements should be enabled in this case. The menu has 3 extra
// elements (label, back and end), but there's an OSD element that we intentionally
// All CMS OSD elements should be enabled in this case. The menu has 2 extra
// elements (label, back+end), but there's an OSD element that we intentionally
// don't show here (OSD_DEBUG).
_Static_assert(ARRAYLEN(menuOsdElemsEntries) - 3 + 1 == OSD_ITEM_COUNT, "missing OSD elements in CMS");
_Static_assert(ARRAYLEN(menuOsdElemsEntries) - 2 + 1 == OSD_ITEM_COUNT, "missing OSD elements in CMS");
#endif

const CMS_Menu menuOsdElements = {
Expand Down Expand Up @@ -301,8 +297,7 @@ static const OSD_Entry cmsx_menuOsdLayoutEntries[] =
#endif
#endif

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuOsdLayout = {
Expand Down Expand Up @@ -344,9 +339,7 @@ static const OSD_Entry menuOsdSettingsEntries[] = {
OSD_SETTING_ENTRY("RIGHT SCROLL", SETTING_OSD_RIGHT_SIDEBAR_SCROLL),
OSD_SETTING_ENTRY("SCROLL ARROWS", SETTING_OSD_SIDEBAR_SCROLL_ARROWS),


OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

static const CMS_Menu cmsx_menuOsdSettings = {
Expand All @@ -367,8 +360,7 @@ static const OSD_Entry menuOsdEntries[] = {
OSD_SUBMENU_ENTRY("SETTINGS", &cmsx_menuOsdSettings),
OSD_SUBMENU_ENTRY("ALARMS", &cmsx_menuAlarms),

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};


Expand Down
3 changes: 1 addition & 2 deletions src/main/cms/cms_menu_vtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ static const OSD_Entry cmsx_menuVtxEntries[] =
OSD_BOOL_ENTRY("LOW POWER", &masterConfig.vtx_power),
#endif // USE_RTC6705

OSD_BACK_ENTRY,
OSD_END_ENTRY,
OSD_BACK_AND_END_ENTRY,
};

const CMS_Menu cmsx_menuVtx = {
Expand Down
Loading