up
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#ifndef LCD_DRIVER_H
|
||||
#define LCD_DRIVER_H
|
||||
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
// ============ 引脚配置 (根据实际硬件修改) ============
|
||||
#define LCD_PIN_NUM_MOSI 7 // SPI MOSI
|
||||
#define LCD_PIN_NUM_SCLK 6 // SPI SCLK
|
||||
#define LCD_PIN_NUM_CS 5 // 片选
|
||||
#define LCD_PIN_NUM_DC 4 // 数据/命令选择
|
||||
#define LCD_PIN_NUM_RST 3 // 复位
|
||||
#define LCD_PIN_NUM_BCKL 2 // 背光控制
|
||||
|
||||
// ============ 屏幕参数 ============
|
||||
#define LCD_H_RES 240 // 水平分辨率
|
||||
#define LCD_V_RES 240 // 垂直分辨率
|
||||
#define LCD_BIT_PER_PIXEL 16 // 16位色深 (RGB565)
|
||||
|
||||
// ============ SPI配置 ============
|
||||
#define LCD_SPI_HOST SPI2_HOST
|
||||
#define LCD_SPI_SPEED_HZ (80 * 1000 * 1000) // 80MHz
|
||||
|
||||
// ============ 屏幕类型 ============
|
||||
typedef enum {
|
||||
LCD_TYPE_ST7789,
|
||||
LCD_TYPE_ILI9341,
|
||||
LCD_TYPE_GC9A01
|
||||
} lcd_type_t;
|
||||
|
||||
// ============ 驱动句柄 ============
|
||||
typedef struct {
|
||||
spi_device_handle_t spi_handle;
|
||||
esp_lcd_panel_handle_t panel_handle;
|
||||
gpio_num_t cs_gpio;
|
||||
gpio_num_t dc_gpio;
|
||||
gpio_num_t rst_gpio;
|
||||
gpio_num_t bckl_gpio;
|
||||
lcd_type_t type;
|
||||
} lcd_driver_t;
|
||||
|
||||
// ============ 函数声明 ============
|
||||
esp_err_t lcd_driver_init(lcd_driver_t *lcd, lcd_type_t type);
|
||||
esp_err_t lcd_driver_deinit(lcd_driver_t *lcd);
|
||||
esp_err_t lcd_draw_pixel(lcd_driver_t *lcd, uint16_t x, uint16_t y, uint16_t color);
|
||||
esp_err_t lcd_fill_rect(lcd_driver_t *lcd, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, uint16_t color);
|
||||
esp_err_t lcd_draw_image(lcd_driver_t *lcd, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, const uint16_t *data);
|
||||
esp_err_t lcd_set_rotation(lcd_driver_t *lcd, uint8_t rotation);
|
||||
esp_err_t lcd_set_backlight(lcd_driver_t *lcd, uint8_t brightness);
|
||||
|
||||
// ============ 颜色宏 ============
|
||||
#define COLOR_BLACK 0x0000
|
||||
#define COLOR_WHITE 0xFFFF
|
||||
#define COLOR_RED 0xF800
|
||||
#define COLOR_GREEN 0x07E0
|
||||
#define COLOR_BLUE 0x001F
|
||||
#define COLOR_YELLOW 0xFFE0
|
||||
#define COLOR_CYAN 0x07FF
|
||||
#define COLOR_MAGENTA 0xF81F
|
||||
#define COLOR_GRAY 0x8410
|
||||
|
||||
// RGB565转换宏
|
||||
#define RGB565(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3))
|
||||
|
||||
#endif // LCD_DRIVER_H
|
||||
Reference in New Issue
Block a user