config.h 5.5 KB

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