29
29
30
30
#include "common/tusb_common.h"
31
31
32
+ enum {
33
+ VIDEO_BCD_1_50 = 0x0150 ,
34
+ };
35
+
32
36
// Table 3-19 Color Matching Descriptor
33
37
typedef enum {
34
38
VIDEO_COLOR_PRIMARIES_UNDEFINED = 0x00 ,
@@ -198,55 +202,98 @@ typedef enum {
198
202
} video_terminal_type_t ;
199
203
200
204
//--------------------------------------------------------------------+
201
- // Descriptors
205
+ // Video Control (VC) Descriptors
202
206
//--------------------------------------------------------------------+
203
207
204
208
/* 2.3.4.2 */
209
+ #define tusb_desc_video_control_header_nitf_t (_nitf ) \
210
+ struct TU_ATTR_PACKED { \
211
+ uint8_t bLength; \
212
+ uint8_t bDescriptorType; \
213
+ uint8_t bDescriptorSubType; \
214
+ uint16_t bcdUVC; \
215
+ uint16_t wTotalLength; \
216
+ uint32_t dwClockFrequency; /* deprecated */ \
217
+ uint8_t bInCollection ; \
218
+ uint8_t baInterfaceNr [_nitf ]; \
219
+ }
220
+
221
+ typedef tusb_desc_video_control_header_nitf_t ( ) tusb_desc_video_control_header_t ;
222
+ typedef tusb_desc_video_control_header_nitf_t (1 ) tusb_desc_video_control_header_1itf_t ;
223
+ typedef tusb_desc_video_control_header_nitf_t (2 ) tusb_desc_video_control_header_2itf_t ;
224
+ typedef tusb_desc_video_control_header_nitf_t (3 ) tusb_desc_video_control_header_3itf_t ;
225
+ typedef tusb_desc_video_control_header_nitf_t (4 ) tusb_desc_video_control_header_4itf_t ;
226
+
205
227
typedef struct TU_ATTR_PACKED {
206
228
uint8_t bLength ;
207
229
uint8_t bDescriptorType ;
208
230
uint8_t bDescriptorSubType ;
209
- uint16_t bcdUVC ;
210
- uint16_t wTotalLength ;
211
- uint32_t dwClockFrequency ;
212
- uint8_t bInCollection ;
213
- uint8_t baInterfaceNr [];
214
- } tusb_desc_cs_video_ctl_itf_hdr_t ;
231
+ uint8_t bTerminalID ;
232
+ uint16_t wTerminalType ;
233
+ uint8_t bAssocTerminal ;
234
+ uint8_t iTerminal ;
235
+ } tusb_desc_video_control_input_terminal_t ;
236
+
237
+ TU_VERIFY_STATIC (sizeof (tusb_desc_video_control_input_terminal_t ) == 8 , "size is not correct" );
215
238
216
- /* 2.4.3.3 */
217
239
typedef struct TU_ATTR_PACKED {
218
- uint8_t bHeaderLength ;
219
- union {
220
- uint8_t bmHeaderInfo ;
221
- struct {
222
- uint8_t FrameID : 1 ;
223
- uint8_t EndOfFrame : 1 ;
224
- uint8_t PresentationTime : 1 ;
225
- uint8_t SourceClockReference : 1 ;
226
- uint8_t PayloadSpecific : 1 ;
227
- uint8_t StillImage : 1 ;
228
- uint8_t Error : 1 ;
229
- uint8_t EndOfHeader : 1 ;
230
- };
231
- };
232
- } tusb_video_payload_header_t ;
240
+ uint8_t bLength ;
241
+ uint8_t bDescriptorType ;
242
+ uint8_t bDescriptorSubType ;
243
+ uint8_t bTerminalID ;
244
+ uint16_t wTerminalType ;
245
+ uint8_t bAssocTerminal ;
246
+ uint8_t bSourceID ;
247
+ uint8_t iTerminal ;
248
+ } tusb_desc_video_control_output_terminal_t ;
249
+
250
+ TU_VERIFY_STATIC (sizeof (tusb_desc_video_control_output_terminal_t ) == 9 , "size is not correct" );
233
251
234
- /* 3.9.2.1 */
235
252
typedef struct TU_ATTR_PACKED {
236
253
uint8_t bLength ;
237
254
uint8_t bDescriptorType ;
238
255
uint8_t bDescriptorSubType ;
239
- uint8_t bNumFormats ;
240
- uint16_t wTotalLength ;
241
- uint8_t bEndpointAddress ;
242
- uint8_t bmInfo ;
243
- uint8_t bTerminalLink ;
244
- uint8_t bStillCaptureMethod ;
245
- uint8_t bTriggerSupport ;
246
- uint8_t bTriggerUsage ;
256
+ uint8_t bTerminalID ;
257
+ uint16_t wTerminalType ;
258
+ uint8_t bAssocTerminal ;
259
+ uint8_t iTerminal ;
260
+
261
+ uint16_t wObjectiveFocalLengthMin ;
262
+ uint16_t wObjectiveFocalLengthMax ;
263
+ uint16_t wOcularFocalLength ;
247
264
uint8_t bControlSize ;
248
- uint8_t bmaControls [];
249
- } tusb_desc_cs_video_stm_itf_in_hdr_t ;
265
+ uint8_t bmControls [3 ];
266
+ } tusb_desc_video_control_camera_terminal_t ;
267
+
268
+ TU_VERIFY_STATIC (sizeof (tusb_desc_video_control_camera_terminal_t ) == 18 , "size is not correct" );
269
+
270
+ //--------------------------------------------------------------------+
271
+ // Video Streaming (VS) Descriptors
272
+ //--------------------------------------------------------------------+
273
+
274
+ /* 3.9.2.1 */
275
+ #define tusb_desc_video_streaming_input_header_nbyte_t (_nb ) \
276
+ struct TU_ATTR_PACKED { \
277
+ uint8_t bLength; \
278
+ uint8_t bDescriptorType; \
279
+ uint8_t bDescriptorSubType; \
280
+ uint8_t bNumFormats; /* Number of video payload Format descriptors for this interface */ \
281
+ uint16_t wTotalLength ; \
282
+ uint8_t bEndpointAddress ; \
283
+ uint8_t bmInfo ; /* Bit 0: dynamic format change supported */ \
284
+ uint8_t bTerminalLink ; \
285
+ uint8_t bStillCaptureMethod ; \
286
+ uint8_t bTriggerSupport ; /* Hardware trigger supported */ \
287
+ uint8_t bTriggerUsage ; \
288
+ uint8_t bControlSize ; /* sizeof of each control item */ \
289
+ uint8_t bmaControls [_nb ]; \
290
+ }
291
+
292
+ typedef tusb_desc_video_streaming_input_header_nbyte_t ( ) tusb_desc_video_streaming_input_header_t ;
293
+ typedef tusb_desc_video_streaming_input_header_nbyte_t (1 ) tusb_desc_video_streaming_input_header_1byte_t ;
294
+ typedef tusb_desc_video_streaming_input_header_nbyte_t (2 ) tusb_desc_video_streaming_input_header_2byte_t ;
295
+ typedef tusb_desc_video_streaming_input_header_nbyte_t (3 ) tusb_desc_video_streaming_input_header_3byte_t ;
296
+ typedef tusb_desc_video_streaming_input_header_nbyte_t (4 ) tusb_desc_video_streaming_input_header_4byte_t ;
250
297
251
298
/* 3.9.2.2 */
252
299
typedef struct TU_ATTR_PACKED {
@@ -259,7 +306,7 @@ typedef struct TU_ATTR_PACKED {
259
306
uint8_t bTerminalLink ;
260
307
uint8_t bControlSize ;
261
308
uint8_t bmaControls [];
262
- } tusb_desc_cs_video_stm_itf_out_hdr_t ;
309
+ } tusb_desc_video_streaming_output_header_t ;
263
310
264
311
typedef struct TU_ATTR_PACKED {
265
312
uint8_t bLength ;
@@ -285,46 +332,109 @@ typedef struct TU_ATTR_PACKED {
285
332
uint8_t bmaControls [];
286
333
} output ;
287
334
};
288
- } tusb_desc_cs_video_stm_itf_hdr_t ;
335
+ } tusb_desc_video_streaming_inout_header_t ;
289
336
337
+ // 3.9.2.6 Color Matching Descriptor
338
+ typedef struct TU_ATTR_PACKED {
339
+ uint8_t bLength ;
340
+ uint8_t bDescriptorType ;
341
+ uint8_t bDescriptorSubType ;
342
+ uint8_t bColorPrimaries ;
343
+ uint8_t bTransferCharacteristics ;
344
+ uint8_t bMatrixCoefficients ;
345
+ } tusb_desc_video_streaming_color_matching_t ;
346
+
347
+ TU_VERIFY_STATIC (sizeof (tusb_desc_video_streaming_color_matching_t ) == 6 , "size is not correct" );
348
+
349
+ //--------------------------------------------------------------------+
350
+ // Format and Frame Descriptor
351
+ // Note: bFormatIndex & bFrameIndex are 1-based index
352
+ //--------------------------------------------------------------------+
353
+
354
+ //------------- Uncompressed -------------//
355
+ // Uncompressed payload specs: 3.1.1 format descriptor
290
356
typedef struct TU_ATTR_PACKED {
291
357
uint8_t bLength ;
292
358
uint8_t bDescriptorType ;
293
359
uint8_t bDescriptorSubType ;
294
360
uint8_t bFormatIndex ;
295
- uint8_t bNumFrameDescriptors ;
361
+ uint8_t bNumFrameDescriptors ; // Number of frame descriptors for this format
296
362
uint8_t guidFormat [16 ];
297
363
uint8_t bBitsPerPixel ;
298
- uint8_t bDefaultFrameIndex ;
364
+ uint8_t bDefaultFrameIndex ; //
299
365
uint8_t bAspectRatioX ;
300
366
uint8_t bAspectRatioY ;
301
367
uint8_t bmInterlaceFlags ;
302
368
uint8_t bCopyProtect ;
303
- } tusb_desc_cs_video_fmt_uncompressed_t ;
304
-
369
+ } tusb_desc_video_format_uncompressed_t ;
370
+
371
+ // Uncompressed payload specs: 3.1.2 frame descriptor
372
+ #define tusb_desc_video_frame_uncompressed_nint_t (_nint ) \
373
+ struct TU_ATTR_PACKED { \
374
+ uint8_t bLength; \
375
+ uint8_t bDescriptorType; \
376
+ uint8_t bDescriptorSubType; \
377
+ uint8_t bFrameIndex; \
378
+ uint8_t bmCapabilities; \
379
+ uint16_t wWidth; \
380
+ uint16_t wHeight; \
381
+ uint32_t dwMinBitRate; \
382
+ uint32_t dwMaxBitRate; \
383
+ uint32_t dwMaxVideoFrameBufferSize; /* deprecated in 1.5 */ \
384
+ uint32_t dwDefaultFrameInterval ; \
385
+ uint8_t bFrameIntervalType ; \
386
+ uint32_t dwFrameInterval [_nint ]; \
387
+ }
388
+
389
+ typedef tusb_desc_video_frame_uncompressed_nint_t ( ) tusb_desc_video_frame_uncompressed_t ;
390
+ typedef tusb_desc_video_frame_uncompressed_nint_t (1 ) tusb_desc_video_frame_uncompressed_1int_t ;
391
+ typedef tusb_desc_video_frame_uncompressed_nint_t (2 ) tusb_desc_video_frame_uncompressed_2int_t ;
392
+ typedef tusb_desc_video_frame_uncompressed_nint_t (3 ) tusb_desc_video_frame_uncompressed_3int_t ;
393
+ typedef tusb_desc_video_frame_uncompressed_nint_t (4 ) tusb_desc_video_frame_uncompressed_4int_t ;
394
+
395
+ // continuous = 3 intervals: min, max, step
396
+ typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_uncompressed_continuous_t ;
397
+
398
+ TU_VERIFY_STATIC (sizeof (tusb_desc_video_frame_uncompressed_continuous_t ) == 38 , "size is not correct" );
399
+
400
+ //------------- MJPEG -------------//
401
+ // MJPEG payload specs: 3.1.1 format descriptor
305
402
typedef struct TU_ATTR_PACKED {
306
403
uint8_t bLength ;
307
404
uint8_t bDescriptorType ;
308
405
uint8_t bDescriptorSubType ;
309
406
uint8_t bFormatIndex ;
310
407
uint8_t bNumFrameDescriptors ;
311
- uint8_t bmFlags ;
408
+ uint8_t bmFlags ; // Bit 0: fixed size samples (1 = yes)
312
409
uint8_t bDefaultFrameIndex ;
313
410
uint8_t bAspectRatioX ;
314
411
uint8_t bAspectRatioY ;
315
412
uint8_t bmInterlaceFlags ;
316
413
uint8_t bCopyProtect ;
317
- } tusb_desc_cs_video_fmt_mjpeg_t ;
414
+ } tusb_desc_video_format_mjpeg_t ;
318
415
416
+ // MJPEG payload specs: 3.1.2 frame descriptor (same as uncompressed)
417
+ typedef tusb_desc_video_frame_uncompressed_t tusb_desc_video_frame_mjpeg_t ;
418
+ typedef tusb_desc_video_frame_uncompressed_1int_t tusb_desc_video_frame_mjpeg_1int_t ;
419
+ typedef tusb_desc_video_frame_uncompressed_2int_t tusb_desc_video_frame_mjpeg_2int_t ;
420
+ typedef tusb_desc_video_frame_uncompressed_3int_t tusb_desc_video_frame_mjpeg_3int_t ;
421
+ typedef tusb_desc_video_frame_uncompressed_4int_t tusb_desc_video_frame_mjpeg_4int_t ;
422
+
423
+ // continuous = 3 intervals: min, max, step
424
+ typedef tusb_desc_video_frame_mjpeg_3int_t tusb_desc_video_frame_mjpeg_continuous_t ;
425
+
426
+ //------------- DV -------------//
427
+ // DV payload specs: 3.1.1
319
428
typedef struct TU_ATTR_PACKED {
320
429
uint8_t bLength ;
321
430
uint8_t bDescriptorType ;
322
431
uint8_t bDescriptorSubType ;
323
432
uint8_t bFormatIndex ;
324
433
uint32_t dwMaxVideoFrameBufferSize ; /* deprecated */
325
434
uint8_t bFormatType ;
326
- } tusb_desc_cs_video_fmt_dv_t ;
435
+ } tusb_desc_video_format_dv_t ;
327
436
437
+ // Frame Based payload specs: 3.1.1
328
438
typedef struct TU_ATTR_PACKED {
329
439
uint8_t bLength ;
330
440
uint8_t bDescriptorType ;
@@ -339,25 +449,7 @@ typedef struct TU_ATTR_PACKED {
339
449
uint8_t bmInterlaceFlags ;
340
450
uint8_t bCopyProtect ;
341
451
uint8_t bVaribaleSize ;
342
- } tusb_desc_cs_video_fmt_frame_based_t ;
343
-
344
- typedef struct TU_ATTR_PACKED {
345
- uint8_t bLength ;
346
- uint8_t bDescriptorType ;
347
- uint8_t bDescriptorSubType ;
348
- uint8_t bFrameIndex ;
349
- uint8_t bmCapabilities ;
350
- uint16_t wWidth ;
351
- uint16_t wHeight ;
352
- uint32_t dwMinBitRate ;
353
- uint32_t dwMaxBitRate ;
354
- uint32_t dwMaxVideoFrameBufferSize ; /* deprecated */
355
- uint32_t dwDefaultFrameInterval ;
356
- uint8_t bFrameIntervalType ;
357
- uint32_t dwFrameInterval [];
358
- } tusb_desc_cs_video_frm_uncompressed_t ;
359
-
360
- typedef tusb_desc_cs_video_frm_uncompressed_t tusb_desc_cs_video_frm_mjpeg_t ;
452
+ } tusb_desc_video_format_framebased_t ;
361
453
362
454
typedef struct TU_ATTR_PACKED {
363
455
uint8_t bLength ;
@@ -373,12 +465,30 @@ typedef struct TU_ATTR_PACKED {
373
465
uint8_t bFrameIntervalType ;
374
466
uint32_t dwBytesPerLine ;
375
467
uint32_t dwFrameInterval [];
376
- } tusb_desc_cs_video_frm_frame_based_t ;
468
+ } tusb_desc_video_frame_framebased_t ;
377
469
378
470
//--------------------------------------------------------------------+
379
471
// Requests
380
472
//--------------------------------------------------------------------+
381
473
474
+ /* 2.4.3.3 */
475
+ typedef struct TU_ATTR_PACKED {
476
+ uint8_t bHeaderLength ;
477
+ union {
478
+ uint8_t bmHeaderInfo ;
479
+ struct {
480
+ uint8_t FrameID : 1 ;
481
+ uint8_t EndOfFrame : 1 ;
482
+ uint8_t PresentationTime : 1 ;
483
+ uint8_t SourceClockReference : 1 ;
484
+ uint8_t PayloadSpecific : 1 ;
485
+ uint8_t StillImage : 1 ;
486
+ uint8_t Error : 1 ;
487
+ uint8_t EndOfHeader : 1 ;
488
+ };
489
+ };
490
+ } tusb_video_payload_header_t ;
491
+
382
492
/* 4.3.1.1 */
383
493
typedef struct TU_ATTR_PACKED {
384
494
union {
@@ -537,7 +647,7 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
537
647
/* Motion-JPEG 3.1.1 Table 3-2 and 3-4 */
538
648
#define TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_DISC (_frmidx , _cap , _width , _height , _minbr , _maxbr , _maxfrmbufsz , _frminterval , ...) \
539
649
TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_DISC_LEN + (TU_ARGS_NUM(__VA_ARGS__)) * 4, \
540
- TUSB_DESC_CS_INTERFACE, VIDEO_CS_VS_INTERFACE_FRAME_MJPEG , \
650
+ TUSB_DESC_CS_INTERFACE, VIDEO_CS_ITF_VS_FRAME_MJPEG , \
541
651
_frmidx, _cap, U16_TO_U8S_LE(_width), U16_TO_U8S_LE(_height), U32_TO_U8S_LE(_minbr), U32_TO_U8S_LE(_maxbr), \
542
652
U32_TO_U8S_LE(_maxfrmbufsz), U32_TO_U8S_LE(_frminterval), (TU_ARGS_NUM(__VA_ARGS__)), __VA_ARGS__
543
653
0 commit comments