Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance UVC decriptors and example #2435

Merged
merged 5 commits into from
Jan 29, 2024
Merged

Enhance UVC decriptors and example #2435

merged 5 commits into from
Jan 29, 2024

Conversation

hathach
Copy link
Owner

@hathach hathach commented Jan 29, 2024

Describe the PR
UVC (as well as UAC) has a sophisticated configuration descriptor depending on user application, which make defining template macros rather difficult. I have update video_capture example to use custom struct to define uvc configuration descriptor. In my opinion, it make thing a bit clearer and easier to customize and troubleshoot descriptor typo/errors.

I also rename some of the video descritpor add several variant of struct/typedef with different number of trailing object. Since C only allow flexible array as the last member of a struct (custom configuration requires as few instance of these struct). There is still more update but @kkitayam please review and let me know what do you think

#define tusb_desc_video_control_header_nitf_t(_nitf) \
  struct TU_ATTR_PACKED { \
    uint8_t  bLength; \
    uint8_t  bDescriptorType; \
    uint8_t  bDescriptorSubType; \
    uint16_t bcdUVC; \
    uint16_t wTotalLength; \
    uint32_t dwClockFrequency; /* deprecated */ \
    uint8_t  bInCollection; \
    uint8_t  baInterfaceNr[_nitf]; \
  }

typedef tusb_desc_video_control_header_nitf_t()  tusb_desc_video_control_header_t;
typedef tusb_desc_video_control_header_nitf_t(1) tusb_desc_video_control_header_1itf_t;
typedef tusb_desc_video_control_header_nitf_t(2) tusb_desc_video_control_header_2itf_t;
typedef tusb_desc_video_control_header_nitf_t(3) tusb_desc_video_control_header_3itf_t;
typedef tusb_desc_video_control_header_nitf_t(4) tusb_desc_video_control_header_4itf_t;

use struct to define uvc descriptor for video_capture since uvc is
rather too complicated to use macro templates
@hathach hathach requested a review from kkitayam January 29, 2024 04:25
src/class/video/video.h Outdated Show resolved Hide resolved
@kkitayam
Copy link
Collaborator

As you said, I agree that defining descriptors using macros was very difficult. I think the method you suggested is very wonderful. Above all, I think it is good that the compiler’s type checking can be used, so that errors can be detected earlier.

@hathach
Copy link
Owner Author

hathach commented Jan 29, 2024

As you said, I agree that defining descriptors using macros was very difficult. I think the method you suggested is very wonderful. Above all, I think it is good that the compiler’s type checking can be used, so that errors can be detected earlier.

thank you very much for your review, glad that makes sense. The macro template in example will be still kept there for referennce

@hathach hathach merged commit b4c0530 into master Jan 29, 2024
94 checks passed
@hathach hathach deleted the enhance-uvc branch January 29, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants