The font is now fixed width.

HUGE performance improvement of the display driver.
This commit is contained in:
JF 2019-12-07 19:15:33 +01:00
parent 6fbb6c8f70
commit 528fc56616
8 changed files with 4356 additions and 4279 deletions

View file

@ -8,7 +8,11 @@ Gfx::Gfx(Pinetime::Drivers::St7789 &lcd) : lcd{lcd} {
}
void Gfx::ClearScreen() {
lcd.FillRectangle(0, 0, width, height, 0xffff);
lcd.FillRectangle(0, 0, width, height, 0x0000);
}
void Gfx::FillRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color) {
lcd.FillRectangle(x, y, width, height, color);
}
void Gfx::DrawString(uint8_t x, uint8_t y, uint16_t color, const char *text, const FONT_INFO *p_font, bool wrap) {
@ -55,17 +59,25 @@ void Gfx::DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint
return;
}
// TODO For now, LCD and SPI driver start a new transfer (cs pin + set address windows + write byte) FOR EACH PIXEL!
// This could be improved by setting CS pin, DC pin and address window ONLY ONCE for the whole character
lcd.BeginDrawBuffer(*x, y, bytes_in_line*8, font->height);
uint16_t bg = 0x0000;
for (uint16_t i = 0; i < font->height; i++) {
for (uint16_t j = 0; j < bytes_in_line; j++) {
for (uint8_t k = 0; k < 8; k++) {
if ((1 << (7 - k)) &
font->data[font->charInfo[char_idx].offset + i * bytes_in_line + j]) {
pixel_draw(*x + j * 8 + k, y + i, color);
lcd.NextDrawBuffer(reinterpret_cast<uint8_t *>(&color), 2);
}
else {
lcd.NextDrawBuffer(reinterpret_cast<uint8_t *>(&bg), 2);
}
}
}
}
lcd.EndDrawBuffer();
*x += font->charInfo[char_idx].widthBits + font->spacePixels;
}

View file

@ -14,7 +14,7 @@ namespace Pinetime {
void ClearScreen();
void DrawString(uint8_t x, uint8_t y, uint16_t color, const char* text, const FONT_INFO *p_font, bool wrap);
void DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint16_t color);
void FillRectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint16_t color);
private:
Drivers::St7789& lcd;

View file

@ -4,6 +4,7 @@
#include <libraries/log/nrf_log.h>
#include <boards.h>
#include <nrf_font.h>
#include <hal/nrf_rtc.h>
#include "Components/Gfx/Gfx.h"
using namespace Pinetime::Applications;
@ -21,6 +22,9 @@ void DisplayApp::Process(void *instance) {
while (1) {
NRF_LOG_INFO("BlinkApp task running!");
app->Refresh();
vTaskDelay(1000);
}
}
@ -48,17 +52,57 @@ void DisplayApp::InitHw() {
gfx->ClearScreen();
uint8_t x = 7;
gfx->DrawChar(&largeFont , '0', &x, 78, 0x0);
gfx->DrawChar(&largeFont , '0', &x, 78, 0xffff);
x = 61;
gfx->DrawChar(&largeFont, '1', &x, 78, 0x0);
gfx->DrawChar(&largeFont, '0', &x, 78, 0xffff);
x = 115;
gfx->DrawChar(&largeFont, ':', &x, 78, 0x0);
x = 94;
gfx->DrawChar(&largeFont, ':', &x, 78, 0xffff);
x = 127;
gfx->DrawChar(&largeFont, '2', &x, 78, 0x0);
gfx->DrawChar(&largeFont, '0', &x, 78, 0xffff);
x = 181;
gfx->DrawChar(&largeFont, '3', &x, 78, 0x0);
gfx->DrawChar(&largeFont, '0', &x, 78, 0xffff);
}
void DisplayApp::Refresh() {
uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG);
auto raw = systick_counter / 1000;
// TODO make this better!
minutes = raw / 60;
seconds = raw - (minutes*60);
char secondChar[3];
sprintf(secondChar, "%02d", seconds);
char minutesChar[3];
sprintf(minutesChar, "%02d", minutes);
uint8_t x = 7;
if(minutesChar[0] != currentChar[0]) {
gfx->DrawChar(&largeFont, minutesChar[0], &x, 78, 0xffff);
currentChar[0] = minutesChar[0];
}
x = 61;
if(minutesChar[1] != currentChar[1]) {
gfx->DrawChar(&largeFont, minutesChar[1], &x, 78, 0xffff);
currentChar[1] = minutesChar[1];
}
x = 127;
if(secondChar[0] != currentChar[2]) {
gfx->DrawChar(&largeFont, secondChar[0], &x, 78, 0xffff);
currentChar[2] = secondChar[0];
}
x = 181;
if(secondChar[1] != currentChar[3]) {
gfx->DrawChar(&largeFont, secondChar[1], &x, 78, 0xffff);
currentChar[3] = secondChar[1];
}
}

View file

@ -22,6 +22,12 @@ namespace Pinetime {
std::unique_ptr<Drivers::St7789> lcd;
std::unique_ptr<Components::Gfx> gfx;
const FONT_INFO largeFont {lCD_70ptFontInfo.height, lCD_70ptFontInfo.startChar, lCD_70ptFontInfo.endChar, lCD_70ptFontInfo.spacePixels, lCD_70ptFontInfo.charInfo, lCD_70ptFontInfo.data};
void Refresh();
uint8_t seconds = 0;
uint8_t minutes = 0;
uint8_t hours = 0;
char currentChar[4];
};
}
}

File diff suppressed because it is too large Load diff

View file

@ -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:

View file

@ -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;
BeginDrawBuffer(x, y, width, height);
SetAddrWindow(0+x, ST7789_ROW_OFFSET+y, x+width-1, y+height-1);
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<const uint8_t *>(&c), 4);
for(x=w; x>0; x--) {
NextDrawBuffer(reinterpret_cast<const uint8_t *>(&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<const uint8_t *>(&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);
}

View file

@ -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;