language.h 4.4 KB

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