两块 ESP32-S3-WROOM-1-N16R8 图传板(DVP 接口接 OV2640/OV3660/OV5640), 向队伍客户端与裁判终端推 UDP 图传。固件是跑在 ESP-IDF 上的 Rust,用官方 esp32-camera 组件采集;客户端是 Rust + Slint 桌面程序。 三个 crate 各自独立构建: . firmware,交叉编译到 Xtensa protocol/ 线路格式与帧重组,两端共用,无 ESP-IDF 依赖,有单元测试 client/ Slint 桌面客户端 视频走 UDP 而非 TCP:实测传感器产出 22 fps,TCP MJPEG 只送出 1.9 fps, 且只占用链路能力的 1%——链路是空的,帧堵在队头阻塞后面等一个实时画面 等不起的重传计时器。改为独立数据报、不重传、缺片丢整帧后达到 20.8 fps。 发现是双向的:板子每 2 秒广播 Hello,客户端广播 Subscribe,板子据此定向 推流。板子身份由 MAC 派生,重启不变,所以客户端可以把绑定存进配置。 裁判端同时收两块板子(每个发送方一个重组器),队伍端绑定其中一块并只显示 自己那一边的血量。装甲板接口已预留(ArmorSource trait + ARMOR_PORT), 当前无数据源,界面显示占位符。 vendor 了 esp32-camera 2.1.7:组件注册表的版本求解器找不到它,且需要打一处 补丁(见 components/esp32-camera/target/esp32s3/ll_cam.c)。 .gitignore 三条 target/ 都锚定在根目录,因为 protocol/ 与 client/ 各自也是 独立 crate;而 components/esp32-camera/target/ 是上游的按芯片分目录,里面是 源码,必须保留。
76 lines
2.2 KiB
C
76 lines
2.2 KiB
C
#include "driver/gpio.h"
|
|
#include "driver/ledc.h"
|
|
#include "esp_err.h"
|
|
#include "esp_log.h"
|
|
#include "esp_system.h"
|
|
#include "xclk.h"
|
|
#include "esp_camera.h"
|
|
|
|
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
|
|
#include "esp32-hal-log.h"
|
|
#else
|
|
#include "esp_log.h"
|
|
static const char* TAG = "camera_xclk";
|
|
#endif
|
|
|
|
#define NO_CAMERA_LEDC_CHANNEL 0xFF
|
|
static ledc_channel_t g_ledc_channel = NO_CAMERA_LEDC_CHANNEL;
|
|
|
|
esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz)
|
|
{
|
|
ledc_timer_config_t timer_conf;
|
|
timer_conf.duty_resolution = LEDC_TIMER_1_BIT;
|
|
timer_conf.freq_hz = xclk_freq_hz;
|
|
timer_conf.speed_mode = LEDC_LOW_SPEED_MODE;
|
|
|
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
|
timer_conf.deconfigure = false;
|
|
#endif
|
|
|
|
#if ESP_IDF_VERSION_MAJOR >= 4
|
|
timer_conf.clk_cfg = LEDC_AUTO_CLK;
|
|
#endif
|
|
timer_conf.timer_num = (ledc_timer_t)ledc_timer;
|
|
esp_err_t err = ledc_timer_config(&timer_conf);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "ledc_timer_config failed for freq %d, rc=%x", xclk_freq_hz, err);
|
|
}
|
|
return err;
|
|
}
|
|
|
|
esp_err_t camera_enable_out_clock(const camera_config_t* config)
|
|
{
|
|
esp_err_t err = xclk_timer_conf(config->ledc_timer, config->xclk_freq_hz);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);
|
|
return err;
|
|
}
|
|
|
|
g_ledc_channel = config->ledc_channel;
|
|
ledc_channel_config_t ch_conf = {0};
|
|
ch_conf.gpio_num = config->pin_xclk;
|
|
ch_conf.speed_mode = LEDC_LOW_SPEED_MODE;
|
|
ch_conf.channel = config->ledc_channel;
|
|
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6,0,0)
|
|
// no need to explicitly configure interrupt, handled in the driver (IDF v6.0 and above)
|
|
ch_conf.intr_type = LEDC_INTR_DISABLE;
|
|
#endif
|
|
ch_conf.timer_sel = config->ledc_timer;
|
|
ch_conf.duty = 1;
|
|
ch_conf.hpoint = 0;
|
|
err = ledc_channel_config(&ch_conf);
|
|
if (err != ESP_OK) {
|
|
ESP_LOGE(TAG, "ledc_channel_config failed, rc=%x", err);
|
|
return err;
|
|
}
|
|
return ESP_OK;
|
|
}
|
|
|
|
void camera_disable_out_clock()
|
|
{
|
|
if (g_ledc_channel != NO_CAMERA_LEDC_CHANNEL) {
|
|
ledc_stop(LEDC_LOW_SPEED_MODE, g_ledc_channel, 0);
|
|
g_ledc_channel = NO_CAMERA_LEDC_CHANNEL;
|
|
}
|
|
}
|