@@ -18,8 +18,12 @@ LOG_MODULE_REGISTER(video_ov7670, CONFIG_VIDEO_LOG_LEVEL);
18
18
19
19
struct ov7670_config {
20
20
struct i2c_dt_spec bus ;
21
- const struct gpio_dt_spec reset ;
22
- const struct gpio_dt_spec pwdn ;
21
+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (reset_gpios )
22
+ struct gpio_dt_spec reset ;
23
+ #endif
24
+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (pwdn_gpios )
25
+ struct gpio_dt_spec pwdn ;
26
+ #endif
23
27
};
24
28
25
29
struct ov7670_ctrls {
@@ -142,7 +146,7 @@ static const struct video_reg8 ov7670_init_regtbl[] = {
142
146
143
147
/* configure the output timing */
144
148
/* PCLK does not toggle during horizontal blank, one PCLK, one pixel */
145
- {OV7670_COM10 , 0x03 }, /* COM10 */
149
+ {OV7670_COM10 , 0x20 }, /* COM10 */
146
150
{OV7670_COM12 , 0x00 }, /* COM12,No HREF when VSYNC is low */
147
151
/* Brightness Control, with signal -128 to +128, 0x00 is middle value */
148
152
{OV7670_BRIGHT , 0x2f },
@@ -291,7 +295,6 @@ static const struct video_reg8 ov7670_init_regtbl[] = {
291
295
{0xb8 , 0x0a },
292
296
};
293
297
294
- #if DT_HAS_COMPAT_STATUS_OKAY (ovti_ov7670 )
295
298
/* Resolution settings for camera, based on those present in MCUX SDK */
296
299
static const struct video_reg8 ov7670_regs_qcif [] = {
297
300
{OV7670_COM7 , 0x2c },
@@ -346,8 +349,8 @@ static const struct video_format_cap fmts[] = {
346
349
OV767X_VIDEO_FORMAT_CAP (320 , 240 , VIDEO_PIX_FMT_YUYV ), /* QVGA */
347
350
OV767X_VIDEO_FORMAT_CAP (352 , 288 , VIDEO_PIX_FMT_YUYV ), /* CIF */
348
351
OV767X_VIDEO_FORMAT_CAP (640 , 480 , VIDEO_PIX_FMT_YUYV ), /* VGA */
349
- {0 }};
350
- #endif
352
+ {0 }
353
+ };
351
354
352
355
static int ov7670_get_caps (const struct device * dev , struct video_caps * caps )
353
356
{
@@ -361,7 +364,7 @@ static int ov7670_set_fmt(const struct device *dev, struct video_format *fmt)
361
364
const struct ov7670_config * config = dev -> config ;
362
365
struct ov7670_data * data = dev -> data ;
363
366
int ret ;
364
- uint8_t i = 0U ;
367
+ uint8_t icount = 0U ;
365
368
366
369
if (fmt -> pixelformat != VIDEO_PIX_FMT_RGB565 && fmt -> pixelformat != VIDEO_PIX_FMT_YUYV ) {
367
370
LOG_ERR ("Only RGB565 and YUYV supported!" );
@@ -375,40 +378,46 @@ static int ov7670_set_fmt(const struct device *dev, struct video_format *fmt)
375
378
376
379
memcpy (& data -> fmt , fmt , sizeof (data -> fmt ));
377
380
381
+ uint32_t a , b , c ;
382
+
378
383
/* Set output resolution */
379
- while (fmts [i ].pixelformat ) {
380
- if (fmts [i ].width_min == fmt -> width &&
381
- fmts [i ].height_min == fmt -> height &&
382
- fmts [i ].pixelformat == fmt -> pixelformat ) {
384
+ ret = - ENOTSUP ;
385
+ icount = 0 ;
386
+ while (fmts [icount ].pixelformat ) {
387
+ a = fmts [icount ].width_min ;
388
+ b = fmts [icount ].height_min ;
389
+ c = fmts [icount ].pixelformat ;
390
+ if (a == fmt -> width && b == fmt -> height && c == fmt -> pixelformat ) {
383
391
/* Set output format */
384
- switch (fmts [i ].width_min ) {
392
+ switch (fmts [icount ].width_min ) {
385
393
case 176 : /* QCIF */
386
394
ret = video_write_cci_multiregs8 (& config -> bus , ov7670_regs_qcif ,
387
395
ARRAY_SIZE (ov7670_regs_qcif ));
388
396
break ;
389
- case 352 : /* CIF */
397
+ case 352 : /* QCIF */
390
398
ret = video_write_cci_multiregs8 (& config -> bus , ov7670_regs_cif ,
391
399
ARRAY_SIZE (ov7670_regs_cif ));
392
400
break ;
393
401
case 320 : /* QVGA */
394
402
ret = video_write_cci_multiregs8 (& config -> bus , ov7670_regs_qvga ,
395
403
ARRAY_SIZE (ov7670_regs_qvga ));
396
- break ;
397
-
398
- default : /* VGA */
404
+ case 640 : /* VGA */
399
405
ret = video_write_cci_multiregs8 (& config -> bus , ov7670_regs_vga ,
400
406
ARRAY_SIZE (ov7670_regs_vga ));
407
+ default : /* QVGA */
408
+ ret = video_write_cci_multiregs8 (& config -> bus , ov7670_regs_qvga ,
409
+ ARRAY_SIZE (ov7670_regs_vga ));
401
410
break ;
402
411
}
403
412
if (ret < 0 ) {
404
- LOG_ERR ("Resolution not set or not supported !" );
413
+ LOG_ERR ("Resolution not set!" );
405
414
return ret ;
406
415
}
407
416
}
408
- i ++ ;
417
+ icount ++ ;
409
418
}
410
419
411
- return 0 ;
420
+ return ret ;
412
421
}
413
422
414
423
static int ov7670_get_fmt (const struct device * dev , struct video_format * fmt )
@@ -564,22 +573,31 @@ static DEVICE_API(video, ov7670_api) = {
564
573
.set_ctrl = ov7670_set_ctrl ,
565
574
};
566
575
567
- #define OV7670_INIT (n , id ) \
568
- static const struct ov7670_config ov7670_config_##n = { \
569
- .bus = I2C_DT_SPEC_INST_GET(n), \
570
- .reset = \
571
- GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {}), \
572
- .pwdn = \
573
- GPIO_DT_SPEC_INST_GET_OR(n, pwdn_gpios, {}), \
574
- }; \
576
+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (reset_gpios )
577
+ #define OV7670_RESET_GPIO (n ) .reset = GPIO_DT_SPEC_INST_GET_OR(n, reset_gpios, {}),
578
+ #else
579
+ #define OV7670_RESET_GPIO (n )
580
+ #endif
581
+
582
+ #if DT_ANY_INST_HAS_PROP_STATUS_OKAY (pwdn_gpios )
583
+ #define OV7670_PWDN_GPIO (n ) .pwdn = GPIO_DT_SPEC_INST_GET_OR(n, pwdn_gpios, {}),
584
+ #else
585
+ #define OV7670_PWDN_GPIO (n )
586
+ #endif
587
+
588
+ #define OV7670_INIT (n ) \
589
+ const struct ov7670_config ov7670_config_##n = { \
590
+ .bus = I2C_DT_SPEC_INST_GET(n), \
591
+ OV7670_RESET_GPIO(n) \
592
+ OV7670_PWDN_GPIO(n)}; \
575
593
\
576
594
static struct ov7670_data ov7670_data_##n; \
577
595
\
578
596
DEVICE_DT_INST_DEFINE(n, \
579
597
ov7670_init, \
580
598
NULL, \
581
- &ov7670##_data_ ##n, \
582
- &ov7670##_config_ ##n, \
599
+ &ov7670_data_ ##n, \
600
+ &ov7670_config_ ##n, \
583
601
POST_KERNEL, CONFIG_VIDEO_INIT_PRIORITY, \
584
602
&ov7670_api); \
585
603
\
@@ -588,4 +606,4 @@ static DEVICE_API(video, ov7670_api) = {
588
606
589
607
#undef DT_DRV_COMPAT
590
608
#define DT_DRV_COMPAT ovti_ov7670
591
- DT_INST_FOREACH_STATUS_OKAY_VARGS (OV7670_INIT , 7670 )
609
+ DT_INST_FOREACH_STATUS_OKAY (OV7670_INIT )
0 commit comments