#ifndef __LCD_Hx__ #define __LCD_Hx__ #include #include #include "gpio.h" #include "drv_spi.h" #include "font.h" enum { COLOR_ID_WHITE=0, COLOR_ID_BLACK, COLOR_ID_BLUE, COLOR_ID_BRED, COLOR_ID_GRED, COLOR_ID_GBLUE, COLOR_ID_RED, COLOR_ID_MAGENTA, COLOR_ID_GREEN, COLOR_ID_CYAN, COLOR_ID_YELLOW, COLOR_ID_BROWN, COLOR_ID_BRRED, COLOR_ID_GRAY, COLOR_ID_MAX, }; #define CS_PIN GET_PIN(B, 12) #define BK_PIN GET_PIN(D, 9) //PD9 #define DC_PIN GET_PIN(D, 8) //PD8 #define RST_PIN GET_PIN(F, 14) //PF14 #if 0 #define LCD_WIDTH 128 #define LCD_HEIGHT 64 #else #define LCD_WIDTH 240 #define LCD_HEIGHT 240 #endif #define RGB565(r, g, b) ((((r)&0xF8) << 8) | (((g)&0xFC) << 3) | ((b) >> 3)) #define BGR565(r, g, b) ((((b)&0xF8) << 8) | (((g)&0xFC) << 3) | ((r) >> 3)) #define RGB RGB565 #define COLOR_BLACK RGB(0, 0, 0) #define COLOR_NAVY RGB(0, 0, 123) #define COLOR_DARKGREEN RGB(0, 125, 0) #define COLOR_DARKCYAN RGB(0, 125, 123) #define COLOR_MAROON RGB(123, 0, 0) #define COLOR_PURPLE RGB(123, 0, 123) #define COLOR_OLIVE RGB(123, 125, 0) #define COLOR_LIGHTGREY RGB(198, 195, 198) #define COLOR_DARKGREY RGB(123, 125, 123) #define COLOR_BLUE RGB(0, 0, 255) #define COLOR_GREEN RGB(0, 255, 0) #define COLOR_CYAN RGB(0, 255, 255) #define COLOR_RED RGB(255, 0, 0) #define COLOR_MAGENTA RGB(255, 0, 255) #define COLOR_YELLOW RGB(255, 255, 0) #define COLOR_WHITE RGB(255, 255, 255) #define COLOR_ORANGE RGB(255, 165, 0) #define COLOR_GREENYELLOW RGB(173, 255, 41) #define COLOR_PINK RGB(255, 130, 198) enum { HORIZONTAL_LEFT=0, HORIZONTAL_CENTER, HORIZONTAL_RIGHT, }; enum { VERTICAL_TOP=0, VERTICAL_CENTER, VERTICAL_BOTTOM, }; enum { COLOR_WB=0, COLOR_RGB8, COLOR_RGB565, COLOR_RGB666, COLOR_RGB888, COLOR_RGBA, }; typedef struct { int width; int height; int color; int rotate; struct rt_spi_device *dev; uint16_t *buf; int buflen; }lcd_handle_t; void lcd_init(int width, int height, int rotate); void lcd_deinit(void); void lcd_rotate(int rotate); int lcd_get_rotate(void); void lcd_set_backlight(int on); void lcd_fill(uint32_t color); void lcd_draw_line(int x1, int y1, int x2, int y2, uint32_t color); void lcd_draw_rect(int x1, int y1, int w, int h, uint32_t color); void lcd_fill_rect(int x1, int y1, int w, int h, uint32_t color); 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); 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); void lcd_refresh(void); #endif