Skip to content

Commit cce409f

Browse files
alexgrachthinkyhead
authored andcommitted
✨ TFT 320x240 portrait (MarlinFirmware#25207)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 2cd82e6 commit cce409f

File tree

8 files changed

+334
-189
lines changed

8 files changed

+334
-189
lines changed

Marlin/src/inc/Conditionals_LCD.h

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@
324324
#define IS_ULTIPANEL 1
325325
#endif
326326

327-
// TFT Compatibility
327+
// TFT Legacy Compatibility
328328
#if ANY(FSMC_GRAPHICAL_TFT, SPI_GRAPHICAL_TFT, TFT_320x240, TFT_480x320, TFT_320x240_SPI, TFT_480x320_SPI, TFT_LVGL_UI_FSMC, TFT_LVGL_UI_SPI)
329329
#define IS_LEGACY_TFT 1
330330
#define TFT_GENERIC
@@ -1525,30 +1525,6 @@
15251525
#endif
15261526
#endif
15271527

1528-
#if ENABLED(TFT_RES_320x240)
1529-
#define TFT_WIDTH 320
1530-
#define TFT_HEIGHT 240
1531-
#define GRAPHICAL_TFT_UPSCALE 2
1532-
#elif ENABLED(TFT_RES_480x272)
1533-
#define TFT_WIDTH 480
1534-
#define TFT_HEIGHT 272
1535-
#define GRAPHICAL_TFT_UPSCALE 2
1536-
#elif ENABLED(TFT_RES_480x320)
1537-
#define TFT_WIDTH 480
1538-
#define TFT_HEIGHT 320
1539-
#define GRAPHICAL_TFT_UPSCALE 3
1540-
#elif ENABLED(TFT_RES_1024x600)
1541-
#define TFT_WIDTH 1024
1542-
#define TFT_HEIGHT 600
1543-
#if ENABLED(TOUCH_SCREEN)
1544-
#define GRAPHICAL_TFT_UPSCALE 6
1545-
#define TFT_PIXEL_OFFSET_X 120
1546-
#else
1547-
#define GRAPHICAL_TFT_UPSCALE 8
1548-
#define TFT_PIXEL_OFFSET_X 0
1549-
#endif
1550-
#endif
1551-
15521528
// FSMC/SPI TFT Panels using standard HAL/tft/tft_(fsmc|spi|ltdc).h
15531529
#if ENABLED(TFT_INTERFACE_FSMC)
15541530
#define HAS_FSMC_TFT 1
@@ -1573,8 +1549,62 @@
15731549
#endif
15741550
#endif
15751551

1552+
// Set TFT_COLOR_UI_PORTRAIT flag, if needed
1553+
#if defined(TFT_ROTATION) && (HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT)
1554+
#define _CMP_TFT_ROTATE_90 90
1555+
#define _CMP_TFT_ROTATE_270 270
1556+
#define _CMP_TFT_ROTATE_90_MIRROR_X 90
1557+
#define _CMP_TFT_ROTATE_90_MIRROR_Y 90
1558+
#define _CMP_TFT_ROTATE_270_MIRROR_X 270
1559+
#define _CMP_TFT_ROTATE_270_MIRROR_Y 270
1560+
#define _ISROT(N) || (_CAT(_CMP_, TFT_ROTATION) == N)
1561+
#define ISROT(V...) (0 MAP(_ISROT, V))
1562+
1563+
#if ISROT(90, 270)
1564+
#define TFT_COLOR_UI_PORTRAIT 1
1565+
#endif
1566+
1567+
#undef _CMP_TFT_ROTATE_90
1568+
#undef _CMP_TFT_ROTATE_270
1569+
#undef _CMP_TFT_ROTATE_90_MIRROR_X
1570+
#undef _CMP_TFT_ROTATE_90_MIRROR_Y
1571+
#undef _CMP_TFT_ROTATE_270_MIRROR_X
1572+
#undef _CMP_TFT_ROTATE_270_MIRROR_Y
1573+
#undef _ISROT
1574+
#undef ISROT
1575+
#endif
1576+
1577+
#if ENABLED(TFT_RES_320x240)
1578+
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
1579+
#define TFT_WIDTH 240
1580+
#define TFT_HEIGHT 320
1581+
#else
1582+
#define TFT_WIDTH 320
1583+
#define TFT_HEIGHT 240
1584+
#endif
1585+
#define GRAPHICAL_TFT_UPSCALE 2
1586+
#elif ENABLED(TFT_RES_480x272)
1587+
#define TFT_WIDTH 480
1588+
#define TFT_HEIGHT 272
1589+
#define GRAPHICAL_TFT_UPSCALE 2
1590+
#elif ENABLED(TFT_RES_480x320)
1591+
#define TFT_WIDTH 480
1592+
#define TFT_HEIGHT 320
1593+
#define GRAPHICAL_TFT_UPSCALE 3
1594+
#elif ENABLED(TFT_RES_1024x600)
1595+
#define TFT_WIDTH 1024
1596+
#define TFT_HEIGHT 600
1597+
#if ENABLED(TOUCH_SCREEN)
1598+
#define GRAPHICAL_TFT_UPSCALE 6
1599+
#define TFT_PIXEL_OFFSET_X 120
1600+
#else
1601+
#define GRAPHICAL_TFT_UPSCALE 8
1602+
#define TFT_PIXEL_OFFSET_X 0
1603+
#endif
1604+
#endif
1605+
15761606
#if ENABLED(TFT_COLOR_UI)
1577-
#if TFT_HEIGHT == 240
1607+
#if (TFT_WIDTH == 320 && TFT_HEIGHT == 240) || (TFT_WIDTH == 240 && TFT_HEIGHT == 320)
15781608
#if ENABLED(TFT_INTERFACE_SPI)
15791609
#define TFT_320x240_SPI
15801610
#elif ENABLED(TFT_INTERFACE_FSMC)
@@ -1612,6 +1642,8 @@
16121642
#endif
16131643
#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272)
16141644
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
1645+
#elif HAS_UI_240x320
1646+
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 8, 6) // Fewer lines with touch buttons onscreen
16151647
#elif HAS_UI_1024x600
16161648
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 12, 13) // Fewer lines with touch buttons onscreen
16171649
#endif

