Skip to content

Commit bf2051b

Browse files
feat(uvc_host): Add global suspend/resume
- usb_host lib supports global suspend and resume - backward compatibility with older IDF releases - UVC Host target tests
1 parent 3ece832 commit bf2051b

File tree

7 files changed

+942
-2
lines changed

7 files changed

+942
-2
lines changed

host/class/uvc/usb_host_uvc/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added support for user-provided frame buffers via `user_frame_buffers` field in `uvc_host_stream_config_t.advanced`
1313

14+
### Added
15+
16+
- Added global suspend/resume support
17+
1418
### Fixed
1519

1620
- Fixed potential buffer overflow in descriptor printing functions by removing unnecessary memcpy operations

host/class/uvc/usb_host_uvc/examples/basic_uvc_stream/main/basic_uvc_stream.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ static void stream_callback(const uvc_host_stream_event_data_t *event, void *use
7171
case UVC_HOST_FRAME_BUFFER_UNDERFLOW:
7272
ESP_LOGW(TAG, "Frame buffer underflow");
7373
break;
74+
#ifdef UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
75+
case UVC_HOST_DEVICE_SUSPENDED:
76+
ESP_LOGI(TAG, "Device suspended");
77+
break;
78+
case UVC_HOST_DEVICE_RESUMED:
79+
ESP_LOGI(TAG, "Device resumed");
80+
break;
81+
#endif // UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
7482
default:
7583
abort();
7684
break;

host/class/uvc/usb_host_uvc/examples/camera_display/main/camera_display.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -62,6 +62,14 @@ void stream_callback(const uvc_host_stream_event_data_t *event, void *user_ctx)
6262
case UVC_HOST_FRAME_BUFFER_UNDERFLOW:
6363
ESP_LOGW(TAG, "Frame buffer underflow");
6464
break;
65+
#ifdef UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
66+
case UVC_HOST_DEVICE_SUSPENDED:
67+
ESP_LOGI(TAG, "Device suspended");
68+
break;
69+
case UVC_HOST_DEVICE_RESUMED:
70+
ESP_LOGI(TAG, "Device resumed");
71+
break;
72+
#endif // UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
6573
default:
6674
abort();
6775
break;

host/class/uvc/usb_host_uvc/include/usb/uvc_host.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
extern "C" {
2121
#endif
2222

23+
// For backward compatibility with IDF versions which do not have suspend/resume api
24+
#ifdef USB_HOST_LIB_EVENT_FLAGS_AUTO_SUSPEND
25+
#define UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
26+
#endif
27+
2328
typedef struct uvc_host_stream_s *uvc_host_stream_hdl_t;
2429

2530
enum uvc_host_driver_event {
@@ -100,6 +105,10 @@ enum uvc_host_dev_event {
100105
UVC_HOST_FRAME_BUFFER_UNDERFLOW, /**< The received frame was discarded because no available buffer was free for storage.
101106
To address this, either optimize your processing speed or increase the `number_of_frame_buffers` parameter in
102107
`uvc_host_stream_config_t.advanced` to allocate additional buffers. */
108+
#ifdef UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
109+
UVC_HOST_DEVICE_SUSPENDED, /**< Device was suspended. The stream is stopped. */
110+
UVC_HOST_DEVICE_RESUMED, /**< Device was resumed. */
111+
#endif // UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
103112
};
104113

105114
/**
@@ -118,6 +127,11 @@ typedef struct {
118127
} frame_overflow; // UVC_HOST_FRAME_BUFFER_OVERFLOW
119128
struct {
120129
} frame_underflow; // UVC_HOST_FRAME_BUFFER_UNDERFLOW
130+
#ifdef UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
131+
struct {
132+
uvc_host_stream_hdl_t stream_hdl;
133+
} device_suspended_resumed;
134+
#endif // UVC_HOST_SUSPEND_RESUME_API_SUPPORTED
121135
};
122136
} uvc_host_stream_event_data_t;
123137

0 commit comments

Comments
 (0)