mirror of
https://github.com/sipeed/Maixduino.git
synced 2026-03-03 09:04:00 +01:00
Added support for binocular camera
This commit is contained in:
35
libraries/Sipeed_GC0328/examples/sipeed_gc0328_binocular.ino
Normal file
35
libraries/Sipeed_GC0328/examples/sipeed_gc0328_binocular.ino
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <Sipeed_GC0328.h>
|
||||
#include <Sipeed_ST7789.h>
|
||||
|
||||
SPIClass spi_(SPI0); // MUST be SPI0 for Maix series on board LCD
|
||||
Sipeed_ST7789 lcd(320, 240, spi_);
|
||||
Sipeed_GC0328 camera(FRAMESIZE_QVGA, PIXFORMAT_RGB565, &Wire);
|
||||
|
||||
// Use left camera if true, right camera when true
|
||||
bool leftCamera = true;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
lcd.begin(15000000, COLOR_RED);
|
||||
|
||||
// Start camera in binocular mode
|
||||
if(!camera.begin(true))
|
||||
Serial.printf("camera init fail\n");
|
||||
else
|
||||
Serial.printf("camera init success\n");
|
||||
camera.run(true);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Switch left/right cameras
|
||||
camera.shutdown(leftCamera);
|
||||
leftCamera = !leftCamera;
|
||||
|
||||
uint8_t*img = camera.snapshot();
|
||||
if(img == nullptr || img==0)
|
||||
Serial.printf("snap fail\r\n");
|
||||
else
|
||||
lcd.drawImage(0, 0, camera.width(), camera.height(), (uint16_t*)img);
|
||||
}
|
||||
@@ -587,6 +587,11 @@ Sipeed_GC0328::~Sipeed_GC0328()
|
||||
}
|
||||
|
||||
bool Sipeed_GC0328::begin()
|
||||
{
|
||||
return begin(false);
|
||||
}
|
||||
|
||||
bool Sipeed_GC0328::begin(bool binocular)
|
||||
{
|
||||
if(_dataBuffer)
|
||||
free(_dataBuffer);
|
||||
@@ -607,12 +612,31 @@ bool Sipeed_GC0328::begin()
|
||||
free(_dataBuffer);
|
||||
return false;
|
||||
}
|
||||
if(!reset())
|
||||
if(!reset(binocular))
|
||||
return false;
|
||||
if(!setPixFormat(_pixFormat))
|
||||
return false;
|
||||
if(!setFrameSize(_frameSize))
|
||||
return false;
|
||||
|
||||
if(binocular) {
|
||||
// Configure sensor 0
|
||||
shutdown(true);
|
||||
if(!setPixFormat(_pixFormat))
|
||||
return false;
|
||||
if(!setFrameSize(_frameSize))
|
||||
return false;
|
||||
|
||||
// Configure sensor 1
|
||||
shutdown(false);
|
||||
if(!setPixFormat(_pixFormat))
|
||||
return false;
|
||||
if(!setFrameSize(_frameSize))
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(!setPixFormat(_pixFormat))
|
||||
return false;
|
||||
if(!setFrameSize(_frameSize))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -626,14 +650,39 @@ void Sipeed_GC0328::end()
|
||||
_aiBuffer = nullptr;
|
||||
}
|
||||
|
||||
bool Sipeed_GC0328::reset()
|
||||
bool Sipeed_GC0328::reset(bool binocular)
|
||||
{
|
||||
if(dvpInit() != 0) // dvp hardware init
|
||||
return false;
|
||||
if(sensro_gc_detect() != 0) // gc0328 camera detect
|
||||
return false;
|
||||
if(gc0328_reset() != 0)
|
||||
return false;
|
||||
|
||||
if(binocular)
|
||||
{
|
||||
// Reset sensor 0
|
||||
shutdown(true);
|
||||
DCMI_RESET_LOW();
|
||||
delay(10);
|
||||
DCMI_RESET_HIGH();
|
||||
delay(10);
|
||||
if(gc0328_reset() != 0)
|
||||
return false;
|
||||
|
||||
// Reset sensor 1
|
||||
shutdown(false);
|
||||
delay(10);
|
||||
DCMI_RESET_LOW();
|
||||
delay(10);
|
||||
DCMI_RESET_HIGH();
|
||||
delay(10);
|
||||
if(gc0328_reset() != 0)
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if(gc0328_reset() != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
if(dvpInitIrq() != 0)
|
||||
return false;
|
||||
return true;
|
||||
@@ -705,6 +754,20 @@ void Sipeed_GC0328::setInvert(bool invert)
|
||||
return;
|
||||
}
|
||||
|
||||
void Sipeed_GC0328::shutdown(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
{
|
||||
DCMI_PWDN_HIGH();
|
||||
}
|
||||
else
|
||||
{
|
||||
DCMI_PWDN_LOW();
|
||||
}
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
int Sipeed_GC0328::dvpInit(uint32_t freq)
|
||||
{
|
||||
// just support RGB565 and YUV442 on k210
|
||||
|
||||
@@ -34,8 +34,9 @@ public:
|
||||
~Sipeed_GC0328();
|
||||
|
||||
virtual bool begin();
|
||||
bool begin(bool binocular);
|
||||
virtual void end();
|
||||
bool reset();
|
||||
bool reset(bool binocular = false);
|
||||
bool setPixFormat(pixformat_t pixFormat);
|
||||
bool setFrameSize(framesize_t frameSize);
|
||||
virtual bool run(bool run);
|
||||
@@ -49,6 +50,7 @@ public:
|
||||
virtual uint8_t* getRGB888(){ return _aiBuffer; };
|
||||
virtual void setRotation(uint8_t rotation);
|
||||
virtual void setInvert(bool invert);
|
||||
virtual void shutdown(bool enable);
|
||||
|
||||
private:
|
||||
uint8_t* _dataBuffer; // put RGB565 data
|
||||
|
||||
Reference in New Issue
Block a user