esp idf好难用。。

This commit is contained in:
2026-02-18 03:23:36 +08:00
parent fb653cb545
commit ce0b15e2fa
29 changed files with 895 additions and 220 deletions
+2
View File
@@ -0,0 +1,2 @@
CompileFlags:
Remove: [-f*, -m*]
+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"]
@@ -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
+19
View File
@@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "C:\\Espressif\\tools\\riscv32-esp-elf\\esp-13.2.0_20240530\\riscv32-esp-elf\\bin\\riscv32-esp-elf-gcc.exe",
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
"includePath": [
"${workspaceFolder}/**"
],
"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"
}
]
}
+11
View File
@@ -0,0 +1,11 @@
{
"idf.currentSetup": "C:/Espressif/frameworks/esp-idf-v5.3.1/",
"idf.flashType": "UART",
"idf.portWin": "COM3",
"idf.openOcdConfigs": [
"board/esp32c3-builtin.cfg"
],
"idf.customExtraVars": {
"IDF_TARGET": "esp32c3"
}
}
+6
View File
@@ -0,0 +1,6 @@
# The following 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(demo1)
+53
View File
@@ -0,0 +1,53 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-P4 | ESP32-S2 | ESP32-S3 | Linux |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | ----- |
# Hello World Example
Starts a FreeRTOS task to print "Hello World".
(See the README.md file in the upper level 'examples' directory for more information about examples.)
## How to use example
Follow detailed instructions provided specifically for this example.
Select the instructions depending on Espressif chip installed on your development board:
- [ESP32 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/stable/get-started/index.html)
- [ESP32-S2 Getting Started Guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/get-started/index.html)
## Example folder contents
The project **hello_world** contains one source file in C language [hello_world_main.c](main/hello_world_main.c). The file is located in folder [main](main).
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` files that provide set of directives and instructions describing the project's source files and targets (executable, library, or both).
Below is short explanation of remaining files in the project folder.
```
├── CMakeLists.txt
├── pytest_hello_world.py Python script used for automated testing
├── main
│ ├── CMakeLists.txt
│ └── hello_world_main.c
└── README.md This is the file you are currently reading
```
For more information on structure and contents of ESP-IDF projects, please refer to Section [Build System](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html) of the ESP-IDF Programming Guide.
## Troubleshooting
* Program upload failure
* Hardware connection is not correct: run `idf.py -p PORT monitor`, and reboot your board to see if there are any output logs.
* The baud rate for downloading is too high: lower your baud rate in the `menuconfig` menu, and try again.
## Technical support and feedback
Please use the following feedback channels:
* For technical queries, go to the [esp32.com](https://esp32.com/) forum
* For a feature request or bug report, create a [GitHub issue](https://github.com/espressif/esp-idf/issues)
We will get back to you as soon as possible.
+6
View File
@@ -0,0 +1,6 @@
# 收集当前目录下所有 .c 文件
file(GLOB_RECURSE SRC_LIST "*.c")
idf_component_register(SRCS ${SRC_LIST}
PRIV_REQUIRES spi_flash esp_driver_spi esp_driver_gpio
INCLUDE_DIRS "")
+62
View File
@@ -0,0 +1,62 @@
/*
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*/
#include <stdio.h>
#include <inttypes.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_chip_info.h"
#include "esp_flash.h"
#include "esp_system.h"
#include "esp_log.h"
#include "spi.h"
#include "lcd.h"
void app_main(void)
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
uint32_t flash_size;
esp_chip_info(&chip_info);
printf("This is %s chip with %d CPU core(s), %s%s%s%s, ",
CONFIG_IDF_TARGET,
chip_info.cores,
(chip_info.features & CHIP_FEATURE_WIFI_BGN) ? "WiFi/" : "",
(chip_info.features & CHIP_FEATURE_BT) ? "BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "BLE" : "",
(chip_info.features & CHIP_FEATURE_IEEE802154) ? ", 802.15.4 (Zigbee/Thread)" : "");
unsigned major_rev = chip_info.revision / 100;
unsigned minor_rev = chip_info.revision % 100;
printf("silicon revision v%d.%d, ", major_rev, minor_rev);
if (esp_flash_get_size(NULL, &flash_size) != ESP_OK)
{
printf("Get flash size failed");
return;
}
printf("%" PRIu32 "MB %s flash\n", flash_size / (uint32_t)(1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
printf("Minimum free heap size: %" PRIu32 " bytes\n", esp_get_minimum_free_heap_size());
spi_init();
lcd_init();
//LCD_Clear(0x1234);
while (1)
{
LCD_Clear(rand());
vTaskDelay(1); // 必须让出CPU
}
}
+184
View File
@@ -0,0 +1,184 @@
#include "lcd.h"
static const char *TAG = "LCD";
/******************************************************************************
函数说明:设置起始和结束地址
入口数据:x1,x2 设置列的起始和结束地址
y1,y2 设置行的起始和结束地址
返回值: 无
******************************************************************************/
void LCD_Address_Set(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
{
#if USE_HORIZONTAL == 0
lcd_spi_reg(0x2a); // 列地址设置
lcd_spi_write16(x1);
lcd_spi_write16(x2);
lcd_spi_reg(0x2b); // 行地址设置
lcd_spi_write16(y1);
lcd_spi_write16(y2);
lcd_spi_reg(0x2c); // 储存器写
#elif USE_HORIZONTAL == 1
lcd_spi_reg(0x2a); // 列地址设置
lcd_spi_write16(x1);
lcd_spi_write16(x2);
lcd_spi_reg(0x2b); // 行地址设置
lcd_spi_write16(y1 + 80);
lcd_spi_write16(y2 + 80);
lcd_spi_reg(0x2c); // 储存器写
#elif USE_HORIZONTAL == 2
lcd_spi_reg(0x2a); // 列地址设置
lcd_spi_write16(x1);
lcd_spi_write16(x2);
lcd_spi_reg(0x2b); // 行地址设置
lcd_spi_write16(y1);
lcd_spi_write16(y2);
lcd_spi_reg(0x2c); // 储存器写
#elif USE_HORIZONTAL == 3
lcd_spi_reg(0x2a); // 列地址设置
lcd_spi_write16(x1 + 80);
lcd_spi_write16(x2 + 80);
lcd_spi_reg(0x2b); // 行地址设置
lcd_spi_write16(y1);
lcd_spi_write16(y2);
lcd_spi_reg(0x2c); // 储存器写
#endif
}
void LCD_Clear(uint16_t Color)
{
uint16_t i, j;
LCD_Address_Set(0, 0, LCD_WW - 1, LCD_HH - 1);
for (i = 0; i < LCD_WW; i++)
{
for (j = 0; j < LCD_HH; j++)
{
lcd_spi_write16(Color);
}
}
}
void lcd_init()
{
ESP_LOGI(TAG, "等待初始化LCD");
vTaskDelay(25); //
ESP_LOGI(TAG, "初始化LCD");
lcd_spi_reg(0x36);
if (USE_HORIZONTAL == 0)
lcd_spi_write8(0x00);
else if (USE_HORIZONTAL == 1)
lcd_spi_write8(0xC0);
else if (USE_HORIZONTAL == 2)
lcd_spi_write8(0x70);
else
lcd_spi_write8(0xA0);
lcd_spi_reg(0x3A);
lcd_spi_write8(0x05);
lcd_spi_reg(0xB2);
lcd_spi_write8(0x0C);
lcd_spi_write8(0x0C);
lcd_spi_write8(0x00);
lcd_spi_write8(0x33);
lcd_spi_write8(0x33);
lcd_spi_reg(0xB7);
lcd_spi_write8(0x35);
lcd_spi_reg(0xBB);
lcd_spi_write8(0x19);
lcd_spi_reg(0xC0);
lcd_spi_write8(0x2C);
lcd_spi_reg(0xC2);
lcd_spi_write8(0x01);
lcd_spi_reg(0xC3);
lcd_spi_write8(0x12);
lcd_spi_reg(0xC4);
lcd_spi_write8(0x20);
lcd_spi_reg(0xC6);
lcd_spi_write8(0x0F);
lcd_spi_reg(0xD0);
lcd_spi_write8(0xA4);
lcd_spi_write8(0xA1);
lcd_spi_reg(0xE0);
lcd_spi_write8(0xD0);
lcd_spi_write8(0x04);
lcd_spi_write8(0x0D);
lcd_spi_write8(0x11);
lcd_spi_write8(0x13);
lcd_spi_write8(0x2B);
lcd_spi_write8(0x3F);
lcd_spi_write8(0x54);
lcd_spi_write8(0x4C);
lcd_spi_write8(0x18);
lcd_spi_write8(0x0D);
lcd_spi_write8(0x0B);
lcd_spi_write8(0x1F);
lcd_spi_write8(0x23);
lcd_spi_reg(0xE1);
lcd_spi_write8(0xD0);
lcd_spi_write8(0x04);
lcd_spi_write8(0x0C);
lcd_spi_write8(0x11);
lcd_spi_write8(0x13);
lcd_spi_write8(0x2C);
lcd_spi_write8(0x3F);
lcd_spi_write8(0x44);
lcd_spi_write8(0x51);
lcd_spi_write8(0x2F);
lcd_spi_write8(0x1F);
lcd_spi_write8(0x1F);
lcd_spi_write8(0x20);
lcd_spi_write8(0x23);
lcd_spi_reg(0x21);
lcd_spi_reg(0x11);
vTaskDelay(12);
lcd_spi_reg(0x29);
ESP_LOGI(TAG, "初始化LCD完成");
LCD_Clear(0xffff);
}
void LCD_test()
{
uint16_t i, j, k , x=100,y=100;
lcd_spi_reg(0x2a); // 列地址设置
lcd_spi_write16(0);
lcd_spi_write16(x - 1);
lcd_spi_reg(0x2b); // 行地址设置
lcd_spi_write16(0);
lcd_spi_write16(y - 1);
lcd_spi_reg(0x2c); // 储存器写
for (i = 0; i < y; i++)
{
k = rand();
for (j = 0; j < x; j++)
{
lcd_spi_write16(k);
}
}
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef LCD_H
#define LCD_H
#include <stdio.h>
#include <inttypes.h>
#include "esp_log.h"
#include "spi.h"
#define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#define LCD_WW 320
#define LCD_HH 240
void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2);
void lcd_init();
void LCD_Clear(uint16_t Color);
void LCD_test();
#endif
+145
View File
@@ -0,0 +1,145 @@
#include "spi.h"
static const char *TAG = "SPI_2";
spi_device_handle_t lcd_spi;
void spi_init()
{
ESP_LOGI(TAG, "配置GPIO");
// 1. 配置GPIO
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << LCD_DS), // LCD_DS
.mode = GPIO_MODE_OUTPUT, // 输出模式
.pull_up_en = GPIO_PULLUP_DISABLE, //
.pull_down_en = GPIO_PULLDOWN_DISABLE, //
.intr_type = GPIO_INTR_DISABLE // 禁用中断
};
// 2. 应用配置
gpio_config(&io_conf);
// 3. 设置初始电平
gpio_set_level(LCD_DS, 0); // 输出低电平
// 1. 配置 GPIO 驱动能力 (ESP32-C3 支持)
gpio_set_drive_capability(VSPI_MISO, GPIO_DRIVE_CAP_3); // 最大驱动
gpio_set_drive_capability(VSPI_MOSI, GPIO_DRIVE_CAP_3);
gpio_set_drive_capability(VSPI_SCLK, GPIO_DRIVE_CAP_3);
ESP_LOGI(TAG, "配置GPIO完成");
ESP_LOGI(TAG,"初始化SPI IO总线");
esp_err_t ret;
// 1. SPI 总线配置
spi_bus_config_t buscfg = {
.miso_io_num = VSPI_MISO, // MISO 引脚
.mosi_io_num = VSPI_MOSI, // MOSI 引脚
.sclk_io_num = VSPI_SCLK, // 时钟引脚
.quadwp_io_num = -1, // 不使用 QWP
.quadhd_io_num = -1, // 不使用 QHD
.max_transfer_sz = 4096, // 最大传输大小
.flags = SPICOMMON_BUSFLAG_MASTER,
};
// 2. 初始化 SPI 总线
ret = spi_bus_initialize(SPI2_HOST, &buscfg,SPI_DMA_CH_AUTO );
if (ret != ESP_OK) {
ESP_LOGE(TAG, "SPI2 IO总线初始化失败");
return;
}
ESP_LOGI(TAG,"SPI IO总线初始化成功");
ESP_LOGI(TAG,"挂载设备片选IO");
spi_device_interface_config_t devcfg = {
.mode = 0, // SPI 模式 0
.clock_speed_hz = 80000000, //
.spics_io_num = LCD_CS,
.queue_size = 7, // 队列深度
.flags = SPI_DEVICE_NO_DUMMY, // 禁用 dummy 周期
};
ret = spi_bus_add_device(SPI2_HOST, &devcfg, &lcd_spi);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "挂载设备片选IO失败");
return;
}
}
// SPI 写数据
esp_err_t lcd_spi_write8(uint8_t data) {
spi_transaction_t trans = {
.length = 8, // 数据位数
.tx_buffer = &data, // 发送缓冲区
.rx_buffer = NULL, // 不接收
};
return spi_device_transmit(lcd_spi, &trans);
}
// SPI 写数据
esp_err_t lcd_spi_write16(uint16_t data) {
uint8_t tx_buf[2];
tx_buf[1] = data & 0xFF;
tx_buf[0] = (data >> 8) & 0xFF;
spi_transaction_t trans = {
.length = 16, // 数据位数
.tx_buffer = tx_buf, // 发送缓冲区
.rx_buffer = NULL, // 不接收
};
return spi_device_transmit(lcd_spi, &trans);
}
// SPI 写命令
esp_err_t lcd_spi_reg(uint8_t data) {
esp_err_t err;
gpio_set_level(LCD_DS, 0);
err=lcd_spi_write8(data);
gpio_set_level(LCD_DS, 1);
if (err != ESP_OK) {
ESP_LOGE(TAG, "命令发送失败");
}
return err;
}
void lcd_ds_test()
{
esp_err_t err;
static uint8_t this_flag=0;
if(this_flag)
{
this_flag=0;
err=gpio_set_level(LCD_DS, 0);
}else{
this_flag=1;
err=gpio_set_level(LCD_DS, 1);
}
if (err != ESP_OK) {
ESP_LOGE(TAG, "GPIO失败");
}
}
+32
View File
@@ -0,0 +1,32 @@
#ifndef SPI_H
#define SPI_H
#include <stdio.h>
#include <inttypes.h>
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "esp_log.h"
#include "esp_system.h"
#define VSPI_MISO -1 //接收引脚不使用,仅发送
#define VSPI_MOSI 3
#define VSPI_SCLK 2
#define LCD_CS 7
#define LCD_DS 6
void spi_init();
// SPI 写数据
esp_err_t lcd_spi_write8(uint8_t data);
// SPI 写数据
esp_err_t lcd_spi_write16(uint16_t data);
// SPI 写命令
esp_err_t lcd_spi_reg(uint8_t data);
void lcd_ds_test();
#endif /* SPI_H */
+53
View File
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: CC0-1.0
import hashlib
import logging
from typing import Callable
import pytest
from pytest_embedded_idf.dut import IdfDut
from pytest_embedded_qemu.app import QemuApp
from pytest_embedded_qemu.dut import QemuDut
@pytest.mark.supported_targets
@pytest.mark.preview_targets
@pytest.mark.generic
def test_hello_world(
dut: IdfDut, log_minimum_free_heap_size: Callable[..., None]
) -> None:
dut.expect('Hello world!')
log_minimum_free_heap_size()
@pytest.mark.linux
@pytest.mark.host_test
def test_hello_world_linux(dut: IdfDut) -> None:
dut.expect('Hello world!')
def verify_elf_sha256_embedding(app: QemuApp, sha256_reported: str) -> None:
sha256 = hashlib.sha256()
with open(app.elf_file, 'rb') as f:
sha256.update(f.read())
sha256_expected = sha256.hexdigest()
logging.info(f'ELF file SHA256: {sha256_expected}')
logging.info(f'ELF file SHA256 (reported by the app): {sha256_reported}')
# the app reports only the first several hex characters of the SHA256, check that they match
if not sha256_expected.startswith(sha256_reported):
raise ValueError('ELF file SHA256 mismatch')
@pytest.mark.esp32 # we only support qemu on esp32 for now
@pytest.mark.host_test
@pytest.mark.qemu
def test_hello_world_host(app: QemuApp, dut: QemuDut) -> None:
sha256_reported = (
dut.expect(r'ELF file SHA256:\s+([a-f0-9]+)').group(1).decode('utf-8')
)
verify_elf_sha256_embedding(app, sha256_reported)
dut.expect('Hello world!')
View File
+4 -6
View File
@@ -139,11 +139,10 @@
},
"teardrop_options": [
{
"td_onpthpad": true,
"td_onpadsmd": true,
"td_onroundshapesonly": false,
"td_onsmdpad": true,
"td_ontrackend": false,
"td_onvia": true
"td_onviapad": true
}
],
"teardrop_parameters": [
@@ -454,7 +453,7 @@
},
"meta": {
"filename": "esp32_pcb.kicad_pro",
"version": 3
"version": 1
},
"net_settings": {
"classes": [
@@ -469,7 +468,6 @@
"microvia_drill": 0.1,
"name": "Default",
"pcb_color": "rgba(0, 0, 0, 0.000)",
"priority": 2147483647,
"schematic_color": "rgba(0, 0, 0, 0.000)",
"track_width": 0.2,
"via_diameter": 0.6,
@@ -478,7 +476,7 @@
}
],
"meta": {
"version": 4
"version": 3
},
"net_colors": null,
"netclass_assignments": null,
+3 -1
View File
@@ -6,12 +6,14 @@ void setup() {
//delay(1000);
lcd_init();
LCD_Clear(rand());
}
void loop() {
// put your main code here, to run repeatedly:
LCD_Clear(rand());
// put your main code here, to run repeatedly:
//LCD_fillRect(50,50,20,10,rand());
}
+116 -164
View File
@@ -3,55 +3,7 @@
SPIClass * vspi = NULL;
/******************************************************************************
函数说明:LCD串行数据写入函数
入口数据:dat 要写入的串行数据
返回值: 无
******************************************************************************/
void LCD_Writ_Bus(uint8_t dat)
{
/*
uint8_t i;
digitalWrite(LCD_CS,0);
for(i=0;i<8;i++)
{
digitalWrite(LCD_SCL,0);
if(dat&0x80)
digitalWrite(LCD_SDA,1);
else
digitalWrite(LCD_SDA,0);
digitalWrite(LCD_SCL,1);
dat<<=1;
}
digitalWrite(LCD_CS,1);
*/
vspi->transfer(dat);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void LCD_WR_DATA8(uint8_t dat)
{
LCD_Writ_Bus(dat);
}
/******************************************************************************
函数说明:LCD写入数据
入口数据:dat 写入的数据
返回值: 无
******************************************************************************/
void LCD_WR_DATA(uint16_t dat)
{
//LCD_Writ_Bus(dat>>8);
vspi->transfer16(dat);
}
/******************************************************************************
@@ -62,7 +14,7 @@ void LCD_WR_DATA(uint16_t dat)
void LCD_WR_REG(uint8_t dat)
{
digitalWrite(LCD_DS,0);//写命令
LCD_Writ_Bus(dat);
vspi->transfer(dat);
digitalWrite(LCD_DS,1);//写数据
}
@@ -77,35 +29,35 @@ void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
#if USE_HORIZONTAL==0
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
vspi->transfer16(x1);
vspi->transfer16(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
vspi->transfer16(y1);
vspi->transfer16(y2);
LCD_WR_REG(0x2c);//储存器写
#elif USE_HORIZONTAL==1
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
vspi->transfer16(x1);
vspi->transfer16(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1+80);
LCD_WR_DATA(y2+80);
vspi->transfer16(y1+80);
vspi->transfer16(y2+80);
LCD_WR_REG(0x2c);//储存器写
#elif USE_HORIZONTAL==2
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1);
LCD_WR_DATA(x2);
vspi->transfer16(x1);
vspi->transfer16(x2);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
vspi->transfer16(y1);
vspi->transfer16(y2);
LCD_WR_REG(0x2c);//储存器写
#elif USE_HORIZONTAL==3
LCD_WR_REG(0x2a);//列地址设置
LCD_WR_DATA(x1+80);
LCD_WR_DATA(x2+80);
vspi->transfer16(x1+80);
vspi->transfer16(x2+80);
LCD_WR_REG(0x2b);//行地址设置
LCD_WR_DATA(y1);
LCD_WR_DATA(y2);
vspi->transfer16(y1);
vspi->transfer16(y2);
LCD_WR_REG(0x2c);//储存器写
#endif
@@ -114,98 +66,18 @@ void LCD_Address_Set(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2)
}
/******************************************************************************
函数说明:LCD初始化函数
入口数据:无
返回值: 无
******************************************************************************/
void Lcd_Init(void)
void LCD_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color)
{
LCD_Address_Set(x,y,width+x-1,height+y-1);
for(uint16_t i=0;i<height;i++)
{
for (uint16_t j=0;j<width;j++)
{
vspi->transfer16(color);
//delay(100);
}
}
//************* Start Initial Sequence **********//
//delay(120);
//LCD_WR_REG(0x01);
//上电后硬件会自己复位
delay(220);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)LCD_WR_DATA8(0x00);
else if(USE_HORIZONTAL==1)LCD_WR_DATA8(0xC0);
else if(USE_HORIZONTAL==2)LCD_WR_DATA8(0x70);
else LCD_WR_DATA8(0xA0);
LCD_WR_REG(0x3A);
LCD_WR_DATA8(0x05);
LCD_WR_REG(0xB2);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x00);
LCD_WR_DATA8(0x33);
LCD_WR_DATA8(0x33);
LCD_WR_REG(0xB7);
LCD_WR_DATA8(0x35);
LCD_WR_REG(0xBB);
LCD_WR_DATA8(0x19);
LCD_WR_REG(0xC0);
LCD_WR_DATA8(0x2C);
LCD_WR_REG(0xC2);
LCD_WR_DATA8(0x01);
LCD_WR_REG(0xC3);
LCD_WR_DATA8(0x12);
LCD_WR_REG(0xC4);
LCD_WR_DATA8(0x20);
LCD_WR_REG(0xC6);
LCD_WR_DATA8(0x0F);
LCD_WR_REG(0xD0);
LCD_WR_DATA8(0xA4);
LCD_WR_DATA8(0xA1);
LCD_WR_REG(0xE0);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2B);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x54);
LCD_WR_DATA8(0x4C);
LCD_WR_DATA8(0x18);
LCD_WR_DATA8(0x0D);
LCD_WR_DATA8(0x0B);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0xE1);
LCD_WR_DATA8(0xD0);
LCD_WR_DATA8(0x04);
LCD_WR_DATA8(0x0C);
LCD_WR_DATA8(0x11);
LCD_WR_DATA8(0x13);
LCD_WR_DATA8(0x2C);
LCD_WR_DATA8(0x3F);
LCD_WR_DATA8(0x44);
LCD_WR_DATA8(0x51);
LCD_WR_DATA8(0x2F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x1F);
LCD_WR_DATA8(0x20);
LCD_WR_DATA8(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
delay(120);
LCD_WR_REG(0x29);
}
@@ -222,9 +94,8 @@ void LCD_Clear(uint16_t Color)
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA(Color);
vspi->transfer16(Color);
}
}
}
@@ -236,7 +107,7 @@ void LCD_Clear_Rand()
{
for (j=0;j<LCD_H;j++)
{
LCD_WR_DATA(rand());
vspi->transfer16(rand());
}
}
@@ -267,23 +138,104 @@ void lcd_init()
pinMode(LCD_CS, OUTPUT);
pinMode(LCD_DS, OUTPUT);
digitalWrite(LCD_SDA,0);
digitalWrite(LCD_SCL,0);
digitalWrite(LCD_CS,0);
digitalWrite(LCD_DS,0);
vspi = new SPIClass(VSPI);
vspi->begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS);
vspi->begin(LCD_SCL, 0, LCD_SDA, LCD_CS);
vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
pinMode(vspi->pinSS(), OUTPUT); //HSPI SS
digitalWrite(vspi->pinSS(), LOW); //pull SS slow to prep other end for transfer
pinMode(LCD_LED, OUTPUT);
digitalWrite(LCD_LED,1);
Lcd_Init();
//************* Start Initial Sequence **********//
//delay(120);
//LCD_WR_REG(0x01);
//上电后硬件会自己复位
delay(220);
LCD_WR_REG(0x36);
if(USE_HORIZONTAL==0)vspi->transfer(0x00);
else if(USE_HORIZONTAL==1)vspi->transfer(0xC0);
else if(USE_HORIZONTAL==2)vspi->transfer(0x70);
else vspi->transfer(0xA0);
LCD_WR_REG(0x3A);
vspi->transfer(0x05);
LCD_WR_REG(0xB2);
vspi->transfer(0x0C);
vspi->transfer(0x0C);
vspi->transfer(0x00);
vspi->transfer(0x33);
vspi->transfer(0x33);
LCD_WR_REG(0xB7);
vspi->transfer(0x35);
LCD_WR_REG(0xBB);
vspi->transfer(0x19);
LCD_WR_REG(0xC0);
vspi->transfer(0x2C);
LCD_WR_REG(0xC2);
vspi->transfer(0x01);
LCD_WR_REG(0xC3);
vspi->transfer(0x12);
LCD_WR_REG(0xC4);
vspi->transfer(0x20);
LCD_WR_REG(0xC6);
vspi->transfer(0x0F);
LCD_WR_REG(0xD0);
vspi->transfer(0xA4);
vspi->transfer(0xA1);
LCD_WR_REG(0xE0);
vspi->transfer(0xD0);
vspi->transfer(0x04);
vspi->transfer(0x0D);
vspi->transfer(0x11);
vspi->transfer(0x13);
vspi->transfer(0x2B);
vspi->transfer(0x3F);
vspi->transfer(0x54);
vspi->transfer(0x4C);
vspi->transfer(0x18);
vspi->transfer(0x0D);
vspi->transfer(0x0B);
vspi->transfer(0x1F);
vspi->transfer(0x23);
LCD_WR_REG(0xE1);
vspi->transfer(0xD0);
vspi->transfer(0x04);
vspi->transfer(0x0C);
vspi->transfer(0x11);
vspi->transfer(0x13);
vspi->transfer(0x2C);
vspi->transfer(0x3F);
vspi->transfer(0x44);
vspi->transfer(0x51);
vspi->transfer(0x2F);
vspi->transfer(0x1F);
vspi->transfer(0x1F);
vspi->transfer(0x20);
vspi->transfer(0x23);
LCD_WR_REG(0x21);
LCD_WR_REG(0x11);
delay(120);
LCD_WR_REG(0x29);
}
+6 -8
View File
@@ -9,16 +9,11 @@
#define LCD_SCL 2
#define LCD_CS 7
#define LCD_DS 6
#define LCD_LED 10
#define VSPI_MISO 10
#define VSPI_MOSI 3
#define VSPI_SCLK 2
#define VSPI_SS 7
#define USE_HORIZONTAL 0 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#define LCD_W 240
#define LCD_H 320
#define USE_HORIZONTAL 2 //设置横屏或者竖屏显示 0或1为竖屏 2或3为横屏
#define LCD_W 320
#define LCD_H 240
#define OLED_CMD 0 //写命令
#define OLED_DATA 1 //写数据
@@ -32,4 +27,7 @@ void lcd_init();
void LCD_Clear(uint16_t Color);
void LCD_fillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
#endif
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="org.eclipse.cdt.core.default.config.395313844">
<storageModule buildSystemId="org.eclipse.cdt.core.defaultConfigDataProvider" id="org.eclipse.cdt.core.default.config.395313844" moduleId="org.eclipse.cdt.core.settings" name="Configuration">
<externalSettings/>
<extensions/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.pathentry">
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
@@ -7,8 +7,6 @@
"vscode": {
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"idf.espIdfPath": "/opt/esp/idf",
"idf.toolsPath": "/opt/esp",
"idf.gitPath": "/usr/bin/git"
},
"extensions": [
+20
View File
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>espidfcode</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.core.cBuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.cmake.core.cmakeNature</nature>
</natures>
</projectDescription>
+1 -5
View File
@@ -2,17 +2,13 @@
"configurations": [
{
"name": "ESP-IDF",
"compilerPath": "${config:idf.toolsPathWin}\\tools\\xtensa-esp-elf\\esp-14.2.0_20251107\\xtensa-esp-elf\\bin\\xtensa-esp32-elf-gcc.exe",
"compilerPath": "C:\\Espressif\\tools\\xtensa-esp-elf\\esp-13.2.0_20240530\\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
-5
View File
@@ -5,11 +5,6 @@
"type": "gdbtarget",
"request": "attach",
"name": "Eclipse CDT GDB Adapter"
},
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}
+2 -17
View File
@@ -1,20 +1,5 @@
{
"C_Cpp.intelliSenseEngine": "default",
"idf.espIdfPathWin": "C:\\Users\\wuwen\\esp\\v5.5.2\\esp-idf",
"idf.pythonInstallPath": "C:\\Espressif\\tools\\idf-python\\3.11.2\\python.exe",
"idf.openOcdConfigs": [
"board/esp32c3-builtin.cfg"
],
"idf.toolsPathWin": "C:\\Espressif",
"idf.customExtraVars": {
"IDF_TARGET": "esp32c3"
},
"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=c:\\Users\\wuwen\\Documents\\prj\\hantai_project\\espidfcode\\build"
],
"idf.currentSetup": "C:/Espressif/frameworks/esp-idf-v5.3.1/",
"idf.flashType": "UART",
"idf.portWin": "COM4"
"idf.portWin": "COM3"
}
-2
View File
@@ -3,6 +3,4 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
idf_build_set_property(MINIMAL_BUILD ON)
project(espidfcode)
+4
View File
@@ -1,3 +1,7 @@
[1217/195831.250:ERROR:gpu\command_buffer\service\shared_image\shared_image_manager.cc:401] SharedImageManager::ProduceSkia: Trying to Produce a Skia representation from a non-existent mailbox.
[1230/230046.279:ERROR:ui\gl\direct_composition_support.cc:615] AMD VideoProcessorGetOutputExtension failed: The parameter is incorrect. (0x80070057)
[1231/002815.642:ERROR:ui\gl\direct_composition_support.cc:615] AMD VideoProcessorGetOutputExtension failed: The parameter is incorrect. (0x80070057)
[0217/223323.072:WARNING:net\dns\dns_config_service_win.cc:605] Failed to read DnsConfig.
[0217/223324.703:WARNING:net\dns\dns_config_service_win.cc:605] Failed to read DnsConfig.
[0217/223341.378:WARNING:net\dns\dns_config_service_win.cc:605] Failed to read DnsConfig.
[0217/223346.054:WARNING:net\dns\dns_config_service_win.cc:605] Failed to read DnsConfig.