Skip to content

Commit

Permalink
Graphical TFT fixes, cleanup (MarlinFirmware#20861)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
tpruvot and thinkyhead committed Apr 29, 2021
1 parent 9292ade commit 0e26ea2
Show file tree
Hide file tree
Showing 14 changed files with 526 additions and 658 deletions.
43 changes: 22 additions & 21 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1156,36 +1156,37 @@
#endif
#endif

#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_320x240_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_320x240
#endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x320_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320
#endif
#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x272_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x272
#if ENABLED(TFT_COLOR_UI)
#if TFT_HEIGHT == 240
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_320x240_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_320x240
#endif
#elif TFT_HEIGHT == 320
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x320_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x320
#endif
#elif TFT_HEIGHT == 272
#if ENABLED(TFT_INTERFACE_SPI)
#define TFT_480x272_SPI
#elif ENABLED(TFT_INTERFACE_FSMC)
#define TFT_480x272
#endif
#endif
#endif

// Fewer lines with touch buttons on-screen
#if EITHER(TFT_320x240, TFT_320x240_SPI)
#define HAS_UI_320x240 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x320, TFT_480x320_SPI)
#define HAS_UI_480x320 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#elif EITHER(TFT_480x272, TFT_480x272_SPI)
#define HAS_UI_480x272 1
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7)
#endif
#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272)
#define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen
#endif

// This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046'
Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,8 +807,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if ENABLED(BABYSTEP_XY)
static_assert(BABYSTEP_MULTIPLICATOR_XY <= 0.25f, "BABYSTEP_MULTIPLICATOR_XY must be less than or equal to 0.25mm.");
#endif
#elif ENABLED(BABYSTEP_DISPLAY_TOTAL) && ANY(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)
#error "New Color UI (TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) does not support BABYSTEP_DISPLAY_TOTAL yet."
#endif
#endif

Expand Down
8 changes: 5 additions & 3 deletions Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ static inline void _lcd_level_bed_corners_get_next_position() {

MenuItem_static::draw(0, GET_TEXT(MSG_PROBING_MESH), SS_INVERT); // "Probing Mesh" heading

uint8_t cy = LCD_HEIGHT - 1, y = LCD_ROW_Y(cy);
uint8_t cy = TERN(TFT_COLOR_UI, 3, LCD_HEIGHT - 1), y = LCD_ROW_Y(cy);

// Display # of good points found vs total needed
if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
SETCURSOR(0, cy);
SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_GOOD_POINTS));
IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, cy));
lcd_put_u8str(GOOD_POINTS_TO_STR(good_points));
lcd_put_wchar('/');
lcd_put_u8str(GOOD_POINTS_TO_STR(nr_edge_points));
Expand All @@ -190,8 +191,9 @@ static inline void _lcd_level_bed_corners_get_next_position() {

// Display the Last Z value
if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) {
SETCURSOR(0, cy);
SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy);
lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_LAST_Z));
IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, 2));
lcd_put_u8str(LAST_Z_TO_STR(last_z));
}
}
Expand Down
13 changes: 10 additions & 3 deletions Marlin/src/lcd/menu/menu_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@
const bool in_view = TERN1(HAS_MARLINUI_U8GLIB, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1));
if (in_view) {
TERN_(HAS_MARLINUI_U8GLIB, ui.set_font(FONT_MENU));
lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
#if ENABLED(TFT_COLOR_UI)
lcd_moveto(4, 3);
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
lcd_moveto(10, 3);
#else
lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1));
lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL));
lcd_put_wchar(':');
#endif
lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)]));
}
#endif
Expand Down
41 changes: 39 additions & 2 deletions Marlin/src/lcd/tft/tft_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
*
*/

#include "../../inc/MarlinConfigPre.h"

#if HAS_GRAPHICAL_TFT

#include "tft_image.h"
#include <stddef.h>

const tImage NoLogo = { nullptr, 0, 0, NOCOLORS };

Expand Down Expand Up @@ -70,4 +73,38 @@ const tImage Leveling_32x32x4 = { (void *)leveling_32x32x4, 32, 32, GREYSC

const tImage Slider8x16x4 = { (void *)slider_8x16x4, 8, 16, GREYSCALE4 };

extern const tImage Images[imgCount];
const tImage Images[imgCount] = {
TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MARLIN_LOGO_FULL_SIZE), NoLogo),
HotEnd_64x64x4,
Bed_64x64x4,
Bed_Heated_64x64x4,
Chamber_64x64x4,
Chamber_Heated_64x64x4,
Fan0_64x64x4,
Fan_Slow0_64x64x4,
Fan_Slow1_64x64x4,
Fan_Fast0_64x64x4,
Fan_Fast1_64x64x4,
Feedrate_32x32x4,
Flowrate_32x32x4,
SD_64x64x4,
Menu_64x64x4,
Settings_64x64x4,
Directory_32x32x4,
Confirm_64x64x4,
Cancel_64x64x4,
Increase_64x64x4,
Decrease_64x64x4,
Back_32x32x4,
Up_32x32x4,
Down_32x32x4,
Left_32x32x4,
Right_32x32x4,
Refresh_32x32x4,
Leveling_32x32x4,
Slider8x16x4,
Home_64x64x4,
BtnRounded_64x52x4,
};

#endif // HAS_GRAPHICAL_TFT
3 changes: 2 additions & 1 deletion Marlin/src/lcd/tft/tft_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
*/
#pragma once

#include "stdint.h"
#include "../../inc/MarlinConfigPre.h"

#include <stdint.h>

extern const uint8_t marlin_logo_112x38x1[];
extern const uint8_t marlin_logo_228x255x2[];
extern const uint8_t marlin_logo_228x255x4[];
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/lcd/tft/tft_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ font_t *TFT_String::font_header;

uint8_t TFT_String::data[];
uint16_t TFT_String::span;
uint16_t TFT_String::length;
uint8_t TFT_String::length;

void TFT_String::set_font(const uint8_t *font) {
font_header = (font_t *)font;
Expand Down Expand Up @@ -122,13 +122,14 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) {
eol();
}

void TFT_String::add(uint8_t *string) {
void TFT_String::add(uint8_t *string, uint8_t max_len) {
wchar_t wchar;
while (*string) {
while (*string && max_len) {
string = get_utf8_value_cb(string, read_byte, &wchar);
if (wchar > 255) wchar |= 0x0080;
uint8_t ch = uint8_t(wchar & 0x00FF);
add_character(ch);
max_len--;
}
eol();
}
Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/lcd/tft/tft_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TFT_String {

static uint8_t data[MAX_STRING_LENGTH + 1];
static uint16_t span; // in pixels
static uint16_t length; // in characters
static uint8_t length; // in characters

static void add_character(uint8_t character);
static void eol() { data[length] = 0x00; }
Expand All @@ -85,7 +85,7 @@ class TFT_String {

static void set();
static void add(uint8_t character) { add_character(character); eol(); }
static void add(uint8_t *string);
static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH);
static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr);
static void set(uint8_t *string) { set(); add(string); };
static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); };
Expand All @@ -96,6 +96,9 @@ class TFT_String {
static void trim(uint8_t character=0x20);
static void rtrim(uint8_t character=0x20);
static void ltrim(uint8_t character=0x20);

static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } }

static uint16_t width() { return span; }
static uint8_t *string() { return data; }
static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; }
Expand Down
Loading

0 comments on commit 0e26ea2

Please sign in to comment.