Skip to content

Commit f6d41f1

Browse files
committed
WIP
1 parent 129b5d2 commit f6d41f1

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/sp140/lvgl/lvgl_core.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LGFX_ST7735 : public lgfx::LGFX_Device {
2222
auto cfg = _bus_instance.config();
2323
cfg.spi_host = SPI2_HOST; // Use SPI2 (HSPI)
2424
cfg.spi_mode = 0;
25-
cfg.freq_write = 27000000; // SPI speed for writing
25+
cfg.freq_write = 20000000; // SPI speed for writing (safer)
2626
cfg.freq_read = 16000000; // SPI speed for reading
2727
cfg.spi_3wire = false;
2828
cfg.use_lock = true;
@@ -39,19 +39,21 @@ class LGFX_ST7735 : public lgfx::LGFX_Device {
3939
cfg.pin_cs = 10;
4040
cfg.pin_rst = 15;
4141
cfg.pin_busy = -1;
42-
cfg.memory_width = 160;
43-
cfg.memory_height = 128;
42+
// Adafruit 1.8" ST7735R (#618) visible 160x128, controller RAM 162x132
43+
cfg.memory_width = 162;
44+
cfg.memory_height = 132;
4445
cfg.panel_width = 160;
4546
cfg.panel_height = 128;
46-
// ST7735 BLACKTAB variant - specific settings for 160x128 display
47-
cfg.offset_x = 0;
48-
cfg.offset_y = 0;
47+
// Typical offsets for BLACKTAB
48+
cfg.offset_x = 1;
49+
cfg.offset_y = 2;
4950
cfg.offset_rotation = 0;
5051
cfg.dummy_read_pixel = 8;
5152
cfg.dummy_read_bits = 1;
5253
cfg.readable = false;
53-
cfg.invert = false; // User reported darker display, so no invert needed
54-
cfg.rgb_order = false; // Try RGB order instead of BGR
54+
// Use BGR order (common for ST7735 BLACKTAB) to correct red/blue swap; no inversion
55+
cfg.invert = false;
56+
cfg.rgb_order = true;
5557
cfg.dlen_16bit = false;
5658
cfg.bus_shared = true; // Important for shared SPI
5759
_panel_instance.config(cfg);
@@ -96,18 +98,21 @@ void setupLvglDisplay(
9698
if (tft_driver == nullptr) {
9799
// Store the shared SPI instance
98100
hardwareSPI = spi;
99-
101+
100102
// Create custom ST7735 configuration for LovyanGFX
101103
tft_driver = new LGFX_ST7735();
102-
104+
103105
// Initialize display with custom configuration
104106
if (tft_driver->init()) {
107+
// Ensure color format matches LVGL (RGB565) and correct byte order
108+
tft_driver->setColorDepth(16);
109+
tft_driver->setSwapBytes(true);
105110
tft_driver->setRotation(deviceData.screen_rotation);
106-
111+
107112
// Clear screen with a test pattern to verify it's working
108113
tft_driver->fillScreen(0x0000); // Black
109114
tft_driver->fillRect(10, 10, 50, 50, 0xF800); // Red square for testing
110-
115+
111116
USBSerial.println("LovyanGFX ST7735 initialized successfully");
112117
} else {
113118
USBSerial.println("ERROR: LovyanGFX ST7735 initialization failed!");
@@ -150,11 +155,8 @@ void lvgl_flush_cb(lv_disp_drv_t* disp, const lv_area_t* area, lv_color_t* color
150155
xSemaphoreTake(spiBusMutex, portMAX_DELAY);
151156
}
152157

153-
// LovyanGFX DMA-optimized pixel transfer
154-
tft_driver->startWrite();
155-
tft_driver->setAddrWindow(area->x1, area->y1, w, h);
156-
tft_driver->writePixels((uint16_t*)color_p, w * h); // NOLINT(readability/casting)
157-
tft_driver->endWrite();
158+
// LovyanGFX optimized pixel transfer
159+
tft_driver->pushImage(area->x1, area->y1, w, h, (const uint16_t*)color_p);
158160

159161
if (spiBusMutex != NULL) {
160162
xSemaphoreGive(spiBusMutex);

0 commit comments

Comments
 (0)