直接修改kevin的2.9inch st7305驱动,如果fullclean再编译会被idf覆盖

This commit is contained in:
kirltrz 2026-02-01 18:12:15 +08:00
commit 6204c22b0e
10 changed files with 358 additions and 0 deletions

2
.clangd Normal file
View File

@ -0,0 +1,2 @@
CompileFlags:
Remove: [-f*, -m*]

78
.gitignore vendored Normal file
View File

@ -0,0 +1,78 @@
# macOS
.DS_Store
.AppleDouble
.LSOverride
# Directory metadata
.directory
# Temporary files
*~
*.swp
*.swo
*.bak
*.tmp
# Log files
*.log
# Build artifacts and directories
**/build/
build/
*.o
*.a
*.out
*.exe # For any host-side utilities compiled on Windows
# ESP-IDF specific build outputs
*.bin
*.elf
*.map
flasher_args.json # Generated in build directory
sdkconfig.old
sdkconfig
# ESP-IDF dependencies
# For older versions or manual component management
/components/.idf/
**/components/.idf/
# For modern ESP-IDF component manager
managed_components/
# If ESP-IDF tools are installed/referenced locally to the project
.espressif/
# CMake generated files
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
install_manifest.txt
CTestTestfile.cmake
# Python environment files
*.pyc
*.pyo
*.pyd
__pycache__/
*.egg-info/
dist/
# Virtual environment folders
venv/
.venv/
env/
# Language Servers
.clangd/
.ccls-cache/
compile_commands.json
# Windows specific
Thumbs.db
ehthumbs.db
Desktop.ini
# User-specific configuration files
*.user
*.workspace # General workspace files, can be from various tools
*.suo # Visual Studio Solution User Options
*.sln.docstates # Visual Studio

23
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,23 @@
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-14.2.0_20250730\\xtensa-esp-elf\\bin\\xtensa-esp32-elf-gcc.exe",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "gdbtarget",
"request": "attach",
"name": "Eclipse CDT GDB Adapter"
},
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}

21
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
"C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPathWin": "c:\\esp\\v5.4.3\\esp-idf",
"idf.pythonInstallPath": "C:\\Espressif\\tools\\idf-python\\3.11.2\\python.exe",
"idf.openOcdConfigs": [
"board/esp32c3-builtin.cfg"
],
"idf.portWin": "COM10",
"idf.toolsPathWin": "C:\\Espressif",
"idf.customExtraVars": {
"IDF_TARGET": "esp32c3"
},
"clangd.path": "C:\\Espressif\\tools\\esp-clang\\esp-18.1.2_20240912\\esp-clang\\bin\\clangd.exe",
"clangd.arguments": [
"--background-index",
"--query-driver=**",
"--compile-commands-dir=c:\\Users\\Kirl\\Documents\\st7305port\\build"
],
"commentTranslate.source": "intellsmi.comment-translate-ali.cloud",
"idf.flashType": "UART"
}

6
CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(st7305port)

35
dependencies.lock Normal file
View File

@ -0,0 +1,35 @@
dependencies:
espressif/cmake_utilities:
component_hash: 351350613ceafba240b761b4ea991e0f231ac7a9f59a9ee901f751bddc0bb18f
dependencies:
- name: idf
require: private
version: '>=4.1'
source:
registry_url: https://components.espressif.com
type: service
version: 0.5.3
idf:
source:
type: idf
version: 5.4.3
kevincoooool/esp_lcd_st7305:
component_hash: 836bdeeaf1284004e4673d302f95e515c54cc407595af1aee95626f53ecfba25
dependencies:
- name: espressif/cmake_utilities
registry_url: https://components.espressif.com
require: private
version: 0.*
- name: idf
require: private
version: '>=4.4'
source:
registry_url: https://components.espressif.com/
type: service
version: 0.0.2
direct_dependencies:
- idf
- kevincoooool/esp_lcd_st7305
manifest_hash: 9ca2e478e648ad30624f04e3cb3dfcbcfd95fdfa2bf0e923bbec1a59b1813bf9
target: esp32c3
version: 2.0.0

2
main/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS ".")

17
main/idf_component.yml Normal file
View File

@ -0,0 +1,17 @@
## IDF Component Manager Manifest File
dependencies:
## Required IDF version
idf:
version: '>=4.1.0'
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true
kevincoooool/esp_lcd_st7305: ^0.0.2

159
main/main.c Normal file
View File

