1+
2+ #include " arducam_dvp.h"
3+ #include " Arduino_H7_Video.h"
4+ #include " dsi.h"
5+ #include " SDRAM.h"
6+
7+ // This example only works with Greyscale cameras (due to the palette + resize&rotate algo)
8+ #define ARDUCAM_CAMERA_HM01B0
9+
10+ #ifdef ARDUCAM_CAMERA_HM01B0
11+ #include " Himax_HM01B0/himax.h"
12+ HM01B0 himax;
13+ Camera cam (himax);
14+ #define IMAGE_MODE CAMERA_GRAYSCALE
15+ #elif defined(ARDUCAM_CAMERA_HM0360)
16+ #include " Himax_HM0360/hm0360.h"
17+ HM0360 himax;
18+ Camera cam (himax);
19+ #define IMAGE_MODE CAMERA_GRAYSCALE
20+ #elif defined(ARDUCAM_CAMERA_OV767X)
21+ #include " OV7670/ov767x.h"
22+ // OV7670 ov767x;
23+ OV7675 ov767x;
24+ Camera cam (ov767x);
25+ #define IMAGE_MODE CAMERA_RGB565
26+ #error "Unsupported camera (at the moment :) )"
27+ #elif defined(ARDUCAM_CAMERA_GC2145)
28+ #include " GC2145/gc2145.h"
29+ GC2145 galaxyCore;
30+ Camera cam (galaxyCore);
31+ #define IMAGE_MODE CAMERA_RGB565
32+ #error "Unsupported camera (at the moment :) )"
33+ #endif
34+
35+ // The buffer used to capture the frame
36+ FrameBuffer fb;
37+ // The buffer used to rotate and resize the frame
38+ FrameBuffer outfb;
39+ // The buffer used to rotate and resize the frame
40+ Arduino_H7_Video Display (800 , 480 , GigaDisplayShield);
41+
42+ void blinkLED (uint32_t count = 0xFFFFFFFF )
43+ {
44+ pinMode (LED_BUILTIN, OUTPUT);
45+ while (count--) {
46+ digitalWrite (LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level)
47+ delay (50 ); // wait for a second
48+ digitalWrite (LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW
49+ delay (50 ); // wait for a second
50+ }
51+ }
52+
53+ uint32_t palette[256 ];
54+
55+ void setup () {
56+ // Init the cam QVGA, 30FPS
57+ if (!cam.begin (CAMERA_R320x240, IMAGE_MODE, 30 )) {
58+ blinkLED ();
59+ }
60+
61+ // Setup the palette to convert 8 bit greyscale to 32bit greyscale
62+ for (int i = 0 ; i < 256 ; i++) {
63+ palette[i] = 0xFF000000 | (i << 16 ) | (i << 8 ) | i;
64+ }
65+
66+ Display.begin ();
67+ dsi_configueCLUT ((uint32_t *)palette);
68+
69+ outfb.setBuffer ((uint8_t *)SDRAM.malloc (1024 *1024 ));
70+
71+ // clear the display (gives a nice black background)
72+ dsi_lcdClear (0 );
73+ dsi_drawCurrentFrameBuffer ();
74+ dsi_lcdClear (0 );
75+ dsi_drawCurrentFrameBuffer ();
76+ }
77+
78+ void loop () {
79+
80+ // Grab frame and write to another framebuffer
81+ if (cam.grabFrame (fb, 3000 ) == 0 ) {
82+
83+ // double the resolution and transpose (rotate by 90 degrees) in the same step
84+ // this only works if the camera feed is 320x240 and the area where we want to display is 640x480
85+ for (int i = 0 ; i < 320 ; i++) {
86+ for (int j = 0 ; j < 240 ; j++) {
87+ ((uint8_t *)outfb.getBuffer ())[j * 2 + (i * 2 ) * 480 ] = ((uint8_t *)fb.getBuffer ())[i + j * 320 ];
88+ ((uint8_t *)outfb.getBuffer ())[j * 2 + (i * 2 ) * 480 + 1 ] = ((uint8_t *)fb.getBuffer ())[i + j * 320 ];
89+ ((uint8_t *)outfb.getBuffer ())[j * 2 + (i * 2 + 1 ) * 480 ] = ((uint8_t *)fb.getBuffer ())[i + j * 320 ];
90+ ((uint8_t *)outfb.getBuffer ())[j * 2 + (i * 2 + 1 ) * 480 + 1 ] = ((uint8_t *)fb.getBuffer ())[i + j * 320 ];
91+ }
92+ }
93+ dsi_lcdDrawImage ((void *)outfb.getBuffer (), (void *)dsi_getCurrentFrameBuffer (), 480 , 640 , DMA2D_INPUT_L8);
94+ dsi_drawCurrentFrameBuffer ();
95+ } else {
96+ blinkLED (20 );
97+ }
98+ }
0 commit comments