mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
T114 Landscape
This commit is contained in:
parent
136f3d1000
commit
67d709b3aa
3 changed files with 32 additions and 24 deletions
|
|
@ -3,7 +3,11 @@
|
|||
#include "ST7789Display.h"
|
||||
|
||||
#ifndef X_OFFSET
|
||||
#define X_OFFSET 16
|
||||
#define X_OFFSET 0 // No offset needed for landscape
|
||||
#endif
|
||||
|
||||
#ifndef Y_OFFSET
|
||||
#define Y_OFFSET 1 // Vertical offset to prevent top row cutoff
|
||||
#endif
|
||||
|
||||
bool ST7789Display::begin() {
|
||||
|
|
@ -88,7 +92,7 @@ void ST7789Display::setColor(Color c) {
|
|||
|
||||
void ST7789Display::setCursor(int x, int y) {
|
||||
_x = x + X_OFFSET;
|
||||
_y = y;
|
||||
_y = y + Y_OFFSET;
|
||||
}
|
||||
|
||||
void ST7789Display::print(const char* str) {
|
||||
|
|
@ -96,15 +100,15 @@ void ST7789Display::print(const char* str) {
|
|||
}
|
||||
|
||||
void ST7789Display::fillRect(int x, int y, int w, int h) {
|
||||
display.fillRect(x + X_OFFSET, y, w, h);
|
||||
display.fillRect(x + X_OFFSET, y + Y_OFFSET, w, h);
|
||||
}
|
||||
|
||||
void ST7789Display::drawRect(int x, int y, int w, int h) {
|
||||
display.drawRect(x + X_OFFSET, y, w, h);
|
||||
display.drawRect(x + X_OFFSET, y + Y_OFFSET, w, h);
|
||||
}
|
||||
|
||||
void ST7789Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
|
||||
display.drawBitmap(x+X_OFFSET, y, w, h, bits);
|
||||
display.drawBitmap(x + X_OFFSET, y + Y_OFFSET, w, h, bits);
|
||||
}
|
||||
|
||||
uint16_t ST7789Display::getTextWidth(const char* str) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class ST7789Display : public DisplayDriver {
|
|||
|
||||
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||
public:
|
||||
ST7789Display() : DisplayDriver(135, 240), display(&SPI1, PIN_TFT_RST, PIN_TFT_DC, PIN_TFT_CS, GEOMETRY_RAWMODE, 240, 135) {_isOn = false;}
|
||||
ST7789Display() : DisplayDriver(240, 135), display(&SPI1, PIN_TFT_RST, PIN_TFT_DC, PIN_TFT_CS, GEOMETRY_RAWMODE, 240, 135) {_isOn = false;}
|
||||
|
||||
// ST7789Display() : DisplayDriver(135, 240), display(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_SDA, PIN_TFT_SCL, PIN_TFT_RST) { _isOn = false; }
|
||||
bool begin();
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ class ST7789Spi : public OLEDDisplay {
|
|||
}
|
||||
|
||||
virtual void resetOrientation() {
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX;
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
|
|
@ -263,13 +263,13 @@ class ST7789Spi : public OLEDDisplay {
|
|||
}
|
||||
|
||||
virtual void landscapeScreen() {
|
||||
|
||||
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB;
|
||||
// For landscape mode rotated 180 degrees with correct text direction
|
||||
// MV swaps rows/columns for landscape orientation
|
||||
// Adding MX (instead of MY) flips X axis and rotates 180 degrees
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB | ST77XX_MADCTL_MV | ST77XX_MADCTL_MX;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -325,20 +325,25 @@ class ST7789Spi : public OLEDDisplay {
|
|||
WriteData(0x55);
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_MADCTL); // 4: Mem access ctrl (directions), Row/col addr, bottom-top refresh
|
||||
WriteData(0x08);
|
||||
// Initialize with landscape orientation rotated 180 degrees
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB | ST77XX_MADCTL_MV | ST77XX_MADCTL_MX;
|
||||
sendCommand(ST77XX_MADCTL); // 4: Mem access ctrl (directions)
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_CASET); // 5: Column addr set,
|
||||
// Set column address range for landscape orientation (240 pixels wide)
|
||||
sendCommand(ST77XX_CASET); // 5: Column addr set
|
||||
WriteData(0x00);
|
||||
WriteData(0x00); // XSTART = 0
|
||||
WriteData(0x00);
|
||||
WriteData(240); // XEND = 240
|
||||
|
||||
sendCommand(ST77XX_RASET); // 6: Row addr set,
|
||||
// Set row address range for landscape orientation (135 pixels tall)
|
||||
sendCommand(ST77XX_RASET); // 6: Row addr set
|
||||
WriteData(0x00);
|
||||
WriteData(0x00); // YSTART = 0
|
||||
WriteData(320>>8);
|
||||
WriteData(320&0xFF); // YSTART = 320
|
||||
WriteData(0x00);
|
||||
WriteData(135); // YEND = 135
|
||||
|
||||
sendCommand(ST77XX_SLPOUT); // 7: hack
|
||||
delay(10);
|
||||
|
|
@ -352,11 +357,8 @@ class ST7789Spi : public OLEDDisplay {
|
|||
sendCommand(ST77XX_INVON); // 10: invert
|
||||
delay(10);
|
||||
|
||||
//uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MX;
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
// Use landscape mode instead of portrait
|
||||
landscapeScreen();
|
||||
setRGB(ST77XX_GREEN);
|
||||
}
|
||||
|
||||
|
|
@ -364,8 +366,10 @@ class ST7789Spi : public OLEDDisplay {
|
|||
private:
|
||||
|
||||
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
x += (320-displayWidth)/2;
|
||||
y += (240-displayHeight)/2;
|
||||
// For landscape orientation (240x135)
|
||||
x += (320-displayWidth)/2; // Center horizontally in 320 pixels
|
||||
y += (240-displayHeight)/2; // Center vertically in 240 pixels
|
||||
|
||||
uint32_t xa = ((uint32_t)x << 16) | (x + w - 1);
|
||||
uint32_t ya = ((uint32_t)y << 16) | (y + h - 1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue