Skip to content

Commit

Permalink
more basic reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and thisiskeithb committed Apr 24, 2023
1 parent 90e2d2a commit 734ca77
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 104 deletions.
1 change: 0 additions & 1 deletion Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
TERN_(TFT_SHARED_IO, while (isBusy()));
}


void TFT_SPI::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
DMAtx.Init.MemInc = MemoryIncrease;
HAL_DMA_Init(&DMAtx);
Expand Down
15 changes: 7 additions & 8 deletions Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,24 @@ uint32_t TFT_SPI::GetID() {
}

uint32_t TFT_SPI::ReadID(uint16_t Reg) {
#if !PIN_EXISTS(TFT_MISO)
return 0;
#else
uint8_t d = 0;
uint32_t data = 0;
uint32_t data = 0;

#if PIN_EXISTS(TFT_MISO)
SPIx.setClockDivider(SPI_CLOCK_DIV16);
DataTransferBegin(DATASIZE_8BIT);
WriteReg(Reg);

LOOP_L_N(i, 4) {
SPIx.read((uint8_t*)&d, 1);
uint8_t d;
SPIx.read(&d, 1);
data = (data << 8) | d;
}

DataTransferEnd();
SPIx.setClockDivider(SPI_CLOCK_MAX);

return data >> 7;
#endif

return data >> 7;
}

