Skip to content

Commit ba68072

Browse files
committed
Add test pattern generation for Portenta camera
1 parent c210269 commit ba68072

File tree

6 files changed

+88
-4
lines changed

6 files changed

+88
-4
lines changed

libraries/Himax_HM01B0/himax.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ static void HIMAX_GrayScale(uint8_t value)
300300
HIMAX_RegWrite(BLC2_TGT, value);
301301
}
302302

303+
void HIMAX_TestPattern(bool enable, bool walking)
304+
{
305+
uint8_t reg = 0;
306+
if (enable) {
307+
reg = 1 | (walking ? (1 << 4) : 0);
308+
}
309+
HIMAX_RegWrite(0x0601, reg );
310+
}
311+
303312
static void HIMAX_FrameRate()
304313
{
305314
HIMAX_RegWrite( FRAME_LEN_LINES_H, 0x02);

libraries/Himax_HM01B0/himax.h

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ typedef struct regval_list_ {
145145

146146
uint8_t HIMAX_Open(void);
147147
void HIMAX_Mode(uint8_t mode);
148+
void HIMAX_TestPattern(bool enable = true, bool walking = true);
148149

149150

150151
#ifdef __cplusplus

libraries/Portenta_Camera/camera.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -588,5 +588,8 @@ uint8_t* CameraClass::snapshot(void)
588588
return (uint8_t *)LCD_FRAME_BUFFER;
589589
}
590590

591-
591+
void CameraClass::testPattern(bool walking)
592+
{
593+
HIMAX_TestPattern(true, walking);
594+
}
592595
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

libraries/Portenta_Camera/camera.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ class CameraClass {
44
uint8_t* snapshot();
55
int start(void);
66
uint8_t* grab(void);
7+
void testPattern(bool walking);
78
};

libraries/Portenta_Camera/examples/Envie_camera/Envie_camera.ino

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ CameraClass cam;
55
void setup() {
66

77
Serial.begin(115200);
8-
while (!Serial);
8+
//while (!Serial);
99

1010
// put your setup code here, to run once:
1111
cam.begin(324, 244);
1212
cam.start();
13+
//cam.testPattern(true);
1314
}
1415

1516
void loop() {
1617
// put your main code here, to run repeatedly:
17-
Serial.write(cam.grab(), 324*244);
18-
}
18+
if (Serial) {
19+
Serial.write(cam.grab(), 324 * 244);
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
This sketch reads a raw Stream of RGB565 pixels
3+
from the Serial port and displays the frame on
4+
the window.
5+
Use with the Examples -> CameraCaptureRawBytes Arduino sketch.
6+
This example code is in the public domain.
7+
*/
8+
9+
import processing.serial.*;
10+
import java.nio.ByteBuffer;
11+
import java.nio.ByteOrder;
12+
13+
Serial myPort;
14+
15+
// must match resolution used in the sketch
16+
final int cameraWidth = 324;
17+
final int cameraHeight = 244;
18+
final int cameraBytesPerPixel = 1;
19+
final int bytesPerFrame = cameraWidth * cameraHeight * cameraBytesPerPixel;
20+
21+
PImage myImage;
22+
byte[] frameBuffer = new byte[bytesPerFrame];
23+
24+
void setup()
25+
{
26+
size(324, 244);
27+
28+
// if you have only ONE serial port active
29+
//myPort = new Serial(this, Serial.list()[0], 9600); // if you have only ONE serial port active
30+
31+
// if you know the serial port name
32+
//myPort = new Serial(this, "COM5", 9600); // Windows
33+
myPort = new Serial(this, "/dev/ttyACM0", 9600); // Linux
34+
//myPort = new Serial(this, "/dev/cu.usbmodem14401", 9600); // Mac
35+
36+
// wait for full frame of bytes
37+
myPort.buffer(bytesPerFrame);
38+
39+
myImage = createImage(cameraWidth, cameraHeight, ALPHA);
40+
}
41+
42+
void draw()
43+
{
44+
image(myImage, 0, 0);
45+
}
46+
47+
void serialEvent(Serial myPort) {
48+
// read the saw bytes in
49+
myPort.readBytes(frameBuffer);
50+
51+
// access raw bytes via byte buffer
52+
ByteBuffer bb = ByteBuffer.wrap(frameBuffer);
53+
bb.order(ByteOrder.BIG_ENDIAN);
54+
55+
int i = 0;
56+
57+
while (bb.hasRemaining()) {
58+
// read 16-bit pixel
59+
byte p = bb.get();
60+
61+
62+
// set pixel color
63+
myImage .pixels[i++] = color(Byte.toUnsignedInt(p));
64+
}
65+
myImage.updatePixels();
66+
67+
}

0 commit comments

Comments
 (0)