Skip to content

Update for zephyr #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
41 changes: 40 additions & 1 deletion src/Arduino_GigaDisplay_GFX.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

#include "Arduino_GigaDisplay_GFX.h"

#ifdef __MBED__
#include "platform/mbed_critical.h"
#endif

#ifdef __ZEPHYR
#include "Arduino_GigaDisplay.h"
#endif

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

Expand All @@ -13,6 +20,7 @@ GigaDisplay_GFX::~GigaDisplay_GFX(void) {

//rtos::Semaphore refresh_sem(1);

#ifdef __MBED__
void GigaDisplay_GFX::refresh_if_needed() {
while (1) {
rtos::ThisThread::flags_wait_any(0x1);
Expand All @@ -23,15 +31,40 @@ void GigaDisplay_GFX::refresh_if_needed() {
delay(10);
}
}

#endif

void GigaDisplay_GFX::begin() {
#ifdef __MBED__
display = new Arduino_H7_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();
#elif defined(__ZEPHYR__)
display = new Display();
display->begin();
#ifdef CONFIG_SHARED_MULTI_HEAP
void* ptrFB = this->display->getFrameBuffer();
if (ptrFB == nullptr){
Serial.println("Memory not allocated successfully." );
while(1){}
}
// Cast the void pointer to an int pointer to use it
buffer = static_cast<uint16_t*>(ptrFB);
//buffer = (uint16_t*)shared_multi_heap_aligned_alloc(SMH_REG_ATTR_EXTERNAL, 16, (this->width() * this-> height() * sizeof(uint16_t)));
#else
SDRAM.begin();
buffer = (uint16_t*)SDRAM.malloc(this->width() * this-> height() * sizeof(uint16_t));
#endif
sizeof_framebuffer = this->width() * this-> height() * sizeof(uint16_t);
this->display->setFrameDesc(this->width(), this-> height(), this-> width(), sizeof_framebuffer);
Serial.print("Buffer: 0x"); Serial.println((uint32_t)buffer, HEX);

// turn on the display backlight
pinMode(74, OUTPUT);
digitalWrite(74, HIGH);
#endif
}

void GigaDisplay_GFX::startWrite() {
Expand All @@ -40,8 +73,14 @@ 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->write8(0, 0, buffer);
#endif

}

// If buffering, defer endWrite calls until endBuffering is called.
Expand Down
17 changes: 16 additions & 1 deletion src/Arduino_GigaDisplay_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
#ifndef __ARDUINO_GIGADISPLAY_GFX__
#define __ARDUINO_GIGADISPLAY_GFX__

#ifdef __ZEPHYR__
#include "Adafruit_GFX.h"
#include "Arduino_GigaDisplay.h"
//#include "Adafruit_SPITFT.h"
#endif

#ifdef __MBED__
#include "Arduino_H7_Video.h"
#include "Adafruit_GFX.h"
#include "Adafruit_SPITFT.h"
#include "dsi.h"
#endif

#include "SDRAM.h"

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

private:
#ifdef __MBED__
Arduino_H7_Video* display;
rtos::Thread* _refresh_thd;
void refresh_if_needed();
#elif defined(__ZEPHYR__)
Display* display;
uint32_t sizeof_framebuffer;
#endif
//bool need_refresh = false;
bool buffering = false;
uint32_t last_refresh = 0;
rtos::Thread* _refresh_thd;

};

#endif //__ARDUINO_GIGADISPLAY_GFX__