Move scaled TFT / touch defines (#18915)
This commit is contained in:
@ -20,40 +20,39 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
u8g_dev_tft_320x240_upscale_from_128x64.cpp
|
||||
|
||||
Universal 8bit Graphics Library
|
||||
|
||||
Copyright (c) 2011, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
/**
|
||||
* u8g_dev_tft_320x240_upscale_from_128x64.cpp
|
||||
*
|
||||
* Universal 8bit Graphics Library
|
||||
*
|
||||
* Copyright (c) 2011, olikraus@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
@ -80,14 +79,16 @@
|
||||
extern void LCD_IO_WriteMultiple(uint16_t color, uint32_t count);
|
||||
#endif
|
||||
|
||||
#define WIDTH LCD_PIXEL_WIDTH
|
||||
#define WIDTH LCD_PIXEL_WIDTH
|
||||
#define HEIGHT LCD_PIXEL_HEIGHT
|
||||
#define PAGE_HEIGHT 8
|
||||
|
||||
#define X_LO LCD_PIXEL_OFFSET_X
|
||||
#define Y_LO LCD_PIXEL_OFFSET_Y
|
||||
#define X_HI (X_LO + (FSMC_UPSCALE) * WIDTH - 1)
|
||||
#define Y_HI (Y_LO + (FSMC_UPSCALE) * HEIGHT - 1)
|
||||
#include "../scaled_tft.h"
|
||||
|
||||
#define UPSCALE0(M) ((M) * (FSMC_UPSCALE))
|
||||
#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
|
||||
|
||||
@ -153,7 +154,6 @@ static uint32_t lcd_id = 0;
|
||||
#define ILI9328_VASTART 0x52 /* Vertical address start position (0-511) */
|
||||
#define ILI9328_VAEND 0x53 /* Vertical address end position (0-511) */
|
||||
|
||||
|
||||
static void setWindow_ili9328(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
|
||||
#if HAS_LCD_IO
|
||||
#define IO_REG_DATA(R,D) do { LCD_IO_WriteReg(R); LCD_IO_WriteData(D); }while(0)
|
||||
@ -216,7 +216,6 @@ static void setWindow_st7789v(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_
|
||||
static void setWindow_none(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {}
|
||||
void (*setWindow)(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) = setWindow_none;
|
||||
|
||||
|
||||
#define ESC_REG(x) 0xFFFF, 0x00FF & (uint16_t)x
|
||||
#define ESC_DELAY(x) 0xFFFF, 0x8000 | (x & 0x7FFF)
|
||||
#define ESC_END 0xFFFF, 0x7FFF
|
||||
@ -552,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 (BUTTOND_X_LO + (FSMC_UPSCALE) * BUTTON_SIZE_X - 1)
|
||||
#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 (BUTTONA_X_LO + (FSMC_UPSCALE) * BUTTON_SIZE_X - 1)
|
||||
#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 (BUTTONB_X_LO + (FSMC_UPSCALE) * BUTTON_SIZE_X - 1)
|
||||
#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 (BUTTONC_X_LO + (FSMC_UPSCALE) * BUTTON_SIZE_X - 1)
|
||||
#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 (BUTTON_Y_LO + (FSMC_UPSCALE) * BUTTON_SIZE_Y - 1)
|
||||
#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)];
|
||||
@ -584,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
|
||||
@ -660,27 +659,27 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
}
|
||||
|
||||
// Clear Screen
|
||||
setWindow(u8g, dev, 0, 0, LCD_FULL_PIXEL_WIDTH - 1, LCD_FULL_PIXEL_HEIGHT - 1);
|
||||
setWindow(u8g, dev, 0, 0, (LCD_FULL_PIXEL_WIDTH) - 1, (LCD_FULL_PIXEL_HEIGHT) - 1);
|
||||
#if HAS_LCD_IO
|
||||
LCD_IO_WriteMultiple(TFT_MARLINBG_COLOR, LCD_FULL_PIXEL_WIDTH * LCD_FULL_PIXEL_HEIGHT);
|
||||
LCD_IO_WriteMultiple(TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
#else
|
||||
memset2(buffer, TFT_MARLINBG_COLOR, 160);
|
||||
for (uint16_t i = 0; i < 960; i++)
|
||||
u8g_WriteSequence(u8g, dev, 160, (uint8_t *)buffer);
|
||||
memset2(buffer, TFT_MARLINBG_COLOR, (LCD_FULL_PIXEL_WIDTH) / 2);
|
||||
for (uint16_t i = 0; i < (LCD_FULL_PIXEL_WIDTH) * 3; i++)
|
||||
u8g_WriteSequence(u8g, dev, (LCD_FULL_PIXEL_WIDTH) / 2, (uint8_t *)buffer);
|
||||
#endif
|
||||
|
||||
// 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
|
||||
|
||||
@ -690,7 +689,7 @@ uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, u
|
||||
|
||||
case U8G_DEV_MSG_PAGE_FIRST:
|
||||
page = 0;
|
||||
setWindow(u8g, dev, X_LO, Y_LO, X_HI, Y_HI);
|
||||
setWindow(u8g, dev, LCD_PIXEL_OFFSET_X, LCD_PIXEL_OFFSET_Y, X_HI, Y_HI);
|
||||
break;
|
||||
|
||||
case U8G_DEV_MSG_PAGE_NEXT:
|
||||
@ -708,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();
|
||||
|
@ -212,30 +212,9 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// LCD_FULL_PIXEL_WIDTH =
|
||||
// LCD_PIXEL_OFFSET_X + (LCD_PIXEL_WIDTH * 2) + LCD_PIXEL_OFFSET_X
|
||||
#if TFT_SCALED_DOGLCD
|
||||
#ifndef LCD_FULL_PIXEL_WIDTH
|
||||
#define LCD_FULL_PIXEL_WIDTH 320
|
||||
#endif
|
||||
#ifndef LCD_PIXEL_OFFSET_X
|
||||
#define LCD_PIXEL_OFFSET_X 32
|
||||
#endif
|
||||
#ifndef LCD_FULL_PIXEL_HEIGHT
|
||||
#define LCD_FULL_PIXEL_HEIGHT 240
|
||||
#endif
|
||||
#ifndef LCD_PIXEL_OFFSET_Y
|
||||
#define LCD_PIXEL_OFFSET_Y 32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// For selective rendering within a Y range
|
||||
#define PAGE_OVER(ya) ((ya) <= u8g.getU8g()->current_page.y1) // Does the current page follow a region top?
|
||||
#define PAGE_UNDER(yb) ((yb) >= u8g.getU8g()->current_page.y0) // Does the current page precede a region bottom?
|
||||
#define PAGE_CONTAINS(ya, yb) ((yb) >= u8g.getU8g()->current_page.y0 && (ya) <= u8g.getU8g()->current_page.y1) // Do two vertical regions overlap?
|
||||
|
||||
#ifndef FSMC_UPSCALE
|
||||
#define FSMC_UPSCALE 2
|
||||
#endif
|
||||
|
||||
extern U8G_CLASS u8g;
|
||||
|
@ -35,9 +35,10 @@
|
||||
#include "pic_manager.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "../../../touch/xpt2046.h"
|
||||
|
||||
#include "../../../../MarlinCore.h"
|
||||
#include "../../../../module/temperature.h"
|
||||
#include "../../../../feature/touch/xpt2046.h"
|
||||
#include "../../../../sd/cardreader.h"
|
||||
|
||||
uint8_t pw_det_sta, pw_off_sta, mt_det_sta, mt_det2_sta, mt_det3_sta;
|
||||
|
@ -41,8 +41,11 @@
|
||||
#include "draw_ui.h"
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "../../../../MarlinCore.h"
|
||||
#include "../../../../feature/touch/xpt2046.h"
|
||||
#include "../../../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_TOUCH_XPT2046
|
||||
#include "../../../touch/xpt2046.h"
|
||||
#endif
|
||||
|
||||
#if ENABLED(POWER_LOSS_RECOVERY)
|
||||
#include "../../../../feature/powerloss.h"
|
||||
@ -50,6 +53,13 @@
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
#ifndef LCD_FULL_PIXEL_WIDTH
|
||||
#define LCD_FULL_PIXEL_WIDTH 480
|
||||
#endif
|
||||
#ifndef LCD_FULL_PIXEL_HEIGHT
|
||||
#define LCD_FULL_PIXEL_HEIGHT 320
|
||||
#endif
|
||||
|
||||
#if HAS_SPI_FLASH_FONT
|
||||
extern void init_gb2312_font();
|
||||
#endif
|
||||
@ -127,9 +137,8 @@ void LCD_WriteRAM_Prepare(void) {
|
||||
|
||||
void tft_set_point(uint16_t x, uint16_t y, uint16_t point) {
|
||||
//if (DeviceCode == 0x9488) {
|
||||
if ((x > 480) || (y > 320)) return;
|
||||
if (x > (LCD_FULL_PIXEL_WIDTH) || y > (LCD_FULL_PIXEL_HEIGHT)) return;
|
||||
//}
|
||||
//**if ( (x>320)||(y>240) ) return;
|
||||
tft_set_cursor(x, y);
|
||||
|
||||
LCD_WriteRAM_Prepare();
|
||||
@ -187,10 +196,10 @@ void ili9320_SetWindows(uint16_t StartX, uint16_t StartY, uint16_t width, uint16
|
||||
LCD_WriteReg(0x0052, StartY);
|
||||
LCD_WriteReg(0x0051, xEnd);
|
||||
LCD_WriteReg(0x0053, yEnd);*/
|
||||
LCD_WriteReg(0x0050, StartY); //Specify the start/end positions of the window address in the horizontal direction by an address unit
|
||||
LCD_WriteReg(0x0051, yEnd); //Specify the start positions of the window address in the vertical direction by an address unit
|
||||
LCD_WriteReg(0x0050, StartY); // Specify the start/end positions of the window address in the horizontal direction by an address unit
|
||||
LCD_WriteReg(0x0051, yEnd); // Specify the start positions of the window address in the vertical direction by an address unit
|
||||
LCD_WriteReg(0x0052, 320 - xEnd);
|
||||
LCD_WriteReg(0x0053, 320 - StartX - 1); //Specify the end positions of the window address in the vertical direction by an address unit
|
||||
LCD_WriteReg(0x0053, 320 - StartX - 1); // Specify the end positions of the window address in the vertical direction by an address unit
|
||||
|
||||
}
|
||||
else {
|
||||
@ -224,16 +233,16 @@ void LCD_Clear(uint16_t Color) {
|
||||
|
||||
if (DeviceCode == 0x9488) {
|
||||
tft_set_cursor(0, 0);
|
||||
ili9320_SetWindows(0, 0, 480, 320);
|
||||
ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
||||
LCD_WriteRAM_Prepare();
|
||||
#ifdef LCD_USE_DMA_FSMC
|
||||
LCD_IO_WriteMultiple(Color, LCD_FULL_PIXEL_WIDTH * LCD_FULL_PIXEL_HEIGHT);
|
||||
LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
#else
|
||||
//index = (160*480);
|
||||
for (index = 0; index < 320 * 480; index++)
|
||||
LCD_IO_WriteData(Color);
|
||||
//index = (LCD_FULL_PIXEL_HEIGHT) / 2 * (LCD_FULL_PIXEL_WIDTH);
|
||||
for (index = 0; index < (LCD_FULL_PIXEL_HEIGHT) * (LCD_FULL_PIXEL_WIDTH); index++)
|
||||
LCD_IO_WriteData(Color);
|
||||
#endif
|
||||
//LCD_IO_WriteMultiple(Color, (480*320));
|
||||
//LCD_IO_WriteMultiple(Color, (LCD_FULL_PIXEL_WIDTH) * (LCD_FULL_PIXEL_HEIGHT));
|
||||
//while(index --) LCD_IO_WriteData(Color);
|
||||
}
|
||||
else if (DeviceCode == 0x5761) {
|
||||
@ -262,7 +271,6 @@ void LCD_Clear(uint16_t Color) {
|
||||
|
||||
extern uint16_t ILI9488_ReadRAM();
|
||||
|
||||
|
||||
void init_tft() {
|
||||
uint16_t i;
|
||||
//************* Start Initial Sequence **********//
|
||||
@ -393,7 +401,7 @@ void init_tft() {
|
||||
for (i = 0; i < 65535; i++);
|
||||
LCD_IO_WriteReg(0x0029);
|
||||
|
||||
ili9320_SetWindows(0, 0, 480, 320);
|
||||
ili9320_SetWindows(0, 0, LCD_FULL_PIXEL_WIDTH, LCD_FULL_PIXEL_HEIGHT);
|
||||
LCD_Clear(0x0000);
|
||||
|
||||
OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
|
||||
@ -486,7 +494,7 @@ void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * co
|
||||
#if ENABLED(TFT_LVGL_UI_SPI)
|
||||
uint16_t i, width, height;
|
||||
uint16_t clr_temp;
|
||||
uint8_t tbuf[480 * 2];
|
||||
uint8_t tbuf[(LCD_FULL_PIXEL_WIDTH) * 2];
|
||||
|
||||
SPI_TFT.spi_init(SPI_FULL_SPEED);
|
||||
|
||||
|
@ -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
|
||||
|
50
Marlin/src/lcd/scaled_tft.h
Normal file
50
Marlin/src/lcd/scaled_tft.h
Normal file
@ -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
|
248
Marlin/src/lcd/touch/xpt2046.cpp
Normal file
248
Marlin/src/lcd/touch/xpt2046.cpp
Normal file
@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "../../inc/MarlinConfig.h"
|
||||
|
||||
#if HAS_TOUCH_XPT2046
|
||||
|
||||
#include "xpt2046.h"
|
||||
#include "../scaled_tft.h"
|
||||
|
||||
#ifndef XPT2046_Z1_THRESHOLD
|
||||
#define XPT2046_Z1_THRESHOLD 10
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Draw and Touch processing
|
||||
*
|
||||
* LCD_PIXEL_WIDTH/HEIGHT (128x64) is the (emulated DOGM) Pixel Drawing resolution.
|
||||
* TOUCH_SENSOR_WIDTH/HEIGHT (320x240) is the Touch Area resolution.
|
||||
* LCD_FULL_PIXEL_WIDTH/HEIGHT (320x240 or 480x320) is the Actual (FSMC) Display resolution.
|
||||
*
|
||||
* - All native (u8g) drawing is done in LCD_PIXEL_* (128x64)
|
||||
* - The DOGM pixels are is upscaled 2-3x (as needed) for display.
|
||||
* - Touch coordinates use TOUCH_SENSOR_* resolution and are converted to
|
||||
* click and scroll-wheel events (emulating of a common DOGM display).
|
||||
*
|
||||
* TOUCH_SCREEN resolution exists to fit our calibration values. The original touch code was made
|
||||
* and originally calibrated for 320x240. If you decide to change the resolution of the touch code,
|
||||
* new calibration values will be needed.
|
||||
*
|
||||
* The Marlin menus are drawn scaled in the upper region of the screen. The bottom region (in a
|
||||
* fixed location in TOUCH_SCREEN* coordinate space) is used for 4 general-purpose buttons to
|
||||
* navigate and select menu items. Both regions are touchable.
|
||||
*
|
||||
* The Marlin screen touchable area starts at LCD_PIXEL_OFFSET_X/Y (translated to SCREEN_START_LEFT/TOP)
|
||||
* and spans LCD_PIXEL_WIDTH/HEIGHT (scaled to SCREEN_WIDTH/HEIGHT).
|
||||
*/
|
||||
|
||||
// Coordinates in terms of touch area
|
||||
#define BUTTON_AREA_TOP 175
|
||||
#define BUTTON_AREA_BOT 234
|
||||
|
||||
// Touch sensor resolution independent of display resolution
|
||||
#define TOUCH_SENSOR_WIDTH 320
|
||||
#define TOUCH_SENSOR_HEIGHT 240
|
||||
|
||||
#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 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
|
||||
|
||||
#ifndef TOUCH_INT_PIN
|
||||
#define TOUCH_INT_PIN -1
|
||||
#endif
|
||||
#ifndef TOUCH_MISO_PIN
|
||||
#define TOUCH_MISO_PIN MISO_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_MOSI_PIN
|
||||
#define TOUCH_MOSI_PIN MOSI_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_SCK_PIN
|
||||
#define TOUCH_SCK_PIN SCK_PIN
|
||||
#endif
|
||||
#ifndef TOUCH_CS_PIN
|
||||
#define TOUCH_CS_PIN CS_PIN
|
||||
#endif
|
||||
|
||||
XPT2046 touch;
|
||||
|
||||
void XPT2046::init() {
|
||||
SET_INPUT(TOUCH_MISO_PIN);
|
||||
SET_OUTPUT(TOUCH_MOSI_PIN);
|
||||
SET_OUTPUT(TOUCH_SCK_PIN);
|
||||
OUT_WRITE(TOUCH_CS_PIN, HIGH);
|
||||
|
||||
#if PIN_EXISTS(TOUCH_INT)
|
||||
// Optional Pendrive interrupt pin
|
||||
SET_INPUT(TOUCH_INT_PIN);
|
||||
#endif
|
||||
|
||||
// Read once to enable pendrive status pin
|
||||
getInTouch(XPT2046_X);
|
||||
}
|
||||
|
||||
#include "../../lcd/ultralcd.h" // For EN_C bit mask
|
||||
|
||||
uint8_t XPT2046::read_buttons() {
|
||||
#ifdef HAS_SPI_LCD
|
||||
int16_t tsoffsets[4] = { 0 };
|
||||
|
||||
if (tsoffsets[0] + tsoffsets[1] == 0) {
|
||||
// Not yet set, so use defines as fallback...
|
||||
tsoffsets[0] = XPT2046_X_CALIBRATION;
|
||||
tsoffsets[1] = XPT2046_X_OFFSET;
|
||||
tsoffsets[2] = XPT2046_Y_CALIBRATION;
|
||||
tsoffsets[3] = XPT2046_Y_OFFSET;
|
||||
}
|
||||
|
||||
// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
|
||||
|
||||
if (!isTouched()) return 0;
|
||||
uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
|
||||
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
|
||||
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
|
||||
|
||||
#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
|
||||
x = TOUCH_SENSOR_WIDTH - x;
|
||||
y = TOUCH_SENSOR_HEIGHT - y;
|
||||
#endif
|
||||
|
||||
// Touch within the button area simulates an encoder button
|
||||
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
|
||||
return WITHIN(x, 14, 77) ? EN_D
|
||||
: WITHIN(x, 90, 153) ? EN_A
|
||||
: WITHIN(x, 166, 229) ? EN_B
|
||||
: WITHIN(x, 242, 305) ? EN_C
|
||||
: 0;
|
||||
|
||||
if (x > TOUCH_SENSOR_WIDTH || !WITHIN(y, SCREEN_START_TOP, SCREEN_START_TOP + SCREEN_HEIGHT)) return 0;
|
||||
|
||||
// Column and row above BUTTON_AREA_TOP
|
||||
int8_t col = (x - (SCREEN_START_LEFT)) * (LCD_WIDTH) / (TOUCHABLE_X_WIDTH),
|
||||
row = (y - (SCREEN_START_TOP)) * (LCD_HEIGHT) / (TOUCHABLE_Y_HEIGHT);
|
||||
|
||||
// Send the touch to the UI (which will simulate the encoder wheel)
|
||||
MarlinUI::screen_click(row, col, x, y);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool XPT2046::isTouched() {
|
||||
return (
|
||||
#if PIN_EXISTS(TOUCH_INT)
|
||||
READ(TOUCH_INT_PIN) != HIGH
|
||||
#else
|
||||
getInTouch(XPT2046_Z1) >= XPT2046_Z1_THRESHOLD
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
#if ENABLED(TOUCH_BUTTONS_HW_SPI)
|
||||
#include <SPI.h>
|
||||
|
||||
static void touch_spi_init(uint8_t spiRate) {
|
||||
/**
|
||||
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
|
||||
* STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
|
||||
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
|
||||
*/
|
||||
uint8_t clock;
|
||||
switch (spiRate) {
|
||||
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV4; break;
|
||||
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4; break;
|
||||
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
|
||||
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
|
||||
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
|
||||
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
|
||||
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
|
||||
}
|
||||
SPI.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
|
||||
SPI.begin();
|
||||
SPI.setClockDivider(clock);
|
||||
SPI.setBitOrder(MSBFIRST);
|
||||
SPI.setDataMode(SPI_MODE0);
|
||||
}
|
||||
#endif // TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
|
||||
uint16_t data[3];
|
||||
const uint8_t coord = uint8_t(coordinate) | XPT2046_CONTROL | XPT2046_DFR_MODE;
|
||||
|
||||
#if ENABLED(TOUCH_BUTTONS_HW_SPI)
|
||||
|
||||
touch_spi_init(SPI_SPEED_6);
|
||||
for (uint16_t i = 0; i < 3; i++) {
|
||||
OUT_WRITE(TOUCH_CS_PIN, LOW);
|
||||
SPI.transfer(coord);
|
||||
data[i] = (((SPI.transfer(0xFF) << 8) | SPI.transfer(0xFF)) >> 3) & 0x0FFF;
|
||||
WRITE(TOUCH_CS_PIN, HIGH);
|
||||
}
|
||||
|
||||
#else // !TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
OUT_WRITE(TOUCH_CS_PIN, LOW);
|
||||
for (uint16_t i = 0; i < 3; i++) {
|
||||
for (uint8_t j = 0x80; j; j >>= 1) {
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
WRITE(TOUCH_MOSI_PIN, bool(coord & j));
|
||||
WRITE(TOUCH_SCK_PIN, HIGH);
|
||||
}
|
||||
|
||||
data[i] = 0;
|
||||
for (uint16_t j = 0x8000; j; j >>= 1) {
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
if (READ(TOUCH_MISO_PIN)) data[i] |= j;
|
||||
WRITE(TOUCH_SCK_PIN, HIGH);
|
||||
}
|
||||
WRITE(TOUCH_SCK_PIN, LOW);
|
||||
data[i] >>= 4;
|
||||
}
|
||||
WRITE(TOUCH_CS_PIN, HIGH);
|
||||
|
||||
#endif // !TOUCH_BUTTONS_HW_SPI
|
||||
|
||||
uint16_t delta01 = _MAX(data[0], data[1]) - _MIN(data[0], data[1]),
|
||||
delta02 = _MAX(data[0], data[2]) - _MIN(data[0], data[2]),
|
||||
delta12 = _MAX(data[1], data[2]) - _MIN(data[1], data[2]);
|
||||
|
||||
if (delta01 <= delta02 && delta01 <= delta12)
|
||||
return (data[0] + data[1]) >> 1;
|
||||
|
||||
if (delta02 <= delta12)
|
||||
return (data[0] + data[2]) >> 1;
|
||||
|
||||
return (data[1] + data[2]) >> 1;
|
||||
}
|
||||
|
||||
bool XPT2046::getTouchPoint(uint16_t &x, uint16_t &y) {
|
||||
if (isTouched()) {
|
||||
x = getInTouch(XPT2046_X);
|
||||
y = getInTouch(XPT2046_Y);
|
||||
}
|
||||
return isTouched();
|
||||
}
|
||||
|
||||
#endif // HAS_TOUCH_XPT2046
|
49
Marlin/src/lcd/touch/xpt2046.h
Normal file
49
Marlin/src/lcd/touch/xpt2046.h
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
|
||||
// Relies on XPT2046-compatible mode of ADS7843,
|
||||
// hence no Z1 / Z2 measurements are possible.
|
||||
|
||||
#define XPT2046_DFR_MODE 0x00
|
||||
#define XPT2046_SER_MODE 0x04
|
||||
#define XPT2046_CONTROL 0x80
|
||||
|
||||
enum XPTCoordinate : uint8_t {
|
||||
XPT2046_X = 0x10,
|
||||
XPT2046_Y = 0x50,
|
||||
XPT2046_Z1 = 0x30,
|
||||
XPT2046_Z2 = 0x40
|
||||
};
|
||||
|
||||
class XPT2046 {
|
||||
public:
|
||||
static void init();
|
||||
static uint8_t read_buttons();
|
||||
bool getTouchPoint(uint16_t &x, uint16_t &y);
|
||||
static bool isTouched();
|
||||
inline void waitForRelease() { while (isTouched()) { /* nada */ } }
|
||||
inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } }
|
||||
private:
|
||||
static uint16_t getInTouch(const XPTCoordinate coordinate);
|
||||
};
|
||||
|
||||
extern XPT2046 touch;
|
@ -150,7 +150,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
|
||||
volatile uint8_t MarlinUI::slow_buttons;
|
||||
#endif
|
||||
#if HAS_TOUCH_XPT2046
|
||||
#include "../feature/touch/xpt2046.h"
|
||||
#include "touch/xpt2046.h"
|
||||
bool MarlinUI::on_edit_screen = false;
|
||||
#endif
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user