Fix UVC not starting on Babble and Xiao boards due to a miss-configuration

This commit is contained in:
Lorow
2025-08-26 23:31:34 +02:00
parent dbc5091500
commit 4a8aacf99e
10 changed files with 41 additions and 24 deletions

View File

@@ -79,10 +79,10 @@ void CameraManager::setupCameraPinout()
.pixel_format = PIXFORMAT_JPEG, // YUV422,GRAYSCALE,RGB565,JPEG
.frame_size = FRAMESIZE_240X240, // QQVGA-UXGA, For ESP32, do not use sizes above QVGA when not JPEG. The performance of the ESP32-S series has improved a lot, but JPEG mode always gives better frame rates.
.jpeg_quality = 7, // 0-63, for OV series camera sensors, lower number means higher quality // Below 6 stability problems
.fb_count = 2, // When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
.jpeg_quality = 7, // 0-63, for OV series camera sensors, lower number means higher quality // Below 6 stability problems
.fb_count = 2, // When jpeg mode is used, if fb_count more than one, the driver will work in continuous mode.
.fb_location = CAMERA_FB_IN_DRAM,
.grab_mode = CAMERA_GRAB_LATEST, //CAMERA_GRAB_WHEN_EMPTY
.grab_mode = CAMERA_GRAB_LATEST, // CAMERA_GRAB_WHEN_EMPTY
};
}
@@ -202,7 +202,8 @@ bool CameraManager::setupCamera()
// Thanks to lick_it, we discovered that OV5640 likes to overheat when
// running at higher than usual xclk frequencies.
// Hence, why we're limiting the faster ones for OV2640
if (const auto camera_id = temp_sensor->id.PID; camera_id == OV5640_PID) {
if (const auto camera_id = temp_sensor->id.PID; camera_id == OV5640_PID)
{
config.xclk_freq_hz = OV5640_XCLK_FREQ_HZ;
esp_camera_deinit();
esp_camera_init(&config);

View File

@@ -36,13 +36,13 @@ struct DeviceMode_t : BaseConfigModel
void load()
{
// Default mode can be controlled via sdkconfig:
// - If CONFIG_GENERAL_DEFAULT_WIRED_MODE is enabled, default to UVC
// - If CONFIG_START_IN_UVC_MODE is enabled, default to UVC
// - Otherwise default to AUTO
int default_mode =
#if CONFIG_GENERAL_DEFAULT_WIRED_MODE
static_cast<int>(StreamingMode::UVC);
#if CONFIG_START_IN_UVC_MODE
static_cast<int>(StreamingMode::UVC);
#else
static_cast<int>(StreamingMode::AUTO);
static_cast<int>(StreamingMode::AUTO);
#endif
int stored_mode = this->pref->getInt("mode", default_mode);

View File

@@ -6,7 +6,8 @@
static const char *UVC_STREAM_TAG = "[UVC DEVICE]";
extern "C" {
extern "C"
{
static char serial_number_str[13];
const char *get_uvc_device_name()
@@ -26,9 +27,9 @@ extern "C" {
return CONFIG_TUSB_SERIAL_NUM;
}
// 12 hex chars without separators
snprintf(serial_number_str, sizeof(serial_number_str), "%02X%02X%02X%02X%02X%02X",
mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);
// 12 hex chars without separators
snprintf(serial_number_str, sizeof(serial_number_str), "%02X%02X%02X%02X%02X%02X",
mac_address[0], mac_address[1], mac_address[2], mac_address[3], mac_address[4], mac_address[5]);
}
return serial_number_str;
}
@@ -91,7 +92,7 @@ static uvc_fb_t *UVCStreamHelpers::camera_fb_get_cb(void *cb_ctx)
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
// Pace frames to exactly 60 fps (drop extras). Uses fixed-point accumulator
// to achieve an exact average of 60.000 fps without drifting.
static int64_t next_deadline_us = 0;
@@ -99,7 +100,7 @@ static uvc_fb_t *UVCStreamHelpers::camera_fb_get_cb(void *cb_ctx)
constexpr int target_fps = 60;
constexpr int64_t us_per_sec = 1000000LL;
constexpr int base_interval_us = us_per_sec / target_fps; // 16666
constexpr int rem_us = us_per_sec % target_fps; // 40
constexpr int rem_us = us_per_sec % target_fps; // 40
const int64_t now_us = esp_timer_get_time();
if (next_deadline_us == 0)
@@ -114,7 +115,7 @@ static uvc_fb_t *UVCStreamHelpers::camera_fb_get_cb(void *cb_ctx)
s_fb.cam_fb_p = nullptr;
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
s_fb.uvc_fb.buf = s_fb.cam_fb_p->buf;
s_fb.uvc_fb.len = s_fb.cam_fb_p->len;
@@ -130,8 +131,8 @@ static uvc_fb_t *UVCStreamHelpers::camera_fb_get_cb(void *cb_ctx)
esp_camera_fb_return(s_fb.cam_fb_p);
return nullptr;
}
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
// Schedule the next allowed frame time: base interval plus distributed remainder
rem_acc += rem_us;
int extra_us = 0;
@@ -143,7 +144,7 @@ static uvc_fb_t *UVCStreamHelpers::camera_fb_get_cb(void *cb_ctx)
// Accumulate from the previous deadline to avoid drift; if we are badly late, catch up from now
const int64_t base_next = next_deadline_us + base_interval_us + extra_us;
next_deadline_us = (base_next < now_us) ? now_us : base_next;
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
return &s_fb.uvc_fb;
}
@@ -175,7 +176,7 @@ esp_err_t UVCStreamManager::setup()
uvc_device_config_t config = {
.uvc_buffer = uvc_buffer,
.uvc_buffer_size = UVCStreamManager::UVC_MAX_FRAMESIZE_SIZE,
.uvc_buffer_size = UVCStreamManager::UVC_MAX_FRAMESIZE_SIZE,
.start_cb = UVCStreamHelpers::camera_start_cb,
.fb_get_cb = UVCStreamHelpers::camera_fb_get_cb,
.fb_return_cb = UVCStreamHelpers::camera_fb_return_cb,