Projectkk2glider/flash savings (#4199)
* Flash savings: getFileExtension() de-templated, saves 160 bytes * Flash savings: several variables moved to rodata, RGB macro optimization (speed and can now be used to initialize rodata) Result for Horus: text data bss dec 1261182 808603 42020 2111805 before 1267149 803335 42124 2112608 after (data size also counts .sram section) 5kB saved in .data section (RAM and FLASH) * Removed compiler warnings * RGB() and ARGB() gtests added * ARGB() optimized
This commit is contained in:
committed by
Bertrand Songis
parent
3b58ee8d3c
commit
82dce3ee60
@@ -25,11 +25,9 @@
|
||||
#undef OPAQUE
|
||||
#undef RGB
|
||||
|
||||
#define TO4BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 4)
|
||||
#define TO5BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 3)
|
||||
#define TO6BITS(x) (uint32_t(limit<int>(0, x, 255)) >> 2)
|
||||
#define RGB(r, g, b) ((TO5BITS(r) << 11) + (TO6BITS(g) << 5) + (TO5BITS(b) << 0))
|
||||
#define ARGB(a, r, g, b) ((TO4BITS(a) << 12) + (TO4BITS(r) << 8) + (TO4BITS(g) << 4) + (TO4BITS(b) << 0))
|
||||
#define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3))
|
||||
#define ARGB(a, r, g, b) (uint16_t)((((a) & 0xF0) << 8) + (((r) & 0xF0) << 4) + (((g) & 0xF0) << 0) + (((b) & 0xF0) >> 4))
|
||||
|
||||
#define WHITE RGB(0xFF, 0xFF, 0xFF)
|
||||
#define BLACK RGB(0, 0, 0)
|
||||
#define YELLOW RGB(0xF0, 0xD0, 0x10)
|
||||
|
||||
@@ -20,59 +20,59 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
uint16_t font_tinsize_specs[] = {
|
||||
const uint16_t font_tinsize_specs[] = {
|
||||
#include "font_tinsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_tinsize[] = {
|
||||
const pm_uchar font_tinsize[] = {
|
||||
#include "font_tinsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_smlsize_specs[] = {
|
||||
const uint16_t font_smlsize_specs[] = {
|
||||
#include "font_smlsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_smlsize[] = {
|
||||
const pm_uchar font_smlsize[] = {
|
||||
#include "font_smlsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_stdsize_specs[] = {
|
||||
const uint16_t font_stdsize_specs[] = {
|
||||
#include "font_stdsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_stdsize[] = {
|
||||
const pm_uchar font_stdsize[] = {
|
||||
#include "font_stdsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_midsize_specs[] = {
|
||||
const uint16_t font_midsize_specs[] = {
|
||||
#include "font_midsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_midsize[] = {
|
||||
const pm_uchar font_midsize[] = {
|
||||
#include "font_midsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_dblsize_specs[] = {
|
||||
const uint16_t font_dblsize_specs[] = {
|
||||
#include "font_dblsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_dblsize[] = {
|
||||
const pm_uchar font_dblsize[] = {
|
||||
#include "font_dblsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_xxlsize_specs[] = {
|
||||
const uint16_t font_xxlsize_specs[] = {
|
||||
#include "font_xxlsize.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_xxlsize[] = {
|
||||
const pm_uchar font_xxlsize[] = {
|
||||
#include "font_xxlsize.lbm"
|
||||
};
|
||||
|
||||
uint16_t font_stdsizebold_specs[] = {
|
||||
const uint16_t font_stdsizebold_specs[] = {
|
||||
#include "font_stdsizebold.specs"
|
||||
};
|
||||
|
||||
pm_uchar font_stdsizebold[] = {
|
||||
const pm_uchar font_stdsizebold[] = {
|
||||
#include "font_stdsizebold.lbm"
|
||||
};
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ bool menuRadioSdManager(event_t _event)
|
||||
if (!strcmp(line, "..")) {
|
||||
break; // no menu for parent dir
|
||||
}
|
||||
char * ext = getFileExtension(line);
|
||||
const char * ext = getFileExtension(line);
|
||||
if (ext) {
|
||||
if (!strcasecmp(ext, SOUNDS_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_PLAY_FILE);
|
||||
@@ -337,7 +337,7 @@ bool menuRadioSdManager(event_t _event)
|
||||
if (reusableBuffer.sdmanager.lines[i][0]) {
|
||||
if (s_editMode == EDIT_MODIFY_STRING && attr) {
|
||||
uint8_t extlen, efflen;
|
||||
char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, 0, 0, NULL, &extlen);
|
||||
const char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, 0, 0, NULL, &extlen);
|
||||
editName(MENUS_MARGIN_LEFT, y, reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH - extlen, _event, attr, 0);
|
||||
efflen = effectiveLen(reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH - extlen);
|
||||
if (s_editMode == 0) {
|
||||
@@ -366,7 +366,7 @@ bool menuRadioSdManager(event_t _event)
|
||||
}
|
||||
}
|
||||
|
||||
char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index]);
|
||||
const char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index]);
|
||||
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
if (currentBitmapIndex != menuVerticalPosition) {
|
||||
currentBitmapIndex = menuVerticalPosition;
|
||||
|
||||
@@ -45,12 +45,12 @@ union ZoneOptionValue
|
||||
#define OPTION_VALUE_UNSIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_SIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_BOOL(x) uint32_t(x)
|
||||
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#define OPTION_VALUE_STRING(...) { .stringValue = {__VA_ARGS__} }
|
||||
#else
|
||||
#define OPTION_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
|
||||
#define OPTION_VALUE_SIGNED(x) { .signedValue = (x) }
|
||||
#define OPTION_VALUE_BOOL(x) { .boolValue = (x) }
|
||||
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *)__VA_ARGS__
|
||||
#define OPTION_VALUE_STRING(...) { .stringValue = {__VA_ARGS__} }
|
||||
#endif
|
||||
|
||||
struct ZoneOption
|
||||
|
||||
@@ -34,7 +34,7 @@ class TextWidget: public Widget
|
||||
};
|
||||
|
||||
const ZoneOption TextWidget::options[] = {
|
||||
{ "Text", ZoneOption::String, OPTION_VALUE_STRING("\015\347\0\14\377\376\373\364") },
|
||||
{ "Text", ZoneOption::String, OPTION_VALUE_STRING('\15', '\347', '\0', '\14', '\377', '\376', '\373', '\364') },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ "Size", ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
|
||||
@@ -258,7 +258,7 @@ void menuRadioSdManager(event_t _event)
|
||||
break; // no menu for parent dir
|
||||
}
|
||||
#if defined(CPUARM)
|
||||
char * ext = getFileExtension(line);
|
||||
const char * ext = getFileExtension(line);
|
||||
if (ext) {
|
||||
if (!strcasecmp(ext, SOUNDS_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_PLAY_FILE);
|
||||
@@ -401,7 +401,7 @@ void menuRadioSdManager(event_t _event)
|
||||
#if defined(CPUARM)
|
||||
if (s_editMode == EDIT_MODIFY_STRING && attr) {
|
||||
uint8_t extlen, efflen;
|
||||
char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, 0, 0, NULL, &extlen);
|
||||
const char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, 0, 0, NULL, &extlen);
|
||||
editName(lcdNextPos, y, reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH - extlen, _event, attr, 0);
|
||||
efflen = effectiveLen(reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH - extlen);
|
||||
if (s_editMode == 0) {
|
||||
@@ -428,7 +428,7 @@ void menuRadioSdManager(event_t _event)
|
||||
}
|
||||
|
||||
#if LCD_DEPTH > 1
|
||||
char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index]);
|
||||
const char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index]);
|
||||
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
if (lastPos != menuVerticalPosition) {
|
||||
if (!lcdLoadBitmap(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
|
||||
|
||||
Reference in New Issue
Block a user