Skip to content

Commit

Permalink
usb: device_next: uvc: merge macros into the main file
Browse files Browse the repository at this point in the history
Signed-off-by: Josuah Demangeon <[email protected]>
  • Loading branch information
josuah committed Oct 20, 2024
1 parent a6430ab commit a70b411
Show file tree
Hide file tree
Showing 6 changed files with 662 additions and 674 deletions.
21 changes: 4 additions & 17 deletions drivers/video/video_emul_imager.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/video.h>
#include <zephyr/drivers/video-controls.h>
#include <zephyr/drivers/video-formats.h>
#include <zephyr/drivers/i2c.h>
#include <zephyr/logging/log.h>

Expand Down Expand Up @@ -375,7 +376,8 @@ static void emul_imager_fill_framebuffer(const struct device *const dev, struct
}
break;
default:
LOG_WRN("unsupported pixel format %x", fmt->pixelformat);
LOG_WRN("Unsupported pixel format %x, supported: %x, %x",
fmt->pixelformat, VIDEO_PIX_FMT_YUYV, VIDEO_PIX_FMT_RGB565);
memset(fb16, 0, fmt->pitch);
}

Expand Down Expand Up @@ -451,21 +453,6 @@ static int emul_imager_get_caps(const struct device *dev, enum video_endpoint_id
return 0;
}

static int emul_imager_bpp(struct video_format *fmt)
{
switch (fmt->pixelformat) {
case VIDEO_PIX_FMT_BGGR8:
return 1;
case VIDEO_PIX_FMT_RGB565:
case VIDEO_PIX_FMT_YUYV:
return 2;
default:
LOG_WRN("querying an unsupported format %x %ux%u",
fmt->pixelformat, fmt->width, fmt->height);
return 0;
}
}

static int emul_imager_stream_start(const struct device *dev)
{
return emul_imager_write_reg(dev, EMUL_IMAGER_REG_CTRL, 1);
Expand Down Expand Up @@ -515,7 +502,7 @@ int emul_imager_init(const struct device *dev)
fmt.pixelformat = fmts[0].pixelformat;
fmt.width = fmts[0].width_min;
fmt.height = fmts[0].height_min;
fmt.pitch = fmt.width * emul_imager_bpp(&fmt);
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / 8;

ret = emul_imager_set_fmt(dev, VIDEO_EP_OUT, &fmt);
if (ret < 0) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/video/video_emul_mipi_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ int emul_mipi_rx_init(const struct device *dev)
fmt.pixelformat = fmts[0].pixelformat;
fmt.width = fmts[0].width_max;
fmt.height = fmts[0].height_max;
fmt.pitch = fmt.width * (fmt.pixelformat == VIDEO_PIX_FMT_BGGR8 ? 1 : 2);
fmt.pitch = fmt.width * video_bits_per_pixel(fmt.pixelformat) / 8;

return emul_mipi_rx_set_fmt(dev, VIDEO_EP_OUT, &fmt);
}
Expand Down
3 changes: 0 additions & 3 deletions dts/bindings/usb/zephyr,uvc-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ include: video-device.yaml
on-bus: usb

properties:
video-controls:
default: []

"#format-cells":
type: int
const: 5
Expand Down
57 changes: 32 additions & 25 deletions include/zephyr/devicetree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3817,11 +3817,13 @@
/**
* @brief Get the remote endpoint node connected to a local endpoint.
*
* Some devices, such as video devices, can be interconnected through port and endpoints.
* Some devices, such as video devices, can be interconnected through port and
* endpoints.
*
* For a selected node's endpoint, the remote endpoint connected to it can be access through
* @ref DT_REMOTE_ENDPOINT().
* This remote endpoint node can then be accessed using other macros to read its properties.
* For a selected node's endpoint, the remote endpoint connected to it can be
* access through @ref DT_REMOTE_ENDPOINT().
* This remote endpoint node can then be accessed using other macros to read
* its properties.
*
* Example devicetree overlay:
*
Expand All @@ -3843,53 +3845,58 @@
* };
* @endcode
*
* Example usage: starting from the sink, access the source endpoint connected to @c endpoint@123:
* Example usage: starting from the sink endpoint, access the source endpoint
* connected to @c endpoint@123:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123)
* DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in))
* @endcode
*
* Example usage, starting from the source, to access the sink endpoint connected to @c endpoint:
* Example usage, starting from the source endpoint, to access the sink endpoint
* connected to @c endpoint:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(source_out), port, endpoint)
* DT_REMOTE_ENDPOINT(DT_NODELABEL(source_out))
* @endcode
*
* @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be
* changed into @c remote-endpoint (phandle).
* @note Once circular phandle references are supported, the
* @c remote-endpoint-label string may be changed into a
* @c remote-endpoint phandle.
*
* @param node The local node.
* @param port The port to search.
* @param ep The endpoint to search.
*
* @return The remote node of the endpoint connected to @p port, @p ep.
* @return The node of the endpoint connected to @p node.
*/
#define DT_REMOTE_ENDPOINT(node, port, ep) DT_REMOTE(DT_ENDPOINT(node, port, ep))
#define DT_REMOTE(node) DT_NODELABEL(DT_STRING_TOKEN(node, remote_endpoint_label))
#define DT_ENDPOINT(node, port, ep) DT_CHILD(DT_CHILD(node, port), ep)
#define DT_REMOTE_ENDPOINT(node) DT_NODELABEL(DT_STRING_TOKEN(node, remote_endpoint_label))

/**
* @brief Get the remote device node connected to a local endpoint.
*
* For a given node, return the remote endpoint node connected to the specified port and endpoint.
* For a given node, return the remote endpoint node connected to the specified
* port and endpoint.
* This permit accessing the remote device properties.
*
* Example usage, starting from the sink, to access the source device connected to @c endpoint@123:
* Example usage, from the sink endpoint, access the source device connected:
*
* @code{.c}
* DT_REMOTE_ENDPOINT(DT_NODELABEL(sink_in), port, endpoint_123)
* DEVICE_DT_GET(DT_REMOTE_DEVICE(DT_NODELABEL(sink_in)))
* @endcode
*
* @note Once circular phandle references are supported, @c remote-endpoint-label (string) may be
* changed into @c remote-endpoint (phandle).
* Example usage, from the sink device, access the source device connected to @c endpoint@123:
*
* @code{.c}
* DEVICE_DT_GET(DT_REMOTE_DEVICE(DT_CHILD(DT_CHILD(sink_node, port), endpoint_123)))
* @endcode
*
* @note Once circular phandle references are supported, the
* @c remote-endpoint-label string may be changed into a
* @c remote-endpoint phandle.
*
* @param node The local node.
* @param port The port to search.
* @param ep The endpoint to search.
*
* @return The remote node of the device connected to @p port, @p ep.
* @return The node of the device connected to @p node.
*/
#define DT_REMOTE_DEVICE(node) DT_GPARENT(DT_REMOTE(node))
#define DT_REMOTE_DEVICE(node) DT_GPARENT(DT_REMOTE_ENDPOINT(node))

/**
* @}
Expand Down
Loading

0 comments on commit a70b411

Please sign in to comment.