firt commit

This commit is contained in:
2026-06-17 17:28:22 +08:00
commit b3bb7002cd
18 changed files with 96507 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
CompileFlags:
Remove: [-f*, -m*]
Add:
- -ID:/esp/Project/lcd/lcd/main
- -ID:/esp/Project/lcd/lcd/build/config
- -ID:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/include
- -ID:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include
- -ID:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos
- -ID:/esp/v5.5.4/esp-idf/components/freertos/config/include
- -ID:/esp/v5.5.4/esp-idf/components/freertos/config/include/freertos
- -ID:/esp/v5.5.4/esp-idf/components/freertos/config/xtensa/include
- -ID:/esp/v5.5.4/esp-idf/components/soc/include
- -ID:/esp/v5.5.4/esp-idf/components/soc/esp32s3/include
- -ID:/esp/v5.5.4/esp-idf/components/soc/esp32s3/register
+13
View File
@@ -0,0 +1,13 @@
ARG DOCKER_TAG=latest
FROM espressif/idf:${DOCKER_TAG}
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8
RUN apt-get update -y && apt-get install udev -y
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
CMD ["/bin/bash", "-c"]
+19
View File
@@ -0,0 +1,19 @@
{
"name": "ESP-IDF QEMU",
"build": {
"dockerfile": "Dockerfile"
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"idf.gitPath": "/usr/bin/git"
},
"extensions": [
"espressif.esp-idf-extension",
"espressif.esp-idf-web"
]
}
},
"runArgs": ["--privileged"]
}
+78
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
+31
View File
@@ -0,0 +1,31 @@
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "C:\\Espressif\\tools\\xtensa-esp-elf\\esp-14.2.0_20260121\\xtensa-esp-elf\\bin\\xtensa-esp32s3-elf-gcc.exe",
"compileCommands": "D:\\esp\\Project\\lcd\\lcd\\build\\compile_commands.json",
"intelliSenseMode": "windows-gcc-x64",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/main",
"${workspaceFolder}/build/config",
"D:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/include",
"D:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include",
"D:/esp/v5.5.4/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/include/freertos",
"D:/esp/v5.5.4/esp-idf/components/freertos/config/include",
"D:/esp/v5.5.4/esp-idf/components/freertos/config/include/freertos",
"D:/esp/v5.5.4/esp-idf/components/freertos/config/xtensa/include",
"D:/esp/v5.5.4/esp-idf/components/soc/include",
"D:/esp/v5.5.4/esp-idf/components/soc/esp32s3/include",
"D:/esp/v5.5.4/esp-idf/components/soc/esp32s3/register"
],
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
+10
View File
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "gdbtarget",
"request": "attach",
"name": "Eclipse CDT GDB Adapter"
}
]
}
+24
View File
@@ -0,0 +1,24 @@
{
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"C_Cpp.default.configurationProvider": "espressif.esp-idf-extension",
"C_Cpp.intelliSenseEngine": "disabled",
"idf.extensionActivationMode": "always",
"idf.openOcdConfigs": [
"board/esp32s3-builtin.cfg"
],
"idf.portWin": "COM14",
"idf.currentSetup": "D:\\esp\\v5.5.4\\esp-idf",
"idf.buildPath": "D:\\esp\\Project\\lcd\\lcd\\build",
"idf.pythonInstallPath": "C:\\Espressif\\tools\\python\\python.exe",
"idf.toolsPathWin": "C:\\Espressif\\tools",
"idf.customExtraVars": {
"IDF_TARGET": "esp32s3"
},
"clangd.path": "C:\\Espressif\\tools\\esp-clang\\esp-19.1.2_20250312\\esp-clang\\bin\\clangd.exe",
"clangd.arguments": [
"--background-index",
"--query-driver=**",
"--compile-commands-dir=d:\\esp\\Project\\lcd\\lcd\\build"
],
"idf.flashType": "JTAG"
}
+6
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(lcd)
+32
View File
@@ -0,0 +1,32 @@
# LCD backlight test
This program only turns on the LCD backlight GPIO.
It does not initialize SPI.
It does not initialize the LCD controller.
It does not write any pixel data.
Set `LCD_PIN_BL` to the GPIO connected to the LCD `BLK` pin.
Set `LCD_BL_ACTIVE_HIGH` to match the board.
Build and flash:
```powershell
idf.py menuconfig
idf.py build
idf.py -p COMx flash
```
Expected result: the LCD backlight turns on and stays on.
## Update image data
Use this script to generate `main/eye_image.c` and `main/eye_image.h` from an
image or GIF:
```powershell
C:\Users\28036\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe D:\esp\Project\lcd\tools\gif_to_eye_image.py D:\esp\Project\lcd\source\eye2.bmp
```
For GIF files, use `--max-frames` or `--step` if the generated file is too
large.
+3
View File
@@ -0,0 +1,3 @@
idf_component_register(SRCS "lcd_reg.c" "main.c" "eye_image.c"
INCLUDE_DIRS "."
PRIV_REQUIRES esp_driver_gpio esp_driver_spi freertos)
+11
View File
@@ -0,0 +1,11 @@
menu "LCD backlight test"
config LCD_PIN_BL
int "LCD BLK/backlight GPIO"
default -1
config LCD_BL_ACTIVE_HIGH
bool "Backlight is active high"
default y
endmenu
+96039
View File
File diff suppressed because it is too large Load Diff
+13
View File
@@ -0,0 +1,13 @@
#ifndef EYE_IMAGE_H
#define EYE_IMAGE_H
#include <stdint.h>
#define EYE_IMAGE_WIDTH 320
#define EYE_IMAGE_HEIGHT 240
#define EYE_IMAGE_FRAME_COUNT 15
extern const uint16_t eye_image[EYE_IMAGE_FRAME_COUNT][EYE_IMAGE_WIDTH * EYE_IMAGE_HEIGHT];
extern const uint16_t eye_image_delay_ms[EYE_IMAGE_FRAME_COUNT];
#endif
+175
View File
@@ -0,0 +1,175 @@
#include "lcd_reg.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define LCD_SPI_HOST SPI2_HOST
#define LCD_PIN_BL 1
#define LCD_PIN_CS 8
#define LCD_PIN_DC 9
#define LCD_PIN_RES 10
#define LCD_PIN_SDA 11
#define LCD_PIN_SCL 12
#define LCD_CMD_SWRESET 0x01
#define LCD_CMD_SLPOUT 0x11
#define LCD_CMD_COLMOD 0x3A
#define LCD_CMD_MADCTL 0x36
#define LCD_CMD_CASET 0x2A
#define LCD_CMD_RASET 0x2B
#define LCD_CMD_RAMWR 0x2C
#define LCD_CMD_INVON 0x21
#define LCD_CMD_DISPON 0x29
static spi_device_handle_t lcd_spi;
static void lcd_delay_ms(uint32_t ms)
{
vTaskDelay(pdMS_TO_TICKS(ms));
}
static void lcd_gpio_init(void)
{
gpio_config_t gpio_config_data = {
.pin_bit_mask = (1ULL << LCD_PIN_BL) | (1ULL << LCD_PIN_DC) | (1ULL << LCD_PIN_RES),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
gpio_config(&gpio_config_data);
gpio_set_level(LCD_PIN_BL, 1);
gpio_set_level(LCD_PIN_DC, 0);
gpio_set_level(LCD_PIN_RES, 1);
}
static void lcd_spi_init(void)
{
spi_bus_config_t bus_config = {
.mosi_io_num = LCD_PIN_SDA,
.miso_io_num = -1,
.sclk_io_num = LCD_PIN_SCL,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_WIDTH * 40 * 2,
};
spi_bus_initialize(LCD_SPI_HOST, &bus_config, SPI_DMA_CH_AUTO);
spi_device_interface_config_t device_config = {
.clock_speed_hz = 40000000,
.mode = 0,
.spics_io_num = LCD_PIN_CS,
.queue_size = 8,
};
spi_bus_add_device(LCD_SPI_HOST, &device_config, &lcd_spi);
}
static void lcd_reset(void)
{
gpio_set_level(LCD_PIN_RES, 1);
lcd_delay_ms(20);
gpio_set_level(LCD_PIN_RES, 0);
lcd_delay_ms(20);
gpio_set_level(LCD_PIN_RES, 1);
lcd_delay_ms(120);
}
static void lcd_spi_write(const void *data, uint32_t length)
{
spi_transaction_t transaction = {
.length = length * 8,
.tx_buffer = data,
};
spi_device_polling_transmit(lcd_spi, &transaction);
}
static void lcd_write_command(uint8_t command)
{
gpio_set_level(LCD_PIN_DC, 0);
lcd_spi_write(&command, 1);
}
static void lcd_write_data8(uint8_t data)
{
gpio_set_level(LCD_PIN_DC, 1);
lcd_spi_write(&data, 1);
}
static void lcd_write_data16(uint16_t data)
{
uint8_t bytes[2] = {
(uint8_t)(data >> 8),
(uint8_t)data,
};
gpio_set_level(LCD_PIN_DC, 1);
lcd_spi_write(bytes, sizeof(bytes));
}
static void lcd_set_window(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
{
lcd_write_command(LCD_CMD_CASET);
lcd_write_data16(x0);
lcd_write_data16(x1);
lcd_write_command(LCD_CMD_RASET);
lcd_write_data16(y0);
lcd_write_data16(y1);
lcd_write_command(LCD_CMD_RAMWR);
}
void lcd_reg_init(void)
{
lcd_gpio_init();
lcd_spi_init();
lcd_reset();
lcd_write_command(LCD_CMD_SWRESET);
lcd_delay_ms(150);
lcd_write_command(LCD_CMD_SLPOUT);
lcd_delay_ms(120);
lcd_write_command(LCD_CMD_COLMOD);
lcd_write_data8(0x05);
lcd_write_command(LCD_CMD_MADCTL);
lcd_write_data8(0x60);
lcd_write_command(LCD_CMD_INVON);
lcd_write_command(LCD_CMD_DISPON);
lcd_delay_ms(120);
}
void lcd_reg_draw_image(const uint16_t *image)
{
enum { LINES_PER_TRANSFER = 20 };
static uint16_t line_buffer[LCD_WIDTH * LINES_PER_TRANSFER];
lcd_set_window(0, 0, LCD_WIDTH - 1, LCD_HEIGHT - 1);
gpio_set_level(LCD_PIN_DC, 1);
for (uint32_t y = 0; y < LCD_HEIGHT; y += LINES_PER_TRANSFER) {
uint32_t lines = LINES_PER_TRANSFER;
if ((y + lines) > LCD_HEIGHT) {
lines = LCD_HEIGHT - y;
}
uint32_t pixels = LCD_WIDTH * lines;
for (uint32_t i = 0; i < pixels; i++) {
uint16_t color = image[(y * LCD_WIDTH) + i];
line_buffer[i] = (uint16_t)((color >> 8) | (color << 8));
}
lcd_spi_write(line_buffer, pixels * 2);
}
}
+12
View File
@@ -0,0 +1,12 @@
#ifndef LCD_REG_H
#define LCD_REG_H
#include <stdint.h>
#define LCD_WIDTH 320
#define LCD_HEIGHT 240
void lcd_reg_init(void);
void lcd_reg_draw_image(const uint16_t *image);
#endif
+16
View File
@@ -0,0 +1,16 @@
#include "eye_image.h"
#include "lcd_reg.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void app_main(void)
{
lcd_reg_init();
while (1) {
for (uint16_t i = 0; i < EYE_IMAGE_FRAME_COUNT; i++) {
lcd_reg_draw_image(eye_image[i]);
vTaskDelay(pdMS_TO_TICKS(eye_image_delay_ms[i]));
}
}
}
+4
View File
@@ -0,0 +1,4 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xF000, 0x1000,
factory, app, factory, 0x10000, 0xE00000,
1 # Name Type SubType Offset Size Flags
2 nvs data nvs 0x9000 0x6000
3 phy_init data phy 0xF000 0x1000
4 factory app factory 0x10000 0xE00000
+7
View File
@@ -0,0 +1,7 @@
CONFIG_IDF_TARGET="esp32s3"
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="16MB"
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096