Files
esp32s3_player/components/BSP/SPILCD/spilcd.h
T

68 lines
2.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
****************************************************************************************************
* @file spilcd.h
* @author HiFi Player Project
* @version V1.0
* @date 2026-01-01
* @brief SPI LCD(ST7789,320x240)驱动
* @note 引脚与初始化流程参考正点原子 DNESP32S3 标准例程(10_spilcd / 30_music)
****************************************************************************************************
*/
#ifndef __SPILCD_H
#define __SPILCD_H
#include <stdint.h>
#include "esp_err.h"
#include "driver/gpio.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_ops.h"
#include "xl9555.h"
/* ---------------- 管脚声明 ---------------- */
#define LCD_DC_PIN GPIO_NUM_40 /* LCD 数据/命令选择脚 */
#define LCD_CS_PIN GPIO_NUM_21 /* LCD 片选脚 */
#define LCD_HOST SPI2_HOST /* LCD 与 SD 卡共用 SPI2 */
/* 背光 / 复位 / 电源由 XL9555 扩展 IO 控制 */
#define LCD_PWR(x) do { x ? xl9555_pin_write(SLCD_PWR_IO, 1) : xl9555_pin_write(SLCD_PWR_IO, 0); } while (0)
#define LCD_RST(x) do { x ? xl9555_pin_write(SLCD_RST_IO, 1) : xl9555_pin_write(SLCD_RST_IO, 0); } while (0)
#define LCD_BL(x) do { x ? xl9555_pin_write(LCD_BL_IO, 1) : xl9555_pin_write(LCD_BL_IO, 0); } while (0)
/* ---------------- 屏幕分辨率(横屏) ---------------- */
#define SPI_LCD_H_RES 320
#define SPI_LCD_V_RES 240
/* 面板句柄,LVGL 移植层需要用到 */
extern esp_lcd_panel_handle_t panel_handle;
/**
* @brief 初始化 SPI LCD(SPI 总线必须已由 my_spi_init() 初始化)
* @retval ESP_OK 成功
*/
esp_err_t spilcd_init(void);
/**
* @brief 设置屏幕方向
* @param dir 0: 竖屏 1: 横屏
*/
void spilcd_display_dir(uint8_t dir);
/**
* @brief 用单色清屏
*/
void spilcd_clear(uint16_t color);
/**
* @brief 将一块 RGB565 图像数据刷到屏幕(阻塞,直到 SPI 传输完成)
* @param x1,y1 左上角坐标(包含)
* @param x2,y2 右下角坐标(不包含,即 x2-x1 为宽度)
* @param data RGB565 像素数据,**按大端字节序存放**(高字节在前)。
* 如果是 LVGL 的原生小端数据,需要在调用前自行做字节交换
* (参考 lvgl_port.c 中 disp_flush_cb() 的实现)。
* @note 该函数供 LVGL 的 flush_cb 调用,也可以在其它地方直接使用
*/
void spilcd_flush(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, const void *data);
#endif