Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

572 Zeilen
18 KiB

  1. /*
  2. * High level EPD functions
  3. * Author: LoBo 06/2017, https://github/loboris
  4. *
  5. */
  6. #ifndef _EPD_H_
  7. #define _EPD_H_
  8. #include <stdlib.h>
  9. #include "EPDspi.h"
  10. typedef uint8_t color_t;
  11. typedef struct {
  12. uint16_t x1;
  13. uint16_t y1;
  14. uint16_t x2;
  15. uint16_t y2;
  16. } dispWin_t;
  17. typedef struct {
  18. uint8_t *font;
  19. uint8_t x_size;
  20. uint8_t y_size;
  21. uint8_t offset;
  22. uint16_t numchars;
  23. uint16_t size;
  24. uint8_t max_x_size;
  25. uint8_t bitmap;
  26. color_t color;
  27. } Font_t;
  28. //==========================================================================================
  29. // ==== Global variables ===================================================================
  30. //==========================================================================================
  31. uint8_t orientation; // current screen orientation
  32. uint16_t font_rotate; // current font font_rotate angle (0~395)
  33. uint8_t font_transparent; // if not 0 draw fonts transparent
  34. uint8_t font_forceFixed; // if not zero force drawing proportional fonts with fixed width
  35. uint8_t font_buffered_char;
  36. uint8_t font_line_space; // additional spacing between text lines; added to font height
  37. uint8_t text_wrap; // if not 0 wrap long text to the new line, else clip
  38. color_t _fg; // current foreground color for fonts
  39. color_t _bg; // current background for non transparent fonts
  40. dispWin_t dispWin; // display clip window
  41. float _angleOffset; // angle offset for arc, polygon and line by angle functions
  42. Font_t cfont; // Current font structure
  43. uint8_t image_debug;
  44. int EPD_X; // X position of the next character after EPD_print() function
  45. int EPD_Y; // Y position of the next character after EPD_print() function
  46. // =========================================================================================
  47. // Buffer is created during jpeg decode for sending data
  48. // Total size of the buffer is 2 * (JPG_IMAGE_LINE_BUF_SIZE * 3)
  49. // The size must be multiple of 256 bytes !!
  50. #define JPG_IMAGE_LINE_BUF_SIZE 512
  51. // --- Constants for ellipse function ---
  52. #define EPD_ELLIPSE_UPPER_RIGHT 0x01
  53. #define EPD_ELLIPSE_UPPER_LEFT 0x02
  54. #define EPD_ELLIPSE_LOWER_LEFT 0x04
  55. #define EPD_ELLIPSE_LOWER_RIGHT 0x08
  56. // Constants for Arc function
  57. // number representing the maximum angle (e.g. if 100, then if you pass in start=0 and end=50, you get a half circle)
  58. // this can be changed with setArcParams function at runtime
  59. #define DEFAULT_ARC_ANGLE_MAX 360
  60. // rotational offset in degrees defining position of value 0 (-90 will put it at the top of circle)
  61. // this can be changed with setAngleOffset function at runtime
  62. #define DEFAULT_ANGLE_OFFSET -90
  63. #define PI 3.14159265359
  64. #define MIN_POLIGON_SIDES 3
  65. #define MAX_POLIGON_SIDES 60
  66. // === Color names constants ===
  67. #define EPD_BLACK 15
  68. #define EPD_WHITE 0
  69. // === Color invert constants ===
  70. #define INVERT_ON 1
  71. #define INVERT_OFF 0
  72. // === Screen orientation constants ===
  73. #define LANDSCAPE_0 1
  74. #define LANDSCAPE_180 2
  75. // === Special coordinates constants ===
  76. #define CENTER -9003
  77. #define RIGHT -9004
  78. #define BOTTOM -9004
  79. #define LASTX 7000
  80. #define LASTY 8000
  81. // === Embedded fonts constants ===
  82. #define DEFAULT_FONT 0
  83. #define DEJAVU18_FONT 1
  84. #define DEJAVU24_FONT 2
  85. #define UBUNTU16_FONT 3
  86. #define COMIC24_FONT 4
  87. #define MINYA24_FONT 5
  88. #define TOONEY32_FONT 6
  89. #define SMALL_FONT 7
  90. #define FONT_7SEG 8
  91. #define USER_FONT 9 // font will be read from file
  92. // ===== PUBLIC FUNCTIONS =========================================================================
  93. /*
  94. * Draw pixel at given x,y coordinates
  95. *
  96. * Params:
  97. * x: horizontal position
  98. * y: vertical position
  99. * color: pixel color
  100. */
  101. //------------------------------------------------------
  102. void EPD_drawPixel(int16_t x, int16_t y, color_t color);
  103. /*
  104. * Read pixel color value from display GRAM at given x,y coordinates
  105. *
  106. * Params:
  107. * x: horizontal position
  108. * y: vertical position
  109. *
  110. * Returns:
  111. * pixel color at x,y
  112. */
  113. //------------------------------------------
  114. color_t EPD_readPixel(int16_t x, int16_t y);
  115. /*
  116. * Draw vertical line at given x,y coordinates
  117. *
  118. * Params:
  119. * x: horizontal start position
  120. * y: vertical start position
  121. * h: line height in pixels
  122. * color: line color
  123. */
  124. //---------------------------------------------------------------------
  125. void EPD_drawFastVLine(int16_t x, int16_t y, int16_t h, color_t color);
  126. /*
  127. * Draw horizontal line at given x,y coordinates
  128. *
  129. * Params:
  130. * x: horizontal start position
  131. * y: vertical start position
  132. * w: line width in pixels
  133. * color: line color
  134. */
  135. //---------------------------------------------------------------------
  136. void EPD_drawFastHLine(int16_t x, int16_t y, int16_t w, color_t color);
  137. /*
  138. * Draw line on screen
  139. *
  140. * Params:
  141. * x0: horizontal start position
  142. * y0: vertical start position
  143. * x1: horizontal end position
  144. * y1: vertical end position
  145. * color: line color
  146. */
  147. //-------------------------------------------------------------------------------
  148. void EPD_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, color_t color);
  149. /*
  150. * Draw line on screen from (x,y) point at given angle
  151. * Line drawing angle starts at lower right quadrant of the screen and is offseted by
  152. * '_angleOffset' global variable (default: -90 degrees)
  153. *
  154. * Params:
  155. * x: horizontal start position
  156. * y: vertical start position
  157. * start: start offset from (x,y)
  158. * len: length of the line
  159. * angle: line angle in degrees
  160. * color: line color
  161. */
  162. //-----------------------------------------------------------------------------------------------------------
  163. void EPD_drawLineByAngle(uint16_t x, uint16_t y, uint16_t start, uint16_t len, uint16_t angle, color_t color);
  164. /*
  165. * Fill given rectangular screen region with color
  166. *
  167. * Params:
  168. * x: horizontal rect start position
  169. * y: vertical rect start position
  170. * w: rectangle width
  171. * h: rectangle height
  172. * color: fill color
  173. */
  174. //---------------------------------------------------------------------------
  175. void EPD_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, color_t color);
  176. /*
  177. * Draw rectangle on screen
  178. *
  179. * Params:
  180. * x: horizontal rect start position
  181. * y: vertical rect start position
  182. * w: rectangle width
  183. * h: rectangle height
  184. * color: rect line color
  185. */
  186. //------------------------------------------------------------------------------
  187. void EPD_drawRect(uint16_t x1,uint16_t y1,uint16_t w,uint16_t h, color_t color);
  188. /*
  189. * Draw rectangle with rounded corners on screen
  190. *
  191. * Params:
  192. * x: horizontal rect start position
  193. * y: vertical rect start position
  194. * w: rectangle width
  195. * h: rectangle height
  196. * r: corner radius
  197. * color: rectangle color
  198. */
  199. //----------------------------------------------------------------------------------------------
  200. void EPD_drawRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color);
  201. /*
  202. * Fill given rectangular screen region with rounded corners with color
  203. *
  204. * Params:
  205. * x: horizontal rect start position
  206. * y: vertical rect start position
  207. * w: rectangle width
  208. * h: rectangle height
  209. * r: corner radius
  210. * color: fill color
  211. */
  212. //----------------------------------------------------------------------------------------------
  213. void EPD_fillRoundRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t r, color_t color);
  214. /*
  215. * Fill the whole screen with color
  216. *
  217. * Params:
  218. * color: fill color
  219. */
  220. //--------------------------------
  221. void EPD_fillScreen(color_t color);
  222. /*
  223. * Fill the current clip window with color
  224. *
  225. * Params:
  226. * color: fill color
  227. */
  228. //---------------------------------
  229. void EPD_fillWindow(color_t color);
  230. /*
  231. * Draw triangle on screen
  232. *
  233. * Params:
  234. * x0: first triangle point x position
  235. * y0: first triangle point y position
  236. * x0: second triangle point x position
  237. * y0: second triangle point y position
  238. * x0: third triangle point x position
  239. * y0: third triangle point y position
  240. * color: triangle color
  241. */
  242. //-----------------------------------------------------------------------------------------------------------------
  243. void EPD_drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, color_t color);
  244. /*
  245. * Fill triangular screen region with color
  246. *
  247. * Params:
  248. * x0: first triangle point x position
  249. * y0: first triangle point y position
  250. * x0: second triangle point x position
  251. * y0: second triangle point y position
  252. * x0: third triangle point x position
  253. * y0: third triangle point y position
  254. * color: fill color
  255. */
  256. //-----------------------------------------------------------------------------------------------------------------
  257. void EPD_fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, color_t color);
  258. /*
  259. * Draw circle on screen
  260. *
  261. * Params:
  262. * x: circle center x position
  263. * y: circle center x position
  264. * r: circle radius
  265. * color: circle color
  266. */
  267. //-------------------------------------------------------------------
  268. void EPD_drawCircle(int16_t x, int16_t y, int radius, color_t color);
  269. /*
  270. * Fill circle on screen with color
  271. *
  272. * Params:
  273. * x: circle center x position
  274. * y: circle center x position
  275. * r: circle radius
  276. * color: circle fill color
  277. */
  278. //-------------------------------------------------------------------
  279. void EPD_fillCircle(int16_t x, int16_t y, int radius, color_t color);
  280. /*
  281. * Draw ellipse on screen
  282. *
  283. * Params:
  284. * x0: ellipse center x position
  285. * y0: ellipse center x position
  286. * rx: ellipse horizontal radius
  287. * ry: ellipse vertical radius
  288. * option: drawing options, multiple options can be combined
  289. 1 (TFT_ELLIPSE_UPPER_RIGHT) draw upper right corner
  290. 2 (TFT_ELLIPSE_UPPER_LEFT) draw upper left corner
  291. 4 (TFT_ELLIPSE_LOWER_LEFT) draw lower left corner
  292. 8 (TFT_ELLIPSE_LOWER_RIGHT) draw lower right corner
  293. to draw the whole ellipse use option value 15 (1 | 2 | 4 | 8)
  294. *
  295. * color: circle color
  296. */
  297. //------------------------------------------------------------------------------------------------------
  298. void EPD_drawEllipse(uint16_t x0, uint16_t y0, uint16_t rx, uint16_t ry, color_t color, uint8_t option);
  299. /*
  300. * Fill elliptical region on screen
  301. *
  302. * Params:
  303. * x0: ellipse center x position
  304. * y0: ellipse center x position
  305. * rx: ellipse horizontal radius
  306. * ry: ellipse vertical radius
  307. * option: drawing options, multiple options can be combined
  308. 1 (TFT_ELLIPSE_UPPER_RIGHT) fill upper right corner
  309. 2 (TFT_ELLIPSE_UPPER_LEFT) fill upper left corner
  310. 4 (TFT_ELLIPSE_LOWER_LEFT) fill lower left corner
  311. 8 (TFT_ELLIPSE_LOWER_RIGHT) fill lower right corner
  312. to fill the whole ellipse use option value 15 (1 | 2 | 4 | 8)
  313. *
  314. * color: fill color
  315. */
  316. //------------------------------------------------------------------------------------------------------
  317. void EPD_fillEllipse(uint16_t x0, uint16_t y0, uint16_t rx, uint16_t ry, color_t color, uint8_t option);
  318. /*
  319. * Draw circle arc on screen
  320. * Arc drawing angle starts at lower right quadrant of the screen and is offseted by
  321. * '_angleOffset' global variable (default: -90 degrees)
  322. *
  323. * Params:
  324. * cx: arc center X position
  325. * cy: arc center Y position
  326. * th: thickness of the drawn arc
  327. * ry: arc vertical radius
  328. * start: arc start angle in degrees
  329. * end: arc end angle in degrees
  330. * color: arc outline color
  331. * fillcolor: arc fill color
  332. */
  333. //----------------------------------------------------------------------------------------------------------------------------
  334. void EPD_drawArc(uint16_t cx, uint16_t cy, uint16_t r, uint16_t th, float start, float end, color_t color, color_t fillcolor);
  335. /*
  336. * Draw polygon on screen
  337. *
  338. * Params:
  339. * cx: polygon center X position
  340. * cy: arc center Y position
  341. * sides: number of polygon sides; MAX_POLIGON_SIDES ~ MAX_POLIGON_SIDES (3 ~ 60)
  342. * diameter: diameter of the circle inside which the polygon is drawn
  343. * color: polygon outline color
  344. * fill: polygon fill color; if same as color, polygon is not filled
  345. * deg: polygon rotation angle; 0 ~ 360
  346. * th: thickness of the polygon outline
  347. */
  348. //--------------------------------------------------------------------------------------------------------------
  349. void EPD_drawPolygon(int cx, int cy, int sides, int diameter, color_t color, color_t fill, int deg, uint8_t th);
  350. //--------------------------------------------------------------------------------------
  351. //void EPD_drawStar(int cx, int cy, int diameter, color_t color, bool fill, float factor);
  352. /*
  353. * Set the font used for writing the text to display.
  354. *
  355. * ------------------------------------------------------------------------------------
  356. * For 7 segment font only characters 0,1,2,3,4,5,6,7,8,9, . , - , : , / are available.
  357. * Character ‘/‘ draws the degree sign.
  358. * ------------------------------------------------------------------------------------
  359. *
  360. * Params:
  361. * font: font number; use defined font names
  362. * font_file: pointer to font file name; NULL for embeded fonts
  363. */
  364. //----------------------------------------------------
  365. void EPD_setFont(uint8_t font, const char *font_file);
  366. /*
  367. * Returns current font height & width in pixels.
  368. *
  369. * Params:
  370. * width: pointer to returned font width
  371. * height: pointer to returned font height
  372. */
  373. //-------------------------------------------
  374. int EPD_getfontsize(int *width, int* height);
  375. /*
  376. * Returns current font height in pixels.
  377. *
  378. */
  379. //----------------------
  380. int EPD_getfontheight();
  381. /*
  382. * Write text to display.
  383. *
  384. * Rotation of the displayed text depends on 'font_rotate' variable (0~360)
  385. * if 'font_transparent' variable is set to 1, no background pixels will be printed
  386. *
  387. * If the text does not fit the screen width it will be clipped (if text_wrap=0),
  388. * or continued on next line (if text_wrap=1)
  389. *
  390. * Two special characters are allowed in strings:
  391. * ‘\r’ CR (0x0D), clears the display to EOL
  392. * ‘\n’ LF (ox0A), continues to the new line, x=0
  393. *
  394. * Params:
  395. * st: pointer to null terminated string to be printed
  396. * x: horizontal position of the upper left point in pixels
  397. * Special values can be entered:
  398. * CENTER, centers the text
  399. * RIGHT, right justifies the text
  400. * LASTX, continues from last X position; offset can be used: LASTX+n
  401. * y: vertical position of the upper left point in pixels
  402. * Special values can be entered:
  403. * CENTER, centers the text
  404. * BOTTOM, bottom justifies the text
  405. * LASTY, continues from last Y position; offset can be used: LASTY+n
  406. *
  407. */
  408. //-------------------------------------
  409. void EPD_print(char *st, int x, int y);
  410. /*
  411. * Set atributes for 7 segment vector font
  412. * == 7 segment font must be the current font to this function to have effect ==
  413. *
  414. * Params:
  415. * l: 6~40; distance between bars in pixels
  416. * w: 1~12, max l/2; bar width in pixels
  417. * outline: draw font outline if set to 1
  418. * color: font outline color, only used if outline=1
  419. *
  420. */
  421. //-------------------------------------------------------------------------
  422. void set_7seg_font_atrib(uint8_t l, uint8_t w, int outline, color_t color);
  423. /*
  424. * Sets the clipping area coordinates.
  425. * All writing to screen is clipped to that area.
  426. * Starting x & y in all functions will be adjusted to the clipping area.
  427. *
  428. * Params:
  429. * x1,y1: upper left point of the clipping area
  430. * x2,y2: bottom right point of the clipping area
  431. *
  432. */
  433. //----------------------------------------------------------------------
  434. void EPD_setclipwin(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
  435. /*
  436. * Resets the clipping area to full screen (0,0),(_wodth,_height)
  437. *
  438. */
  439. //----------------------
  440. void EPD_resetclipwin();
  441. /*
  442. * Save current clipping area to temporary variable
  443. *
  444. */
  445. //---------------------
  446. void EPD_saveClipWin();
  447. /*
  448. * Restore current clipping area from temporary variable
  449. *
  450. */
  451. //------------------------
  452. void EPD_restoreClipWin();
  453. /*
  454. * returns the string width in pixels.
  455. * Useful for positions strings on the screen.
  456. */
  457. //--------------------------------
  458. int EPD_getStringWidth(char* str);
  459. /*
  460. * Fills the rectangle occupied by string with current background color
  461. */
  462. void EPD_clearStringRect(int x, int y, char *str);
  463. /*
  464. * Compile font c source file to .fnt file
  465. * which can be used in EPD_setFont() function to select external font
  466. * Created file have the same name as source file and extension .fnt
  467. *
  468. * Params:
  469. * fontfile: pointer to c source font file name; must have .c extension
  470. * dbg: if set to 1, prints debug information
  471. *
  472. * Returns:
  473. * 0 on success
  474. * err no on error
  475. *
  476. */
  477. //------------------------------------------------
  478. int compile_font_file(char *fontfile, uint8_t dbg);
  479. /*
  480. * Get all font's characters to buffer
  481. */
  482. void getFontCharacters(uint8_t *buf);
  483. /*
  484. * Decodes and displays JPG image. RGB colors are converted to 4-bit Gray scale
  485. * Limits:
  486. * Baseline only. Progressive and Lossless JPEG format are not supported.
  487. * Image size: Up to 65520 x 65520 pixels
  488. * Color space: YCbCr three components only. Gray scale image is not supported.
  489. * Sampling factor: 4:4:4, 4:2:2 or 4:2:0.
  490. *
  491. * Params:
  492. * x: image left position; constants CENTER & RIGHT can be used; negative value is accepted
  493. * y: image top position; constants CENTER & BOTTOM can be used; negative value is accepted
  494. * scale: image scale factor: 0~3; if scale>0, image is scaled by factor 1/(2^scale) (1/2, 1/4 or 1/8)
  495. * fname: pointer to the name of the file from which the image will be read
  496. * if set to NULL, image will be read from memory buffer pointed to by 'buf'
  497. * buf: pointer to the memory buffer from which the image will be read; used if fname=NULL
  498. * size: size of the memory buffer from which the image will be read; used if fname=NULL & buf!=NULL
  499. *
  500. */
  501. int EPD_jpg_image(int x, int y, uint8_t scale, char *fname, uint8_t *buf, int size);
  502. #endif