lcd.h 2.8 KB

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