bool TFT_SPI::isBusy() {
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,10 @@
#endif
#endif

#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
#include "../lcd/tft_io/tft_orientation.h" // for TFT_COLOR_UI_PORTRAIT
#endif

#if ENABLED(TFT_RES_320x240)
#if ENABLED(TFT_COLOR_UI_PORTRAIT)
#define TFT_WIDTH 240
Expand Down
35 changes: 35 additions & 0 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,41 @@
#endif
#endif

// Touch Calibration
#if ANY(HAS_SPI_TFT, HAS_FSMC_TFT, HAS_LTDC_TFT)
#ifndef TOUCH_CALIBRATION_X
#ifdef XPT2046_X_CALIBRATION
#define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION
#else
#define TOUCH_CALIBRATION_X 0
#endif
#endif
#ifndef TOUCH_CALIBRATION_Y
#ifdef XPT2046_Y_CALIBRATION
#define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION
#else
#define TOUCH_CALIBRATION_Y 0
#endif
#endif
#ifndef TOUCH_OFFSET_X
#ifdef XPT2046_X_OFFSET
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
#else
#define TOUCH_OFFSET_X 0
#endif
#endif
#ifndef TOUCH_OFFSET_Y
#ifdef XPT2046_Y_OFFSET
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
#else
#define TOUCH_OFFSET_Y 0
#endif
#endif
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif
#endif

// Number of VFAT entries used. Each entry has 13 UTF-16 characters
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
#define VFAT_ENTRIES_LIMIT 5
Expand Down
12 changes: 1 addition & 11 deletions Marlin/src/lcd/extui/mks_ui/draw_print_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ bool have_pre_pic(char *path) {
static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
uint8_t i, file_count = 0;
//switch (obj->mks_obj_id)
//{
if (obj->mks_obj_id == ID_P_UP) {
if (dir_offset[curDirLever].curPage > 0) {
// 2015.05.19
Expand Down Expand Up @@ -435,21 +433,13 @@ void lv_gcode_file_read(uint8_t *data_buf) {
break;
}
}

for (i = 0; i < 200;) {
p_index = (uint16_t *)(&public_buf[i]);
//Color = (*p_index >> 8);
//*p_index = Color | ((*p_index & 0xFF) << 8);
i += 2;
if (*p_index == 0x0000) {
#if HAS_TFT_LVGL_UI_SPI
*p_index = LV_COLOR_BACKGROUND.full;
#else
*p_index = LV_COLOR_BACKGROUND.full; // 0x18C3
#endif
}
if (*p_index == 0x0000) *p_index = LV_COLOR_BACKGROUND.full;
}

memcpy(data_buf, public_buf, 200);
#endif // HAS_MEDIA
}
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
#include <lvgl.h>

#include "../../../MarlinCore.h"
#include "../../marlinui.h"

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

#include HAL_PATH(../../../HAL, tft/xpt2046.h)
#include "../../marlinui.h"
XPT2046 touch;

#if ENABLED(POWER_LOSS_RECOVERY)
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/lcd/extui/mks_ui/wifi_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,6 +1804,7 @@ void stopEspTransfer() {

W25QXX.init(SPI_QUARTER_SPEED);

// ?? Workaround for SPI / Servo issues ??
TERN_(HAS_TFT_LVGL_UI_SPI, SPI_TFT.spi_init(SPI_FULL_SPEED));
TERN_(HAS_SERVOS, servo_init());
TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());
Expand Down
10 changes: 0 additions & 10 deletions Marlin/src/lcd/tft_io/ili9488.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,6 @@
#define ILI9488_ADJCTL6 0xFC // Adjust Control 6
#define ILI9488_ADJCTL7 0xFF // Adjust Control 7

#if 0
// https://forum.mikroe.com/viewtopic.php?t=74586
#if ANY(MKS_ROBIN_TFT35, TFT_TRONXY_X5SA, ANYCUBIC_TFT35) // ILI9488
#define TFT_DRIVER ILI9488
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_RES_480x320
#define TFT_INTERFACE_FSMC
#endif
#endif

static const uint16_t ili9488_init[] = {
DATASIZE_8BIT,
ESC_REG(ILI9488_SWRESET), ESC_DELAY(120),
Expand Down
46 changes: 0 additions & 46 deletions Marlin/src/lcd/tft_io/tft_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,6 @@
#error "DMA_MAX_SIZE is not configured for this platform."
#endif

#define TFT_EXCHANGE_XY _BV32(1)
#define TFT_INVERT_X _BV32(2)
#define TFT_INVERT_Y _BV32(3)

#define TFT_NO_ROTATION (0x00)
#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X)
#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y)

#define TFT_MIRROR_X (TFT_INVERT_Y)
#define TFT_MIRROR_Y (TFT_INVERT_X)

#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_MIRROR_X)
#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_MIRROR_Y)

#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_MIRROR_X)
#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_MIRROR_Y)

#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_MIRROR_X)
#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_MIRROR_Y)

// TFT_ROTATION is user configurable
#ifndef TFT_ROTATION
#define TFT_ROTATION TFT_NO_ROTATION
#endif

// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))

// Set TFT_COLOR_UI_PORTRAIT flag, if needed
#if ((TFT_ORIENTATION) & TFT_EXCHANGE_XY) == 0
#define TFT_COLOR_UI_PORTRAIT 1
#endif

#define TFT_COLOR_RGB _BV32(3)
#define TFT_COLOR_BGR _BV32(4)

// Each TFT Driver is responsible for its default color mode.
//#ifndef TFT_COLOR
// #define TFT_COLOR TFT_COLOR_RGB
//#endif

#define TOUCH_ORIENTATION_NONE 0
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2

#ifndef TFT_DRIVER
#define TFT_DRIVER AUTO
#endif
Expand Down
68 changes: 68 additions & 0 deletions Marlin/src/lcd/tft_io/tft_orientation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 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

#define TFT_EXCHANGE_XY _BV32(1)
#define TFT_INVERT_X _BV32(2)
#define TFT_INVERT_Y _BV32(3)

#define TFT_NO_ROTATION (0x00)
#define TFT_ROTATE_90 (TFT_EXCHANGE_XY | TFT_INVERT_X)
#define TFT_ROTATE_180 (TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_ROTATE_270 (TFT_EXCHANGE_XY | TFT_INVERT_Y)

#define TFT_MIRROR_X (TFT_INVERT_Y)
#define TFT_MIRROR_Y (TFT_INVERT_X)

#define TFT_ROTATE_90_MIRROR_X (TFT_ROTATE_90 ^ TFT_MIRROR_X)
#define TFT_ROTATE_90_MIRROR_Y (TFT_ROTATE_90 ^ TFT_MIRROR_Y)

#define TFT_ROTATE_180_MIRROR_X (TFT_ROTATE_180 ^ TFT_MIRROR_X)
#define TFT_ROTATE_180_MIRROR_Y (TFT_ROTATE_180 ^ TFT_MIRROR_Y)

#define TFT_ROTATE_270_MIRROR_X (TFT_ROTATE_270 ^ TFT_MIRROR_X)
#define TFT_ROTATE_270_MIRROR_Y (TFT_ROTATE_270 ^ TFT_MIRROR_Y)

// TFT_ROTATION is user configurable
#ifndef TFT_ROTATION
#define TFT_ROTATION TFT_NO_ROTATION
#endif

// TFT_ORIENTATION is the "sum" of TFT_DEFAULT_ORIENTATION plus user TFT_ROTATION
#define TFT_ORIENTATION ((TFT_DEFAULT_ORIENTATION) ^ (TFT_ROTATION))

// Set TFT_COLOR_UI_PORTRAIT flag, if needed
#if ((TFT_ORIENTATION) & TFT_EXCHANGE_XY) == 0
#define TFT_COLOR_UI_PORTRAIT 1
#endif

#define TFT_COLOR_RGB _BV32(3)
#define TFT_COLOR_BGR _BV32(4)

// Each TFT Driver is responsible for its default color mode.
//#ifndef TFT_COLOR
// #define TFT_COLOR TFT_COLOR_RGB
//#endif

#define TOUCH_ORIENTATION_NONE 0
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2
28 changes: 1 addition & 27 deletions Marlin/src/lcd/tft_io/touch_calibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
#pragma once

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

#ifndef TOUCH_SCREEN_CALIBRATION_PRECISION
#define TOUCH_SCREEN_CALIBRATION_PRECISION 80
Expand All @@ -30,32 +30,6 @@
#define TOUCH_SCREEN_HOLD_TO_CALIBRATE_MS 2500
#endif

// XPT2046_** Compatibility
#if defined(XPT2046_X_CALIBRATION) && defined(XPT2046_Y_CALIBRATION) && defined(XPT2046_X_OFFSET) && defined(XPT2046_Y_OFFSET) \
&& !(defined(TOUCH_CALIBRATION_X) || defined(TOUCH_CALIBRATION_Y) || defined(TOUCH_OFFSET_X) || defined(TOUCH_OFFSET_Y) || defined(TOUCH_ORIENTATION))
#define TOUCH_CALIBRATION_X XPT2046_X_CALIBRATION
#define TOUCH_CALIBRATION_Y XPT2046_Y_CALIBRATION
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif

#ifndef TOUCH_CALIBRATION_X
#define TOUCH_CALIBRATION_X 0
#endif
#ifndef TOUCH_CALIBRATION_Y
#define TOUCH_CALIBRATION_Y 0
#endif
#ifndef TOUCH_OFFSET_X
#define TOUCH_OFFSET_X 0
#endif
#ifndef TOUCH_OFFSET_Y
#define TOUCH_OFFSET_Y 0
#endif
#ifndef TOUCH_ORIENTATION
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif

typedef struct __attribute__((__packed__)) {
int32_t x, y;
int16_t offset_x, offset_y;
Expand Down

0 comments on commit 734ca77

Please sign in to comment.