-
Notifications
You must be signed in to change notification settings - Fork 7k
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
drivers: video: introduce semantics for enum endpoint_id
#73009
drivers: video: introduce semantics for enum endpoint_id
#73009
Conversation
@CharlesDias FYI |
would it make sense to have a bit assigned to OUT/IN in the ID and corresponding macro, so that we can have some type enforcement, like |
It could be an extra (A) This can be a nibble: (B) This can be a byte: (C) This can be a nibble after bytes: This can also be hidden behind a macro on the With the matching macro definitions in C, i.e. for a nibble: [EDIT: selected option (A)] |
8229acb
to
2bbfd19
Compare
I changed
Extra |
@josuah please address the CI issues |
Yes, some more API changes are needed. converting back to a draft, sorry for the burden involved. |
drivers/video/video_mcux_csi.c
Outdated
@@ -121,7 +121,16 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_ | |||
unsigned int bpp = video_pix_fmt_bpp(fmt->pixelformat); | |||
status_t ret; | |||
|
|||
if (!bpp || ep != VIDEO_EP_OUT) { | |||
switch (ep) { |
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.
That repeated pattern would probably deserve a macro or function.
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.
I will propose something in another PR when there will be a pretext to touch to the video drivers again (to limit review burden), but it seems possible to use macros with the new scheme:
#define VIDEO_EP_OUT_SELECTED(ep, match) \
((ep) == VIDEO_EP_OUT || (ep) == VIDEO_EP_ALL || (ep) == (match))
#define VIDEO_EP_IN_SELECTED(ep, match) \
((ep) == VIDEO_EP_IN || (ep) == VIDEO_EP_ALL || (ep) == (match))
/* Filter away, 0x00 used when only 1 endpoint supported */
if (bpp == 0 || !VIDEO_EP_OUT_SELECTED(ep, 0x00)) {
return -EINVAL;
}
/* Matches endpoint 0x00 or 0x01 or 0x02 */
if (VIDEO_EP_OUT_SELECTED(ep, 0x00)) {
work_on_ep0();
}
if (VIDEO_EP_OUT_SELECTED(ep, 0x01)) {
work_on_ep1();
}
if (VIDEO_EP_IN_SELECTED(ep, 0x02)) {
work_on_ep2();
}
/* If ep == VIDEO_EP_ALL, then all endpoint are enacted... this works */
2bbfd19
to
86a99a2
Compare
Here is a simpler, less intrusive attempt: just give negative values to |
@@ -449,7 +453,7 @@ static inline int video_stream_stop(const struct device *dev) | |||
} | |||
|
|||
ret = api->stream_stop(dev); | |||
video_flush(dev, VIDEO_EP_ANY, true); |
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.
This is the only place I have found VIDEO_EP_ANY
used.
If video_endpoint_id
is a direction, "ANY" makes a lot of sense, but if allowing it to be an endpoint number, "ALL" seems less ambiguous (i.e. here flushing all endpoints rather than flushing endpoints for any direction).
include/zephyr/drivers/video.h
Outdated
/** Targets some part of the video device not bound to an endpoint */ | ||
VIDEO_EP_NONE = -1, | ||
/** Targets all input or output endpoints of the device */ | ||
VIDEO_EP_ALL = -2, | ||
/** Targets all input endpoints of the device */ | ||
VIDEO_EP_IN = -3, | ||
/** Targets all output endpoints of the device */ | ||
VIDEO_EP_OUT = -4, |
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.
This does not encode any direction information into the video_endpoint_id
, which allow using endpoint IDs exactly as in the manufacturer datasheet. Does it make sense?
drivers/video/video_mcux_csi.c
Outdated
@@ -155,7 +155,7 @@ static int video_mcux_csi_set_fmt(const struct device *dev, enum video_endpoint_ | |||
status_t ret; | |||
struct video_format format = *fmt; | |||
|
|||
if (!bpp || ep != VIDEO_EP_OUT) { | |||
if (bpp != 0 || (ep != VIDEO_EP_OUT && ep != VIDEO_EP_ALL)) { |
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.
Changing !bpp
to bpp != 0
in the process, let me know if I should avoid it.
[EDIT: sorry I should pay more attention! !bpp
is bpp == 0
!]
86a99a2
to
bea302c
Compare
This define the enum values so that they never clash with custom endpoint IDs passed numerically, for devices that supports more than one IN or OUT enpoint. This also documents semantics for VIDEO_EP_IN/OUT/ALL/NONE, while renaming VIDEO_EP_ANY to VIDEO_EP_ALL to remove the ambiguity when there are several IN and/or OUT endpoints. Signed-off-by: Josuah Demangeon <[email protected]>
As pointed out by @XenuIsWatching, one use-case would be:
Something like this could work after this gets merged: /* Configure format RGB on 0 and InfraRed on 1 */
video_set_format(video_dev, 0, &fmt_rgb);
video_set_format(video_dev, 1, &fmt_ir);
/* Enqueue transfers separately to endpoints 0 and 1 */
video_enqueue(video_dev, 0, &vbuf_rgb);
video_enqueue(video_dev, 1, &vbuf_ir);
/* Enqueue transfers on both endpoints at the same time in the same feed */
video_enqueue(video_dev, VIDEO_EP_OUT, &vbuf_either); Maybe a flag would need to be added to |
Folks, I'm the assignee because I guess I won the files touched lottery. I need some of the relevant subject matter experts to weigh in and give their +1/-1 so we can move this PR along. |
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.
LGTM
bea302c
to
7745d17
Compare
The current video drivers did not allow VIDEO_EP_ALL to be selected, as used by video_stream_stop(). This adds the VIDEO_EP_ALL to each video driver that filtered endpoints. Signed-off-by: Josuah Demangeon <[email protected]>
7745d17
to
4efb6b8
Compare
Sorry, I did a beginner mistake by converting |
@loicpoulain can you give this a +1 then? @erwango and ST driver was also touched so +1? |
This is part of a series of proposal for incremental changes for the Video API:
This adds slightly new semantics for
endpoint_id
:IN
is not "the main input endpoint" anymore but "each and every input endpoint"OUT
is not "the main output endpoint" anymore but "each and every output endpoint"ANY
ALL
is not "one endpoint of choice" anymore but "every single endpoint"NONE
is not "does not affect any interface" anymore but "affects something not bound to any interface"