lcd.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #ifndef __LCD_Hx__
  2. #define __LCD_Hx__
  3. #include "gd32f30x_libopt.h"
  4. //#include "font.h"
  5. enum {
  6. COLOR_ID_WHITE=0,
  7. COLOR_ID_BLACK,
  8. COLOR_ID_BLUE,
  9. COLOR_ID_BRED,
  10. COLOR_ID_GRED,
  11. COLOR_ID_GBLUE,
  12. COLOR_ID_RED,
  13. COLOR_ID_MAGENTA,
  14. COLOR_ID_GREEN,
  15. COLOR_ID_CYAN,
  16. COLOR_ID_YELLOW,
  17. COLOR_ID_BROWN,
  18. COLOR_ID_BRRED,
  19. COLOR_ID_GRAY,
  20. COLOR_ID_MAX,
  21. };
  22. #define CS_PIN GET_PIN(B, 12)
  23. #define BK_PIN GET_PIN(D, 9) //PD9
  24. #define DC_PIN GET_PIN(D, 8) //PD8
  25. #define RST_PIN GET_PIN(F, 14) //PF14
  26. #if 0
  27. #define LCD_WIDTH 128
  28. #define LCD_HEIGHT 64
  29. #else
  30. #define LCD_WIDTH 240
  31. #define LCD_HEIGHT 240
  32. #endif
  33. #define RGB565(r, g, b) ((((r)&0xF8) << 8) | (((g)&0xFC) << 3) | ((b) >> 3))
  34. #define BGR565(r, g, b) ((((b)&0xF8) << 8) | (((g)&0xFC) << 3) | ((r) >> 3))
  35. #define RGB RGB565
  36. #define COLOR_BLACK RGB(0, 0, 0)
  37. #define COLOR_NAVY RGB(0, 0, 123)
  38. #define COLOR_DARKGREEN RGB(0, 125, 0)
  39. #define COLOR_DARKCYAN RGB(0, 125, 123)
  40. #define COLOR_MAROON RGB(123, 0, 0)
  41. #define COLOR_PURPLE RGB(123, 0, 123)
  42. #define COLOR_OLIVE RGB(123, 125, 0)
  43. #define COLOR_LIGHTGREY RGB(198, 195, 198)
  44. #define COLOR_DARKGREY RGB(123, 125, 123)
  45. #define COLOR_BLUE RGB(0, 0, 255)
  46. #define COLOR_GREEN RGB(0, 255, 0)
  47. #define COLOR_CYAN RGB(0, 255, 255)
  48. #define COLOR_RED RGB(255, 0, 0)
  49. #define COLOR_MAGENTA RGB(255, 0, 255)
  50. #define COLOR_YELLOW RGB(255, 255, 0)
  51. #define COLOR_WHITE RGB(255, 255, 255)
  52. #define COLOR_ORANGE RGB(255, 165, 0)
  53. #define COLOR_GREENYELLOW RGB(173, 255, 41)
  54. #define COLOR_PINK RGB(255, 130, 198)
  55. enum {
  56. HORIZONTAL_LEFT=0,
  57. HORIZONTAL_CENTER,
  58. HORIZONTAL_RIGHT,
  59. };
  60. enum {
  61. VERTICAL_TOP=0,
  62. VERTICAL_CENTER,
  63. VERTICAL_BOTTOM,
  64. };
  65. enum {
  66. COLOR_WB=0,
  67. COLOR_RGB8,
  68. COLOR_RGB565,
  69. COLOR_RGB666,
  70. COLOR_RGB888,
  71. COLOR_RGBA,
  72. };
  73. typedef struct {
  74. int width;
  75. int height;
  76. int color;
  77. int rotate;
  78. uint16_t *buf;
  79. int buflen;
  80. }lcd_handle_t;
  81. void lcd_init(int width, int height, int rotate);
  82. void lcd_deinit(void);
  83. void lcd_rotate(int rotate);
  84. int lcd_get_rotate(void);
  85. void lcd_set_backlight(int on);
  86. void lcd_fill(uint32_t color);
  87. void lcd_draw_line(int x1, int y1, int x2, int y2, uint32_t color);
  88. void lcd_draw_rect(int x1, int y1, int w, int h, uint32_t color);
  89. void lcd_fill_rect(int x1, int y1, int w, int h, uint32_t color);
  90. int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int font, uint32_t color, uint32_t bgcolor, int vert);
  91. void lcd_draw_string(int x, int y, int width, int height, char *str, int font, uint32_t color, uint32_t bgcolor, int hori, int vert);
  92. void lcd_refresh(void);
  93. void LCD_Fill(unsigned short xsta,unsigned short ysta,unsigned short xend,unsigned short yend,unsigned short color);
  94. #endif