Skip to content

Commit 2fb643a

Browse files
fix(uvc): Fix UVC driver re-installation
UVC uninstall function was using a static variable to track driver state, which caused issues when re-installing the driver. This commit changes the implementation to use driver_state EventGroupBits instead
1 parent 2dcc708 commit 2fb643a

File tree

14 files changed

+437
-23
lines changed

14 files changed

+437
-23
lines changed

host/class/uvc/usb_host_uvc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Added `uvc_host_stream_format_get()` function that returns current stream's format
44
- Added `uvc_host_buf_info_get()` function for esp_video binding
55
- Added option to request default FPS by setting FPS = 0
6+
- Fixed UVC driver re-installation
67

78
## 2.2.0
89

host/class/uvc/usb_host_uvc/host_test/main/opening/test_opening.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ SCENARIO("UVC driver install/uninstall")
6767
}
6868

6969
REQUIRE(ESP_OK == test_uvc_host_uninstall());
70+
71+
AND_WHEN("UVC driver is installed again") {
72+
THEN("Installation succeeds") {
73+
REQUIRE(ESP_OK == test_uvc_host_install(&uvc_driver_config));
74+
REQUIRE(ESP_OK == test_uvc_host_uninstall());
75+
}
76+
}
7077
}
7178
}
7279

host/class/uvc/usb_host_uvc/host_test/main/parsing/test_parsing_helpers.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#pragma once
88

99
/**
10-
* @brief Define MJPEG formats with FPS 30-5
10+
* @brief Define MJPEG formats with FPS 30-5 and 0 (default)
1111
*/
1212
#define FORMAT_MJPEG_30_5(x, y) \
1313
{x, y, 30, UVC_VS_FORMAT_MJPEG}, \
@@ -19,7 +19,7 @@
1919
{x, y, 0, UVC_VS_FORMAT_MJPEG}
2020

2121
/**
22-
* @brief Define MJPEG formats with FPS 30-15
22+
* @brief Define MJPEG formats with FPS 30-15 and 0 (default)
2323
*/
2424
#define FORMAT_MJPEG_30_25_15(x, y) \
2525
{x, y, 30, UVC_VS_FORMAT_MJPEG}, \
@@ -28,7 +28,7 @@
2828
{x, y, 0, UVC_VS_FORMAT_MJPEG}
2929

3030
/**
31-
* @brief Define MJPEG formats with FPS 30-15
31+
* @brief Define MJPEG formats with FPS 30-15 and 0 (default)
3232
*/
3333
#define FORMAT_MJPEG_30_20_15(x, y) \
3434
{x, y, 30, UVC_VS_FORMAT_MJPEG}, \
@@ -37,7 +37,7 @@
3737
{x, y, 0, UVC_VS_FORMAT_MJPEG}
3838

3939
/**
40-
* @brief Define YUY2 formats with FPS 30-5
40+
* @brief Define YUY2 formats with FPS 30-5 and 0 (default)
4141
*/
4242
#define FORMAT_UNCOMPRESSED_30_5(x, y) \
4343
{x, y, 30, UVC_VS_FORMAT_YUY2}, \
@@ -49,7 +49,7 @@
4949
{x, y, 0, UVC_VS_FORMAT_YUY2}
5050

5151
/**
52-
* @brief Define YUY2 formats with FPS 30-15
52+
* @brief Define YUY2 formats with FPS 30-15 and 0 (default)
5353
*/
5454
#define FORMAT_UNCOMPRESSED_30_25_15(x, y) \
5555
{x, y, 30, UVC_VS_FORMAT_YUY2}, \
@@ -58,7 +58,7 @@
5858
{x, y, 0, UVC_VS_FORMAT_YUY2}
5959

6060
/**
61-
* @brief Define YUY2 formats with FPS 30-15
61+
* @brief Define YUY2 formats with FPS 30-15 and 0 (default)
6262
*/
6363
#define FORMAT_UNCOMPRESSED_30_20_15(x, y) \
6464
{x, y, 30, UVC_VS_FORMAT_YUY2}, \
@@ -67,7 +67,7 @@
6767
{x, y, 0, UVC_VS_FORMAT_YUY2}
6868

