language.h 4.0 KB

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