diff options
author | JF <jf@codingfield.com> | 2020-01-19 19:47:49 +0100 |
---|---|---|
committer | JF <jf@codingfield.com> | 2020-01-19 19:47:49 +0100 |
commit | b4bd41cd562f89bcd320ac0985e9b33c766babe1 (patch) | |
tree | e64c79bd4f61452c93ee45b75aa26bbf8252d731 /src/Components/Gfx | |
parent | 9dc4e32e36eb1167ee241cdf8027089cad593cf1 (diff) |
Implement the SPI driver using DMA.
Diffstat (limited to 'src/Components/Gfx')
-rw-r--r-- | src/Components/Gfx/Gfx.cpp | 28 | ||||
-rw-r--r-- | src/Components/Gfx/Gfx.h | 8 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/Components/Gfx/Gfx.cpp b/src/Components/Gfx/Gfx.cpp index 9e680687..6c19518a 100644 --- a/src/Components/Gfx/Gfx.cpp +++ b/src/Components/Gfx/Gfx.cpp @@ -11,11 +11,21 @@ void Gfx::Init() { } void Gfx::ClearScreen() { - lcd.FillRectangle(0, 0, width, height, 0x0000); + SetBackgroundColor(0x0000); + lcd.BeginDrawBuffer(0, 0, width, height); + for(int i = 0; i < height; i++) { + lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2); + } + lcd.EndDrawBuffer(); } 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); + SetBackgroundColor(color); + lcd.BeginDrawBuffer(0, 0, width, height); + for(int i = 0; i < height; i++) { + lcd.NextDrawBuffer(reinterpret_cast<const uint8_t *>(buffer), width * 2); + } + lcd.EndDrawBuffer(); } void Gfx::DrawString(uint8_t x, uint8_t y, uint16_t color, const char *text, const FONT_INFO *p_font, bool wrap) { @@ -70,15 +80,15 @@ void Gfx::DrawChar(const FONT_INFO *font, uint8_t c, uint8_t *x, uint8_t y, uint 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]) { - lcd.NextDrawBuffer(reinterpret_cast<uint8_t *>(&color), 2); + if ((1 << (7 - k)) & font->data[font->charInfo[char_idx].offset + i * bytes_in_line + j]) { + buffer[(j*8)+k] = color; } else { - lcd.NextDrawBuffer(reinterpret_cast<uint8_t *>(&bg), 2); + buffer[(j*8)+k] = bg; } } } + lcd.NextDrawBuffer(reinterpret_cast<uint8_t *>(&buffer), bytes_in_line*8*2); } lcd.EndDrawBuffer(); *x += font->charInfo[char_idx].widthBits + font->spacePixels; @@ -96,4 +106,10 @@ void Gfx::Wakeup() { lcd.Wakeup(); } +void Gfx::SetBackgroundColor(uint16_t color) { + for(int i = 0; i < width; i++) { + buffer[i] = color; + } +} + diff --git a/src/Components/Gfx/Gfx.h b/src/Components/Gfx/Gfx.h index 9bd07fee..d8728701 100644 --- a/src/Components/Gfx/Gfx.h +++ b/src/Components/Gfx/Gfx.h @@ -21,10 +21,14 @@ namespace Pinetime { void Wakeup(); private: + static constexpr uint8_t width = 240; + static constexpr uint8_t height = 240; + + uint16_t buffer[width]; // 1 line buffer Drivers::St7789& lcd; - const uint8_t width = 240; - const uint8_t height = 240; + void pixel_draw(uint8_t x, uint8_t y, uint16_t color); + void SetBackgroundColor(uint16_t color); }; } } |