6969
/**
70-
* @brief Define YUY2 formats with FPS 20-5
70+
* @brief Define YUY2 formats with FPS 20-5 and 0 (default)
7171
*/
7272
#define FORMAT_UNCOMPRESSED_20_5(x, y) \
7373
{x, y, 20, UVC_VS_FORMAT_YUY2}, \
@@ -77,7 +77,7 @@
7777
{x, y, 0, UVC_VS_FORMAT_YUY2}
7878

7979
/**
80-
* @brief Define h264 formats with FPS 30-15
80+
* @brief Define h264 formats with FPS 30-15 and 0 (default)
8181
*/
8282
#define FORMAT_H264_30_25_15(x, y) \
8383
{x, y, 30, UVC_VS_FORMAT_H264}, \
@@ -86,7 +86,7 @@
8686
{x, y, 0, UVC_VS_FORMAT_H264}
8787

8888
/**
89-
* @brief Define h264 formats with FPS 30-15
89+
* @brief Define h264 formats with FPS 30-15 and 0 (default)
9090
*/
9191
#define FORMAT_H264_30_20_15(x, y) \
9292
{x, y, 30, UVC_VS_FORMAT_H264}, \
@@ -95,7 +95,7 @@
9595
{x, y, 0, UVC_VS_FORMAT_H264}
9696

9797
/**
98-
* @brief Define h265 formats with FPS 30-15
98+
* @brief Define h265 formats with FPS 30-15 and 0 (default)
9999
*/
100100
#define FORMAT_H265_30_20_15(x, y) \
101101
{x, y, 30, UVC_VS_FORMAT_H265}, \

host/class/uvc/usb_host_uvc/include/esp_private/uvc_esp_video.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414

1515
/**
1616
* This API provides access to advanced UVC features.
17-
* It is intended for use with esp_vide component.
17+
* It is intended for use with esp_video component.
1818
*/
1919

2020
typedef struct {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The following five lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
6+
set(COMPONENTS main)
7+
8+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
9+
project(test_app_usb_host_uvc)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
| Supported Targets | ESP32-S2 | ESP32-S3 | ESP32-P4 |
2+
| ----------------- | -------- | -------- | -------- |
3+
4+
# USB: UVC Class test application
5+
6+
## UVC driver
7+
8+
Target tests for USB Host UVC driver.
9+
10+
### Hardware Required
11+
12+
A USB camera and USB enabled ESP SoC is needed. Connect the camera to USB host port on ESP.
13+
Format negotiation results are tested against values from Logitech C270 camera. These constants must be modified if different camera is used.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
idf_component_register(SRC_DIRS .
2+
INCLUDE_DIRS .
3+
REQUIRES unity
4+
WHOLE_ARCHIVE)
5+
6+
# So we have access to private_include:
7+
target_include_directories(${COMPONENT_LIB} PRIVATE "../../")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
# Needed as DUT
4+
espressif/usb_host_uvc:
5+
version: "*"
6+
override_path: "../../../usb_host_uvc"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <string.h>
9+
#include "unity.h"
10+
#include "unity_test_runner.h"
11+
#include "unity_test_utils_memory.h"
12+
13+
void setUp(void)
14+
{
15+
unity_utils_record_free_mem();
16+
}
17+
18+
void tearDown(void)
19+
{
20+
unity_utils_evaluate_leaks();
21+
}
22+
23+
void app_main(void)
24+
{
25+
/*
26+
____ _______ _____________ __ __
27+
| | \ \ / /\_ ___ \ _/ |_ ____ _______/ |_
28+
| | /\ Y / / \ \/ \ __\/ __ \ / ___/\ __\
29+
| | / \ / \ \____ | | \ ___/ \___ \ | |
30+
|______/ \___/ \______ / |__| \___ >____ > |__|
31+
\/ \/ \/
32+
*/
33+
printf(" ____ _______ _____________ __ __ \r\n");
34+
printf("| | \\ \\ / /\\_ ___ \\ _/ |_ ____ _______/ |_ \r\n");
35+
printf("| | /\\ Y / / \\ \\/ \\ __\\/ __ \\ / ___/\\ __\\\r\n");
36+
printf("| | / \\ / \\ \\____ | | \\ ___/ \\___ \\ | | \r\n");
37+
printf("|______/ \\___/ \\______ / |__| \\___ >____ > |__| \r\n");
38+
printf(" \\/ \\/ \\/ \r\n");
39+
40+
unity_utils_setup_heap_record(80);
41+
unity_utils_set_leak_level(530);
42+
unity_run_menu();
43+
}

0 commit comments

Comments
 (0)