From 2f452e694c2f0fb4cd7984bdccac88967c841053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=96=87=E5=B3=B0?= Date: Tue, 24 Feb 2026 20:49:23 +0800 Subject: [PATCH] =?UTF-8?q?up=20=E4=BF=AE=E5=A4=8D=20=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCB/lichuang_pcb/lichuang_eda.eprj2 | Bin 2715648 -> 2715648 bytes code/esp32c3_espidf/main/CMakeLists.txt | 3 +- code/esp32c3_espidf/main/e11.c | 30 +++++++++++ code/esp32c3_espidf/main/e11.h | 53 ++++++++++++++++++++ code/esp32c3_espidf/main/hello_world_main.c | 16 +++--- 5 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 code/esp32c3_espidf/main/e11.c create mode 100644 code/esp32c3_espidf/main/e11.h diff --git a/PCB/lichuang_pcb/lichuang_eda.eprj2 b/PCB/lichuang_pcb/lichuang_eda.eprj2 index 68e6394ba967b225decc68dc70745012ddc47d4b..0552588850200695db2e50ecda6c24a7040837b4 100644 GIT binary patch delta 144 zcmWN=$rZs+06@|6&GQhm1Th75XykQZlLBJ#_HS;$giNn|B!*+?o|*~wlGa+FL? Ja{h36-G0l_FuVW& delta 144 zcmWN=$rZs+06@|6&GQhm1Th75XykQZkp^P%_HS;$giNn|B!*+?o|*~wlGa+FL? Ja{h36-G0i +#include +#include "driver/pcnt.h" +#include "driver/gpio.h" +#include "esp_log.h" +#include "esp_system.h" + +#define EC11_A_PIN GPIO_NUM_18 // 相位A (CLK) +#define EC11_B_PIN GPIO_NUM_19 // 相位B (DT) +#define EC11_SW_PIN GPIO_NUM_9 // 按键引脚 + + +#define PCNT_UNIT PCNT_UNIT_0 // 使用PCNT单元0 +#define PCNT_CHANNEL PCNT_CHANNEL_0 // 使用通道0 +#define PCNT_H_LIMIT 10000 // 计数上限 +#define PCNT_L_LIMIT -10000 // 计数下限 + +// 滤波参数(消除抖动) +#define PCNT_FILTER_VAL 1023 // 最大滤波值(约102us) + + + +// PCNT事件结构体 +typedef struct { + int unit; // PCNT单元号 + uint32_t status; // 状态寄存器值 + int64_t timestamp; // 时间戳 +} pcnt_evt_t; + +// GPIO事件结构体 +typedef struct { + uint32_t gpio_num; // GPIO引脚号 + uint32_t level; // 电平状态 + int64_t timestamp; // 时间戳 +} gpio_evt_t; + +// 编码器状态结构体 +typedef struct { + int32_t count; // 当前计数值 + int32_t delta; // 上次变化量 + bool direction; // 旋转方向: true=CW, false=CCW + bool button_state; // 按键状态: true=按下, false=释放 +} encoder_state_t; + + + +void e11_init(); +void e11_loop(); + +#endif \ No newline at end of file diff --git a/code/esp32c3_espidf/main/hello_world_main.c b/code/esp32c3_espidf/main/hello_world_main.c index 7e1b0b9..d1df705 100644 --- a/code/esp32c3_espidf/main/hello_world_main.c +++ b/code/esp32c3_espidf/main/hello_world_main.c @@ -16,6 +16,7 @@ #include "esp_system.h" #include "esp_spiffs.h" #include "esp_log.h" +#include "esp_timer.h" #include #include @@ -25,24 +26,15 @@ #include // 时间相关函数 #include "spiffs.h" - #include "spi.h" - #include "lcd.h" - -#include "esp_timer.h" - +#include "e11.h" #include "lv_conf.h" - -/* 然后包含 lvgl.h */ #include "lvgl/lvgl.h" - #include "lv_port_disp.h" #include "lv_port_fs.h" - #include "lv_log_to_esp.h" - #include "lv_apps/helloworld/lv_helloworld.h" static const char *TAG = "SYS"; @@ -133,6 +125,8 @@ void app_main(void) list_spiffs_files_safe(spiffs_base_path); } + e11_init(); + spi_init(); lcd_init(); @@ -145,6 +139,8 @@ void app_main(void) lv_example_get_started_1(); + + while (1) {