Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 86d0fcf

Browse filesBrowse files
committed
Update UVC descriptors
1 parent 6790bc6 commit 86d0fcf
Copy full SHA for 86d0fcf

File tree

Expand file treeCollapse file tree

4 files changed

+93
-19
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+93
-19
lines changed

‎cores/esp32/esp32-hal-tinyusb.c

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-tinyusb.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static void usb_device_task(void *param) {
554554
/*
555555
* PUBLIC API
556556
* */
557-
static const char *tinyusb_interface_names[USB_INTERFACE_MAX] = {"MSC", "DFU", "HID", "VENDOR", "VIDEO", "CDC", "MIDI", "CUSTOM"};
557+
static const char *tinyusb_interface_names[USB_INTERFACE_MAX] = {"VIDEO", "MSC", "DFU", "HID", "VENDOR", "CDC", "MIDI", "CUSTOM"};
558558

559559
static bool tinyusb_is_initialized = false;
560560

‎cores/esp32/esp32-hal-tinyusb.h

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-tinyusb.h
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ void usb_persist_restart(restart_type_t mode);
8282

8383
// The following definitions and functions are to be used only by the drivers
8484
typedef enum {
85+
USB_INTERFACE_VIDEO,
8586
USB_INTERFACE_MSC,
8687
USB_INTERFACE_DFU,
8788
USB_INTERFACE_HID,
8889
USB_INTERFACE_VENDOR,
89-
USB_INTERFACE_VIDEO,
9090
USB_INTERFACE_CDC,
9191
USB_INTERFACE_MIDI,
9292
USB_INTERFACE_CUSTOM,

‎libraries/USB/src/USBVideo.cpp

Copy file name to clipboardExpand all lines: libraries/USB/src/USBVideo.cpp
+78-12Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#if CONFIG_TINYUSB_VIDEO_ENABLED
1717

1818
#include "esp32-hal-tinyusb.h"
19+
//#include "esp_camera.h"
1920

2021
/* Time stamp base clock. It is a deprecated parameter. */
2122
#define UVC_CLOCK_FREQUENCY 27000000
@@ -28,7 +29,7 @@
2829
/* control */\
2930
+ TUD_VIDEO_DESC_STD_VC_LEN\
3031
+ (TUD_VIDEO_DESC_CS_VC_LEN + 1/*bInCollection*/)\
31-
+ TUD_VIDEO_DESC_INPUT_TERM_LEN\
32+
+ TUD_VIDEO_DESC_CAMERA_TERM_LEN\
3233
+ TUD_VIDEO_DESC_OUTPUT_TERM_LEN\
3334
/* Interface 1, Alternate 0 */\
3435
+ TUD_VIDEO_DESC_STD_VS_LEN\
@@ -54,14 +55,16 @@
5455
TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR(_fmtidx, _numfmtdesc, TUD_VIDEO_GUID_I420, 12, _frmidx, _asrx, _asry, _interlace, _cp)
5556

5657
#define TUD_VIDEO_CAPTURE_DESCRIPTOR(_itf, _stridx, _epin, _width, _height, _fps, _epsize) \
57-
TUD_VIDEO_DESC_IAD(_itf, (_itf+2), _stridx), \
58+
TUD_VIDEO_DESC_IAD(_itf, 2, _stridx), \
5859
/* Video control 0 */ \
5960
TUD_VIDEO_DESC_STD_VC(_itf, 0, _stridx), \
6061
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150, \
6162
/* wTotalLength - bLength */ \
62-
TUD_VIDEO_DESC_INPUT_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
63+
TUD_VIDEO_DESC_CAMERA_TERM_LEN + TUD_VIDEO_DESC_OUTPUT_TERM_LEN, \
6364
UVC_CLOCK_FREQUENCY, 1), \
64-
TUD_VIDEO_DESC_INPUT_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, VIDEO_ETT_COMPOSITE_CONNECTOR, 0, 0), \
65+
TUD_VIDEO_DESC_CAMERA_TERM(UVC_ENTITY_CAP_INPUT_TERMINAL, 0, 0,\
66+
/*wObjectiveFocalLengthMin*/0, /*wObjectiveFocalLengthMax*/0,\
67+
/*wObjectiveFocalLength*/0, /*bmControls*/0), \
6568
TUD_VIDEO_DESC_OUTPUT_TERM(UVC_ENTITY_CAP_OUTPUT_TERMINAL, VIDEO_TT_STREAMING, 0, 1, 0), \
6669
/* Video stream alt. 0 */ \
6770
TUD_VIDEO_DESC_STD_VS( (_itf+1), 0, 0, 0), \
@@ -86,15 +89,15 @@
8689
/* VS alt 1 */\
8790
TUD_VIDEO_DESC_STD_VS((_itf+1), 1, 1, 0), \
8891
/* EP */ \
89-
TUD_VIDEO_DESC_EP_ISO(_epin, _epsize, 1)
92+
TUD_VIDEO_DESC_EP_BULK(_epin, _epsize, 1)
9093

