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.

fontutils.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * @file fontutils.h
  3. * @brief help functions for font and char
  4. * @author Yunhui Fu (yhfudev@gmail.com)
  5. * @version 1.0
  6. * @date 2016-08-19
  7. * @copyright GPL/BSD
  8. */
  9. #ifndef _FONT_UTILS_H
  10. #define _FONT_UTILS_H
  11. #define DEBUG 0
  12. #ifdef ARDUINO
  13. #include <Arduino.h>
  14. #else // ARDUINO
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #endif // ARDUINO
  19. #ifndef pgm_read_word_near // __AVR__
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. //#define pgm_read_word_near(a) *((uint16_t *)(a))
  24. #define pgm_read_word_near(a) (*(a))
  25. #define pgm_read_byte_near(a) *((uint8_t *)(a))
  26. #define pgm_read_byte pgm_read_byte_near
  27. #elif defined(__AVR__)
  28. #include <avr/pgmspace.h>
  29. #endif
  30. #ifndef PROGMEM
  31. #define PROGMEM
  32. #define strlen_P strlen
  33. #define memcpy_P memcpy
  34. #define vsnprintf_P vsnprintf
  35. #endif // PROGMEM
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. // read a byte from ROM or RAM
  40. typedef uint8_t (* read_byte_cb_t)(uint8_t * str);
  41. //inline uint8_t read_byte_ram(uint8_t * str) { return *str; }
  42. //inline uint8_t read_byte_rom(uint8_t * str) { return pgm_read_byte(str); }
  43. uint8_t read_byte_ram(uint8_t * str);
  44. uint8_t read_byte_rom(uint8_t * str);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #include <stddef.h> // wchar_t
  49. #include <stdint.h> // uint32_t
  50. #ifdef ARDUINO
  51. // there's overflow of the wchar_t due to the 2-byte size in Arduino
  52. // sizeof(wchar_t)=2; sizeof(size_t)=2; sizeof(uint32_t)=4;
  53. // sizeof(int)=2; sizeof(long)=4; sizeof(unsigned)=2;
  54. //#undef wchar_t
  55. #define wchar_t uint32_t
  56. //typedef uint32_t wchar_t;
  57. #else
  58. #include <sys/types.h> // ssize_t
  59. #include <assert.h>
  60. // x86_64
  61. // sizeof(wchar_t)=4; sizeof(size_t)=8; sizeof(uint32_t)=4;
  62. // sizeof(int)=4; sizeof(long)=8; sizeof(unsigned)=4;
  63. //#define wchar_t uint32_t
  64. #define wchar_t size_t
  65. #ifndef PRIu32
  66. #define PRIu32 "lu"
  67. #endif
  68. #ifndef PRIX32
  69. #define PRIX32 "lX"
  70. #endif
  71. #endif
  72. #define UNUSED_VARIABLE(a) ((void)(a))
  73. #ifndef MIN
  74. #define MIN(a,b) (((a)>(b))?(b):(a))
  75. #endif
  76. #ifndef NUM_ARRAY
  77. #define NUM_ARRAY(a) (sizeof(a)/sizeof((a)[0]))
  78. #endif // NUM_ARRAY
  79. #ifdef __cplusplus
  80. extern "C" {
  81. #endif
  82. //#define pixel_len_t u8g_uint_t
  83. #define pixel_len_t uint16_t
  84. //#define pixel_len_t uint8_t
  85. //typedef uint16_t pixel_len_t;
  86. #define PIXEL_LEN_NOLIMIT ((pixel_len_t)(-1))
  87. typedef int (* pf_bsearch_cb_comp_t)(void *userdata, size_t idx, void * data_pin); /*"data_list[idx] - *data_pin"*/
  88. int pf_bsearch_r(void *userdata, size_t num_data, pf_bsearch_cb_comp_t cb_comp, void *data_pinpoint, size_t *ret_idx);
  89. //wchar_t get_val_utf82uni(uint8_t *pstart);
  90. //uint8_t * get_utf8_value(uint8_t *pstart, wchar_t *pval);
  91. uint8_t * get_utf8_value_cb(uint8_t *pstart, read_byte_cb_t cb_read_byte, wchar_t *pval);
  92. uint8_t utf8_strlen(const char *pstart);
  93. uint8_t utf8_strlen_P(const char *pstart);
  94. char * utf8_strncpy(char * destination, const char * source, size_t num);
  95. char * utf8_strncpy_P(char * destination, const char * source, size_t num);
  96. int my_strlen_P(const char *pstart);
  97. #if 0 // DEBUG
  98. #if 0 //defined(ARDUINO)
  99. #if defined(__AVR__)
  100. #define TRACE(fmt, ...) {static const PROGMEM char CONSTSTR[] = "%d %d " fmt " {ln:%d;}\n"; serial_printf_P(CONSTSTR, millis(), ##__VA_ARGS__, __LINE__); }
  101. #else
  102. #define TRACE(fmt, ...) {static const PROGMEM char CONSTSTR[] = "%d " fmt " {ln:%d, fn:" __FILE__ "}\n"; serial_printf_P(CONSTSTR, millis(), ##__VA_ARGS__, __LINE__); }
  103. #endif
  104. #define FU_ASSERT(a) if (!(a)) {TRACE("Assert: " # a ); }
  105. #ifdef __cplusplus
  106. extern "C" {
  107. #endif
  108. void serial_printf_P(const char *format, ...);
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #else // ARDUINO
  113. #include <stdio.h>
  114. #define FU_ASSERT(a) if (!(a)) {printf("Assert: " # a); exit(1);}
  115. #define TRACE(fmt, ...) fprintf(stdout, "[%s()] " fmt " {ln:%d, fn:" __FILE__ "}\n", __func__, ##__VA_ARGS__, __LINE__)
  116. //#else
  117. //#define FU_ASSERT(a)
  118. //#define TRACE(...)
  119. #endif // ARDUINO
  120. #else // DEBUG
  121. #define TRACE(fmt, ...)
  122. #define FU_ASSERT(a)
  123. #endif // DEBUG
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif // _FONT_UTILS_H