1
0
forked from me/IronOS

[RFC] Multi-language firmware (second try) (#941)

* Impl. sectioned font table in firmware

* make_translation.py: Extract build_symbol_conversion_table function

* Put translation indices and strings in a struct

* Move translation objcopy step to Python

* Impl. multi-language firmware demo

* Impl. strings-compressed multi-lang firmware demo

* Add font compression to multi-lang demo

* Refactor Makefile a bit

* Fix rules for make < 4.3

* Add more multi-lang groups

* Add Pinecil multi-lang CI build

* Add lzfx compression license text

* Remote multi-language demo group

* Fix build after merge

* Import code from BriefLZ

* Change brieflz for our use case

* Change compression to use brieflz

* Remove lzfx code

* Update license file for brieflz

* Exclude brieflz files from format check

* Add BriefLZ test
This commit is contained in:
alvinhochun
2021-04-30 16:51:13 +08:00
committed by GitHub
parent a51e3e9f03
commit 1a0b542ae6
57 changed files with 3447 additions and 767 deletions

View File

@@ -10,7 +10,7 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include <stdint.h>
#define SETTINGSVERSION (0x29)
#define SETTINGSVERSION (0x2A)
/*Change this if you change the struct below to prevent people getting \
out of sync*/
@@ -59,6 +59,7 @@ typedef struct {
uint8_t hallEffectSensitivity; // Operating mode of the hall effect sensor
uint8_t accelMissingWarningCounter; // Counter of how many times we have warned we cannot detect the accelerometer
uint8_t pdMissingWarningCounter; // Counter of how many times we have warned we cannot detect the pd interface
char uiLanguage[8]; // Selected UI Language code, null-terminated *only if* the length is less than 8 chars
uint32_t padding; // This is here for in case we are not an even divisor so
// that nothing gets cut off

View File

@@ -57,6 +57,7 @@ enum class SettingsItemIndex : uint8_t {
AnimSpeed,
PowerPulseWait,
PowerPulseDuration,
LanguageSwitch,
NUM_ITEMS,
};
@@ -110,11 +111,28 @@ struct TranslationIndexTable {
uint16_t SettingsMenuEntriesDescriptions[5]; // unused
};
extern const TranslationIndexTable *const Tr;
extern const char *const TranslationStrings;
extern const TranslationIndexTable *Tr;
extern const char * TranslationStrings;
extern const uint8_t *const Font_12x16;
extern const uint8_t *const Font_6x8;
struct TranslationData {
TranslationIndexTable indices;
// Translation strings follows the translation index table.
// C++ does not support flexible array member as in C, so we use a 1-element
// array as a placeholder.
char strings[1];
};
struct FontSection {
/// Start index of font section, inclusive
uint16_t symbol_start;
/// End index of font section, exclusive
uint16_t symbol_end;
const uint8_t *font12_start_ptr;
const uint8_t *font06_start_ptr;
};
extern const FontSection *const FontSections;
extern const uint8_t FontSectionsCount;
constexpr uint8_t settings_item_index(const SettingsItemIndex i) { return static_cast<uint8_t>(i); }
// Use a constexpr function for type-checking.
@@ -123,5 +141,7 @@ constexpr uint8_t settings_item_index(const SettingsItemIndex i) { return static
const char *translatedString(uint16_t index);
void prepareTranslations();
bool settings_displayLanguageSwitch(void);
bool settings_setLanguageSwitch(void);
#endif /* TRANSLATION_H_ */

View File

@@ -0,0 +1,42 @@
#ifndef TRANSLATION_MULTI_H_
#define TRANSLATION_MULTI_H_
#include "Translation.h"
// The compressed translation data will be decompressed to this buffer. These
// data may include:
// - TranslationData (translation index table and translation strings)
// - Font table(s)
// The translation index table consists of uint16_t (half words) which has a
// 2-byte alignment. Therefore, the declaration of this buffer must include
// the alignment specifier `alignas(TranslationData)` to satisfy its alignment.
// TranslationData must always be decompressed to the start of this buffer.
extern uint8_t translation_data_out_buffer[];
extern const uint16_t translation_data_out_buffer_size;
struct FontSectionDataInfo {
uint16_t symbol_start;
uint16_t symbol_count;
uint16_t data_size : 15;
bool data_is_compressed : 1;
// Font12x16 data followed by font6x8 data
const uint8_t *data_ptr;
};
extern const FontSectionDataInfo FontSectionDataInfos[];
extern const uint8_t FontSectionDataCount;
extern FontSection DynamicFontSections[];
struct LanguageMeta {
char code[8];
const uint8_t *translation_data;
uint16_t translation_size : 15;
bool translation_is_compressed : 1;
};
extern const LanguageMeta LanguageMetas[];
extern const uint8_t LanguageCount;
#endif /* TRANSLATION_MULTI_H_ */