lcd.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _LCD_H_
  2. #define _LCD_H_
  3. #include <stdint.h>
  4. #include <rtthread.h>
  5. #ifndef BSP_USING_LCD
  6. /* clang-format off */
  7. #define LCD_X_MAX (240)
  8. #define LCD_Y_MAX (320)
  9. #define BLACK 0x0000
  10. #define NAVY 0x000F
  11. #define DARKGREEN 0x03E0
  12. #define DARKCYAN 0x03EF
  13. #define MAROON 0x7800
  14. #define PURPLE 0x780F
  15. #define OLIVE 0x7BE0
  16. #define LIGHTGREY 0xC618
  17. #define DARKGREY 0x7BEF
  18. #define BLUE 0x001F
  19. #define GREEN 0x07E0
  20. #define CYAN 0x07FF
  21. #define RED 0xF800
  22. #define MAGENTA 0xF81F
  23. #define YELLOW 0xFFE0
  24. #define WHITE 0xFFFF
  25. #define ORANGE 0xFD20
  26. #define GREENYELLOW 0xAFE5
  27. #define PINK 0xF81F
  28. #define USER_COLOR 0xAA55
  29. /* clang-format on */
  30. /* LCD显示方向 */
  31. typedef enum _lcd_dir
  32. {
  33. DIR_XY_RLUD = 0x00,
  34. DIR_YX_RLUD = 0x20,
  35. DIR_XY_LRUD = 0x40,
  36. DIR_YX_LRUD = 0x60,
  37. DIR_XY_RLDU = 0x80,
  38. DIR_YX_RLDU = 0xA0,
  39. DIR_XY_LRDU = 0xC0,
  40. DIR_YX_LRDU = 0xE0,
  41. DIR_XY_MASK = 0x20,
  42. DIR_MASK = 0xE0,
  43. } lcd_dir_t;
  44. /* LCD结构体 */
  45. typedef struct _lcd_ctl
  46. {
  47. uint8_t mode;
  48. uint8_t dir;
  49. uint16_t width;
  50. uint16_t height;
  51. } lcd_ctl_t;
  52. void lcd_polling_enable(void);
  53. void lcd_interrupt_enable(void);
  54. void lcd_init(void);
  55. void lcd_clear(uint16_t color);
  56. void lcd_set_direction(lcd_dir_t dir);
  57. void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
  58. void lcd_set_area(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
  59. void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color);
  60. void lcd_draw_string(uint16_t x, uint16_t y, char *str, uint16_t color);
  61. void lcd_draw_picture(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint32_t *ptr);
  62. void lcd_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t width, uint16_t color);
  63. void lcd_ram_draw_string(char *str, uint32_t *ptr, uint16_t font_color, uint16_t bg_color);
  64. void lcd_draw_picture_half(uint16_t x1, uint16_t y1, uint16_t width, uint16_t height, uint16_t *ptr);
  65. #else //#ifndef BSP_USING_LCD
  66. /* 使用RTT自带LCD驱动,将LCD接口声明与上述一致 */
  67. #include <drv_lcd.h>
  68. #define __DO_WHILE0(_expr) do{ _expr }while(0)
  69. /* for mpy machine.lcd */
  70. // void lcd_display_on(void);
  71. // void lcd_display_off(void);
  72. // void lcd_clear(int color);
  73. // void lcd_set_direction(lcd_dir_t dir);
  74. void lcd_draw_circle(int x1, int y1, int r);
  75. void lcd_set_color(int back, int fore);
  76. #define lcd_draw_point( x, y, color) __DO_WHILE0( lcd_draw_point_color((x), (y), (color)); )
  77. #define lcd_draw_string(x, y, str, color) __DO_WHILE0( lcd_set_color(0x0000, (color)); lcd_show_string((x), (y), 16, (str)); )
  78. #define lcd_draw_line( x1, y1, x2, y2, color) __DO_WHILE0( lcd_set_color(0x0000, (color)); lcd_draw_line( (x1), (y1), (x2), (y2)); )
  79. #define lcd_draw_rectangle(x1 , y1 , x2, y2, width, color) __DO_WHILE0( lcd_set_color(0x0000, (color)); lcd_draw_rectangle((x1), (y1) , (x2), (y2)); )
  80. #define lcd_draw_picture(x1, y1, width, height, ptr) __DO_WHILE0( lcd_show_image((x1), (y1) , (height), (width), (ptr)); )
  81. #endif //BSP_USING_LCD
  82. #endif