Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

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