language.h 3.9 KB

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