language.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 reserved1; //+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. // Number of languages available in the language table.
  63. #define LANG_NUM 2
  64. // Magic number at begin of lang table.
  65. #define LANG_MAGIC 0x4bb45aa5
  66. // Language codes (ISO639-1)
  67. #define LANG_CODE_XX 0x3f3f //'??'
  68. #define LANG_CODE_EN 0x656e //'en'
  69. #define LANG_CODE_CZ 0x6373 //'cs'
  70. #define LANG_CODE_DE 0x6465 //'de'
  71. #define LANG_CODE_ES 0x6573 //'es'
  72. #define LANG_CODE_IT 0x6974 //'it'
  73. #define LANG_CODE_PL 0x706c //'pl'
  74. #if defined(__cplusplus)
  75. extern "C" {
  76. #endif //defined(__cplusplus)
  77. // Currectly active language selection.
  78. extern uint8_t lang_selected;
  79. #if (LANG_MODE != 0)
  80. extern const char _SEC_LANG[LANG_SIZE_RESERVED];
  81. extern const char* lang_get_translation(const char* s);
  82. extern const char* lang_get_sec_lang_str(const char* s);
  83. #endif //(LANG_MODE != 0)
  84. //selects
  85. extern uint8_t lang_select(uint8_t lang);
  86. //get total number of languages (primary + all in xflash)
  87. extern uint8_t lang_get_count();
  88. extern uint8_t lang_get_header(uint8_t lang, lang_table_header_t* header, uint32_t* offset);
  89. extern uint16_t lang_get_code(uint8_t lang);
  90. extern const char* lang_get_name_by_code(uint16_t code);
  91. #ifdef DEBUG_SEC_LANG
  92. extern const char* lang_get_sec_lang_str_by_id(uint16_t id);
  93. extern uint16_t lang_print_sec_lang(FILE* out);
  94. #endif //DEBUG_SEC_LANG
  95. #if defined(__cplusplus)
  96. }
  97. #endif //defined(__cplusplus)
  98. #define CAT2(_s1, _s2) _s1
  99. #define CAT4(_s1, _s2, _s3, _s4) _s1
  100. //Localized language name
  101. //extern const char MSG_LANGUAGE_NAME[];
  102. #include "messages.h"
  103. #endif //LANGUAGE_H