Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
/*
GigaDisplay GFX - Basic
This sketch initializes the Arduino Giga Display in Landscape mode (rotated 90°)
and draws a solid red rectangle perfectly centered on the screen.
Default orientation is Portrait (480x800).
*/

#include "Arduino_GigaDisplay_GFX.h"

GigaDisplay_GFX display;

void setup() {
Serial.begin(115200);
display.begin();

// Set rotation to 90 degrees (Landscape)
// Default is 0 (Portrait, where width is the short side: 480)
display.setRotation(1);

// Clear screen to black
display.fillScreen(0x0000);

// Define rectangle dimensions
int rectW = 200;
int rectH = 100;

// Calculate centered coordinates (now based on 800x480)
int x = (display.width() - rectW) / 2;
int y = (display.height() - rectH) / 2;

// Generate 16-bit RGB565 red color
uint16_t red = display.color565(255, 0, 0);

// Draw filled red rectangle at center
display.fillRect(x, y, rectW, rectH, red);
}

void loop() {
Serial.println(millis());
display.fillScreen(0);
display.fillRect(120, 180, 120, 180, 0x8888);
display.print(false);
delay(100);
}
10 changes: 10 additions & 0 deletions examples/Demo/Demo.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/*
GigaDisplay GFX - Demo
This sketch performs a comprehensive speed test of the GFX library,
measuring performance for text, lines, shapes, and rotations.
Optimized for Landscape mode (800x480) on the Arduino Giga Display.
*/

#include "Arduino_GigaDisplay_GFX.h"

GigaDisplay_GFX tft;
Expand All @@ -16,6 +23,9 @@ void setup() {
Serial.println("GC9A01A Test!");

tft.begin();
// Rotate 90° clockwise to Landscape (800x480)
// By default, width is the short side (480)
tft.setRotation(1);

Serial.println(F("Benchmark Time (microseconds)"));
delay(10);
Expand Down
53 changes: 33 additions & 20 deletions src/Arduino_GigaDisplay_GFX.cpp
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@

#include "Arduino_GigaDisplay_GFX.h"
#include "platform/mbed_critical.h"

GigaDisplay_GFX::GigaDisplay_GFX() : Adafruit_GFX(480, 800) {
#ifdef __MBED__
#include "platform/mbed_critical.h"
#endif

}
GigaDisplay_GFX::GigaDisplay_GFX() : Adafruit_GFX(480, 800) { }

GigaDisplay_GFX::~GigaDisplay_GFX(void) {
if (buffer)
free(buffer);
}

//rtos::Semaphore refresh_sem(1);

#ifdef __MBED__
void GigaDisplay_GFX::refresh_if_needed() {
while (1) {
rtos::ThisThread::flags_wait_any(0x1);
//refresh_sem.acquire();
dsi_lcdDrawImage((void *) this->getBuffer(), (void *)(dsi_getActiveFrameBuffer()), 480, 800, DMA2D_INPUT_RGB565);
//dsi_lcdDrawImage((void *) this->getBuffer(), (void *)(dsi_getActiveFrameBuffer()), this->width(), this->height(), DMA2D_INPUT_RGB565);
//refresh_sem.release();
delay(10);
}
}

#endif

void GigaDisplay_GFX::begin() {
display = new Arduino_H7_Video(480, 800, GigaDisplayShield);
display = new Arduino_Video(480, 800, GigaDisplayShield);
display->begin();
buffer = (uint16_t*)ea_malloc(this->width() * this-> height() * 2);
_refresh_thd = new rtos::Thread(osPriorityHigh);
_refresh_thd->start(mbed::callback(this, &GigaDisplay_GFX::refresh_if_needed));
//buffer = (uint16_t*)dsi_getActiveFrameBuffer();
}

void GigaDisplay_GFX::startWrite() {
//refresh_sem.acquire();
#ifdef __MBED__
buffer = (uint16_t*)ea_malloc(this->width() * this-> height() * 2);
_refresh_thd = new rtos::Thread(osPriorityHigh);
_refresh_thd->start(mbed::callback(this, &GigaDisplay_GFX::refresh_if_needed));
#elif defined(__ZEPHYR__)
#ifdef CONFIG_SHARED_MULTI_HEAP
void* ptrFB = this->display->getFramebuffer();
if (ptrFB == nullptr){
while(1){}
}
// Cast the void pointer to an int pointer to use it
buffer = static_cast<uint16_t*>(ptrFB);
#else
SDRAM.begin();
buffer = (uint16_t*)SDRAM.malloc(this->width() * this-> height() * sizeof(uint16_t));
#endif
this->display->setFrameDesc(this->width(), this->height(), this->width(), (this->width() * this-> height() * sizeof(uint16_t)));
#endif
}

void GigaDisplay_GFX::startWrite() { }

void GigaDisplay_GFX::endWrite() {
//refresh_sem.release();
#ifdef __MBED__
if (!buffering)
_refresh_thd->flags_set(0x1);
#elif defined(__ZEPHYR__)
if (!buffering)
this->display->drawBuffer(0, 0, buffer);
#endif
}

// If buffering, defer endWrite calls until endBuffering is called.
Expand All @@ -50,8 +64,7 @@ void GigaDisplay_GFX::startBuffering() {
}

void GigaDisplay_GFX::endBuffering() {
if (buffering)
{
if (buffering) {
buffering = false;
endWrite();
}
Expand Down
12 changes: 8 additions & 4 deletions src/Arduino_GigaDisplay_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
#ifndef __ARDUINO_GIGADISPLAY_GFX__
#define __ARDUINO_GIGADISPLAY_GFX__

#include "Arduino_H7_Video.h"
#include "Arduino_Video.h"
#include "Adafruit_GFX.h"

#if __MBED__
#include "Adafruit_SPITFT.h"
#include "dsi.h"
#include "SDRAM.h"
#endif

class GigaDisplay_GFX : public Adafruit_GFX {
public:
Expand Down Expand Up @@ -45,12 +48,13 @@ class GigaDisplay_GFX : public Adafruit_GFX {
uint16_t *buffer = nullptr; ///< Raster data: no longer private, allow subclass access

private:
Arduino_H7_Video* display;
Arduino_Video* display;
#ifdef __MBED__
rtos::Thread* _refresh_thd;
void refresh_if_needed();
//bool need_refresh = false;
#endif
bool buffering = false;
uint32_t last_refresh = 0;
rtos::Thread* _refresh_thd;
};

#endif //__ARDUINO_GIGADISPLAY_GFX__