9194

9295
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_VIDEO_EVENTS);
9396
esp_err_t arduino_usb_event_post(esp_event_base_t event_base, int32_t event_id, void *event_data, size_t event_data_size, TickType_t ticks_to_wait);
9497
esp_err_t arduino_usb_event_handler_register_with(esp_event_base_t event_base, int32_t event_id, esp_event_handler_t event_handler, void *event_handler_arg);
9598

96-
#define FRAME_WIDTH 80
97-
#define FRAME_HEIGHT 60
99+
#define FRAME_WIDTH 160
100+
#define FRAME_HEIGHT 120
98101
#define FRAME_RATE 10
99102

100103
uint16_t tusb_video_load_descriptor(uint8_t * dst, uint8_t * itf)
@@ -103,15 +106,12 @@ uint16_t tusb_video_load_descriptor(uint8_t * dst, uint8_t * itf)
103106
uint8_t ep_num = tinyusb_get_free_in_endpoint();
104107
TU_VERIFY (ep_num != 0);
105108
uint8_t descriptor[TUD_VIDEO_CAPTURE_DESC_LEN] = {
106-
// Interface number, string index, EP Out & IN address, EP size
109+
// Interface number, string index, EP IN address, width, height, frame rate, EP size
107110
TUD_VIDEO_CAPTURE_DESCRIPTOR(*itf, str_index, (uint8_t)(0x80 | ep_num), FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, 64)
108111
};
109112
*itf+=2;
110113
memcpy(dst, descriptor, TUD_VIDEO_CAPTURE_DESC_LEN);
111114
return TUD_VIDEO_CAPTURE_DESC_LEN;
112-
// size_t desc_len = sizeof(UVCConfigurationDescriptor);
113-
// memcpy(dst, UVCConfigurationDescriptor, desc_len);
114-
// return desc_len;
115115
}
116116

117117
static unsigned frame_num = 0;
@@ -171,16 +171,32 @@ void video_task(void)
171171
if (!already_sent) {
172172
already_sent = 1;
173173
start_ms = millis();
174+
175+
log_d("TX: %u", frame_num);
174176
fill_color_bar(frame_buffer, frame_num);
175177
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
178+
// camera_fb_t *fb = esp_camera_fb_get();
179+
// if(fb){
180+
// log_d("TX: %u", fb->len);
181+
// tud_video_n_frame_xfer(0, 0, (void*)fb->buf, fb->len);
182+
// esp_camera_fb_return(fb);
183+
// }
176184
}
177185

178186
unsigned cur = millis();
179187
if (cur - start_ms < interval_ms) return; // not enough time
180188
if (tx_busy) return;
181189
start_ms += interval_ms;
190+
191+
log_d("TX: %u", frame_num);
182192
fill_color_bar(frame_buffer, frame_num);
183193
tud_video_n_frame_xfer(0, 0, (void*)frame_buffer, FRAME_WIDTH * FRAME_HEIGHT * 16/8);
194+
// camera_fb_t *fb = esp_camera_fb_get();
195+
// if(fb){
196+
// log_d("TX: %u", fb->len);
197+
// tud_video_n_frame_xfer(0, 0, (void*)fb->buf, fb->len);
198+
// esp_camera_fb_return(fb);
199+
// }
184200
}
185201

186202

