My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef UTF_MAPPER_H
  23. #define UTF_MAPPER_H
  24. #include "../inc/MarlinConfig.h"
  25. #if ENABLED(DOGLCD)
  26. #define HARDWARE_CHAR_OUT u8g.print
  27. #else
  28. #define HARDWARE_CHAR_OUT lcd.write
  29. #endif
  30. #if DISABLED(SIMULATE_ROMFONT) && ENABLED(DOGLCD)
  31. #if ENABLED(DISPLAY_CHARSET_ISO10646_1) \
  32. || ENABLED(DISPLAY_CHARSET_ISO10646_5) \
  33. || ENABLED(DISPLAY_CHARSET_ISO10646_KANA) \
  34. || ENABLED(DISPLAY_CHARSET_ISO10646_GREEK) \
  35. || ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  36. #define MAPPER_ONE_TO_ONE
  37. #endif
  38. #else // SIMULATE_ROMFONT || !DOGLCD
  39. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  40. #if ENABLED(MAPPER_C2C3)
  41. const PROGMEM uint8_t utf_recode[] =
  42. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is fair for symbols
  43. 0x20,0x3F,0xEC,0xED,0x3F,0x5C,0x7C,0x3F,0x22,0x63,0x61,0x7F,0x3F,0x3F,0x52,0xB0, // c2a
  44. //' ' ¢ £ ­ l " c a « R
  45. 0xDF,0x3F,0x32,0x33,0x27,0xE4,0xF1,0xA5,0x2C,0x31,0xDF,0x7E,0x3F,0x3F,0x3F,0x3F, // c2b but relatively bad for letters.
  46. // ° 2 3 ` N p . , 1 ° »
  47. 0x3F,0x3F,0x3F,0x3F,0xE1,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, // c38
  48. // ä
  49. 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0xEF,0x78,0x3F,0x3F,0x3F,0x3F,0xF5,0x3F,0x3F,0xE2, // c39 missing characters display as '?'
  50. // ö x ü ß
  51. 0x3F,0x3F,0x3F,0x3F,0xE1,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F, // c3a
  52. // ä
  53. 0x3F,0xEE,0x3F,0x3F,0x3F,0x3F,0xEF,0xFD,0x3F,0x3F,0x3F,0x3F,0xF5,0x3F,0x3F,0x3F // c3b
  54. // n ö ÷ ü
  55. };
  56. #elif ENABLED(MAPPER_E382E383)
  57. const PROGMEM uint8_t utf_recode[] =
  58. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f
  59. 0x3D,0xB1,0xB1,0xA8,0xB2,0xA9,0xB3,0xAA,0xB4,0xAB,0xB5,0xB6,0xB6,0xB7,0xB7,0xB8, // e382a Please test and correct
  60. // = ア ア ィ イ ゥ ウ ェ エ ォ オ ガ ガ キ キ ク
  61. 0xB8,0xB9,0xB9,0xBA,0xBA,0xBB,0xBB,0xBC,0xBC,0xBD,0xBD,0xBE,0xBE,0xBF,0xBF,0xC0, // e382b
  62. // ク ケ ケ コ コ サ サ シ シ ス ス セ セ ソ ソ タ
  63. 0xC0,0xC1,0xC1,0xC2,0xC2,0xC2,0xC3,0xC3,0xC4,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA, // e3838
  64. // タ チ チ ッ ッ ッ テ テ ト ト ナ ニ ヌ ネ ノ ハ
  65. 0xCA,0xCA,0xCB,0xCB,0xCB,0xCC,0xCC,0xCC,0xCD,0xCD,0xCD,0xCE,0xCE,0xCE,0xCF,0xD0, // e3839
  66. // ハ ハ ヒ ヒ ヒ フ フ フ ヘ ヘ ヘ ホ ホ ホ マ ミ
  67. 0xD1,0xD2,0xD3,0xD4,0xD4,0xD5,0xD5,0xAE,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDC, // e383a
  68. // ム メ モ ャ ャ ユ ユ ョ ヨ ラ リ ル レ ロ ワ ワ
  69. 0xEC,0xA7,0xA6,0xDD,0xCC,0x3F,0x3F,0x3F,0x3F,0x3F,0xA6,0xA5,0xB0,0xA4,0xA4,0x3F // e383b
  70. // ヰ ヱ ヲ ン フ ? ? ? ? ? ヲ ・ ー ヽ ヽ ?
  71. };
  72. #elif ENABLED(MAPPER_D0D1)
  73. #error "Cyrillic on a JAPANESE display makes no sense. There are no matching symbols."
  74. #endif
  75. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  76. #if ENABLED(MAPPER_C2C3)
  77. const PROGMEM uint8_t utf_recode[] =
  78. { // 0 1 2 3 4 5 6 7 8 9 a b c d e f This is relative complete.
  79. 0x20,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0x22,0xA9,0xAA,0xAB,0x3F,0x3F,0xAE,0x3F, // c2a ¡¢£¤¥¦§¨©ª«¬­®¯
  80. //' ' ¡ ¢ £ ¤ ¥ ¦ § " © ª « ? ? ® ?
  81. 0xB0,0xB1,0xB2,0xB3,0x27,0xB5,0xB6,0xB7,0x2C,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, // c2b °±²³´µ¶·¸¹º»¼½¾¿
  82. // ° ± ³ ² ? µ ¶ · , ¹ º » ¼ ½ ¾ ¿
  83. 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, // c38 ÀÁÃÄÅÆÇÈÉÊËÌÍÎÏ
  84. // À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï
  85. 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, // c39 ÐÑÓÔÕÖ×ØÙÚÛÜÝÞß
  86. // Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß
  87. 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, // c3a àáãäåæçèéêëìíîï
  88. // à á â ã ä å æ ç è é ê ë ì í î ï
  89. 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF // c3b ðñóôõö÷øùúûüýþÿ
  90. // ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ
  91. };
  92. #elif ENABLED(MAPPER_D0D1)
  93. #define MAPPER_D0D1_MOD
  94. const PROGMEM uint8_t utf_recode[] =
  95. {//0 1 2 3 4 5 6 7 8 9 a b c d e f
  96. 0x41,0x80,0x42,0x92,0x81,0x45,0x82,0x83,0x84,0x85,0x4B,0x86,0x4D,0x48,0x4F,0x87, // d0a
  97. // A Б B Г Д E Ж З И Й K Л M H O П
  98. 0x50,0x43,0x54,0x88,0xD8,0x58,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x62,0x8F,0xAC,0xAD, // d0b
  99. // P C T У Ф X Ч ч Ш Щ Ъ Ы b Э Ю Я
  100. 0x61,0x36,0x42,0x92,0x81,0x65,0x82,0xB3,0x84,0x85,0x6B,0x86,0x4D,0x48,0x6F,0x87, // d18
  101. // a 6 B Г Д e Ж ³ И Й k Л M H o П
  102. 0x70,0x63,0x54,0x79,0xD8,0x78,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x62,0x8F,0xAC,0xAD // d19
  103. // p c T y Ф x Ч ч Ш Щ Ъ Ы b Э Ю Я
  104. };
  105. #elif ENABLED(MAPPER_E382E383)
  106. #error "Katakana on a WESTERN display makes no sense. There are no matching symbols."
  107. #endif
  108. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  109. #if ENABLED(MAPPER_D0D1)
  110. #define MAPPER_D0D1_MOD
  111. // it is a Russian alphabet translation
  112. // except 0401 --> 0xA2 = Ё, 0451 --> 0xB5 = ё
  113. const PROGMEM uint8_t utf_recode[] =
  114. { 0x41,0xA0,0x42,0xA1,0xE0,0x45,0xA3,0xA4, // unicode U+0400 to U+047f
  115. // A Б->Ё B Г Д E Ж З // 0 Ѐ Ё Ђ Ѓ Є Ѕ І Ї
  116. 0xA5,0xA6,0x4B,0xA7,0x4D,0x48,0x4F,0xA8, // Ј Љ Њ Ћ Ќ Ѝ Ў Џ
  117. // И Й K Л M H O П // 1 А Б В Г Д Е Ж З
  118. 0x50,0x43,0x54,0xA9,0xAA,0x58,0xE1,0xAB, // И Й К Л М Н О П
  119. // P C T У Ф X Ч ч // 2 Р С Т У Ф Х Г Ч
  120. 0xAC,0xE2,0xAD,0xAE,0x62,0xAF,0xB0,0xB1, // Ш Щ Ъ Ы Ь Э Ю Я
  121. // Ш Щ Ъ Ы b Э Ю Я // 3 а б в г д е ж з
  122. 0x61,0xB2,0xB3,0xB4,0xE3,0x65,0xB6,0xB7, // и й к л м н о п
  123. // a б->ё в г д e ж з // 4 р с т у ф х ц ч
  124. 0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0x6F,0xBE, // ш щ ъ ы ь э ю я
  125. // и й к л м н o п // 5 ѐ ё ђ ѓ є ѕ і ї
  126. 0x70,0x63,0xBF,0x79,0xE4,0x78,0xE5,0xC0, // ј љ њ ћ ќ ѝ ў џ
  127. // p c т y ф x ц ч // 6 Ѡ ѡ Ѣ ѣ Ѥ ѥ Ѧ ѧ
  128. 0xC1,0xE6,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7 // Ѫ ѩ Ѫ ѫ Ѭ ѭ Ѯ ѯ
  129. // ш щ ъ ы ь э ю я // 7 Ѱ ѱ Ѳ ѳ Ѵ ѵ Ѷ ѷ
  130. }; // ѻ ѹ Ѻ ѻ Ѽ ѽ Ѿ ѿ
  131. #elif ENABLED(MAPPER_C2C3)
  132. #error "Western languages on a CYRILLIC display makes no sense. There are no matching symbols."
  133. #elif ENABLED(MAPPER_E382E383)
  134. #error "Katakana on a CYRILLIC display makes no sense. There are no matching symbols."
  135. #endif
  136. #else
  137. #error "Something went wrong in the setting of DISPLAY_CHARSET_HD44780"
  138. #endif // DISPLAY_CHARSET_HD44780
  139. #endif // SIMULATE_ROMFONT
  140. #define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
  141. #if ENABLED(MAPPER_C2C3)
  142. char charset_mapper(const char c) {
  143. static uint8_t utf_hi_char; // UTF-8 high part
  144. static bool seen_c2 = false;
  145. uint8_t d = c;
  146. if (d >= 0x80u) { // UTF-8 handling
  147. if (d >= 0xC0u && !seen_c2) {
  148. utf_hi_char = d - 0xC2u;
  149. seen_c2 = true;
  150. return 0;
  151. }
  152. else if (seen_c2) {
  153. d &= 0x3Fu;
  154. #ifndef MAPPER_ONE_TO_ONE
  155. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  156. #else
  157. HARDWARE_CHAR_OUT((char)(0x80u + (utf_hi_char << 6) + d)) ;
  158. #endif
  159. }
  160. else {
  161. HARDWARE_CHAR_OUT('?');
  162. }
  163. }
  164. else {
  165. HARDWARE_CHAR_OUT((char) c );
  166. }
  167. seen_c2 = false;
  168. return 1;
  169. }
  170. #elif ENABLED(MAPPER_C2C3_TR)
  171. // the C2C3-mapper extended for the 6 altered symbols from C4 and C5 range.
  172. char charset_mapper(const char c) {
  173. static uint8_t utf_hi_char; // UTF-8 high part
  174. static bool seen_c2 = false,
  175. seen_c4 = false,
  176. seen_c5 = false;
  177. uint8_t d = c;
  178. if (d >= 0x80u) { // UTF-8 handling
  179. if (d == 0xC4u) { seen_c4 = true; return 0; }
  180. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  181. else if (d >= 0xC0u && !seen_c2) {
  182. utf_hi_char = d - 0xC2u;
  183. seen_c2 = true;
  184. return 0;
  185. }
  186. else if (seen_c4) {
  187. switch(d) {
  188. case 0x9Eu: d = 0xD0u; break;
  189. case 0x9Fu: d = 0xF0u; break;
  190. case 0xB0u: d = 0xDDu; break;
  191. case 0xB1u: d = 0xFDu; break;
  192. default: d = '?';
  193. }
  194. HARDWARE_CHAR_OUT((char)d) ;
  195. }
  196. else if (seen_c5) {
  197. switch(d) {
  198. case 0x9Eu: d = 0xDEu; break;
  199. case 0x9Fu: d = 0xFEu; break;
  200. default: d = '?';
  201. }
  202. HARDWARE_CHAR_OUT((char)d) ;
  203. }
  204. else if (seen_c2) {
  205. d &= 0x3Fu;
  206. #ifndef MAPPER_ONE_TO_ONE
  207. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  208. #else
  209. HARDWARE_CHAR_OUT((char)(0x80u + (utf_hi_char << 6) + d)) ;
  210. #endif
  211. }
  212. else {
  213. HARDWARE_CHAR_OUT('?');
  214. }
  215. }
  216. else {
  217. HARDWARE_CHAR_OUT((char) c );
  218. }
  219. seen_c2 = seen_c4 = seen_c5 = false;
  220. return 1;
  221. }
  222. #elif ENABLED(MAPPER_CECF)
  223. char charset_mapper(const char c) {
  224. static uint8_t utf_hi_char; // UTF-8 high part
  225. static bool seen_ce = false;
  226. uint8_t d = c;
  227. if (d >= 0x80) { // UTF-8 handling
  228. if (d >= 0xC0 && !seen_ce) {
  229. utf_hi_char = d - 0xCE;
  230. seen_ce = true;
  231. return 0;
  232. }
  233. else if (seen_ce) {
  234. d &= 0x3F;
  235. #ifndef MAPPER_ONE_TO_ONE
  236. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  237. #else
  238. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  239. #endif
  240. }
  241. else {
  242. HARDWARE_CHAR_OUT('?');
  243. }
  244. }
  245. else {
  246. HARDWARE_CHAR_OUT((char)c);
  247. }
  248. seen_ce = false;
  249. return 1;
  250. }
  251. #elif ENABLED(MAPPER_CECF)
  252. char charset_mapper(const char c) {
  253. static uint8_t utf_hi_char; // UTF-8 high part
  254. static bool seen_ce = false;
  255. uint8_t d = c;
  256. if (d >= 0x80) { // UTF-8 handling
  257. if (d >= 0xC0 && !seen_ce) {
  258. utf_hi_char = d - 0xCE;
  259. seen_ce = true;
  260. return 0;
  261. }
  262. else if (seen_ce) {
  263. d &= 0x3F;
  264. #ifndef MAPPER_ONE_TO_ONE
  265. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  266. #else
  267. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  268. #endif
  269. }
  270. else {
  271. HARDWARE_CHAR_OUT('?');
  272. }
  273. }
  274. else {
  275. HARDWARE_CHAR_OUT((char) c );
  276. }
  277. seen_ce = false;
  278. return 1;
  279. }
  280. #elif ENABLED(MAPPER_D0D1_MOD)
  281. char charset_mapper(const char c) {
  282. // it is a Russian alphabet translation
  283. // except 0401 --> 0xA2 = Ё, 0451 --> 0xB5 = ё
  284. static uint8_t utf_hi_char; // UTF-8 high part
  285. static bool seen_d5 = false;
  286. uint8_t d = c;
  287. if (d >= 0x80) { // UTF-8 handling
  288. if (d >= 0xD0 && !seen_d5) {
  289. utf_hi_char = d - 0xD0;
  290. seen_d5 = true;
  291. return 0;
  292. }
  293. else if (seen_d5) {
  294. d &= 0x3F;
  295. if (!utf_hi_char && d == 1) {
  296. HARDWARE_CHAR_OUT((char) 0xA2); // Ё
  297. }
  298. else if (utf_hi_char == 1 && d == 0x11) {
  299. HARDWARE_CHAR_OUT((char)0xB5); // ё
  300. }
  301. else {
  302. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x10));
  303. }
  304. }
  305. else {
  306. HARDWARE_CHAR_OUT('?');
  307. }
  308. }
  309. else {
  310. HARDWARE_CHAR_OUT((char) c );
  311. }
  312. seen_d5 = false;
  313. return 1;
  314. }
  315. #elif ENABLED(MAPPER_D0D1)
  316. char charset_mapper(const char c) {
  317. static uint8_t utf_hi_char; // UTF-8 high part
  318. static bool seen_d5 = false;
  319. uint8_t d = c;
  320. if (d >= 0x80u) { // UTF-8 handling
  321. if (d >= 0xD0u && !seen_d5) {
  322. utf_hi_char = d - 0xD0u;
  323. seen_d5 = true;
  324. return 0;
  325. }
  326. else if (seen_d5) {
  327. d &= 0x3Fu;
  328. #ifndef MAPPER_ONE_TO_ONE
  329. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  330. #else
  331. HARDWARE_CHAR_OUT((char)(0xA0u + (utf_hi_char << 6) + d)) ;
  332. #endif
  333. }
  334. else {
  335. HARDWARE_CHAR_OUT('?');
  336. }
  337. }
  338. else {
  339. HARDWARE_CHAR_OUT((char) c );
  340. }
  341. seen_d5 = false;
  342. return 1;
  343. }
  344. #elif ENABLED(MAPPER_E382E383)
  345. char charset_mapper(const char c) {
  346. static uint8_t utf_hi_char; // UTF-8 high part
  347. static bool seen_e3 = false,
  348. seen_82_83 = false;
  349. uint8_t d = c;
  350. if (d >= 0x80) { // UTF-8 handling
  351. if (d == 0xE3 && !seen_e3) {
  352. seen_e3 = true;
  353. return 0; // eat 0xE3
  354. }
  355. else if (d >= 0x82 && seen_e3 && !seen_82_83) {
  356. utf_hi_char = d - 0x82;
  357. seen_82_83 = true;
  358. return 0;
  359. }
  360. else if (seen_e3 && seen_82_83) {
  361. d &= 0x3F;
  362. #ifndef MAPPER_ONE_TO_ONE
  363. HARDWARE_CHAR_OUT((char)pgm_read_byte_near(utf_recode + d + (utf_hi_char << 6) - 0x20));
  364. #else
  365. HARDWARE_CHAR_OUT((char)(0x80 + (utf_hi_char << 6) + d)) ;
  366. #endif
  367. }
  368. else {
  369. HARDWARE_CHAR_OUT((char) '?' );
  370. }
  371. }
  372. else {
  373. HARDWARE_CHAR_OUT((char) c );
  374. }
  375. seen_e3 = false;
  376. seen_82_83 = false;
  377. return 1;
  378. }
  379. #elif ENABLED(MAPPER_C3C4C5_PL)
  380. /**
  381. * Ą C4 84 = 80
  382. * ą C4 85 = 81
  383. * Ć C4 86 = 82
  384. * ć C4 87 = 83
  385. * Ę C4 98 = 84
  386. * ę C4 99 = 85
  387. * Ł C5 81 = 86
  388. * ł C5 82 = 87
  389. * Ń C5 83 = 88
  390. * ń C5 84 = 89
  391. * Ó C3 93 = 8A
  392. * ó C3 B3 = 8B
  393. * Ś C5 9A = 8C
  394. * ś C5 9B = 8D
  395. * Ź C5 B9 = 8E
  396. * ź C5 BA = 8F
  397. * Ż C5 BB = 90
  398. * ż C5 BC = 91
  399. */
  400. char charset_mapper(const char c) {
  401. static bool seen_c3 = false,
  402. seen_c4 = false,
  403. seen_c5 = false;
  404. uint8_t d = c;
  405. if (d >= 0x80u) { // UTF-8 handling
  406. if (d == 0xC4u) { seen_c4 = true; return 0; }
  407. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  408. else if (d == 0xC3u) { seen_c3 = true; return 0; }
  409. else if (seen_c4) {
  410. switch(d) {
  411. case 0x84u ... 0x87u: d -= 4; break; //Ą - ć
  412. case 0x98u ... 0x99u: d -= 20; break; //Ę i ę
  413. default: d = '?';
  414. }
  415. HARDWARE_CHAR_OUT((char)d) ;
  416. }
  417. else if (seen_c5) {
  418. switch(d) {
  419. case 0x81u ... 0x84u: d += 5; break; //Ł - ń
  420. case 0x9Au ... 0x9Bu: d -= 0x0Eu; break; //Ś i ś
  421. case 0xB9u ... 0xBCu: d -= 0x2Bu; break; //Ź - ż
  422. default: d = '?';
  423. }
  424. HARDWARE_CHAR_OUT((char)d) ;
  425. }
  426. else if (seen_c3) {
  427. switch(d) {
  428. case 0x93u: d = 0x8Au; break; //Ó
  429. case 0xB3u: d = 0x8Bu; break; //ó
  430. d = '?';
  431. }
  432. HARDWARE_CHAR_OUT((char)d) ;
  433. }
  434. }
  435. else {
  436. HARDWARE_CHAR_OUT((char) c );
  437. }
  438. seen_c3 = seen_c4 = seen_c5 = false;
  439. return 1;
  440. }
  441. #elif ENABLED(MAPPER_C3C4C5_CZ)
  442. /**
  443. * Á C3 81 = 80
  444. * É C3 89 = 81
  445. * Í C3 8D = 82
  446. * Ó C3 93 = 83
  447. * Ú C3 9A = 84
  448. * Ý C3 9D = 85
  449. * á C3 A1 = 86
  450. * é C3 A9 = 87
  451. * í C3 AD = 88
  452. * ó C3 B3 = 89
  453. * ú C3 BA = 8A
  454. * ý C3 BD = 8B
  455. * Č C4 8C = 8C
  456. * č C4 8D = 8D
  457. * Ď C4 8E = 8E
  458. * ď C4 8F = 8F
  459. * Ě C4 9A = 90
  460. * ě C4 9B = 91
  461. * Ň C5 87 = 92
  462. * ň C5 88 = 93
  463. * Ř C5 98 = 94
  464. * ř C5 99 = 95
  465. * Š C5 A0 = 96
  466. * š C5 A1 = 97
  467. * Ť C5 A4 = 98
  468. * ť C5 A5 = 99
  469. * Ů C5 AE = 9A
  470. * ů C5 AF = 9B
  471. * Ž C5 BD = 9C
  472. * ž C5 BE = 9D
  473. */
  474. char charset_mapper(const char c) {
  475. static bool seen_c3 = false,
  476. seen_c4 = false,
  477. seen_c5 = false;
  478. uint8_t d = c;
  479. if (d >= 0x80u) { // UTF-8 handling
  480. if (d == 0xC4u) { seen_c4 = true; return 0; }
  481. else if (d == 0xC5u) { seen_c5 = true; return 0; }
  482. else if (d == 0xC3u) { seen_c3 = true; return 0; }
  483. else if (seen_c4) {
  484. switch(d) {
  485. case 0x8Cu ... 0x8Fu: break; // ČčĎď Mapping 1:1
  486. case 0x9Au ... 0x9Bu: d -= 10; break; // Ěě
  487. default: d = '?';
  488. }
  489. HARDWARE_CHAR_OUT((char)d) ;
  490. }
  491. else if (seen_c5) {
  492. switch(d) {
  493. case 0x87u ... 0x88u: d += 0x0Bu; break; // Ňň
  494. case 0x98u ... 0x99u: d -= 0x04u; break; // Řř
  495. case 0xA0u ... 0xA1u: d -= 0x0Au; break; // Šš
  496. case 0xA4u ... 0xA5u: d -= 0x0Cu; break; // Ťť
  497. case 0xAEu ... 0xAFu: d -= 0x14u; break; // Ůů
  498. case 0xBDu ... 0xBEu: d -= 0x21u; break; // Žž
  499. default: d = '?';
  500. }
  501. HARDWARE_CHAR_OUT((char)d) ;
  502. }
  503. else if (seen_c3) {
  504. switch(d) {
  505. case 0x81u: d = 0x80u; break; // Á
  506. case 0x89u: d = 0x81u; break; // É
  507. case 0x8Du: d = 0x82u; break; // Í
  508. case 0x93u: d = 0x83u; break; // Ó
  509. case 0x9Au: d = 0x84u; break; // Ú
  510. case 0x9Du: d = 0x85u; break; // Ý
  511. case 0xA1u: d = 0x86u; break; // á
  512. case 0xA9u: d = 0x87u; break; // é
  513. case 0xADu: d = 0x88u; break; // í
  514. case 0xB3u: d = 0x89u; break; // ó
  515. case 0xBAu: d = 0x8Au; break; // ú
  516. case 0xBDu: d = 0x8Bu; break; // ý
  517. default: d = '?';
  518. }
  519. HARDWARE_CHAR_OUT((char)d) ;
  520. }
  521. }
  522. else {
  523. HARDWARE_CHAR_OUT((char) c );
  524. }
  525. seen_c3 = seen_c4 = seen_c5 = false;
  526. return 1;
  527. }
  528. #elif ENABLED(MAPPER_C3C4C5_SK)
  529. // TBD
  530. #error "No mapping for Slovak at this time. Use MAPPER_NON."
  531. #else
  532. #define MAPPER_NON
  533. #undef PRINTABLE
  534. #define PRINTABLE(C) true
  535. char charset_mapper(const char c) {
  536. HARDWARE_CHAR_OUT(c);
  537. return 1;
  538. }
  539. #endif // code mappers
  540. #endif // UTF_MAPPER_H