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