Skip to content

Commit 2c64005

Browse files
drivers/video/gc0308: add YUYV output format support
GC0308 sensor supports multiple output formats via register 0x24. Add YUYV (YCbCr422) alongside existing RGB565 in fmtdescs and configure the output format register dynamically in start_capture() based on the requested pixel format. Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
1 parent cc5e917 commit 2c64005

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

drivers/video/gc0308.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ struct gc0308_dev_s
154154
struct i2c_master_s *i2c;
155155
uint16_t width;
156156
uint16_t height;
157+
uint32_t pixelformat;
157158
struct v4l2_frmsizeenum frmsizes;
158159
bool streaming;
159160
};
@@ -455,6 +456,10 @@ static const struct imgsensor_ops_s g_gc0308_ops =
455456

456457
static const struct v4l2_fmtdesc g_gc0308_fmtdescs[] =
457458
{
459+
{
460+
.pixelformat = V4L2_PIX_FMT_YUYV,
461+
.description = "YUV 4:2:2 (YUYV)",
462+
},
458463
{
459464
.pixelformat = V4L2_PIX_FMT_RGB565,
460465
.description = "RGB565",
@@ -648,7 +653,7 @@ static int gc0308_init(struct imgsensor_s *sensor)
648653

649654
up_mdelay(80);
650655

651-
/* Set RGB565 output format: reg 0x24 bits[3:0] = 6 */
656+
/* Set default RGB565 output format: reg 0x24 bits[3:0] = 6 */
652657

653658
ret = gc0308_putreg(priv->i2c, GC0308_REG_RESET, 0x00);
654659
if (ret < 0)
@@ -657,6 +662,7 @@ static int gc0308_init(struct imgsensor_s *sensor)
657662
}
658663

659664
ret = gc0308_modreg(priv->i2c, GC0308_REG_OUTPUT_FMT, 0x0f, 0x06);
665+
priv->pixelformat = IMGSENSOR_PIX_FMT_RGB565;
660666
if (ret < 0)
661667
{
662668
return ret;
@@ -752,6 +758,8 @@ static int gc0308_validate_frame_setting(struct imgsensor_s *sensor,
752758
}
753759

754760
if (datafmts[IMGSENSOR_FMT_MAIN].pixelformat !=
761+
IMGSENSOR_PIX_FMT_YUYV &&
762+
datafmts[IMGSENSOR_FMT_MAIN].pixelformat !=
755763
IMGSENSOR_PIX_FMT_RGB565)
756764
{
757765
return -EINVAL;
@@ -777,12 +785,32 @@ static int gc0308_start_capture(struct imgsensor_s *sensor,
777785
imgsensor_interval_t *interval)
778786
{
779787
struct gc0308_dev_s *priv = (struct gc0308_dev_s *)sensor;
788+
uint8_t fmtval;
789+
int ret;
780790

781791
if (priv->streaming)
782792
{
783793
return -EBUSY;
784794
}
785795

796+
/* Configure output format register based on requested pixel format */
797+
798+
if (datafmts[IMGSENSOR_FMT_MAIN].pixelformat == IMGSENSOR_PIX_FMT_RGB565)
799+
{
800+
fmtval = 0x06; /* RGB565 */
801+
}
802+
else
803+
{
804+
fmtval = 0x02; /* YCbCr422 */
805+
}
806+
807+
ret = gc0308_modreg(priv->i2c, GC0308_REG_OUTPUT_FMT, 0x0f, fmtval);
808+
if (ret < 0)
809+
{
810+
return ret;
811+
}
812+
813+
priv->pixelformat = datafmts[IMGSENSOR_FMT_MAIN].pixelformat;
786814
priv->streaming = true;
787815
return OK;
788816
}

0 commit comments

Comments
 (0)