Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1059edb

Browse files
iabdalkadergiulcioffi
authored andcommitted
Add support for more resolutions and pixel formats.
1 parent 0c9a574 commit 1059edb

File tree

7 files changed

+188
-122
lines changed

7 files changed

+188
-122
lines changed

‎libraries/GC2145/gc2145.cpp‎

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
#define GC_MAX_WIN_W (1600)
1313
#define GC_MAX_WIN_H (1200)
1414

15-
#define FRAMESIZE_QVGA_W (320)
16-
#define FRAMESIZE_QVGA_H (240)
17-
18-
#define FRAMESIZE_VGA_W (640)
19-
#define FRAMESIZE_VGA_H (480)
20-
21-
#define FRAMESIZE_SVGA_W (800)
22-
#define FRAMESIZE_SVGA_H (600)
23-
24-
#define FRAMESIZE_UXGA_W (1600)
25-
#define FRAMESIZE_UXGA_H (1200)
26-
2715
#define REG_AMODE1 (0x17)
2816
#define REG_AMODE1_DEF (0x14)
2917
#define REG_AMODE1_SET_HMIRROR(r, x) ((r&0xFE)|((x&1)<<0))
@@ -716,11 +704,6 @@ int GC2145::Init()
716704
reg_write(GC2145_I2C_ADDR, default_regs[i][0], default_regs[i][1]);
717705
}
718706

719-
// TODO:
720-
// Set the format to bayer (1BPP) for now so things keep working.
721-
reg_write(GC2145_I2C_ADDR, 0xFE, 0x00); // P0 regs page.
722-
uint8_t reg = reg_read(GC2145_I2C_ADDR, REG_OUTPUT_FMT);
723-
reg_write(GC2145_I2C_ADDR, REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_BAYER));
724707
return 0;
725708
}
726709

@@ -755,54 +738,45 @@ int GC2145::Reset()
755738
return 0;
756739
}
757740

758-
int GC2145::SetFrameRate(uint32_t framerate)
741+
int GC2145::SetFrameRate(int32_t framerate)
759742
{
760743
return 0;
761744
}
762745

763-
int GC2145::SetResolution(uint32_t resolution)
746+
int GC2145::SetResolution(int32_t resolution)
764747
{
765748
int ret = 0;
766749

767750
uint16_t win_w;
768751
uint16_t win_h;
769752

770-
uint16_t w, h;
753+
uint16_t w = restab[resolution][0];
754+
uint16_t h = restab[resolution][1];
771755

772756
switch (resolution) {
773757
case CAMERA_R160x120:
774-
w = 160;
775-
h = 120;
758+
win_w = w * 4;
759+
win_h = h * 4;
776760
break;
777761
case CAMERA_R320x240:
778-
w = 320;
779-
h = 240;
780-
break;
781762
case CAMERA_R320x320:
782-
w = 320;
783-
h = 320;
784-
break;
763+
win_w = w * 3;
764+
win_h = h * 3;
765+
break;
766+
case CAMERA_R640x480:
767+
win_w = w * 2;
768+
win_h = h * 2;
769+
break;
770+
case CAMERA_R800x600:
771+
case CAMERA_R1600x1200:
772+
// For frames bigger than subsample using full UXGA window.
773+
win_w = 1600;
774+
win_h = 1200;
775+
break;
785776
default:
786777
return -1;
787778
}
788779

789-
if (w < FRAMESIZE_QVGA_W && h < FRAMESIZE_QVGA_H) {
790-
win_w = w * 4;
791-
win_h = h * 4;
792-
} else if (w < FRAMESIZE_VGA_W && h < FRAMESIZE_VGA_H) {
793-
win_w = w * 3;
794-
win_h = h * 3;
795-
} else if (w < FRAMESIZE_SVGA_W && h < FRAMESIZE_SVGA_H) {
796-
win_w = w * 2;
797-
win_h = h * 2;
798-
} else if (w <= FRAMESIZE_UXGA_W && h <= FRAMESIZE_UXGA_H) {
799-
// For frames bigger than subsample using full UXGA window.
800-
win_w = FRAMESIZE_UXGA_W;
801-
win_h = FRAMESIZE_UXGA_H;
802-
} else {
803-
return -1;
804-
}
805-
806780
uint16_t c_ratio = win_w / w;
807781
uint16_t r_ratio = win_h / h;
808782

@@ -829,7 +803,38 @@ int GC2145::SetResolution(uint32_t resolution)
829803

830804
}
831805

