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
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\
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), \
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
9295ESP_EVENT_DEFINE_BASE(ARDUINO_USB_VIDEO_EVENTS);
9396esp_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);
9497esp_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
100103uint16_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
117117static 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
221237USBVideo::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
226241void 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
230296void USBVideo::end (){
0 commit comments