53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#ifndef E11_H
|
||
#define E11_H
|
||
|
||
#include <stdio.h>
|
||
#include <inttypes.h>
|
||
#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 |