Skip to content

Commit 5564bbd

Browse files
committed
update tinyusb to have lastest uvc upstream
1 parent 766a14b commit 5564bbd

File tree

4 files changed

+254
-178
lines changed

4 files changed

+254
-178
lines changed

src/class/cdc/cdc_host.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ typedef struct {
8585
uint8_t bInterfaceSubClass;
8686
uint8_t bInterfaceProtocol;
8787

88+
uint8_t ep_notif;
8889
uint8_t serial_drid; // Serial Driver ID
90+
bool mounted; // Enumeration is complete
8991
cdc_acm_capability_t acm_capability;
90-
uint8_t ep_notif;
9192

92-
uint8_t line_state; // DTR (bit0), RTS (bit1)
9393
TU_ATTR_ALIGNED(4) cdc_line_coding_t line_coding; // Baudrate, stop bits, parity, data width
94+
uint8_t line_state; // DTR (bit0), RTS (bit1)
9495

9596
#if CFG_TUH_CDC_FTDI || CFG_TUH_CDC_CP210X || CFG_TUH_CDC_CH34X
9697
cdc_line_coding_t requested_line_coding;
@@ -337,7 +338,8 @@ bool tuh_cdc_itf_get_info(uint8_t idx, tuh_itf_info_t* info) {
337338

338339
bool tuh_cdc_mounted(uint8_t idx) {
339340
cdch_interface_t* p_cdc = get_itf(idx);
340-
return p_cdc != NULL;
341+
TU_VERIFY(p_cdc);
342+
return p_cdc->mounted;
341343
}
342344

343345
bool tuh_cdc_get_dtr(uint8_t idx) {
@@ -676,9 +678,9 @@ void cdch_close(uint8_t daddr) {
676678
// Invoke application callback
677679
if (tuh_cdc_umount_cb) tuh_cdc_umount_cb(idx);
678680

679-
//tu_memclr(p_cdc, sizeof(cdch_interface_t));
680681
p_cdc->daddr = 0;
681682
p_cdc->bInterfaceNumber = 0;
683+
p_cdc->mounted = false;
682684
tu_edpt_stream_close(&p_cdc->stream.tx);
683685
tu_edpt_stream_close(&p_cdc->stream.rx);
684686
}
@@ -779,6 +781,7 @@ bool cdch_open(uint8_t rhport, uint8_t daddr, tusb_desc_interface_t const *itf_d
779781

780782
static void set_config_complete(cdch_interface_t * p_cdc, uint8_t idx, uint8_t itf_num) {
781783
TU_LOG_DRV("CDCh Set Configure complete\r\n");
784+
p_cdc->mounted = true;
782785
if (tuh_cdc_mount_cb) tuh_cdc_mount_cb(idx);
783786

784787
// Prepare for incoming data

src/class/video/video.h

Lines changed: 174 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#include "common/tusb_common.h"
3131

32+
enum {
33+
VIDEO_BCD_1_50 = 0x0150,
34+
};
35+
3236
// Table 3-19 Color Matching Descriptor
3337
typedef enum {
3438
VIDEO_COLOR_PRIMARIES_UNDEFINED = 0x00,
@@ -198,55 +202,98 @@ typedef enum {
198202
} video_terminal_type_t;
199203

200204
//--------------------------------------------------------------------+
201-
// Descriptors
205+
// Video Control (VC) Descriptors
202206
//--------------------------------------------------------------------+
203207

204208
/* 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+
205227
typedef struct TU_ATTR_PACKED {
206228
uint8_t bLength;
207229
uint8_t bDescriptorType;
208230
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");
215238

216-
/* 2.4.3.3 */
217239
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");
233251

234-
/* 3.9.2.1 */
235252
typedef struct TU_ATTR_PACKED {
236253
uint8_t bLength;
237254
uint8_t bDescriptorType;
238255
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;
247264
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;
250297

251298
/* 3.9.2.2 */
252299
typedef struct TU_ATTR_PACKED {
@@ -259,7 +306,7 @@ typedef struct TU_ATTR_PACKED {
259306
uint8_t bTerminalLink;
260307
uint8_t bControlSize;
261308
uint8_t bmaControls[];
262-
} tusb_desc_cs_video_stm_itf_out_hdr_t;
309+
} tusb_desc_video_streaming_output_header_t;
263310

264311
typedef struct TU_ATTR_PACKED {
265312
uint8_t bLength;
@@ -285,46 +332,109 @@ typedef struct TU_ATTR_PACKED {
285332
uint8_t bmaControls[];
286333
} output;
287334
};
288-
} tusb_desc_cs_video_stm_itf_hdr_t;
335+
} tusb_desc_video_streaming_inout_header_t;
289336

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
290356
typedef struct TU_ATTR_PACKED {
291357
uint8_t bLength;
292358
uint8_t bDescriptorType;
293359
uint8_t bDescriptorSubType;
294360
uint8_t bFormatIndex;
295-
uint8_t bNumFrameDescriptors;
361+
uint8_t bNumFrameDescriptors; // Number of frame descriptors for this format
296362
uint8_t guidFormat[16];
297363
uint8_t bBitsPerPixel;
298-
uint8_t bDefaultFrameIndex;
364+
uint8_t bDefaultFrameIndex; //
299365
uint8_t bAspectRatioX;
300366
uint8_t bAspectRatioY;
301367
uint8_t bmInterlaceFlags;
302368
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
305402
typedef struct TU_ATTR_PACKED {
306403
uint8_t bLength;
307404
uint8_t bDescriptorType;
308405
uint8_t bDescriptorSubType;
309406
uint8_t bFormatIndex;
310407
uint8_t bNumFrameDescriptors;
311-
uint8_t bmFlags;
408+
uint8_t bmFlags; // Bit 0: fixed size samples (1 = yes)
312409
uint8_t bDefaultFrameIndex;
313410
uint8_t bAspectRatioX;
314411
uint8_t bAspectRatioY;
315412
uint8_t bmInterlaceFlags;
316413
uint8_t bCopyProtect;
317-
} tusb_desc_cs_video_fmt_mjpeg_t;
414+
} tusb_desc_video_format_mjpeg_t;
318415

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
319428
typedef struct TU_ATTR_PACKED {
320429
uint8_t bLength;
321430
uint8_t bDescriptorType;
322431
uint8_t bDescriptorSubType;
323432
uint8_t bFormatIndex;
324433
uint32_t dwMaxVideoFrameBufferSize; /* deprecated */
325434
uint8_t bFormatType;
326-
} tusb_desc_cs_video_fmt_dv_t;
435+
} tusb_desc_video_format_dv_t;
327436

437+
// Frame Based payload specs: 3.1.1
328438
typedef struct TU_ATTR_PACKED {
329439
uint8_t bLength;
330440
uint8_t bDescriptorType;
@@ -339,25 +449,7 @@ typedef struct TU_ATTR_PACKED {
339449
uint8_t bmInterlaceFlags;
340450
uint8_t bCopyProtect;
341451
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;
361453

362454
typedef struct TU_ATTR_PACKED {
363455
uint8_t bLength;
@@ -373,12 +465,30 @@ typedef struct TU_ATTR_PACKED {
373465
uint8_t bFrameIntervalType;
374466
uint32_t dwBytesPerLine;
375467
uint32_t dwFrameInterval[];
376-
} tusb_desc_cs_video_frm_frame_based_t;
468+
} tusb_desc_video_frame_framebased_t;
377469

378470
//--------------------------------------------------------------------+
379471
// Requests
380472
//--------------------------------------------------------------------+
381473

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+
382492
/* 4.3.1.1 */
383493
typedef struct TU_ATTR_PACKED {
384494
union {
@@ -537,7 +647,7 @@ TU_VERIFY_STATIC( sizeof(video_probe_and_commit_control_t) == 48, "size is not c
537647
/* Motion-JPEG 3.1.1 Table 3-2 and 3-4 */
538648
#define TUD_VIDEO_DESC_CS_VS_FRM_MJPEG_DISC(_frmidx, _cap, _width, _height, _minbr, _maxbr, _maxfrmbufsz, _frminterval, ...) \
539649
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, \
541651
_frmidx, _cap, U16_TO_U8S_LE(_width), U16_TO_U8S_LE(_height), U32_TO_U8S_LE(_minbr), U32_TO_U8S_LE(_maxbr), \
542652
U32_TO_U8S_LE(_maxfrmbufsz), U32_TO_U8S_LE(_frminterval), (TU_ARGS_NUM(__VA_ARGS__)), __VA_ARGS__
543653

0 commit comments

Comments
 (0)