From 9e291b59ce63db826cd0fa0bc9d3917fd183a876 Mon Sep 17 00:00:00 2001 From: Kurt Eckhardt Date: Sat, 21 Jun 2025 11:45:52 -0700 Subject: [PATCH] video: add more resolutions to GC2145 video: add more resolutions to GC2145 As I mentioned in issue #91968, It would be great if the camera drivers would support a larger number of resolutions. For example those resolutions of the displays that they wish to display an image on. Potentially in both landscape and portrait mode. So far I have added one the works in landscape mode for ILI948x and ST7796 displays as well as a QVGA in portrait mode, which should be good for LI9341 and some ST7789 displays. If this looks like a valid approach, I will also add the GIGA Display Adapter size. Probably need to add the duplicate items to the FORMAT_CAP list for YUYV mode. Note: the other than add the items to the list, I just added code to set resolution which computes the c_ratio/r_ratio chooses the smaller of the two to use. We may also remove most if not all of the items in the switch statement and simply use the default clause code for them. Signed-off-by: Kurt Eckhardt --- drivers/video/gc2145.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/video/gc2145.c b/drivers/video/gc2145.c index ef369dec7b87a..42e32f76a074b 100644 --- a/drivers/video/gc2145.c +++ b/drivers/video/gc2145.c @@ -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), @@ -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; + } + 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 */ @@ -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);