From 528fc5661679feeef91e76d633c94c945bb0a3df Mon Sep 17 00:00:00 2001 From: JF Date: Sat, 7 Dec 2019 19:15:33 +0100 Subject: The font is now fixed width. HUGE performance improvement of the display driver. --- src/drivers/SpiMaster.h | 1 - src/drivers/St7789.cpp | 32 ++++++++++++++++++++++---------- src/drivers/St7789.h | 4 ++++ 3 files changed, 26 insertions(+), 11 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/SpiMaster.h b/src/drivers/SpiMaster.h index 10cab12c..9f2208e0 100644 --- a/src/drivers/SpiMaster.h +++ b/src/drivers/SpiMaster.h @@ -21,7 +21,6 @@ namespace Pinetime { uint8_t pinCSN; }; bool Init(const SpiModule spi, const Parameters& params); - bool Write(const uint8_t* data, size_t size); private: diff --git a/src/drivers/St7789.cpp b/src/drivers/St7789.cpp index dcc32fe6..0c18a610 100644 --- a/src/drivers/St7789.cpp +++ b/src/drivers/St7789.cpp @@ -91,22 +91,17 @@ void St7789::DisplayOn() { } void St7789::FillRectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color) { - // rudimentary clipping (drawChar w/big text requires this) - if((x >= Width) || (y >= Height)) return; - if((x + width - 1) >= Width) width = Width - x; - if((y + height - 1) >= Height) height = Height - y; - - SetAddrWindow(0+x, ST7789_ROW_OFFSET+y, x+width-1, y+height-1); + BeginDrawBuffer(x, y, width, height); - uint8_t hi = color >> 8, lo = color; uint32_t c = color + (color << 16); + uint8_t w = width/2; - nrf_gpio_pin_set(pinDataCommand); for(y=height+ST7789_ROW_OFFSET; y>ST7789_ROW_OFFSET; y--) { - for(x=width; x>0; x--) { - WriteSpi(reinterpret_cast(&c), 4); + for(x=w; x>0; x--) { + NextDrawBuffer(reinterpret_cast(&c), 4); } } + EndDrawBuffer(); } void St7789::SetAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { @@ -147,3 +142,20 @@ void St7789::DrawPixel(uint16_t x, uint16_t y, uint32_t color) { WriteSpi(reinterpret_cast(&color), 2); } +void St7789::BeginDrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { + if((x >= Width) || (y >= Height)) return; + if((x + width - 1) >= Width) width = Width - x; + if((y + height - 1) >= Height) height = Height - y; + + SetAddrWindow(0+x, ST7789_ROW_OFFSET+y, x+width-1, y+height-1); + nrf_gpio_pin_set(pinDataCommand); +} + +void St7789::EndDrawBuffer() { +} + +void St7789::NextDrawBuffer(const uint8_t *data, size_t size) { + spi.Write(data, size); +} + + diff --git a/src/drivers/St7789.h b/src/drivers/St7789.h index bd7f9799..97427753 100644 --- a/src/drivers/St7789.h +++ b/src/drivers/St7789.h @@ -12,6 +12,10 @@ namespace Pinetime { void DrawPixel(uint16_t x, uint16_t y, uint32_t color); void FillRectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color); + void BeginDrawBuffer(uint16_t x, uint16_t y, uint16_t width, uint16_t height); + void NextDrawBuffer(const uint8_t* data, size_t size); + void EndDrawBuffer(); + private: SpiMaster& spi; -- cgit v1.2.3-70-g09d2