language.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /** @file */
  2. //language.h
  3. #ifndef LANGUAGE_H
  4. #define LANGUAGE_H
  5. #include "config.h"
  6. #include <inttypes.h>
  7. #ifdef DEBUG_SEC_LANG
  8. #include <stdio.h>
  9. #endif //DEBUG_SEC_LANG
  10. #define PROTOCOL_VERSION "1.0"
  11. #ifndef CUSTOM_MENDEL_NAME
  12. #define MACHINE_NAME "Mendel"
  13. #endif
  14. #ifndef MACHINE_UUID
  15. #define MACHINE_UUID "00000000-0000-0000-0000-000000000000"
  16. #endif
  17. #define MSG_FW_VERSION "Firmware"
  18. #define STRINGIFY_(n) #n
  19. #define STRINGIFY(n) STRINGIFY_(n)
  20. #if (LANG_MODE == 0) //primary language only
  21. #define PROGMEM_I2 __attribute__((section(".progmem0")))
  22. #define PROGMEM_I1 __attribute__((section(".progmem1")))
  23. #define PROGMEM_N1 __attribute__((section(".progmem2")))
  24. #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = s; &__c[0];}))
  25. #define ISTR(s) s
  26. #define _i(s) _I(s)
  27. #define _T(s) s
  28. #else //(LANG_MODE == 0)
  29. // section .loc_sec (originaly .progmem0) will be used for localized translated strings
  30. #define PROGMEM_I2 __attribute__((section(".loc_sec")))
  31. // section .loc_pri (originaly .progmem1) will be used for localized strings in english
  32. #define PROGMEM_I1 __attribute__((section(".loc_pri")))
  33. // section .noloc (originaly progmem2) will be used for not localized strings in english
  34. #define PROGMEM_N1 __attribute__((section(".noloc")))
  35. #define _I(s) (__extension__({static const char __c[] PROGMEM_I1 = "\xff\xff" s; &__c[0];}))
  36. #define ISTR(s) "\xff\xff" s
  37. #define _i(s) lang_get_translation(_I(s))
  38. #define _T(s) lang_get_translation(s)
  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)
  42. /** @brief lang_table_header_t structure - (size= 16byte) */
  43. typedef struct
  44. {
  45. uint32_t magic; //+0
  46. uint16_t size; //+4
  47. uint16_t count; //+6
  48. uint16_t checksum; //+8
  49. uint16_t code; //+10
  50. uint32_t signature; //+12
  51. } lang_table_header_t;
  52. /** @brief lang_table_t structure - (size= 16byte + 2*count) */
  53. typedef struct
  54. {
  55. lang_table_header_t header;
  56. uint16_t table[];
  57. } lang_table_t;
  58. /** @name Language indices into their particular symbol tables.*/
  59. ///@{
  60. #define LANG_ID_PRI 0
  61. #define LANG_ID_SEC 1
  62. ///@}
  63. /** @def LANG_ID_FORCE_SELECTION
  64. * @brief Language is not defined and it shall be selected from the menu.*/
  65. #define LANG_ID_FORCE_SELECTION 254
  66. /** @def LANG_ID_UNDEFINED
  67. * @brief Language is not defined on a virgin RAMBo board. */
  68. #define LANG_ID_UNDEFINED 255
  69. /** @def LANG_ID_DEFAULT
  70. * @brief Default language ID, if no language is selected. */
  71. #define LANG_ID_DEFAULT LANG_ID_PRI
  72. /** @def LANG_MAGIC
  73. * @brief Magic number at begin of lang table. */
  74. #define LANG_MAGIC 0x4bb45aa5
  75. /** @name Language codes (ISO639-1)*/
  76. ///@{
  77. #define LANG_CODE_XX 0x3f3f //!<'??'
  78. #define LANG_CODE_EN 0x656e //!<'en'
  79. #define LANG_CODE_CZ 0x6373 //!<'cs'
  80. #define LANG_CODE_DE 0x6465 //!<'de'
  81. #define LANG_CODE_ES 0x6573 //!<'es'
  82. #define LANG_CODE_FR 0x6672 //!<'fr'
  83. #define LANG_CODE_IT 0x6974 //!<'it'
  84. #define LANG_CODE_PL 0x706c //!<'pl'
  85. ///@}
  86. #if defined(__cplusplus)
  87. extern "C" {
  88. #endif //defined(__cplusplus)
  89. /** @brief Currectly active language selection.*/
  90. extern uint8_t lang_selected;
  91. #if (LANG_MODE != 0)
  92. extern const char _SEC_LANG[LANG_SIZE_RESERVED];
  93. extern const char* lang_get_translation(const char* s);
  94. /** @def _SEC_LANG_TABLE
  95. * @brief Align table to start of 256 byte page */
  96. #define _SEC_LANG_TABLE ((((uint16_t)&_SEC_LANG) + 0x00ff) & 0xff00)
  97. #endif //(LANG_MODE != 0)
  98. /** @brief selects language, eeprom is updated in case of success */
  99. extern uint8_t lang_select(uint8_t lang);
  100. /** @brief performs checksum test of secondary language data */
  101. extern uint8_t lang_check(uint16_t addr);
  102. /** @return total number of languages (primary + all in xflash) */
  103. extern uint8_t lang_get_count(void);
  104. /** @brief reads lang table header and offset in xflash or progmem */
  105. extern uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset);
  106. /** @brief reads lang code from xflash or progmem */
  107. extern uint16_t lang_get_code(uint8_t lang);
  108. /** @return localized language name (text for menu item) */
  109. extern const char* lang_get_name_by_code(uint16_t code);
  110. /** @brief reset language to "LANG_ID_FORCE_SELECTION", epprom is updated */
  111. extern void lang_reset(void);
  112. /** @retval 1 language is selected */
  113. extern uint8_t lang_is_selected(void);
  114. #ifdef DEBUG_SEC_LANG
  115. extern const char* lang_get_sec_lang_str_by_id(uint16_t id);
  116. extern uint16_t lang_print_sec_lang(FILE* out);
  117. #endif //DEBUG_SEC_LANG
  118. extern void lang_boot_update_start(uint8_t lang);
  119. #if defined(__cplusplus)
  120. }
  121. #endif //defined(__cplusplus)
  122. #define CAT2(_s1, _s2) _s1
  123. #define CAT4(_s1, _s2, _s3, _s4) _s1
  124. #include "messages.h"
  125. #endif //LANGUAGE_H