diff --git a/src/helpers/ui/ST7789Display.cpp b/src/helpers/ui/ST7789Display.cpp index 71f88ff1..fcb36c3b 100644 --- a/src/helpers/ui/ST7789Display.cpp +++ b/src/helpers/ui/ST7789Display.cpp @@ -2,6 +2,10 @@ #include "ST7789Display.h" +#ifndef X_OFFSET +#define X_OFFSET 16 +#endif + bool ST7789Display::begin() { if(!_isOn) { pinMode(PIN_TFT_VDD_CTL, OUTPUT); @@ -11,6 +15,7 @@ bool ST7789Display::begin() { digitalWrite(PIN_TFT_RST, HIGH); display.init(); + display.landscapeScreen(); display.displayOn(); _isOn = true; @@ -26,34 +31,23 @@ void ST7789Display::turnOff() { digitalWrite(PIN_TFT_VDD_CTL, HIGH); digitalWrite(PIN_TFT_LEDA_CTL, HIGH); digitalWrite(PIN_TFT_RST, LOW); - // digitalWrite(PIN_TFT_VDD_CTL, LOW); - // digitalWrite(PIN_TFT_LEDA_CTL, LOW); _isOn = false; } void ST7789Display::clear() { - // display.fillScreen(ST77XX_BLACK); display.clear(); } void ST7789Display::startFrame(Color bkg) { display.clear(); - // display.fillScreen(0x00); - // display.setTextColor(ST77XX_WHITE); - // display.setTextSize(2); - // display.cp437(true); // Use full 256 char 'Code Page 437' font } void ST7789Display::setTextSize(int sz) { -// display.setTextSize(sz); switch(sz) { case 1 : display.setFont(ArialMT_Plain_10); break; case 2 : - display.setFont(ArialMT_Plain_16); - break; - case 3 : display.setFont(ArialMT_Plain_24); break; default: @@ -89,12 +83,10 @@ void ST7789Display::setColor(Color c) { break; } display.setRGB(_color); - //display.setColor((OLEDDISPLAY_COLOR) 4); } void ST7789Display::setCursor(int x, int y) { - //display.setCursor(x, y); - _x = x; + _x = x + X_OFFSET; _y = y; } @@ -103,15 +95,15 @@ void ST7789Display::print(const char* str) { } void ST7789Display::fillRect(int x, int y, int w, int h) { - display.fillRect(x, y, w, h); + display.fillRect(x + X_OFFSET, y, w, h); } void ST7789Display::drawRect(int x, int y, int w, int h) { - display.drawRect(x, y, w, h); + display.drawRect(x + X_OFFSET, y, w, h); } void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) { - display.drawXbm(x, y, w, h, bits); + display.drawBitmap(x+X_OFFSET, y, w, h, bits); } void ST7789Display::endFrame() { diff --git a/src/helpers/ui/ST7789Spi.h b/src/helpers/ui/ST7789Spi.h index a43fa1f5..ec32f3b0 100644 --- a/src/helpers/ui/ST7789Spi.h +++ b/src/helpers/ui/ST7789Spi.h @@ -262,6 +262,17 @@ class ST7789Spi : public OLEDDisplay { delay(10); } + virtual void landscapeScreen() { + + + uint8_t madctl = ST77XX_MADCTL_RGB; + sendCommand(ST77XX_MADCTL); + WriteData(madctl); + delay(10); + + } + + void setRGB(uint16_t c) { @@ -276,6 +287,26 @@ class ST7789Spi : public OLEDDisplay { //sendCommand(DISPLAYOFF); } + void drawBitmap(int16_t xMove, int16_t yMove, int16_t width, int16_t height, const uint8_t *xbm) { + int16_t widthInXbm = (width + 7) / 8; + uint8_t data = 0; + + for(int16_t y = 0; y < height; y++) { + for(int16_t x = 0; x < width; x++ ) { + if (x & 7) { + data <<= 1; // Move a bit + } else { // Read new data every 8 bit + data = pgm_read_byte(xbm + (x / 8) + y * widthInXbm); + } + // if there is a bit draw it + if (data & 0x80) { + setPixel(xMove + x, yMove + y); + } + } + } + } + + //#define ST77XX_MADCTL_MY 0x80 //#define ST77XX_MADCTL_MX 0x40 //#define ST77XX_MADCTL_MV 0x20