Skip to content

Commit a32c796

Browse files
committed
camera: giga: fix display example for rgb sensors
The STM32 DMA is unable to modify the endianness of the 16bit data being tranferred, so we need to do it manually. Anyway, it's not a big deal since we already needed to copy every file for scaling+transpose feature..
1 parent 8ce1093 commit a32c796

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Diff for: libraries/Camera/examples/GigaCameraDisplay/GigaCameraDisplay.ino

+18-9
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ Camera cam(himax);
2222
OV7675 ov767x;
2323
Camera cam(ov767x);
2424
#define IMAGE_MODE CAMERA_RGB565
25-
#error "Unsupported camera (at the moment :) )"
2625
#elif defined(ARDUCAM_CAMERA_GC2145)
2726
#include "GC2145/gc2145.h"
2827
GC2145 galaxyCore;
2928
Camera cam(galaxyCore);
3029
#define IMAGE_MODE CAMERA_RGB565
31-
#error "Unsupported camera (at the moment :) )"
3230
#endif
3331

3432
// The buffer used to capture the frame
@@ -63,9 +61,11 @@ void setup() {
6361
}
6462

6563
Display.begin();
66-
dsi_configueCLUT((uint32_t*)palette);
6764

68-
outfb.setBuffer((uint8_t*)SDRAM.malloc(1024*1024));
65+
if (IMAGE_MODE == CAMERA_GRAYSCALE) {
66+
dsi_configueCLUT((uint32_t*)palette);
67+
}
68+
outfb.setBuffer((uint8_t*)SDRAM.malloc(1024 * 1024));
6969

7070
// clear the display (gives a nice black background)
7171
dsi_lcdClear(0);
@@ -74,6 +74,8 @@ void setup() {
7474
dsi_drawCurrentFrameBuffer();
7575
}
7676

77+
#define HTONS(x) (((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00))
78+
7779
void loop() {
7880

7981
// Grab frame and write to another framebuffer
@@ -83,13 +85,20 @@ void loop() {
8385
// this only works if the camera feed is 320x240 and the area where we want to display is 640x480
8486
for (int i = 0; i < 320; i++) {
8587
for (int j = 0; j < 240; j++) {
86-
((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480] = ((uint8_t*)fb.getBuffer())[i + j * 320];
87-
((uint8_t*)outfb.getBuffer())[j * 2 + (i * 2) * 480 + 1] = ((uint8_t*)fb.getBuffer())[i + j * 320];
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];
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+
}
9099
}
91100
}
92-
dsi_lcdDrawImage((void*)outfb.getBuffer(), (void*)dsi_getCurrentFrameBuffer(), 480, 640, DMA2D_INPUT_L8);
101+
dsi_lcdDrawImage((void*)outfb.getBuffer(), (void*)dsi_getCurrentFrameBuffer(), 480, 640, IMAGE_MODE == CAMERA_GRAYSCALE ? DMA2D_INPUT_L8 : DMA2D_INPUT_RGB565);
93102
dsi_drawCurrentFrameBuffer();
94103
} else {
95104
blinkLED(20);

0 commit comments

Comments
 (0)