@@ -38,6 +38,8 @@ LOG_MODULE_REGISTER(video_gc2145, CONFIG_VIDEO_LOG_LEVEL);
3838#define GC2145_REG_SYNC_MODE_DEF 0x03
3939#define GC2145_REG_SYNC_MODE_COL_SWITCH 0x10
4040#define GC2145_REG_SYNC_MODE_ROW_SWITCH 0x20
41+ #define GC2145_REG_BYPASS_MODE 0x89
42+ #define GC2145_REG_BYPASS_MODE_SWITCH BIT(5)
4143#define GC2145_REG_CHIP_ID GC2145_REG16_BE(0xF0)
4244#define GC2145_REG_RESET 0xFE
4345#define GC2145_REG_SW_RESET 0x80
@@ -168,7 +170,7 @@ static const struct video_reg8 default_regs[] = {
168170 {GC2145_REG_OUTPUT_FMT , GC2145_REG_OUTPUT_FMT_RGB565 },
169171 {GC2145_REG_SYNC_MODE , GC2145_REG_SYNC_MODE_DEF },
170172 {0x88 , 0x03 },
171- {0x89 , 0x03 },
173+ {GC2145_REG_BYPASS_MODE , 0x03 },
172174 {0x85 , 0x08 },
173175 {0x8a , 0x00 },
174176 {0x8b , 0x00 },
@@ -835,6 +837,7 @@ static int gc2145_soft_reset(const struct device *dev)
835837static int gc2145_set_output_format (const struct device * dev , int output_format )
836838{
837839 const struct gc2145_config * cfg = dev -> config ;
840+ uint8_t bypass_switch = 0 ;
838841 int ret ;
839842
840843 ret = video_write_cci_reg (& cfg -> i2c , GC2145_REG8 (GC2145_REG_RESET ),
@@ -846,6 +849,14 @@ static int gc2145_set_output_format(const struct device *dev, int output_format)
846849 /* Map format to sensor format */
847850 if (output_format == VIDEO_PIX_FMT_RGB565 ) {
848851 output_format = GC2145_REG_OUTPUT_FMT_RGB565 ;
852+
853+ /*
854+ * For RGB565 format on CSI, it is necessary to set switch bit in order to
855+ * have proper RGB565 CSI format (aka _LE) generated
856+ */
857+ if (cfg -> bus_type == VIDEO_BUS_TYPE_CSI2_DPHY ) {
858+ bypass_switch = GC2145_REG_BYPASS_MODE_SWITCH ;
859+ }
849860 } else if (output_format == VIDEO_PIX_FMT_YUYV ) {
850861 output_format = GC2145_REG_OUTPUT_FMT_YCBYCR ;
851862 } else {
@@ -859,6 +870,14 @@ static int gc2145_set_output_format(const struct device *dev, int output_format)
859870 return ret ;
860871 }
861872
873+ if (cfg -> bus_type == VIDEO_BUS_TYPE_CSI2_DPHY ) {
874+ ret = video_modify_cci_reg (& cfg -> i2c , GC2145_REG8 (GC2145_REG_BYPASS_MODE ),
875+ GC2145_REG_BYPASS_MODE_SWITCH , bypass_switch );
876+ if (ret < 0 ) {
877+ return ret ;
878+ }
879+ }
880+
862881 k_sleep (K_MSEC (30 ));
863882
864883 return 0 ;
0 commit comments