diff --git a/src/Adafruit_dvhstx.cpp b/src/Adafruit_dvhstx.cpp index 71c1c79..f32fc81 100644 --- a/src/Adafruit_dvhstx.cpp +++ b/src/Adafruit_dvhstx.cpp @@ -74,6 +74,7 @@ void DVHSTX16::swap(bool copy_framebuffer) { memcpy(hstx.get_front_buffer(), hstx.get_back_buffer(), sizeof(uint16_t) * _width * _height); } + buffer = hstx.get_back_buffer(); } void DVHSTX8::swap(bool copy_framebuffer) { if (!double_buffered) { @@ -84,6 +85,18 @@ void DVHSTX8::swap(bool copy_framebuffer) { memcpy(hstx.get_front_buffer(), hstx.get_back_buffer(), sizeof(uint8_t) * _width * _height); } + buffer = hstx.get_back_buffer(); +} +void DVHSTXText::swap(bool copy_framebuffer) { + if (!double_buffered) { + return; + } + hstx.flip_blocking(); + if (copy_framebuffer) { + memcpy(hstx.get_front_buffer(), hstx.get_back_buffer(), + sizeof(uint16_t) * _width * _height); + } + buffer = hstx.get_back_buffer(); } void DVHSTXText::clear() { diff --git a/src/Adafruit_dvhstx.h b/src/Adafruit_dvhstx.h index d3f4ab7..bf56f08 100644 --- a/src/Adafruit_dvhstx.h +++ b/src/Adafruit_dvhstx.h @@ -283,11 +283,12 @@ public: /*! @brief Instatiate a DVHSTX 8-bit canvas context for graphics @param pinout Details of the HSTX pinout + @param double_buffered Whether to allocate two buffers */ /**************************************************************************/ - DVHSTXText(DVHSTXPinout pinout) - : GFXcanvas16(91, 30, false), pinout(pinout), res{}, - attr{TextColor::TEXT_WHITE} {} + DVHSTXText(DVHSTXPinout pinout, bool double_buffered = false) + : GFXcanvas16(91, 30, false), double_buffered{double_buffered}, + pinout(pinout), res{}, attr{TextColor::TEXT_WHITE} {} ~DVHSTXText() { end(); } /**************************************************************************/ @@ -305,8 +306,8 @@ public: */ /**************************************************************************/ bool begin() { - bool result = - hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111, false, pinout); + bool result = hstx.init(91, 30, pimoroni::DVHSTX::MODE_TEXT_RGB111, + double_buffered, pinout); if (!result) return false; buffer = hstx.get_back_buffer(); @@ -428,6 +429,16 @@ public: /**************************************************************************/ int getCursorY() const { return cursor_y; } + /**********************************************************************/ + /*! + @brief If double-buffered, wait for retrace and swap buffers. Otherwise, + do nothing (returns immediately) + @param copy_framebuffer if true, copy the new screen to the new back buffer. + Otherwise, the content is undefined. + */ + /**********************************************************************/ + void swap(bool copy_framebuffer = false); + private: DVHSTXPinout pinout; DVHSTXResolution res; diff --git a/src/drivers/dvhstx/dvhstx.hpp b/src/drivers/dvhstx/dvhstx.hpp index 7ca148f..46f5da2 100644 --- a/src/drivers/dvhstx/dvhstx.hpp +++ b/src/drivers/dvhstx/dvhstx.hpp @@ -126,7 +126,6 @@ namespace pimoroni { private: RGB888 palette[PALETTE_SIZE]; - bool double_buffered; uint8_t* frame_buffer_display; uint8_t* frame_buffer_back; uint32_t* font_cache = nullptr;