Skip to content

Commit 596a556

Browse files
committed
Camera: fix GigaCameraDisplay example with Arducam module
1 parent 52caeac commit 596a556

File tree

3 files changed

+51
-7050
lines changed

3 files changed

+51
-7050
lines changed
Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
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"
45

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"
1211
HM01B0 himax;
1312
Camera cam(himax);
1413
#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+
#error "Unsupported camera (at the moment :) )"
26+
#elif defined(ARDUCAM_CAMERA_GC2145)
27+
#include "GC2145/gc2145.h"
28+
GC2145 galaxyCore;
29+
Camera cam(galaxyCore);
30+
#define IMAGE_MODE CAMERA_RGB565
31+
#error "Unsupported camera (at the moment :) )"
1532
#endif
1633

17-
/*
18-
Other buffer instantiation options:
19-
FrameBuffer fb(0x30000000);
20-
FrameBuffer fb(320,240,2);
21-
*/
34+
// The buffer used to capture the frame
2235
FrameBuffer fb;
23-
24-
unsigned long lastUpdate = 0;
25-
36+
// The buffer used to rotate and resize the frame
37+
FrameBuffer outfb;
38+
// The buffer used to rotate and resize the frame
39+
Arduino_H7_Video Display(800, 480, GigaDisplayShield);
2640

2741
void blinkLED(uint32_t count = 0xFFFFFFFF)
2842
{
@@ -34,68 +48,50 @@ void blinkLED(uint32_t count = 0xFFFFFFFF)
3448
delay(50); // wait for a second
3549
}
3650
}
37-
void LCD_ST7701_Init();
3851

3952
uint32_t palette[256];
4053

4154
void setup() {
42-
pinMode(PA_1, OUTPUT);
43-
digitalWrite(PA_1, HIGH);
44-
45-
pinMode(PD_4, OUTPUT);
46-
digitalWrite(PD_4, LOW);
47-
4855
// Init the cam QVGA, 30FPS
4956
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
5057
blinkLED();
5158
}
5259

60+
// Setup the palette to convert 8 bit greyscale to 32bit greyscale
5361
for (int i = 0; i < 256; i++) {
5462
palette[i] = 0xFF000000 | (i << 16) | (i << 8) | i;
5563
}
5664

57-
giga_init_video();
58-
LCD_ST7701_Init();
65+
Display.begin();
66+
dsi_configueCLUT((uint32_t*)palette);
5967

60-
blinkLED(5);
68+
outfb.setBuffer((uint8_t*)SDRAM.malloc(1024*1024));
6169

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();
6775
}
6876

69-
#include "avir.h"
70-
7177
void loop() {
7278

73-
lastUpdate = millis();
74-
75-
// Grab frame and write to serial
79+
// Grab frame and write to another framebuffer
7680
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++) {
81+
82+
// double the resolution and transpose (rotate by 90 degrees) in the same step
83+
// this only works if the camera feed is 320x240 and the area where we want to display is 640x480
84+
for (int i = 0; i < 320; i++) {
8285
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
8586
((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320];
8687
((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+
((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320];
89+
((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2 + 1) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320];
9390
}
9491
}
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);
92+
dsi_lcdDrawImage((void*)outfb.getBuffer(), (void*)dsi_getCurrentFrameBuffer(), 480, 640, DMA2D_INPUT_L8);
93+
dsi_drawCurrentFrameBuffer();
9894
} else {
9995
blinkLED(20);
10096
}
101-
}
97+
}

0 commit comments

Comments
 (0)