@ -0,0 +1,159 @@
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_err.h"
#include "driver/gpio.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_panel_dev.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lcd_io_spi.h"
#include "esp_lcd_st7305.h"
#define LCD_HOST SPI2_HOST
#define LCD_PIN_SCLK 6
#define LCD_PIN_SDI 7
#define LCD_PIN_RST 5
#define LCD_PIN_DC 4
#define LCD_PIN_CS 3
#define LCD_PIN_TE 2
#define DC_HIGH gpio_set_level(LCD_PIN_DC, 1)
#define DC_LOW gpio_set_level(LCD_PIN_DC, 0)
#define CS_HIGH gpio_set_level(LCD_PIN_CS, 1)
#define CS_LOW gpio_set_level(LCD_PIN_CS, 0)
// 绘制测试图案
// 画两条边缘线和一个中心点
bool is_rotated = 0; // 跟踪旋转状态
// 绘制测试图案函数
void draw_test_pattern(uint8_t *buffer, bool rotated)
{
memset(buffer, 0, ST7305_RESOLUTION_HOR * ST7305_RESOLUTION_VER / 8);
int width = rotated ? ST7305_RESOLUTION_VER : ST7305_RESOLUTION_HOR;
int height = rotated ? ST7305_RESOLUTION_HOR : ST7305_RESOLUTION_VER;
// 画左边竖线
for (int y = 0; y < height; y++)
{
int x = 10; // 距离左边10像素
uint16_t byte_idx = (y >> 3) * width + x;
uint8_t bit_pos = y & 0x07;
if (byte_idx < width * ((height + 7) >> 3))
{
buffer[byte_idx] |= (1 << bit_pos);
}
}
// 画右边竖线
for (int y = 0; y < height; y++)
{
int x = width - 10; // 距离右边10像素
uint16_t byte_idx = (y >> 3) * width + x;
uint8_t bit_pos = y & 0x07;
if (byte_idx < width * ((height + 7) >> 3))
{
buffer[byte_idx] |= (1 << bit_pos);
}
}
// 在中心画一个5x5的方块
int center_x = width / 2;
int center_y = height / 2;
for (int y = center_y - 2; y <= center_y + 2; y++)
{
for (int x = center_x - 2; x <= center_x + 2; x++)
{
uint16_t byte_idx = (y >> 3) * width + x;
uint8_t bit_pos = y & 0x07;
if (byte_idx < width * ((height + 7) >> 3))
{
buffer[byte_idx] |= (1 << bit_pos);
}
}
}
}
void app_main(void)
{
/*创建SPI总线*/
spi_bus_config_t buscfg = {
.sclk_io_num = LCD_PIN_SCLK,
.mosi_io_num = LCD_PIN_SDI,
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 200 * 200 / 8,
};
ESP_ERROR_CHECK(spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO)); // 启用 DMA
/*从 SPI 总线分配一个 LCD IO 设备句柄*/
esp_lcd_panel_io_handle_t io_handle = NULL;
esp_lcd_panel_io_spi_config_t io_config = {
.dc_gpio_num = LCD_PIN_DC,
.cs_gpio_num = LCD_PIN_CS,
.pclk_hz = 20 * 1000 * 1000,
.lcd_cmd_bits = 8,
.lcd_param_bits = 8,
.spi_mode = 0,
.trans_queue_depth = 10,
};
// 将 LCD 连接到 SPI 总线
ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)LCD_HOST, &io_config, &io_handle));
esp_lcd_panel_handle_t panel_handle = NULL;
esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = LCD_PIN_RST,
.rgb_endian = LCD_RGB_ENDIAN_RGB,
.bits_per_pixel = 1,
};
// 为 ST7305 创建 LCD 面板句柄,并指定 SPI IO 设备句柄
ESP_ERROR_CHECK(esp_lcd_new_panel_st7305(io_handle, &panel_config, &panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_swap_xy(panel_handle, is_rotated));
// ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, true));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, false));
ESP_ERROR_CHECK(esp_lcd_panel_invert_color(panel_handle, true));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
printf("Display simple pattern");
// 准备测试数据
uint8_t *test_pattern = heap_caps_malloc(ST7305_RESOLUTION_HOR * ST7305_RESOLUTION_VER / 8, MALLOC_CAP_DMA);
assert(test_pattern);
memset(test_pattern, 0x00, ST7305_RESOLUTION_HOR * ST7305_RESOLUTION_VER / 8);
// 初始填充并显示:累积字节扫描,完成一次后翻转配色并继续扫描
size_t buf_size = ST7305_RESOLUTION_HOR * ST7305_RESOLUTION_VER / 8;
size_t idx = 0;
bool scanned_is_ff = true; // true已扫描字节为 0xFFfalse已扫描字节为 0x00
while (1)
{
if (scanned_is_ff) {
// 已扫描区域为 0xFF未扫描为 0x00
memset(test_pattern, 0x00, buf_size);
memset(test_pattern, 0xFF, idx + 1);
} else {
// 已扫描区域为 0x00未扫描为 0xFF配色相反
memset(test_pattern, 0xFF, buf_size);
memset(test_pattern, 0x00, idx + 1);
}
ESP_ERROR_CHECK(esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, ST7305_RESOLUTION_HOR, ST7305_RESOLUTION_VER, test_pattern));
idx++;
if (idx >= buf_size) {
// 完成一次扫描,重置索引并翻转配色
idx = 0;
scanned_is_ff = !scanned_is_ff;
vTaskDelay(pdMS_TO_TICKS(200)); // 稍作停顿以便观察配色翻转
} else {
vTaskDelay(pdMS_TO_TICKS(2)); // 平常的扫描速度
}
}
// 释放资源
free(test_pattern);
}