ESP32/main/st7305_rlcd.h
2026-06-23 20:38:23 +08:00

99 lines
2.9 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 st7305_rlcd.h
* @brief ST7305 反射式 LCD 驱动(纯 C, ESP-IDF 原生)
*
* 移植自微雪官方 waveshareteam/ESP32-S3-RLCD-4.2 仓库里的
* 02_Example/XiaoZhi/.../boards/waveshare-s3-rlcd-4.2/custom_lcd_display.cc
*
* 改动:
* - C++ 改纯 C
* - 去掉 LcdDisplay / WifiBoard 等 XiaoZhi 框架依赖
* - 去掉 LVGL 集成(由调用方自己接,本驱动只负责把像素写到显存并刷新)
* - 横屏 LUT 算法原样保留(InitLandscapeLUT)
* - ST7305 寄存器初始化序列原样保留(RLCD_Init)
*
* 板子:Waveshare ESP32-S3-RLCD-4.2
* - 屏幕:4.2 寸 400×300 黑白反射屏(ST7305)
* - 接口:SPI3, 40MHz
* - 引脚:DC=5, CS=40, SCK=11, MOSI=12, RST=41
*
* 显存布局(横屏,关键!):
* 每字节装 8 个像素,排列是 2列×4行 的块
* 详见 st7305_rlcd.c 里 init_landscape_lut() 的注释
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_lcd_panel_io.h"
#include "driver/spi_master.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ===========================================================
* 屏幕参数(来自官方 config.h)
* =========================================================== */
#define ST7305_RLCD_WIDTH 400 /* 横屏宽 */
#define ST7305_RLCD_HEIGHT 300 /* 横屏高 */
#define ST7305_RLCD_SPI_HOST SPI3_HOST
#define ST7305_RLCD_SPI_HZ (40 * 1000 * 1000) /* 40 MHz */
#define ST7305_RLCD_PIN_DC 5
#define ST7305_RLCD_PIN_CS 40
#define ST7305_RLCD_PIN_SCK 11
#define ST7305_RLCD_PIN_MOSI 12
#define ST7305_RLCD_PIN_RST 41
/* ===========================================================
* 颜色(反射屏只有黑白两色)
* =========================================================== */
typedef enum {
ST7305_COLOR_WHITE = 0xFF, /* 像素关闭 = 白(反射屏底色) */
ST7305_COLOR_BLACK = 0x00, /* 像素点亮 = 黑 */
} st7305_color_t;
/* ===========================================================
* 对外 API
* =========================================================== */
/**
* 初始化屏幕:配置 SPI 总线、复位 ST7305、发送初始化序列、
* 分配显存、构建横屏像素 LUT、清屏。
* 整个流程只调用一次,在 app_main 开头。
*/
esp_err_t st7305_rlcd_init(void);
/**
* 把 (x, y) 处的像素设成指定颜色。
* 颜色取值见 st7305_color_t。
* 越界坐标会被忽略。
*/
void st7305_rlcd_set_pixel(int x, int y, uint8_t color);
/**
* 把整个显存一次性推到屏幕(SPI DMA 传输)。
* 调完才会真正在屏幕上看到变化。
*/
void st7305_rlcd_flush(void);
/**
* 用指定颜色填满整个显存(不会自动刷新到屏幕,
* 还要再调 st7305_rlcd_flush)。
*/
void st7305_rlcd_clear(uint8_t color);
/**
* 获取屏幕宽度 / 高度(主要是给 LVGL 用)。
*/
int st7305_rlcd_get_width(void);
int st7305_rlcd_get_height(void);
#ifdef __cplusplus
}
#endif