832-
int GC2145::SetPixelFormat(uint32_t pixelformat)
806+
int GC2145::SetPixelFormat(int32_t pixformat)
833807
{
834-
return 0;
808+
int ret = 0;
809+
uint8_t reg;
810+
811+
// P0 regs
812+
ret |= reg_write(GC2145_I2C_ADDR, 0xFE, 0x00);
813+
814+
// Read current output format reg
815+
reg = reg_read(GC2145_I2C_ADDR, REG_OUTPUT_FMT);
816+
817+
switch (pixformat) {
818+
case CAMERA_RGB565:
819+
ret |= reg_write(GC2145_I2C_ADDR,
820+
REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_RGB565));
821+
break;
822+
case CAMERA_GRAYSCALE:
823+
// TODO: There's no support for extracting GS from YUV so we use Bayer for 1BPP for now.
824+
//ret |= reg_write(GC2145_I2C_ADDR,
825+
// REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_YCBYCR));
826+
//break;
827+
case CAMERA_BAYER:
828+
// There's no BAYER support so it will just look off.
829+
// Make sure odd/even row are switched to work with our bayer conversion.
830+
ret |= reg_write(GC2145_I2C_ADDR,
831+
REG_SYNC_MODE, REG_SYNC_MODE_DEF | REG_SYNC_MODE_ROW_SWITCH);
832+
ret |= reg_write(GC2145_I2C_ADDR,
833+
REG_OUTPUT_FMT, REG_OUTPUT_SET_FMT(reg, REG_OUTPUT_FMT_BAYER));
834+
break;
835+
default:
836+
return -1;
837+
}
838+
839+
return ret;
835840
}

‎libraries/GC2145/gc2145.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class GC2145: public ImageSensor {
1919
int Reset();
2020
int GetID() { return GC2145_I2C_ADDR; };
2121
uint32_t GetClockFrequency() { return 12000000; };
22-
int SetFrameRate(uint32_t framerate);
23-
int SetResolution(uint32_t resolution);
24-
int SetPixelFormat(uint32_t pixelformat);
22+
int SetFrameRate(int32_t framerate);
23+
int SetResolution(int32_t resolution);
24+
int SetPixelFormat(int32_t pixformat);
2525
};
2626

2727
#endif /* __GC2145_H */

‎libraries/Himax_HM01B0/himax.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int HM01B0::Reset()
317317
return max_timeout>0 ? 0: -1 ;
318318
}
319319

320-
int HM01B0::SetResolution(uint32_t resolution)
320+
int HM01B0::SetResolution(int32_t resolution)
321321
{
322322
int ret = 0;
323323

@@ -344,7 +344,7 @@ int HM01B0::SetResolution(uint32_t resolution)
344344
return ret;
345345
}
346346

347-
int HM01B0::SetFrameRate(uint32_t framerate)
347+
int HM01B0::SetFrameRate(int32_t framerate)
348348
{
349349
uint8_t osc_div = 0;
350350
// binning is enabled for QQVGA
@@ -371,9 +371,9 @@ int HM01B0::SetFrameRate(uint32_t framerate)
371371
return reg_write(HM01B0_I2C_ADDR, OSC_CLK_DIV, 0x08 | osc_div, true);
372372
}
373373

374-
int HM01B0::SetPixelFormat(uint32_t pixelformat)
374+
int HM01B0::SetPixelFormat(int32_t pixformat)
375375
{
376-
return -1;
376+
return (pixformat == CAMERA_GRAYSCALE) ? 0 : -1;
377377
}
378378

379379
int HM01B0::SetTestPattern(bool enable, bool walking)

‎libraries/Himax_HM01B0/himax.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class HM01B0: public ImageSensor {
1717
int Reset();
1818
int GetID() { return HM01B0_I2C_ADDR; };
1919
uint32_t GetClockFrequency() { return 6000000; };
20-
int SetFrameRate(uint32_t framerate);
21-
int SetResolution(uint32_t resolution);
22-
int SetPixelFormat(uint32_t pixelformat);
20+
int SetFrameRate(int32_t framerate);
21+
int SetResolution(int32_t resolution);
22+
int SetPixelFormat(int32_t pixformat);
2323
int SetTestPattern(bool enable, bool walking);
2424
int EnableMD(bool enable);
2525
int SetMDThreshold(uint32_t threshold);

‎libraries/Portenta_Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
#include "camera.h"
22
#include "SDRAM.h"
3-
#include"himax.h"
3+
44
//REDIRECT_STDOUT_TO(Serial);
55

6+
// Uncomment for HM01B0
7+
#include "himax.h"
68
Camera cam(new HM01B0());
9+
10+
// Uncomment to use GC2145 instead
11+
//#include "gc2145.h"
12+
//Camera cam(new GC2145());
13+
714
uint8_t *fb = (uint8_t*) SDRAM_START_ADDRESS;
815

9-
void blink_error(uint32_t count)
16+
void blink_error(uint32_t count = 0xFFFFFFFF)
1017
{
1118
pinMode(LED_BUILTIN, OUTPUT);
1219
while (count--) {
@@ -21,11 +28,11 @@ void setup() {
2128
Serial.begin(921600);
2229

2330
// Init DRAM and reserve 2MB for framebuffer.
24-
SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024);
31+
SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024);
2532

2633
// Init the cam QVGA, 30FPS
27-
if (cam.begin(CAMERA_R320x240, 30) != 0) {
28-
blink_error(0xFFFFFFFF);
34+
if (cam.begin(CAMERA_R320x240, CAMERA_GRAYSCALE, 30) != 0) {
35+
blink_error();
2936
}
3037

3138
//Serial.print("Sensor ID:");
@@ -39,8 +46,8 @@ void loop() {
3946

4047
// Grab frame and write to serial
4148
if (cam.GrabFrame(fb, 3000) == 0) {
42-
Serial.write(fb, 320*240);
49+
Serial.write(fb, cam.FrameSize());
4350
} else {
44-
blink_error(0xFFFFFFFF);
45-
}
51+
blink_error();
52+
}
4653
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /