config.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #ifndef CONFIG_H
  2. #define CONFIG_H
  3. // clang-format off
  4. #include <freetype2/ft2build.h>
  5. #include <freetype/freetype.h>
  6. // clang-format on
  7. /// raspberry pi CM3
  8. #ifdef CM4
  9. // make CFLAGS=-DCM4=1
  10. #define BCM_GPIO_28 18
  11. #define BCM_GPIO_29 19
  12. #define BCM_GPIO_30 20
  13. #define BCM_GPIO_31 21
  14. #define BCM_GPIO_32 14
  15. #define BCM_GPIO_33 15
  16. #define BCM_GPIO_34 24
  17. #define BCM_GPIO_35 25
  18. #define BCM_GPIO_36 26
  19. #define BCM_GPIO_37 27
  20. #define BCM_GPIO_38 6
  21. #define BCM_GPIO_39 7
  22. #define BCM_GPIO_40 16
  23. #define BCM_GPIO_41 17
  24. #define BCM_GPIO_43 23
  25. #else
  26. #define BCM_GPIO_28 28
  27. #define BCM_GPIO_29 29
  28. #define BCM_GPIO_30 30
  29. #define BCM_GPIO_31 31
  30. #define BCM_GPIO_32 32
  31. #define BCM_GPIO_33 33
  32. #define BCM_GPIO_34 34
  33. #define BCM_GPIO_35 35
  34. #define BCM_GPIO_36 36
  35. #define BCM_GPIO_37 37
  36. #define BCM_GPIO_38 38
  37. #define BCM_GPIO_39 39
  38. #define BCM_GPIO_40 40
  39. #define BCM_GPIO_41 41
  40. #define BCM_GPIO_42 42
  41. #define BCM_GPIO_43 43
  42. #define BCM_GPIO_44 44
  43. #define BCM_GPIO_45 45
  44. #endif
  45. // PA8-12 UART1
  46. //#define SPI1_NSS_PIN PA4 //SPI_1 Chip Select pin is PA4. //no use in
  47. //DevTerm
  48. #define VH_PIN BCM_GPIO_40 // ENABLE_VH required,PRT_EN
  49. #define LATCH_PIN BCM_GPIO_36 // 18
  50. #define PEM_PIN BCM_GPIO_34 // 1 [PS,PAPER]
  51. /*
  52. #define PEM_CTL_PIN BCM_GPIO_32 //3 VPS
  53. #define ENABLE_PEM digitalWrite(PEM_CTL_PIN,HIGH)
  54. #define DISABLE_PEM digitalWrite(PEM_CTL_PIN,LOW)
  55. */
  56. // DevTerm no VPS IO
  57. //#define PEM_CTL_PIN
  58. #define ENABLE_PEM
  59. #define DISABLE_PEM
  60. // https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md
  61. // enable SPI0 ALT0 in CM3 first
  62. // in /boot/config.txt
  63. // dtparam=spi=on
  64. // dtoverlay=spi-gpio35-39
  65. // then we can see GPIO38 GPIO39 in ALT0 Mode by `gpio readall`
  66. #define MOSI_PIN BCM_GPIO_38
  67. #define CLK_PIN BCM_GPIO_39
  68. /**
  69. *@brief STB_NUMBER stand for STROBE NUMBER of lines, which means how many lines
  70. * are going to be activated
  71. **/
  72. #define STB_NUMBER 1
  73. #define STB1_PIN BCM_GPIO_37 // 13
  74. #define STB2_PIN STB1_PIN
  75. #define STB3_PIN STB1_PIN
  76. #define STB4_PIN STB1_PIN
  77. #define STB5_PIN STB1_PIN
  78. #define STB6_PIN STB1_PIN
  79. #define PH1_PIN BCM_GPIO_28
  80. #define PH2_PIN BCM_GPIO_29
  81. #define PH3_PIN BCM_GPIO_30
  82. #define PH4_PIN BCM_GPIO_31
  83. /// 0 1 3 2 mine
  84. #define PA_PIN PH1_PIN //
  85. #define PNA_PIN PH2_PIN //
  86. #define PB_PIN PH3_PIN //
  87. #define PNB_PIN PH4_PIN //
  88. //#define ENABLE1_PIN PA13
  89. //#define ENABLE2_PIN PA14
  90. #define THERMISTORPIN BCM_GPIO_35 // ADC,14
  91. #define MOTOR_ENABLE1
  92. #define MOTOR_ENABLE2
  93. #define MOTOR_DISABLE1
  94. #define MOTOR_DISABLE2
  95. #define ENABLE_VH digitalWrite(VH_PIN, HIGH)
  96. #define DISABLE_VH digitalWrite(VH_PIN, LOW)
  97. #define READ_VH digitalRead(VH_PIN)
  98. #define LATCH_ENABLE digitalWrite(LATCH_PIN, LOW)
  99. #define LATCH_DISABLE digitalWrite(LATCH_PIN, HIGH)
  100. #define ASK4PAPER digitalRead(PEM_PIN)
  101. #define ERROR_FEED_PITCH ((uint8_t)0x01)
  102. #define IS_PAPER 0x00
  103. #define NO_PAPER 0x01
  104. #define HOT_PRINTER 0x02
  105. #define FORWARD 0x01
  106. #define BACKWARD 0x00
  107. #define HOT 64
  108. #define BCoefficent 3950
  109. #define RthNominal 30000
  110. #define TempNominal 25
  111. #define ADCResolution 1024
  112. #define SeriesResistor 30000
  113. #define NumSamples 1
  114. #define KELVIN 1
  115. #define CELSIUS 0
  116. #define ADC_FILE_PAT "/tmp/devterm_adc"
  117. #define HEAT_TIME 100 // heat time + (0-f)*46
  118. #define BAT_CAP "/sys/class/power_supply/axp20x-battery/capacity"
  119. #define BAT_THRESHOLD 14 // %14 battery = low power
  120. #define int16 uint16_t
  121. #define int8 uint8_t
  122. #define asciistart ((uint8_t)'A')
  123. #define netxcharacter ((uint8_t)24)
  124. #define Fontrows ((uint8_t)24)
  125. #define FontColums ((uint8_t)16)
  126. #define nextcharactercolum ((uint8_t)Fontrows / 8) // = 3
  127. #define ASCII_TAB '\t' // Horizontal tab
  128. #define ASCII_LF '\n' // Line feed,10
  129. #define ASCII_FF '\f' // Form feed
  130. #define ASCII_CR '\r' // Carriage return
  131. #define ASCII_EOT 4 // End of Transmission
  132. #define ASCII_DLE 16 // Data Link Escape
  133. #define ASCII_DC2 18 // Device control 2 //0x12
  134. #define ASCII_ESC 27 // Escape //0x1b
  135. #define ASCII_FS 28 // Field separator//0x1c
  136. #define ASCII_GS 29 // Group separator //0x1d
  137. #define PRINT_STATE 0
  138. #define ESC_STATE 1
  139. #define GET_IMAGE 2
  140. #define GET_GRAY_IMAGE 3
  141. #define ALIGN_LEFT 0
  142. #define ALIGN_CENTER 1
  143. #define ALIGN_RIGHT 2
  144. #define IMAGE_MAX (9224*64)
  145. #define BITS8 8
  146. #define MAX_DOTS 384
  147. #define PRINTER_BITS MAX_DOTS
  148. #define MAXPIXELS 48
  149. #ifdef MTP03
  150. #define MAX_DOTS 576
  151. #define PRINTER_BITS MAX_DOTS
  152. #define MAXPIXELS 72
  153. #endif
  154. #define FONT_MODE_0 0 // Internal
  155. #define FONT_MODE_1 1 // External
  156. // extract bits
  157. #define LAST(k, n) ((k) & ((1 << (n)) - 1))
  158. #define MID(k, m, n) LAST((k) >> (m), ((n) - (m)))
  159. typedef struct _Margin {
  160. uint16_t width;
  161. uint8_t esgs;
  162. } Margin;
  163. typedef struct _FONT {
  164. uint8_t width; // in bits
  165. uint8_t height;
  166. uint8_t mode; // 0 internal pcf font array,1 external ttf font file
  167. const uint8_t *data;
  168. char *file;
  169. } FONT;
  170. typedef struct _ImageCache {
  171. uint16_t idx;
  172. uint16_t num;
  173. uint16_t width;
  174. uint16_t height;
  175. uint8_t need_print : 1;
  176. uint8_t revert_bits : 1; // MSB OR LSB
  177. uint8_t cache[IMAGE_MAX]; // 48x192bytes(384x192 pixels) ,max
  178. } ImageCache;
  179. typedef struct _CONFIG {
  180. uint8_t state;
  181. uint8_t line_space;
  182. uint8_t align;
  183. uint8_t reverse; // reverse print
  184. uint8_t orient;
  185. uint8_t under_line;
  186. uint8_t feed_pitch;
  187. uint8_t density : 4; // 0-f,300+density*46 HEAT_TIME
  188. uint16_t wordgap : 10; // 1023 max
  189. uint8_t max_pts; // max pts in print_dots_8bit_split
  190. uint8_t lock;
  191. int16_t degree; // char rotate 0,90,180,270, -90,-180,-270
  192. Margin margin;
  193. FONT *font;
  194. ImageCache *img;
  195. FILE *fp;
  196. FT_Face face;
  197. FT_Library ft;
  198. int (*printf)(struct _CONFIG *, char *, ...);
  199. } CONFIG;
  200. typedef struct _SerialCache {
  201. uint8_t idx;
  202. uint8_t utf8idx; // 0-4
  203. // uint8_t data[77];//384/5, minium size font 5 pixel
  204. uint32_t data[MAX_DOTS]; // uint32_t for utf8 characters
  205. } SerialCache;
  206. typedef struct _TimeRec {
  207. unsigned int time;
  208. uint8_t last_status;
  209. uint8_t check;
  210. } TimeRec;
  211. void PrintDots8bit(uint8_t *Array, uint8_t characters, uint8_t feed_num);
  212. uint8_t invert_bit(uint8_t a);
  213. #endif