Skip to content

Commit

Permalink
Custom header for upscale
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 4, 2020
1 parent b569a4c commit a7413c6
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 72 deletions.
66 changes: 23 additions & 43 deletions Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,12 @@
#define HEIGHT LCD_PIXEL_HEIGHT
#define PAGE_HEIGHT 8

#ifndef LCD_FULL_PIXEL_WIDTH
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_WIDTH 480
#else
#define LCD_FULL_PIXEL_WIDTH 320
#endif
#endif
#ifndef LCD_FULL_PIXEL_HEIGHT
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_HEIGHT 320
#else
#define LCD_FULL_PIXEL_HEIGHT 240
#endif
#endif

#ifndef LCD_PIXEL_OFFSET_X
#define LCD_PIXEL_OFFSET_X 48
#endif
#ifndef LCD_PIXEL_OFFSET_Y
#define LCD_PIXEL_OFFSET_Y 48
#endif

#define UPSCALE(A,B) ((A) + (FSMC_UPSCALE) * (B) - 1)
#include "../scaled_tft.h"

#define X_HI UPSCALE(LCD_PIXEL_OFFSET_X, WIDTH)
#define Y_HI UPSCALE(LCD_PIXEL_OFFSET_Y, HEIGHT)
#define UPSCALE0(M) ((FSMC_UPSCALE) * (M))
#define UPSCALE(A,M) ((UPSCALE0(M)) + (A))
#define X_HI (UPSCALE(LCD_PIXEL_OFFSET_X, WIDTH) - 1)
#define Y_HI (UPSCALE(LCD_PIXEL_OFFSET_Y, HEIGHT) - 1)

// see https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html

Expand Down Expand Up @@ -571,20 +551,20 @@ static const uint16_t st9677_init[] = {
#define BUTTON_SIZE_Y 20

// 14, 90, 166, 242, 185 are the original values upscaled 2x.
#define BUTTOND_X_LO (14 / 2) * (FSMC_UPSCALE)
#define BUTTOND_X_HI UPSCALE(BUTTOND_X_LO, BUTTON_SIZE_X)
#define BUTTOND_X_LO UPSCALE0(14 / 2)
#define BUTTOND_X_HI (UPSCALE(BUTTOND_X_LO, BUTTON_SIZE_X) - 1)

#define BUTTONA_X_LO (90 / 2) * (FSMC_UPSCALE)
#define BUTTONA_X_HI UPSCALE(BUTTONA_X_LO, BUTTON_SIZE_X)
#define BUTTONA_X_LO UPSCALE0(90 / 2)
#define BUTTONA_X_HI (UPSCALE(BUTTONA_X_LO, BUTTON_SIZE_X) - 1)

#define BUTTONB_X_LO (166 / 2) * (FSMC_UPSCALE)
#define BUTTONB_X_HI UPSCALE(BUTTONB_X_LO, BUTTON_SIZE_X)
#define BUTTONB_X_LO UPSCALE0(166 / 2)
#define BUTTONB_X_HI (UPSCALE(BUTTONB_X_LO, BUTTON_SIZE_X) - 1)

#define BUTTONC_X_LO (242 / 2) * (FSMC_UPSCALE)
#define BUTTONC_X_HI UPSCALE(BUTTONC_X_LO, BUTTON_SIZE_X)
#define BUTTONC_X_LO UPSCALE0(242 / 2)
#define BUTTONC_X_HI (UPSCALE(BUTTONC_X_LO, BUTTON_SIZE_X) - 1)

#define BUTTON_Y_LO (140 / 2) * (FSMC_UPSCALE) + 44 //184 2x, 254 3x
#define BUTTON_Y_HI UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y)
#define BUTTON_Y_LO UPSCALE0(140 / 2) + 44 // 184 2x, 254 3x
#define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1)

void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
uint16_t buffer[BUTTON_SIZE_X * sq(FSMC_UPSCALE)];
Expand All @@ -603,8 +583,8 @@ static const uint16_t st9677_init[] = {
}
#if HAS_LCD_IO
LOOP_S_L_N(n, 1, FSMC_UPSCALE)
for (uint16_t l = 0; l < length * (FSMC_UPSCALE); l++)
buffer[l + (length * (FSMC_UPSCALE) * n)] = buffer[l];
for (uint16_t l = 0; l < UPSCALE0(length); l++)
buffer[l + n * UPSCALE0(length)] = buffer[l];

LCD_IO_WriteSequence(buffer, length * sq(FSMC_UPSCALE));
#else
Expand Down Expand Up @@ -690,16 +670,16 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u

// Bottom buttons
#if HAS_TOUCH_XPT2046
setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI);
setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI);
drawImage(buttonD, u8g, dev, 32, 20, TFT_BTCANCEL_COLOR);

setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI);
setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI);
drawImage(buttonA, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);

setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI);
setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI);
drawImage(buttonB, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);

setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI);
setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI);
drawImage(buttonC, u8g, dev, 32, 20, TFT_BTOKMENU_COLOR);
#endif // HAS_TOUCH_XPT2046

Expand Down Expand Up @@ -727,8 +707,8 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
}
#if HAS_LCD_IO
LOOP_S_L_N(n, 1, FSMC_UPSCALE)
for (uint16_t l = 0; l < WIDTH * (FSMC_UPSCALE); l++)
buffer[l + WIDTH * (FSMC_UPSCALE) * n] = buffer[l];
for (uint16_t l = 0; l < UPSCALE0(WIDTH); l++)
buffer[l + n * UPSCALE0(WIDTH)] = buffer[l];

if (allow_async) {
if (y > 0 || page > 1) LCD_IO_WaitSequence_Async();
Expand Down
22 changes: 22 additions & 0 deletions Marlin/src/lcd/lcdprint.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/

/**
* @file lcdprint.h
* @brief LCD print api
Expand Down
50 changes: 50 additions & 0 deletions Marlin/src/lcd/scaled_tft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "../inc/MarlinConfig.h"

#ifndef FSMC_UPSCALE
#define FSMC_UPSCALE 2
#endif

#ifndef LCD_FULL_PIXEL_WIDTH
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_WIDTH 480
#else
#define LCD_FULL_PIXEL_WIDTH 320
#endif
#endif
#ifndef LCD_FULL_PIXEL_HEIGHT
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_HEIGHT 320
#else
#define LCD_FULL_PIXEL_HEIGHT 240
#endif
#endif

#ifndef LCD_PIXEL_OFFSET_X
#define LCD_PIXEL_OFFSET_X 48
#endif
#ifndef LCD_PIXEL_OFFSET_Y
#define LCD_PIXEL_OFFSET_Y 48
#endif
36 changes: 7 additions & 29 deletions Marlin/src/lcd/touch/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@

#if HAS_TOUCH_XPT2046

#if TFT_SCALED_DOGLCD
#include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
#endif

#include "xpt2046.h"
#include "../scaled_tft.h"

#ifndef XPT2046_Z1_THRESHOLD
#define XPT2046_Z1_THRESHOLD 10
Expand Down Expand Up @@ -63,32 +60,13 @@
#define TOUCH_SENSOR_WIDTH 320
#define TOUCH_SENSOR_HEIGHT 240

#ifndef LCD_FULL_PIXEL_WIDTH
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_WIDTH 480
#else
#define LCD_FULL_PIXEL_WIDTH 320
#endif
#endif
#ifndef LCD_FULL_PIXEL_HEIGHT
#if FSMC_UPSCALE == 3
#define LCD_FULL_PIXEL_HEIGHT 320
#else
#define LCD_FULL_PIXEL_HEIGHT 240
#endif
#endif

#ifndef LCD_PIXEL_OFFSET_X
#define LCD_PIXEL_OFFSET_X 48
#endif
#ifndef LCD_PIXEL_OFFSET_Y
#define LCD_PIXEL_OFFSET_Y 48
#endif
#define SCREEN_WIDTH_PCT(X) ((X) * (TOUCH_SENSOR_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
#define SCREEN_HEIGHT_PCT(Y) ((Y) * (TOUCH_SENSOR_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))

#define SCREEN_START_LEFT ((LCD_PIXEL_OFFSET_X) * (TOUCH_SENSOR_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
#define SCREEN_START_TOP ((LCD_PIXEL_OFFSET_Y) * (TOUCH_SENSOR_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
#define SCREEN_WIDTH ((LCD_PIXEL_WIDTH) * (FSMC_UPSCALE) * (TOUCH_SENSOR_WIDTH) / (LCD_FULL_PIXEL_WIDTH))
#define SCREEN_HEIGHT ((LCD_PIXEL_HEIGHT) * (FSMC_UPSCALE) * (TOUCH_SENSOR_HEIGHT) / (LCD_FULL_PIXEL_HEIGHT))
#define SCREEN_START_LEFT SCREEN_WIDTH_PCT(LCD_PIXEL_OFFSET_X)
#define SCREEN_START_TOP SCREEN_HEIGHT_PCT(LCD_PIXEL_OFFSET_Y)
#define SCREEN_WIDTH SCREEN_WIDTH_PCT((LCD_PIXEL_WIDTH) * (FSMC_UPSCALE))
#define SCREEN_HEIGHT SCREEN_HEIGHT_PCT((LCD_PIXEL_HEIGHT) * (FSMC_UPSCALE))

#define TOUCHABLE_X_WIDTH SCREEN_WIDTH
#define TOUCHABLE_Y_HEIGHT SCREEN_HEIGHT
Expand Down

0 comments on commit a7413c6

Please sign in to comment.