#include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "freertos/semphr.h" #include "esp_err.h" #include "esp_timer.h" #include "stdlib.h" #include "config.h" #include "utils.h" #include "ads1220.h" #include "fram.h" #include "rotary_encoder.h" #include "esp_log.h" #include "esp_check.h" #include "soc/rtc.h" #include "driver/mcpwm.h" // #include "driver/mcpwm_prelude.h" // #include "bt_server.h" // #include "../ble_gatts_server.h" #include "esp_system.h" #include "driver/uart.h" #include "string.h" #include "driver/gpio.h" #include #include static const char *TAG = "depth"; typedef struct { uint32_t capture_signal; mcpwm_capture_signal_t sel_cap_signal; } capture; typedef struct capture_event { int ch; uint32_t val; } capture_event_t; // #define DEPTH_PIN_CLK GPIO_NUM_36 // 捕获GPIO端口 // #define GPIO_PCNT_PIN_1 36 // Set GPIO 18 as phaseA/C1 // #define GPIO_PCNT_PIN_2 35 // Set GPIO 19 as phaseB/C2 // #define DEPTH_PIN_PULSE 36 //深度脉冲GPIO端口 // #define DEPTH_PIN_CTRL 35 //深度控制GPIO端口 #define FLOW_SYNC_PIN 7 // 捕获GPIO端口 SPI2_nIRQ #define DEPTH_PIN_PULSE 39 // 深度脉冲GPIO端口 TIM15_CH1 #define DEPTH_PIN_CTRL 38 // 深度控制GPIO端口 TIM15_CH2 #define DEPTH_PIN_ENC_A 42 // 深度脉冲GPIO端口 TIM3_CH1 #define DEPTH_PIN_ENC_B 41 // 深度控制GPIO端口 TIM3_CH2 #define SEND_DATA_TEST 0 #define PILE_STATE_STOP 0x0100 #define PILE_STATE_PAUSE 0x0200 #define PILE_STATE_WORK 0x0300 #define PILE_DIR_NONE 0x01 #define PILE_DIR_UP 0x02 #define PILE_DIR_DOWN 0x03 rotary_encoder_t *encoder_ = NULL; // 编码器测量深度参数 void pcnt_rotary_encoder_init_(void) { // Rotary encoder underlying device is represented by a PCNT unit in this example uint32_t pcnt_unit = 0; int pulse_pin; int ctrl_pin; pulse_pin = DEPTH_PIN_ENC_A; ctrl_pin = DEPTH_PIN_ENC_B; // Create rotary encoder instance rotary_encoder_config_t config = ROTARY_ENCODER_DEFAULT_CONFIG((rotary_encoder_dev_t)pcnt_unit, pulse_pin, ctrl_pin); config.flags = 0; ESP_ERROR_CHECK(rotary_encoder_new_ec11(&config, &encoder_)); // Filter out glitch (1us) ESP_ERROR_CHECK(encoder_->set_glitch_filter(encoder_, 10)); // Start encoder ESP_ERROR_CHECK(encoder_->start(encoder_)); }