Skip to content

Commit d9025fe

Browse files
committed
drivers: video Add Restructure of set_fmt function
drivers: video Add Restructure of set_fmt function set_fmt split to 0v7670_set_fmt & 0v7675_set_fmt. Signed-off-by: Mike S <[email protected]>
1 parent 305c5d0 commit d9025fe

File tree

1 file changed

+98
-37
lines changed

1 file changed

+98
-37
lines changed

drivers/video/ov767x.c

Lines changed: 98 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ struct ov767x_data {
132132
#define OV7670_HAECC5 0xA8
133133
#define OV7670_HAECC6 0xA9
134134

135-
/* Addition defines for OV7675 */
136-
#define OV7675_RGB444 0x8C /* REG444 */
137-
#define OV7675_COM3_DCW_EN 0x04 /* DCW enable */
135+
/* Addition defines to support OV7675 */
136+
#define OV7670_RGB444 0x8C /* REG444 */
138137
#define OV7670_COM1 0x04 /*Com Cntrl1 */
138+
#define OV7675_COM3_DCW_EN 0x04 /* DCW enable */
139139
#define OV7675_COM7_RGB_FMT 0x04 /* Output format RGB */
140140
#define OV7675_COM13_GAMMA_EN 0x80 /* Gamma enable */
141141
#define OV7675_COM13_UVSAT_AUTO 0x40 /* UV saturation level - UV auto adjustment. */
@@ -192,7 +192,7 @@ static const struct video_reg8 ov767x_init_regtbl[] = {
192192

193193
/* configure the output timing */
194194
/* PCLK does not toggle during horizontal blank, one PCLK, one pixel */
195-
{OV7670_COM10, 0x20}, /* COM10 */
195+
{OV7670_COM10, 0x03}, /* COM10 */
196196
{OV7670_COM12, 0x00}, /* COM12,No HREF when VSYNC is low */
197197
/* Brightness Control, with signal -128 to +128, 0x00 is middle value */
198198
{OV7670_BRIGHT, 0x2f},
@@ -343,7 +343,7 @@ static const struct video_reg8 ov767x_init_regtbl[] = {
343343

344344
static const struct video_reg8 ov767x_rgb565_regs[] = {
345345
{OV7670_COM7, OV7675_COM7_RGB_FMT}, /* Selects RGB mode */
346-
{OV7675_RGB444, 0x00}, /* No RGB444 please */
346+
{OV7670_RGB444, 0x00}, /* No RGB444 please */
347347
{OV7670_COM1, 0x00}, /* CCIR601 */
348348
{OV7670_COM15, OV7675_COM15_OUT_00_FF | OV7675_COM15_FMT_RGB565},
349349
{OV7670_COM9, 0x38}, /* 16x gain ceiling; 0x8 is reserved bit */
@@ -359,7 +359,7 @@ static const struct video_reg8 ov767x_rgb565_regs[] = {
359359
/* TODO: These registers probably need to be fixed too. */
360360
static const struct video_reg8 ov767x_yuv422_regs[] = {
361361
{OV7670_COM7, 0x00}, /* Selects YUV mode */
362-
{OV7675_RGB444, 0x00}, /* No RGB444 please */
362+
{OV7670_RGB444, 0x00}, /* No RGB444 please */
363363
{OV7670_COM1, 0x00}, /* CCIR601 */
364364
{OV7670_COM15, OV7675_COM15_OUT_00_FF},
365365
{OV7670_COM9, 0x48}, /* 32x gain ceiling; 0x8 is reserved bit */
@@ -372,6 +372,7 @@ static const struct video_reg8 ov767x_yuv422_regs[] = {
372372
{OV7670_COM13, OV7675_COM13_GAMMA_EN | OV7675_COM13_UVSAT_AUTO},
373373
};
374374

375+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7670)
375376
/* Resolution settings for camera, based on those present in MCUX SDK */
376377
static const struct video_reg8 ov7670_regs_qcif[] = {
377378
{OV7670_COM7, 0x2c},
@@ -416,19 +417,27 @@ static const struct video_reg8 ov7670_regs_vga[] = {
416417
{OV7670_SCALING_PCLK_DIV, 0xf0},
417418
{OV7670_SCALING_PCLK_DELAY, 0x02},
418419
};
420+
#endif
419421

422+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7675)
420423
static const struct video_reg8 ov7675_regs_vga[] = {
421-
{OV7670_COM3, 0x00}, {OV7670_COM14, 0x00}, {0x72, 0x11}, /* downsample by 4 */
422-
{0x73, 0xf0}, /* divide by 4 */
423-
{OV7670_HSTART, 0x12}, {OV7670_HSTOP, 0x00}, {OV7670_HREF, 0xb6},
424-
{OV7670_VSTRT, 0x02}, {OV7670_VSTOP, 0x7a}, {OV7670_VREF, 0x00},
424+
{OV7670_COM3, 0x00},
425+
{OV7670_COM14, 0x00},
426+
{0x72, 0x11}, /* downsample by 4 */
427+
{0x73, 0xf0}, /* divide by 4 */
428+
{OV7670_HSTART, 0x12},
429+
{OV7670_HSTOP, 0x00},
430+
{OV7670_HREF, 0xb6},
431+
{OV7670_VSTRT, 0x02},
432+
{OV7670_VSTOP, 0x7a},
433+
{OV7670_VREF, 0x00},
425434
};
426435

427436
static const struct video_reg8 ov7675_regs_qvga[] = {
428437
{OV7670_COM3, OV7675_COM3_DCW_EN},
429438
{OV7670_COM14, 0x11}, /* Divide by 2 */
430-
{0x72, 0x22}, /* This has no effect on OV7675 */
431-
{0x73, 0xf2}, /* This has no effect on OV7675 */
439+
{0x72, 0x22},
440+
{0x73, 0xf2},
432441
{OV7670_HSTART, 0x15},
433442
{OV7670_HSTOP, 0x03},
434443
{OV7670_HREF, 0xC0},
@@ -440,15 +449,16 @@ static const struct video_reg8 ov7675_regs_qvga[] = {
440449
static const struct video_reg8 ov7675_regs_qqvga[] = {
441450
{OV7670_COM3, OV7675_COM3_DCW_EN},
442451
{OV7670_COM14, 0x11}, /* Divide by 2 */
443-
{0x72, 0x22}, /* This has no effect on OV7675*/
444-
{0x73, 0xf2}, /* This has no effect on OV7675*/
452+
{0x72, 0x22},
453+
{0x73, 0xf2},
445454
{OV7670_HSTART, 0x16},
446455
{OV7670_HSTOP, 0x04},
447456
{OV7670_HREF, 0xa4},
448457
{OV7670_VSTRT, 0x22},
449458
{OV7670_VSTOP, 0x7a},
450459
{OV7670_VREF, 0xfa},
451460
};
461+
#endif
452462

453463
static int ov767x_get_caps(const struct device *dev, struct video_caps *caps)
454464
{
@@ -458,42 +468,21 @@ static int ov767x_get_caps(const struct device *dev, struct video_caps *caps)
458468
return 0;
459469
}
460470

461-
static int ov767x_set_fmt(const struct device *dev, struct video_format *fmt)
471+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7670)
472+
static int ov7670_set_fmt(const struct device *dev, struct video_format *fmt)
462473
{
463474
const struct ov767x_config *config = dev->config;
464475
struct ov767x_data *data = dev->data;
465476
int ret = -ENOTSUP;
466477
uint8_t i = 0U;
467478

468-
if (fmt->pixelformat != VIDEO_PIX_FMT_RGB565 && fmt->pixelformat != VIDEO_PIX_FMT_YUYV) {
469-
LOG_ERR("Only RGB565 and YUYV supported!");
470-
return -ENOTSUP;
471-
}
472-
473479
if (!memcmp(&data->fmt, fmt, sizeof(data->fmt))) {
474480
/* nothing to do */
475481
return 0;
476482
}
477483

478484
memcpy(&data->fmt, fmt, sizeof(data->fmt));
479485

480-
/* Set RGB Format */
481-
if (fmt->pixelformat == VIDEO_PIX_FMT_RGB565) {
482-
ret = video_write_cci_multiregs8(&config->bus, ov767x_rgb565_regs,
483-
ARRAY_SIZE(ov767x_rgb565_regs));
484-
} else if (fmt->pixelformat == VIDEO_PIX_FMT_YUYV) {
485-
ret = video_write_cci_multiregs8(&config->bus, ov767x_yuv422_regs,
486-
ARRAY_SIZE(ov767x_yuv422_regs));
487-
} else {
488-
LOG_ERR("Image formaat not supported");
489-
ret = -ENOTSUP;
490-
}
491-
492-
if (ret < 0) {
493-
LOG_ERR("Format not set!");
494-
return ret;
495-
}
496-
497486
if (config->camera_model == OV767X_MODEL_OV7670) {
498487
/* Set output resolution */
499488
while (config->fmts[i].pixelformat) {
@@ -536,6 +525,26 @@ static int ov767x_set_fmt(const struct device *dev, struct video_format *fmt)
536525
i++;
537526
}
538527
}
528+
if (ret < 0) {
529+
LOG_ERR("Resolution not supported!");
530+
return ret;
531+
}
532+
533+
return 0;
534+
}
535+
#endif
536+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7675)
537+
static int ov7675_set_fmt(const struct device *dev, struct video_format *fmt)
538+
{
539+
const struct ov767x_config *config = dev->config;
540+
struct ov767x_data *data = dev->data;
541+
int ret = -ENOTSUP;
542+
uint8_t i = 0U;
543+
544+
if (!memcmp(&data->fmt, fmt, sizeof(data->fmt))) {
545+
/* nothing to do */
546+
return 0;
547+
}
539548

540549
if (config->camera_model == OV767X_MODEL_OV7675) {
541550
while (config->fmts[i].pixelformat) {
@@ -581,6 +590,58 @@ static int ov767x_set_fmt(const struct device *dev, struct video_format *fmt)
581590

582591
return 0;
583592
}
593+
#endif
594+
595+
static int ov767x_set_fmt(const struct device *dev, struct video_format *fmt)
596+
{
597+
const struct ov767x_config *config = dev->config;
598+
struct ov767x_data *data = dev->data;
599+
int ret;
600+
601+
if (fmt->pixelformat != VIDEO_PIX_FMT_RGB565 && fmt->pixelformat != VIDEO_PIX_FMT_YUYV) {
602+
LOG_ERR("Only RGB565 and YUYV supported!");
603+
return -ENOTSUP;
604+
}
605+
606+
if (!memcmp(&data->fmt, fmt, sizeof(data->fmt))) {
607+
/* nothing to do */
608+
return 0;
609+
}
610+
611+
memcpy(&data->fmt, fmt, sizeof(data->fmt));
612+
613+
/* Set RGB Format */
614+
if (fmt->pixelformat == VIDEO_PIX_FMT_RGB565) {
615+
ret = video_write_cci_multiregs8(&config->bus, ov767x_rgb565_regs,
616+
ARRAY_SIZE(ov767x_rgb565_regs));
617+
} else if (fmt->pixelformat == VIDEO_PIX_FMT_YUYV) {
618+
ret = video_write_cci_multiregs8(&config->bus, ov767x_yuv422_regs,
619+
ARRAY_SIZE(ov767x_yuv422_regs));
620+
} else {
621+
LOG_ERR("Image format not supported");
622+
ret = -ENOTSUP;
623+
}
624+
625+
if (ret < 0) {
626+
LOG_ERR("Format not set!");
627+
return ret;
628+
}
629+
630+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7670)
631+
ret = ov7670_set_fmt(dev, fmt);
632+
if (ret < 0) {
633+
return ret;
634+
}
635+
#endif
636+
#if DT_HAS_COMPAT_STATUS_OKAY(ovti_ov7675)
637+
ret = ov7675_set_fmt(dev, fmt);
638+
if (ret < 0) {
639+
return ret;
640+
}
641+
#endif
642+
643+
return 0;
644+
}
584645

585646
static int ov767x_get_fmt(const struct device *dev, struct video_format *fmt)
586647
{

0 commit comments

Comments
 (0)