language.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /** @file */
  2. //language.h
  3. #ifndef LANGUAGE_H
  4. #define LANGUAGE_H
  5. #include "config.h"
  6. #include "macros.h"
  7. #include <inttypes.h>
  8. #ifdef DEBUG_SEC_LANG
  9. #include <stdio.h>
  10. #endif //DEBUG_SEC_LANG
  11. #define PROTOCOL_VERSION "1.0"
  12. #ifndef CUSTOM_MENDEL_NAME
  13. #define MACHINE_NAME "Mendel"
  14. #endif
  15. #ifndef MACHINE_UUID
  16. #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
  17. #endif
  18. #if (LANG_MODE == 0) //primary language only
  19. #define PROGMEM_I2 __attribute__((section(".progmem0")))
  20. #define PROGMEM_I1 __attribute__((section(".progmem1")))
  21. #define PROGMEM_N1 __attribute__((section(".progmem2")))
  22. #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = s; &__c[0];}))
  23. #define ISTR(s) (s) // declare a translatable string
  24. #define _i(s) _I(s) // declare a translatable string and return the translated form
  25. #define _T(s) (s) // return translated string from reference
  26. #define _O(s) (s) // return original (untranslated) string from reference
  27. #else //(LANG_MODE == 0)
  28. // section .loc_sec (originaly .progmem0) will be used for localized translated strings
  29. #define PROGMEM_I2 __attribute__((section(".loc_sec")))
  30. // section .loc_pri (originaly .progmem1) will be used for localized strings in english
  31. #define PROGMEM_I1 __attribute__((section(".loc_pri")))
  32. // section .noloc (originaly progmem2) will be used for not localized strings in english
  33. #define PROGMEM_N1 __attribute__((section(".noloc")))
  34. #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = "\xff\xff" s; &__c[0];}))
  35. #define ISTR(s) "\xff\xff" s
  36. #define _i(s) lang_get_translation(_I(s))
  37. #define _T(s) lang_get_translation(s)
  38. #define _O(s) (s + 2)
  39. #endif //(LANG_MODE == 0)
  40. #define _N(s) (__extension__({static const char __c[] PROGMEM_N1 = s; &__c[0];}))
  41. #define _n(s) _N(s) // declare and return untranslated string
  42. #define _R(s) (s) // return reference to translatable string (for warning suppression)
  43. /** @brief lang_table_header_t structure - (size= 16byte) */
  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
  52. } lang_table_header_t;
  53. /** @brief lang_table_t structure - (size= 16byte + 2*count) */
  54. typedef struct
  55. {
  56. lang_table_header_t header;
  57. uint16_t table[];
  58. } lang_table_t;
  59. /** @name Language indices into their particular symbol tables.*/
  60. ///@{
  61. #define LANG_ID_PRI 0
  62. #define LANG_ID_SEC 1
  63. ///@}
  64. /** @def LANG_ID_FORCE_SELECTION
  65. * @brief Language is not defined and it shall be selected from the menu.*/
  66. #define LANG_ID_FORCE_SELECTION 254
  67. /** @def LANG_ID_UNDEFINED
  68. * @brief Language is not defined on a virgin RAMBo board. */
  69. #define LANG_ID_UNDEFINED 255
  70. /** @def LANG_ID_DEFAULT
  71. * @brief Default language ID, if no language is selected. */
  72. #define LANG_ID_DEFAULT LANG_ID_PRI
  73. /** @def LANG_MAGIC
  74. * @brief Magic number at begin of lang table. */
  75. #define LANG_MAGIC 0x4bb45aa5
  76. /** @name Language codes (ISO639-1)*/
  77. ///@{
  78. #define LANG_CODE_XX 0x3f3f //!<'??'
  79. #define LANG_CODE_EN 0x656e //!<'en'
  80. #define LANG_CODE_CZ 0x6373 //!<'cs'
  81. #define LANG_CODE_DE 0x6465 //!<'de'
  82. #define LANG_CODE_ES 0x6573 //!<'es'
  83. #define LANG_CODE_FR 0x6672 //!<'fr'
  84. #define LANG_CODE_IT 0x6974 //!<'it'
  85. #define LANG_CODE_PL 0x706c //!<'pl'
  86. #ifdef COMMUNITY_LANGUAGE_SUPPORT //Community language support
  87. #ifdef COMMUNITY_LANG_GROUP1_NL
  88. #define LANG_CODE_NL 0x6e6c //!<'nl'
  89. #endif // COMMUNITY_LANG_GROUP1_NL
  90. #ifdef COMMUNITY_LANG_GROUP1_SV
  91. #define LANG_CODE_SV 0x7376 //!<'sv'
  92. #endif // COMMUNITY_LANG_GROUP1_SV
  93. #ifdef COMMUNITY_LANG_GROUP1_NO
  94. #define LANG_CODE_NO 0x6E6F //!<'no'
  95. #endif // COMMUNITY_LANG_GROUP1_NO
  96. #ifdef COMMUNITY_LANG_GROUP1_DA
  97. #define LANG_CODE_DA 0x6461 //!<'da'
  98. #endif // COMMUNITY_LANG_GROUP1_DA
  99. #ifdef COMMUNITY_LANG_GROUP1_SL
  100. #define LANG_CODE_SL 0x736C //!<'sl'
  101. #endif // COMMUNITY_LANG_GROUP1_SL
  102. #ifdef COMMUNITY_LANG_GROUP1_HU
  103. #define LANG_CODE_HU 0x6875 //!<'hu'
  104. #endif // COMMUNITY_LANG_GROUP1_HU
  105. #ifdef COMMUNITY_LANG_GROUP1_LB
  106. #define LANG_CODE_LB 0x6C62 //!<'lb'
  107. #endif // COMMUNITY_LANG_GROUP1_LB
  108. #ifdef COMMUNITY_LANG_GROUP1_HR
  109. #define LANG_CODE_HR 0x6872 //!<'hr'
  110. #endif // COMMUNITY_LANG_GROUP1_HR
  111. #ifdef COMMUNITY_LANG_GROUP2_LT
  112. #define LANG_CODE_LT 0x6C74 //!<'lt'
  113. #endif // COMMUNITY_LANG_GROUP2_LT
  114. #ifdef COMMUNITY_LANG_GROUP1_SK
  115. #define LANG_CODE_SK 0x736b //!<'sk'
  116. #endif // COMMUNITY_LANG_GROUP1_SK
  117. #ifdef COMMUNITY_LANG_GROUP1_RO
  118. #define LANG_CODE_RO 0x726F //!<'ro'
  119. #endif // COMMUNITY_LANG_GROUP1_RO
  120. //Use the 3 lines below as a template and replace 'QR', '0X7172' and 'qr'
  121. //#ifdef COMMUNITY_LANG_GROUP1_QR
  122. //#define LANG_CODE_QR 0x7172 //!<'qr'
  123. //#endif // COMMUNITY_LANG_GROUP1_QR
  124. #endif // COMMUNITY_LANGUAGE_SUPPORT
  125. ///@}
  126. #if defined(__cplusplus)
  127. extern "C" {
  128. #endif //defined(__cplusplus)
  129. /** @brief Currectly active language selection.*/
  130. extern uint8_t lang_selected;
  131. #if (LANG_MODE != 0)
  132. extern const char _SEC_LANG[LANG_SIZE_RESERVED];
  133. extern const char* lang_get_translation(const char* s);
  134. #define _SEC_LANG_TABLE ((uint16_t)&_SEC_LANG)
  135. #endif //(LANG_MODE != 0)
  136. /** @brief selects language, eeprom is updated in case of success */
  137. extern uint8_t lang_select(uint8_t lang);
  138. /** @brief performs checksum test of secondary language data */
  139. extern uint8_t lang_check(uint16_t addr);
  140. /** @return total number of languages (primary + all in xflash) */
  141. extern uint8_t lang_get_count(void);
  142. /** @brief reads lang table header and offset in xflash or progmem */
  143. extern uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset);
  144. /** @brief reads lang code from xflash or progmem */
  145. extern uint16_t lang_get_code(uint8_t lang);
  146. /** @return localized language name (text for menu item) */
  147. extern const char* lang_get_name_by_code(uint16_t code);
  148. /** @brief reset language to "LANG_ID_FORCE_SELECTION", epprom is updated */
  149. extern void lang_reset(void);
  150. /** @retval 1 language is selected */
  151. extern uint8_t lang_is_selected(void);
  152. #ifdef DEBUG_SEC_LANG
  153. extern const char* lang_get_sec_lang_str_by_id(uint16_t id);
  154. extern uint16_t lang_print_sec_lang(FILE* out);
  155. #endif //DEBUG_SEC_LANG
  156. extern void lang_boot_update_start(uint8_t lang);
  157. #if defined(__cplusplus)
  158. }
  159. #endif //defined(__cplusplus)
  160. #define CAT2(_s1, _s2) _s1
  161. #define CAT4(_s1, _s2, _s3, _s4) _s1
  162. #include "messages.h"
  163. #endif //LANGUAGE_H