@@ -220,11 +236,61 @@ extern "C" int tud_video_power_mode_cb(uint_fast8_t ctl_idx, uint8_t power_mod){
220236

221237
USBVideo::USBVideo(uint8_t ctl, uint8_t stm):_ctl(ctl), _stm(stm){
222238
tinyusb_enable_interface(USB_INTERFACE_VIDEO, TUD_VIDEO_CAPTURE_DESC_LEN, tusb_video_load_descriptor);
223-
//tinyusb_enable_interface(USB_INTERFACE_VIDEO, sizeof(UVCConfigurationDescriptor), tusb_video_load_descriptor);
224239
}
225240

226241
void USBVideo::begin(){
227242

243+
// #define PWDN_GPIO_NUM 1
244+
// #define RESET_GPIO_NUM 2
245+
// #define XCLK_GPIO_NUM 42
246+
// #define SIOD_GPIO_NUM 41
247+
// #define SIOC_GPIO_NUM 18
248+
249+
// #define Y9_GPIO_NUM 16
250+
// #define Y8_GPIO_NUM 39
251+
// #define Y7_GPIO_NUM 40
252+
// #define Y6_GPIO_NUM 15
253+
// #define Y5_GPIO_NUM 13
254+
// #define Y4_GPIO_NUM 5
255+
// #define Y3_GPIO_NUM 12
256+
// #define Y2_GPIO_NUM 14
257+
// #define VSYNC_GPIO_NUM 38
258+
// #define HREF_GPIO_NUM 4
259+
// #define PCLK_GPIO_NUM 3
260+
261+
// camera_config_t config;
262+
// config.ledc_channel = LEDC_CHANNEL_0;
263+
// config.ledc_timer = LEDC_TIMER_0;
264+
// config.pin_d0 = Y2_GPIO_NUM;
265+
// config.pin_d1 = Y3_GPIO_NUM;
266+
// config.pin_d2 = Y4_GPIO_NUM;
267+
// config.pin_d3 = Y5_GPIO_NUM;
268+
// config.pin_d4 = Y6_GPIO_NUM;
269+
// config.pin_d5 = Y7_GPIO_NUM;
270+
// config.pin_d6 = Y8_GPIO_NUM;
271+
// config.pin_d7 = Y9_GPIO_NUM;
272+
// config.pin_xclk = XCLK_GPIO_NUM;
273+
// config.pin_pclk = PCLK_GPIO_NUM;
274+
// config.pin_vsync = VSYNC_GPIO_NUM;
275+
// config.pin_href = HREF_GPIO_NUM;
276+
// config.pin_sscb_sda = SIOD_GPIO_NUM;
277+
// config.pin_sscb_scl = SIOC_GPIO_NUM;
278+
// config.pin_pwdn = PWDN_GPIO_NUM;
279+
// config.pin_reset = RESET_GPIO_NUM;
280+
// config.xclk_freq_hz = 8000000;
281+
// config.pixel_format = PIXFORMAT_YUV422;
282+
// config.frame_size = FRAMESIZE_QQVGA;
283+
// config.jpeg_quality = 12;
284+
// config.fb_count = 2;
285+
// config.fb_location = CAMERA_FB_IN_PSRAM;
286+
// config.grab_mode = CAMERA_GRAB_LATEST;
287+
288+
// camera init
289+
// esp_err_t err = esp_camera_init(&config);
290+
// if (err != ESP_OK) {
291+
// log_e("Camera init failed with error 0x%x", err);
292+
// return;
293+
// }
228294
}
229295

230296
void USBVideo::end(){

‎tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/video/video.h

Copy file name to clipboardExpand all lines: tools/sdk/esp32s2/include/arduino_tinyusb/tinyusb/src/class/video/video.h
+13-5Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
373373
#define TUD_VIDEO_DESC_CS_VC_LEN 12
374374
#define TUD_VIDEO_DESC_INPUT_TERM_LEN 8
375375
#define TUD_VIDEO_DESC_OUTPUT_TERM_LEN 9
376+
#define TUD_VIDEO_DESC_CAMERA_TERM_LEN 18
376377
#define TUD_VIDEO_DESC_STD_VS_LEN 9
377378
#define TUD_VIDEO_DESC_CS_VS_IN_LEN 13
378379
#define TUD_VIDEO_DESC_CS_VS_OUT_LEN 9
@@ -382,10 +383,10 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
382383
#define TUD_VIDEO_DESC_CS_VS_COLOR_MATCHING_LEN 6
383384

384385
/* 2.2 compression formats */
385-
#define TUD_VIDEO_GUID_YUY2 0x59,0x55,0x59,0x32,0x00,0x00,0x10,0x00,0x00,0x80,0x71,0x9B,0x38,0x00,0xAA,0x00
386-
#define TUD_VIDEO_GUID_NV12 0x4E,0x56,0x31,0x32,0x00,0x00,0x10,0x00,0x00,0x80,0x71,0x9B,0x38,0x00,0xAA,0x00
387-
#define TUD_VIDEO_GUID_M420 0x4D,0x34,0x32,0x30,0x00,0x00,0x10,0x00,0x00,0x80,0x71,0x9B,0x38,0x00,0xAA,0x00
388-
#define TUD_VIDEO_GUID_I420 0x49,0x34,0x32,0x30,0x00,0x00,0x10,0x00,0x00,0x80,0x71,0x9B,0x38,0x00,0xAA,0x00
386+
#define TUD_VIDEO_GUID_YUY2 0x59,0x55,0x59,0x32,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
387+
#define TUD_VIDEO_GUID_NV12 0x4E,0x56,0x31,0x32,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
388+
#define TUD_VIDEO_GUID_M420 0x4D,0x34,0x32,0x30,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
389+
#define TUD_VIDEO_GUID_I420 0x49,0x34,0x32,0x30,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71
389390

390391
#define TUD_VIDEO_DESC_IAD(_firstitfs, _nitfs, _stridx) \
391392
TUD_VIDEO_DESC_IAD_LEN, TUSB_DESC_INTERFACE_ASSOCIATION, \
@@ -397,7 +398,7 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
397398
_nEPs, TUSB_CLASS_VIDEO, VIDEO_SUBCLASS_CONTROL, VIDEO_ITF_PROTOCOL_15, _stridx
398399

399400
/* 3.7.2 */
400-
#define TUD_VIDEO_DESC_CS_VC(_bcdUVC, _totallen, _clkfreq, ...) \
401+
#define TUD_VIDEO_DESC_CS_VC(_bcdUVC, _totallen, _clkfreq, ...) \
401402
TUD_VIDEO_DESC_CS_VC_LEN + (TU_ARGS_NUM(__VA_ARGS__)), TUSB_DESC_CS_INTERFACE, VIDEO_CS_ITF_VC_HEADER, \
402403
U16_TO_U8S_LE(_bcdUVC), U16_TO_U8S_LE((_totallen) + TUD_VIDEO_DESC_CS_VC_LEN + (TU_ARGS_NUM(__VA_ARGS__))), \
403404
U32_TO_U8S_LE(_clkfreq), TU_ARGS_NUM(__VA_ARGS__), __VA_ARGS__
@@ -412,6 +413,13 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
412413
TUD_VIDEO_DESC_OUTPUT_TERM_LEN, TUSB_DESC_CS_INTERFACE, VIDEO_CS_ITF_VC_OUTPUT_TERMINAL, \
413414
_tid, U16_TO_U8S_LE(_tt), _at, _srcid, _stridx
414415

416+
/* 3.7.2.3 */
417+
#define TUD_VIDEO_DESC_CAMERA_TERM(_tid, _at, _stridx, _focal_min, _focal_max, _focal, _ctls) \
418+
TUD_VIDEO_DESC_CAMERA_TERM_LEN, TUSB_DESC_CS_INTERFACE, VIDEO_CS_ITF_VC_INPUT_TERMINAL, \
419+
_tid, U16_TO_U8S_LE(VIDEO_ITT_CAMERA), _at, _stridx, \
420+
U16_TO_U8S_LE(_focal_min), U16_TO_U8S_LE(_focal_max), U16_TO_U8S_LE(_focal), 3, \
421+
TU_U32_BYTE0(_ctls), TU_U32_BYTE1(_ctls), TU_U32_BYTE2(_ctls)
422+
415423
/* 3.9.1 */
416424
#define TUD_VIDEO_DESC_STD_VS(_itfnum, _alt, _epn, _stridx) \
417425
TUD_VIDEO_DESC_STD_VS_LEN, TUSB_DESC_INTERFACE, _itfnum, _alt, \

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.