-
Notifications
You must be signed in to change notification settings - Fork 9.1k
usb: device_next: uvc: move files to common directory #103369
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| # SPDX-FileCopyrightText: Copyright Nordic Semiconductor ASA | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_include_directories(include) | ||
| if(CONFIG_USBD_VIDEO_CLASS) | ||
| zephyr_include_directories(.) | ||
| zephyr_sources(uvc.c) | ||
| endif() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright tinyVision.ai Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include <zephyr/drivers/video-controls.h> | ||
| #include <zephyr/drivers/video.h> | ||
| #include <zephyr/sys/byteorder.h> | ||
|
|
||
| #include "uvc.h" | ||
|
|
||
| static const struct uvc_guid_quirk uvc_guid_quirks[] = { | ||
| { | ||
| .fourcc = VIDEO_PIX_FMT_YUYV, | ||
| .guid = UVC_FORMAT_GUID("YUY2"), | ||
| }, | ||
| { | ||
| .fourcc = VIDEO_PIX_FMT_GREY, | ||
| .guid = UVC_FORMAT_GUID("Y800"), | ||
| }, | ||
| }; | ||
|
|
||
| static const struct uvc_control_map uvc_control_map_ct[] = { | ||
| { | ||
| .size = 1, | ||
| .bit = 1, | ||
| .selector = UVC_CT_AE_MODE_CONTROL, | ||
| .cid = VIDEO_CID_EXPOSURE_AUTO, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 1, | ||
| .bit = 2, | ||
| .selector = UVC_CT_AE_PRIORITY_CONTROL, | ||
| .cid = VIDEO_CID_EXPOSURE_AUTO_PRIORITY, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 4, | ||
| .bit = 3, | ||
| .selector = UVC_CT_EXPOSURE_TIME_ABS_CONTROL, | ||
| .cid = VIDEO_CID_EXPOSURE, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 5, | ||
| .selector = UVC_CT_FOCUS_ABS_CONTROL, | ||
| .cid = VIDEO_CID_FOCUS_ABSOLUTE, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 6, | ||
| .selector = UVC_CT_FOCUS_REL_CONTROL, | ||
| .cid = VIDEO_CID_FOCUS_RELATIVE, | ||
| .type = UVC_CONTROL_SIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 7, | ||
| .selector = UVC_CT_IRIS_ABS_CONTROL, | ||
| .cid = VIDEO_CID_IRIS_ABSOLUTE, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 1, | ||
| .bit = 8, | ||
| .selector = UVC_CT_IRIS_REL_CONTROL, | ||
| .cid = VIDEO_CID_IRIS_RELATIVE, | ||
| .type = UVC_CONTROL_SIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 9, | ||
| .selector = UVC_CT_ZOOM_ABS_CONTROL, | ||
| .cid = VIDEO_CID_ZOOM_ABSOLUTE, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 3, | ||
| .bit = 10, | ||
| .selector = UVC_CT_ZOOM_REL_CONTROL, | ||
| .cid = VIDEO_CID_ZOOM_RELATIVE, | ||
| .type = UVC_CONTROL_SIGNED, | ||
| }, | ||
| }; | ||
|
|
||
| static const struct uvc_control_map uvc_control_map_pu[] = { | ||
| { | ||
| .size = 2, | ||
| .bit = 0, | ||
| .selector = UVC_PU_BRIGHTNESS_CONTROL, | ||
| .cid = VIDEO_CID_BRIGHTNESS, | ||
| .type = UVC_CONTROL_SIGNED, | ||
| }, | ||
| { | ||
| .size = 1, | ||
| .bit = 1, | ||
| .selector = UVC_PU_CONTRAST_CONTROL, | ||
| .cid = VIDEO_CID_CONTRAST, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 9, | ||
| .selector = UVC_PU_GAIN_CONTROL, | ||
| .cid = VIDEO_CID_GAIN, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 3, | ||
| .selector = UVC_PU_SATURATION_CONTROL, | ||
| .cid = VIDEO_CID_SATURATION, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 2, | ||
| .bit = 6, | ||
| .selector = UVC_PU_WHITE_BALANCE_TEMP_CONTROL, | ||
| .cid = VIDEO_CID_WHITE_BALANCE_TEMPERATURE, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| }; | ||
|
|
||
| static const struct uvc_control_map uvc_control_map_su[] = { | ||
| { | ||
| .size = 1, | ||
| .bit = 0, | ||
| .selector = UVC_SU_INPUT_SELECT_CONTROL, | ||
| .cid = VIDEO_CID_TEST_PATTERN, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| }; | ||
|
|
||
| static const struct uvc_control_map uvc_control_map_xu[] = { | ||
| { | ||
| .size = 4, | ||
| .bit = 0, | ||
| .selector = UVC_XU_BASE_CONTROL + 0, | ||
| .cid = VIDEO_CID_PRIVATE_BASE + 0, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 4, | ||
| .bit = 1, | ||
| .selector = UVC_XU_BASE_CONTROL + 1, | ||
| .cid = VIDEO_CID_PRIVATE_BASE + 1, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 4, | ||
| .bit = 2, | ||
| .selector = UVC_XU_BASE_CONTROL + 2, | ||
| .cid = VIDEO_CID_PRIVATE_BASE + 2, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| { | ||
| .size = 4, | ||
| .bit = 3, | ||
| .selector = UVC_XU_BASE_CONTROL + 3, | ||
| .cid = VIDEO_CID_PRIVATE_BASE + 3, | ||
| .type = UVC_CONTROL_UNSIGNED, | ||
| }, | ||
| }; | ||
|
|
||
| int uvc_get_control_map(uint8_t subtype, const struct uvc_control_map **map, size_t *length) | ||
| { | ||
| switch (subtype) { | ||
| case UVC_VC_INPUT_TERMINAL: | ||
| *map = uvc_control_map_ct; | ||
| *length = ARRAY_SIZE(uvc_control_map_ct); | ||
| break; | ||
| case UVC_VC_SELECTOR_UNIT: | ||
| *map = uvc_control_map_su; | ||
| *length = ARRAY_SIZE(uvc_control_map_su); | ||
| break; | ||
| case UVC_VC_PROCESSING_UNIT: | ||
| *map = uvc_control_map_pu; | ||
| *length = ARRAY_SIZE(uvc_control_map_pu); | ||
| break; | ||
| case UVC_VC_EXTENSION_UNIT: | ||
| *map = uvc_control_map_xu; | ||
| *length = ARRAY_SIZE(uvc_control_map_xu); | ||
| break; | ||
| default: | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void uvc_fourcc_to_guid(uint8_t guid[16], const uint32_t fourcc) | ||
| { | ||
| uint32_t fourcc_le; | ||
|
|
||
| /* Lookup in the "quirk table" if the UVC format GUID is custom */ | ||
| for (int i = 0; i < ARRAY_SIZE(uvc_guid_quirks); i++) { | ||
| if (uvc_guid_quirks[i].fourcc == fourcc) { | ||
| memcpy(guid, uvc_guid_quirks[i].guid, 16); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| /* By default, UVC GUIDs are the four character code followed by a common suffix */ | ||
| fourcc_le = sys_cpu_to_le32(fourcc); | ||
| /* Copy the common suffix with the GUID set to 'XXXX' */ | ||
| memcpy(guid, UVC_FORMAT_GUID("XXXX"), 16); | ||
| /* Replace the 'XXXX' by the actual GUID of the format */ | ||
| memcpy(guid, &fourcc_le, 4); | ||
| } | ||
|
|
||
| uint32_t uvc_guid_to_fourcc(const uint8_t guid[16]) | ||
| { | ||
| uint32_t fourcc; | ||
|
|
||
| /* Lookup in the "quirk table" if the UVC format GUID is custom */ | ||
| for (int i = 0; i < ARRAY_SIZE(uvc_guid_quirks); i++) { | ||
| if (memcmp(guid, uvc_guid_quirks[i].guid, 16) == 0) { | ||
| return uvc_guid_quirks[i].fourcc; | ||
| } | ||
| } | ||
|
|
||
| /* Extract the four character code out of the leading 4 bytes of the GUID */ | ||
| memcpy(&fourcc, guid, 4); | ||
| fourcc = sys_le32_to_cpu(fourcc); | ||
|
|
||
| return fourcc; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use
uvc.cin CMakeLists.txt in commit prior to whereuvc.cis introduced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes my bad, there was some bad rebase happening.
I think I fixed it in API3 without fixing it in
uvc_common.