lcd.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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(B, 14) //PB14
  29. #define LCD_COLOR COLOR_RGB565
  30. #if 0
  31. #define LCD_WIDTH 128
  32. #define LCD_HEIGHT 64
  33. #else
  34. #define LCD_WIDTH 240
  35. #define LCD_HEIGHT 240
  36. #endif
  37. /* 颜色 */
  38. #if 1
  39. #define COLOR_WHITE 0xFFFF
  40. #define COLOR_BLACK 0x0000
  41. #define COLOR_BLUE 0x001F
  42. #define COLOR_BRED 0XF81F
  43. #define COLOR_GRED 0XFFE0
  44. #define COLOR_GBLUE 0X07FF
  45. #define COLOR_RED 0xF800
  46. #define COLOR_MAGENTA 0xF81F
  47. #define COLOR_GREEN 0x07E0
  48. #define COLOR_CYAN 0x7FFF
  49. #define COLOR_YELLOW 0xFFE0
  50. #define COLOR_BROWN 0XBC40
  51. #define COLOR_BRRED 0XFC07
  52. #define COLOR_GRAY 0X8430
  53. #elif (LCD_COLOR==COLOR_RGB666)
  54. #elif (LCD_COLOR==COLOR_RGB888)
  55. #else
  56. #endif
  57. enum {
  58. HORIZONTAL_LEFT=0,
  59. HORIZONTAL_CENTER,
  60. HORIZONTAL_RIGHT,
  61. };
  62. enum {
  63. VERTICAL_TOP=0,
  64. VERTICAL_CENTER,
  65. VERTICAL_BOTTOM,
  66. };
  67. enum {
  68. COLOR_WB=0,
  69. COLOR_RGB8,
  70. COLOR_RGB565,
  71. COLOR_RGB666,
  72. COLOR_RGB888,
  73. COLOR_RGBA,
  74. };
  75. typedef struct {
  76. int width;
  77. int height;
  78. int color;
  79. int rotate;
  80. struct rt_spi_device *dev;
  81. uint16_t *buf;
  82. int buflen;
  83. }lcd_handle_t;
  84. void lcd_init(int width, int height, uint32_t color);
  85. void lcd_deinit(void);
  86. void lcd_rotate(int angle);
  87. int lcd_get_rotate(void);
  88. void lcd_set_backlight(int on);
  89. void lcd_fill(uint32_t color);
  90. void lcd_draw_line(int x1, int y1, int x2, int y2, uint32_t color);
  91. void lcd_draw_rect(int x1, int y1, int w, int h, uint32_t color);
  92. void lcd_fill_rect(int x1, int y1, int w, int h, uint32_t color);
  93. 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);
  94. void lcd_refresh(void);
  95. #endif