Prusa3d Marlin fork
language.h
Go to the documentation of this file.
1 
2 //language.h
3 #ifndef LANGUAGE_H
4 #define LANGUAGE_H
5 
6 
7 #include "config.h"
8 #include "macros.h"
9 #include <inttypes.h>
10 #ifdef DEBUG_SEC_LANG
11  #include <stdio.h>
12 #endif //DEBUG_SEC_LANG
13 
14 #define PROTOCOL_VERSION "1.0"
15 
16 #if (LANG_MODE == 0) //primary language only
17 #define PROGMEM_I2 __attribute__((section(".progmem0")))
18 #define PROGMEM_I1 __attribute__((section(".progmem1")))
19 #define PROGMEM_N1 __attribute__((section(".progmem2")))
20 #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = s; &__c[0];}))
21 #define ISTR(s) (s) // declare a translatable string
22 #define _i(s) _I(s) // declare a translatable string and return the translated form
23 #define _T(s) (s) // return translated string from reference
24 #define _O(s) (s) // return original (untranslated) string from reference
25 #else //(LANG_MODE == 0)
26 // section .loc_sec (originaly .progmem0) will be used for localized translated strings
27 #define PROGMEM_I2 __attribute__((section(".loc_sec")))
28 // section .loc_pri (originaly .progmem1) will be used for localized strings in english
29 #define PROGMEM_I1 __attribute__((section(".loc_pri")))
30 // section .noloc (originaly progmem2) will be used for not localized strings in english
31 #define PROGMEM_N1 __attribute__((section(".noloc")))
32 #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = "\xff\xff" s; &__c[0];}))
33 #define ISTR(s) "\xff\xff" s
34 #define _i(s) lang_get_translation(_I(s))
35 #define _T(s) lang_get_translation(s)
36 #define _O(s) (s + 2)
37 #endif //(LANG_MODE == 0)
38 
39 #define _N(s) (__extension__({static const char __c[] PROGMEM_N1 = s; &__c[0];}))
40 #define _n(s) _N(s) // declare and return untranslated string
41 #define _R(s) (s) // return reference to translatable string (for warning suppression)
42 
44 typedef struct
45 {
46  uint32_t magic; //+0
47  uint16_t size; //+4
48  uint16_t count; //+6
49  uint16_t checksum; //+8
50  uint16_t code; //+10
51  uint32_t signature; //+12
53 
55 typedef struct
56 {
57  lang_table_header_t header;
58  uint16_t table[];
59 } lang_table_t;
60 
63 #define LANG_ID_PRI 0
64 #define LANG_ID_SEC 1
66 
69 #define LANG_ID_FORCE_SELECTION 254
70 
73 #define LANG_ID_UNDEFINED 255
74 
77 #define LANG_ID_DEFAULT LANG_ID_PRI
78 
81 #define LANG_MAGIC 0x4bb45aa5
82 
85 #define LANG_CODE_XX 0x3f3f
86 #define LANG_CODE_EN 0x656e
87 #define LANG_CODE_CZ 0x6373
88 #define LANG_CODE_DE 0x6465
89 #define LANG_CODE_ES 0x6573
90 #define LANG_CODE_FR 0x6672
91 #define LANG_CODE_IT 0x6974
92 #define LANG_CODE_PL 0x706c
93 #ifdef COMMUNITY_LANGUAGE_SUPPORT //Community language support
94 #ifdef COMMUNITY_LANG_GROUP1_NL
95 #define LANG_CODE_NL 0x6e6c
96 #endif // COMMUNITY_LANG_GROUP1_NL
97 #ifdef COMMUNITY_LANG_GROUP1_SV
98 #define LANG_CODE_SV 0x7376
99 #endif // COMMUNITY_LANG_GROUP1_SV
100 #ifdef COMMUNITY_LANG_GROUP1_NO
101 #define LANG_CODE_NO 0x6E6F
102 #endif // COMMUNITY_LANG_GROUP1_NO
103 #ifdef COMMUNITY_LANG_GROUP1_DA
104 #define LANG_CODE_DA 0x6461
105 #endif // COMMUNITY_LANG_GROUP1_DA
106 #ifdef COMMUNITY_LANG_GROUP1_SL
107 #define LANG_CODE_SL 0x736C
108 #endif // COMMUNITY_LANG_GROUP1_SL
109 #ifdef COMMUNITY_LANG_GROUP1_HU
110 #define LANG_CODE_HU 0x6875
111 #endif // COMMUNITY_LANG_GROUP1_HU
112 #ifdef COMMUNITY_LANG_GROUP1_LB
113 #define LANG_CODE_LB 0x6C62
114 #endif // COMMUNITY_LANG_GROUP1_LB
115 #ifdef COMMUNITY_LANG_GROUP1_HR
116 #define LANG_CODE_HR 0x6872
117 #endif // COMMUNITY_LANG_GROUP1_HR
118 #ifdef COMMUNITY_LANG_GROUP2_LT
119 #define LANG_CODE_LT 0x6C74
120 #endif // COMMUNITY_LANG_GROUP2_LT
121 #ifdef COMMUNITY_LANG_GROUP1_SK
122 #define LANG_CODE_SK 0x736b
123 #endif // COMMUNITY_LANG_GROUP1_SK
124 #ifdef COMMUNITY_LANG_GROUP1_RO
125 #define LANG_CODE_RO 0x726F
126 #endif // COMMUNITY_LANG_GROUP1_RO
127 //Use the 3 lines below as a template and replace 'QR', '0X7172' and 'qr'
128 //#ifdef COMMUNITY_LANG_GROUP1_QR
129 //#define LANG_CODE_QR 0x7172 //!<'qr'
130 //#endif // COMMUNITY_LANG_GROUP1_QR
131 #endif // COMMUNITY_LANGUAGE_SUPPORT
133 
134 #if defined(__cplusplus)
135 extern "C" {
136 #endif //defined(__cplusplus)
137 
139 extern uint8_t lang_selected;
140 
141 #if (LANG_MODE != 0)
142 extern const char _SEC_LANG[LANG_SIZE_RESERVED];
143 extern const char* lang_get_translation(const char* s);
144 #define _SEC_LANG_TABLE ((uint16_t)&_SEC_LANG)
145 #endif //(LANG_MODE != 0)
146 
148 extern uint8_t lang_select(uint8_t lang);
150 extern uint8_t lang_check(uint16_t addr);
152 extern uint8_t lang_get_count(void);
154 extern uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset);
156 extern uint16_t lang_get_code(uint8_t lang);
158 extern const char* lang_get_name_by_code(uint16_t code);
160 extern void lang_reset(void);
162 extern uint8_t lang_is_selected(void);
163 
164 #ifdef DEBUG_SEC_LANG
165 extern const char* lang_get_sec_lang_str_by_id(uint16_t id);
166 extern uint16_t lang_print_sec_lang();
167 #endif //DEBUG_SEC_LANG
168 
169 extern void lang_boot_update_start(uint8_t lang);
170 
171 #if defined(__cplusplus)
172 }
173 #endif //defined(__cplusplus)
174 
175 #define CAT2(_s1, _s2) _s1
176 #define CAT4(_s1, _s2, _s3, _s4) _s1
177 
178 #include "messages.h"
179 
180 
181 #endif //LANGUAGE_H
182 
uint8_t lang_selected
Currectly active language selection.
Definition: language.c:17
uint8_t lang_is_selected(void)
Definition: language.c:27
uint8_t lang_select(uint8_t lang)
selects language, eeprom is updated in case of success
Definition: language.c:52
const char * lang_get_name_by_code(uint16_t code)
Definition: language.c:204
uint8_t lang_check(uint16_t addr)
performs checksum test of secondary language data
Definition: language.c:96
uint8_t lang_get_count(void)
Definition: language.c:23
uint16_t lang_get_code(uint8_t lang)
reads lang code from xflash or progmem
Definition: language.c:170
void lang_reset(void)
reset language to "LANG_ID_FORCE_SELECTION", epprom is updated
Definition: language.c:26
uint8_t lang_get_header(uint8_t lang, lang_table_header_t *header, uint32_t *offset)
reads lang table header and offset in xflash or progmem
Definition: language.c:136
lang_table_header_t structure - (size= 16byte)
Definition: language.h:45
lang_table_t structure - (size= 16byte + 2*count)
Definition: language.h:56