mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
refactor(peripherals): avoid using esp private feature in examples
This commit is contained in:
@@ -28,8 +28,6 @@ static dac_channel_info_t s_dac_chan[SOC_DAC_CHAN_NUM] = {
|
|||||||
.mode = NULL,
|
.mode = NULL,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/* Global dac spin lock for the whole DAC driver */
|
|
||||||
portMUX_TYPE dac_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
|
||||||
|
|
||||||
static const char *TAG = "dac_common";
|
static const char *TAG = "dac_common";
|
||||||
|
|
||||||
|
|||||||
-1
@@ -11,7 +11,6 @@
|
|||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
#include "driver/dedic_gpio.h"
|
#include "driver/dedic_gpio.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
#include "esp_private/gpio.h"
|
|
||||||
#include "matrix_keyboard.h"
|
#include "matrix_keyboard.h"
|
||||||
|
|
||||||
static const char *TAG = "mkbd";
|
static const char *TAG = "mkbd";
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
pid_ctrl: "^0.1.1"
|
pid_ctrl: "^0.3.0"
|
||||||
bdc_motor: "^0.2.0"
|
bdc_motor: "^0.2.0"
|
||||||
|
|||||||
+6
-6
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
static const char *TAG = "example";
|
static const char *TAG = "example";
|
||||||
|
|
||||||
// Enable this config, we will print debug formated string, which in return can be captured and parsed by Serial-Studio
|
// Enable this config, we will print debug formatted string, which in return can be captured and parsed by Serial-Studio
|
||||||
#define SERIAL_STUDIO_DEBUG CONFIG_SERIAL_STUDIO_DEBUG
|
#define SERIAL_STUDIO_DEBUG CONFIG_SERIAL_STUDIO_DEBUG
|
||||||
|
|
||||||
#define BDC_MCPWM_TIMER_RESOLUTION_HZ 10000000 // 10MHz, 1 tick = 0.1us
|
#define BDC_MCPWM_TIMER_RESOLUTION_HZ 10000000 // 10MHz, 1 tick = 0.1us
|
||||||
@@ -37,7 +37,7 @@ static const char *TAG = "example";
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bdc_motor_handle_t motor;
|
bdc_motor_handle_t motor;
|
||||||
pcnt_unit_handle_t pcnt_encoder;
|
pcnt_unit_handle_t pcnt_encoder;
|
||||||
pid_ctrl_block_handle_t pid_ctrl;
|
pid_ctrl_block_handle_f_t pid_ctrl;
|
||||||
int report_pulses;
|
int report_pulses;
|
||||||
} motor_control_context_t;
|
} motor_control_context_t;
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ static void pid_loop_cb(void *args)
|
|||||||
static int last_pulse_count = 0;
|
static int last_pulse_count = 0;
|
||||||
motor_control_context_t *ctx = (motor_control_context_t *)args;
|
motor_control_context_t *ctx = (motor_control_context_t *)args;
|
||||||
pcnt_unit_handle_t pcnt_unit = ctx->pcnt_encoder;
|
pcnt_unit_handle_t pcnt_unit = ctx->pcnt_encoder;
|
||||||
pid_ctrl_block_handle_t pid_ctrl = ctx->pid_ctrl;
|
pid_ctrl_block_handle_f_t pid_ctrl = ctx->pid_ctrl;
|
||||||
bdc_motor_handle_t motor = ctx->motor;
|
bdc_motor_handle_t motor = ctx->motor;
|
||||||
|
|
||||||
// get the result from rotary encoder
|
// get the result from rotary encoder
|
||||||
@@ -121,7 +121,7 @@ void app_main(void)
|
|||||||
motor_ctrl_ctx.pcnt_encoder = pcnt_unit;
|
motor_ctrl_ctx.pcnt_encoder = pcnt_unit;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Create PID control block");
|
ESP_LOGI(TAG, "Create PID control block");
|
||||||
pid_ctrl_parameter_t pid_runtime_param = {
|
pid_ctrl_parameter_f_t pid_runtime_param = {
|
||||||
.kp = 0.6,
|
.kp = 0.6,
|
||||||
.ki = 0.4,
|
.ki = 0.4,
|
||||||
.kd = 0.2,
|
.kd = 0.2,
|
||||||
@@ -131,8 +131,8 @@ void app_main(void)
|
|||||||
.max_integral = 1000,
|
.max_integral = 1000,
|
||||||
.min_integral = -1000,
|
.min_integral = -1000,
|
||||||
};
|
};
|
||||||
pid_ctrl_block_handle_t pid_ctrl = NULL;
|
pid_ctrl_block_handle_f_t pid_ctrl = NULL;
|
||||||
pid_ctrl_config_t pid_config = {
|
pid_ctrl_config_f_t pid_config = {
|
||||||
.init_param = pid_runtime_param,
|
.init_param = pid_runtime_param,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(pid_new_control_block(&pid_config, &pid_ctrl));
|
ESP_ERROR_CHECK(pid_new_control_block(&pid_config, &pid_ctrl));
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_private/esp_clk.h"
|
|
||||||
#include "driver/mcpwm_cap.h"
|
#include "driver/mcpwm_cap.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
@@ -99,13 +98,16 @@ void app_main(void)
|
|||||||
ESP_ERROR_CHECK(mcpwm_capture_timer_enable(cap_timer));
|
ESP_ERROR_CHECK(mcpwm_capture_timer_enable(cap_timer));
|
||||||
ESP_ERROR_CHECK(mcpwm_capture_timer_start(cap_timer));
|
ESP_ERROR_CHECK(mcpwm_capture_timer_start(cap_timer));
|
||||||
|
|
||||||
|
uint32_t cap_timer_resolution;
|
||||||
|
ESP_ERROR_CHECK(mcpwm_capture_timer_get_resolution(cap_timer, &cap_timer_resolution));
|
||||||
|
|
||||||
uint32_t tof_ticks;
|
uint32_t tof_ticks;
|
||||||
while (1) {
|
while (1) {
|
||||||
// trigger the sensor to start a new sample
|
// trigger the sensor to start a new sample
|
||||||
gen_trig_output();
|
gen_trig_output();
|
||||||
// wait for echo done signal
|
// wait for echo done signal
|
||||||
if (xTaskNotifyWait(0x00, ULONG_MAX, &tof_ticks, pdMS_TO_TICKS(1000)) == pdTRUE) {
|
if (xTaskNotifyWait(0x00, ULONG_MAX, &tof_ticks, pdMS_TO_TICKS(1000)) == pdTRUE) {
|
||||||
float pulse_width_us = tof_ticks * (1000000.0 / esp_clk_apb_freq());
|
float pulse_width_us = tof_ticks * (1000000.0 / cap_timer_resolution);
|
||||||
if (pulse_width_us > 35000) {
|
if (pulse_width_us > 35000) {
|
||||||
// out of range
|
// out of range
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
# Refer to https://ast-grep.github.io/guide/rule-config.html for Rule Essentials
|
||||||
|
id: no-esp-private-header-in-c-examples
|
||||||
|
message: Don't include esp_private headers in the examples
|
||||||
|
severity: error # error, warning, info, hint
|
||||||
|
note: esp_private headers are internal to ESP-IDF and are not guaranteed to be stable across versions.
|
||||||
|
language: C
|
||||||
|
files:
|
||||||
|
- "examples/**/*"
|
||||||
|
ignores:
|
||||||
|
- "examples/network/eth2ap/main/ethernet_example_main.c"
|
||||||
|
- "examples/network/sta2eth/main/sta2eth_main.c"
|
||||||
|
- "examples/openthread/ot_sleepy_device/light_sleep/main/esp_ot_sleepy_device.c"
|
||||||
|
- "examples/peripherals/usb/device/tusb_ncm/main/tusb_ncm_main.c"
|
||||||
|
- "examples/wifi/itwt/main/wifi_stats_cmd.c"
|
||||||
|
- "examples/wifi/wifi_aware/nan_console/main/nan_main.c"
|
||||||
|
- "examples/peripherals/usb/device/tusb_cdc_acm_wakeup/main/tusb_cdc_acm_wakeup_main.c"
|
||||||
|
rule:
|
||||||
|
kind: preproc_include
|
||||||
|
has:
|
||||||
|
field: path
|
||||||
|
regex: "esp_private/.*h"
|
||||||
|
pattern: $N
|
||||||
|
fix: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
id: no-esp-private-header-in-cpp-examples
|
||||||
|
message: Don't include esp_private headers in the examples
|
||||||
|
severity: error # error, warning, info, hint
|
||||||
|
note: esp_private headers are internal to ESP-IDF and are not guaranteed to be stable across versions.
|
||||||
|
language: Cpp
|
||||||
|
files:
|
||||||
|
- "examples/**/*"
|
||||||
|
rule:
|
||||||
|
kind: preproc_include
|
||||||
|
has:
|
||||||
|
field: path
|
||||||
|
regex: "esp_private/.*h"
|
||||||
|
pattern: $N
|
||||||
|
fix: ''
|
||||||
Reference in New Issue
Block a user