Skip to content

video: add more resolutions to GC2145 #91975

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions drivers/video/gc2145.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ static const struct video_format_cap fmts[] = {
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_QVGA_W, RESOLUTION_QVGA_H, VIDEO_PIX_FMT_RGB565),
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_VGA_W, RESOLUTION_VGA_H, VIDEO_PIX_FMT_RGB565),
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_UXGA_W, RESOLUTION_UXGA_H, VIDEO_PIX_FMT_RGB565),
GC2145_VIDEO_FORMAT_CAP(480, 320, VIDEO_PIX_FMT_RGB565), /* ILI948x, ST7796 */
GC2145_VIDEO_FORMAT_CAP(240, 320, VIDEO_PIX_FMT_RGB565), /* ILI9341, ST7785 port */
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_QVGA_W, RESOLUTION_QVGA_H, VIDEO_PIX_FMT_YUYV),
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_VGA_W, RESOLUTION_VGA_H, VIDEO_PIX_FMT_YUYV),
GC2145_VIDEO_FORMAT_CAP(RESOLUTION_UXGA_W, RESOLUTION_UXGA_H, VIDEO_PIX_FMT_YUYV),
Expand Down Expand Up @@ -1036,8 +1038,19 @@ static int gc2145_set_resolution(const struct device *dev, uint32_t w, uint32_t
r_ratio = 1;
break;
default:
LOG_ERR("Unsupported resolution %d %d", w, h);
return -EIO;
if ((w > UXGA_HSIZE) || (h > UXGA_VSIZE)) {
LOG_ERR("Unsupported resolution %d %d", w, h);
return -EIO;
}
c_ratio = UXGA_HSIZE / w;
r_ratio = UXGA_VSIZE / h;
if (c_ratio < r_ratio) {
r_ratio = c_ratio;
} else {
c_ratio = r_ratio;
}
Comment on lines +1045 to +1051
Copy link
Contributor

@josuah josuah Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like some convenient "catch-all" rule to configure the exact resolution one needs but there is another way to do it:

  • The role of video_set_format() is to configure the "effective resolution", the size after binning is appplied (the row and column ratio like you configure now).

  • The role of video_set_selection() is to apply a cropping to the "effective/binned resolution" into an "output resolution" to give full control over what the sensor supports.

This should be merged this week so if it is possible for you to wait (or implement it!), then this would allow you to control this sensor features fully.

Thank you for the proposal!

LOG_DBG("set resolution(%u %u): ratio: %u %u\n", w, h, c_ratio, r_ratio);
break;
};

/* Calculates the window boundaries to obtain the desired resolution */
Expand All @@ -1048,6 +1061,7 @@ static int gc2145_set_resolution(const struct device *dev, uint32_t w, uint32_t
win_x = ((UXGA_HSIZE - win_w) / 2);
win_y = ((UXGA_VSIZE - win_h) / 2);

LOG_DBG("xy: %u %u win: %u %u\n", x, y, win_w, win_h);
/* Set readout window first. */
ret = gc2145_set_window(dev, GC2145_REG_BLANK_WINDOW_BASE, win_x, win_y, win_w + 16,
win_h + 8);
Expand Down