Marlin/src/lcd/tft/tft.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,6 @@
3737
#define ENDIAN_COLOR(C) (C)
3838
#endif
3939

40-
#if HAS_UI_320x240
41-
#define TFT_WIDTH 320
42-
#define TFT_HEIGHT 240
43-
#elif HAS_UI_480x320
44-
#define TFT_WIDTH 480
45-
#define TFT_HEIGHT 320
46-
#elif HAS_UI_480x272
47-
#define TFT_WIDTH 480
48-
#define TFT_HEIGHT 272
49-
#elif HAS_UI_1024x600
50-
#define TFT_WIDTH 1024
51-
#define TFT_HEIGHT 600
52-
#else
53-
#error "Unsupported display resolution!"
54-
#endif
55-
5640
#ifndef TFT_BUFFER_SIZE
5741
#ifdef STM32F103xB
5842
#define TFT_BUFFER_SIZE 1024

Marlin/src/lcd/tft/ui_1024x600.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,12 +700,12 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
700700
probe.offset.z = new_offs;
701701
else
702702
TERN(BABYSTEP_HOTEND_Z_OFFSET, hotend_offset[active_extruder].z = new_offs, NOOP);
703-
drawMessage(""); // clear the error
703+
drawMessage(F("")); // clear the error
704704
drawAxisValue(axis);
705705
}
706-
else {
706+
else
707707
drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS));
708-
}
708+
709709
#elif HAS_BED_PROBE
710710
// only change probe.offset.z
711711
probe.offset.z += diff;
@@ -717,9 +717,9 @@ static void moveAxis(const AxisEnum axis, const int8_t direction) {
717717
current_position[axis] = Z_PROBE_OFFSET_RANGE_MAX;
718718
drawMessage(GET_TEXT_F(MSG_LCD_SOFT_ENDSTOPS));
719719
}
720-
else {
721-
drawMessage(""); // clear the error
722-
}
720+
else
721+
drawMessage(F("")); // clear the error
722+
723723
drawAxisValue(axis);
724724
#endif
725725
return;
@@ -765,10 +765,8 @@ static void z_minus() { moveAxis(Z_AXIS, -1); }
765765

766766
#if ENABLED(TOUCH_SCREEN)
767767
static void e_select() {
768-
motionAxisState.e_selection++;
769-
if (motionAxisState.e_selection >= EXTRUDERS) {
768+
if (++motionAxisState.e_selection >= EXTRUDERS)
770769
motionAxisState.e_selection = 0;
771-
}
772770

773771
quick_feedback();
774772
drawCurESelection();
@@ -810,8 +808,8 @@ static void disable_steppers() {
810808
}
811809

812810
static void drawBtn(int x, int y, const char *label, intptr_t data, MarlinImage img, uint16_t bgColor, bool enabled = true) {
813-
uint16_t width = Images[imgBtn52Rounded].width;
814-
uint16_t height = Images[imgBtn52Rounded].height;
811+
uint16_t width = Images[imgBtn52Rounded].width,
812+
height = Images[imgBtn52Rounded].height;
815813

816814
if (!enabled) bgColor = COLOR_CONTROL_DISABLED;
817815

0 commit comments

Comments
 (0)