16
16
#if CONFIG_TINYUSB_VIDEO_ENABLED
17
17
18
18
#include " esp32-hal-tinyusb.h"
19
+ // #include "esp_camera.h"
19
20
20
21
/* Time stamp base clock. It is a deprecated parameter. */
21
22
#define UVC_CLOCK_FREQUENCY 27000000
28
29
/* control */ \
29
30
+ TUD_VIDEO_DESC_STD_VC_LEN\
30
31
+ (TUD_VIDEO_DESC_CS_VC_LEN + 1 /* bInCollection*/ )\
31
- + TUD_VIDEO_DESC_INPUT_TERM_LEN \
32
+ + TUD_VIDEO_DESC_CAMERA_TERM_LEN \
32
33
+ TUD_VIDEO_DESC_OUTPUT_TERM_LEN\
33
34
/* Interface 1, Alternate 0 */ \
34
35
+ TUD_VIDEO_DESC_STD_VS_LEN\
54
55
TUD_VIDEO_DESC_CS_VS_FMT_UNCOMPR (_fmtidx, _numfmtdesc, TUD_VIDEO_GUID_I420, 12 , _frmidx, _asrx, _asry, _interlace, _cp)
55
56
56
57
#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), \
58
59
/* Video control 0 */ \
59
60
TUD_VIDEO_DESC_STD_VC(_itf, 0 , _stridx), \
60
61
TUD_VIDEO_DESC_CS_VC( /* UVC 1.5*/ 0x0150 , \
61
62
/* 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, \
63
64
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 ), \
65
68
TUD_VIDEO_DESC_OUTPUT_TERM(UVC_ENTITY_CAP_OUTPUT_TERMINAL, VIDEO_TT_STREAMING, 0 , 1 , 0 ), \
66
69
/* Video stream alt. 0 */ \
67
70
TUD_VIDEO_DESC_STD_VS( (_itf+1 ), 0, 0, 0), \
86
89
/* VS alt 1 */ \
87
90
TUD_VIDEO_DESC_STD_VS((_itf+1 ), 1, 1, 0), \
88
91
/* EP */ \
89
- TUD_VIDEO_DESC_EP_ISO (_epin, _epsize, 1 )
92
+ TUD_VIDEO_DESC_EP_BULK (_epin, _epsize, 1 )
90
93
91
94
92
95
ESP_EVENT_DEFINE_BASE(ARDUINO_USB_VIDEO_EVENTS);
93
96
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);
94
97
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);
95
98
96
- #define FRAME_WIDTH 80
97
- #define FRAME_HEIGHT 60
99
+ #define FRAME_WIDTH 160
100
+ #define FRAME_HEIGHT 120
98
101
#define FRAME_RATE 10
99
102
100
103
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)
103
106
uint8_t ep_num = tinyusb_get_free_in_endpoint ();
104
107
TU_VERIFY (ep_num != 0 );
105
108
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
107
110
TUD_VIDEO_CAPTURE_DESCRIPTOR (*itf, str_index, (uint8_t )(0x80 | ep_num), FRAME_WIDTH, FRAME_HEIGHT, FRAME_RATE, 64 )
108
111
};
109
112
*itf+=2 ;
110
113
memcpy (dst, descriptor, TUD_VIDEO_CAPTURE_DESC_LEN);
111
114
return TUD_VIDEO_CAPTURE_DESC_LEN;
112
- // size_t desc_len = sizeof(UVCConfigurationDescriptor);
113
- // memcpy(dst, UVCConfigurationDescriptor, desc_len);
114
- // return desc_len;
115
115
}
116
116
117
117
static unsigned frame_num = 0 ;
@@ -171,16 +171,32 @@ void video_task(void)
171
171
if (!already_sent) {
172
172
already_sent = 1 ;
173
173
start_ms = millis ();
174
+
175
+ log_d (" TX: %u" , frame_num);
174
176
fill_color_bar (frame_buffer, frame_num);
175
177
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
+ // }
176
184
}
177
185
178
186
unsigned cur = millis ();
179
187
if (cur - start_ms < interval_ms) return ; // not enough time
180
188
if (tx_busy) return ;
181
189
start_ms += interval_ms;
190
+
191
+ log_d (" TX: %u" , frame_num);
182
192
fill_color_bar (frame_buffer, frame_num);
183
193
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
+ // }
184
200
}
185
201
186
202
@@ -220,11 +236,61 @@ extern "C" int tud_video_power_mode_cb(uint_fast8_t ctl_idx, uint8_t power_mod){
220
236
221
237
USBVideo::USBVideo (uint8_t ctl, uint8_t stm):_ctl(ctl), _stm(stm){
222
238
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);
224
239
}
225
240
226
241
void USBVideo::begin (){
227
242
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
+ // }
228
294
}
229
295
230
296
void USBVideo::end (){
0 commit comments