Skip to content

Commit 66de2be

Browse files
authored
Merge pull request #717 from facchinm/giga_camera_example
Restructure Giga camera example
2 parents 4a002de + a32c796 commit 66de2be

File tree

4 files changed

+63
-7051
lines changed

4 files changed

+63
-7051
lines changed

Diff for: .github/workflows/compile-examples.yml

+2
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,13 @@ jobs:
140140
- name: ArduinoBLE
141141
- name: ArduinoGraphics
142142
- name: Arduino_GigaDisplayTouch
143+
- name: arducam_dvp
143144
additional-sketch-paths: |
144145
- libraries/PDM
145146
- libraries/MCUboot
146147
- libraries/Camera/examples/CameraCaptureRawBytes
147148
- libraries/Camera/examples/CameraMotionDetect
149+
- libraries/Camera/examples/GigaCameraDisplay
148150
- libraries/Portenta_SDCARD
149151
- libraries/Portenta_SDRAM
150152
- libraries/Arduino_H7_Video
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
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+
#elif defined(ARDUCAM_CAMERA_GC2145)
26+
#include "GC2145/gc2145.h"
27+
GC2145 galaxyCore;
28+
Camera cam(galaxyCore);
29+
#define IMAGE_MODE CAMERA_RGB565
1530
#endif
1631

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
2233
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);
2638

2739
void blinkLED(uint32_t count = 0xFFFFFFFF)
2840
{
@@ -34,68 +46,61 @@ void blinkLED(uint32_t count = 0xFFFFFFFF)
3446
delay(50); // wait for a second
3547
}
3648
}
37-
void LCD_ST7701_Init();
3849

3950
uint32_t palette[256];
4051

4152
void setup() {
42-
pinMode(PA_1, OUTPUT);
43-
digitalWrite(PA_1, HIGH);
44-
45-
pinMode(PD_4, OUTPUT);
46-
digitalWrite(PD_4, LOW);
47-
4853
// Init the cam QVGA, 30FPS
4954
if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) {
5055
blinkLED();
5156
}
5257

58+
// Setup the palette to convert 8 bit greyscale to 32bit greyscale
5359
for (int i = 0; i < 256; i++) {
5460
palette[i] = 0xFF000000 | (i << 16) | (i << 8) | i;
5561
}
5662

57-
giga_init_video();
58-
LCD_ST7701_Init();
63+
Display.begin();
5964

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));
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"
77+
#define HTONS(x) (((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00))
7078

7179
void loop() {
7280

73-
lastUpdate = millis();
74-
75-
// Grab frame and write to serial
81+
// Grab frame and write to another framebuffer
7682
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++) {
8287
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+
}
9399
}
94100
}
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();
98103
} else {
99104
blinkLED(20);
100105
}
101-
}
106+
}

0 commit comments

Comments
 (0)