Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for TFT and touch screens #18130

Merged
merged 106 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
e3e6482
Pre-requisites for TFT and touch screen support
jmz52 May 27, 2020
639b488
Add support for TFT and touch screen
jmz52 May 27, 2020
dd5f13c
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jun 1, 2020
ab4ed92
Update Sd2Card_sdio_stm32duino.cpp
thinkyhead Jun 2, 2020
3eada56
Update tft_spi.cpp
thinkyhead Jun 2, 2020
afe667d
No wrapper on headers
thinkyhead Jun 2, 2020
87c957f
Update xpt2046.cpp
thinkyhead Jun 2, 2020
a604a04
No wrappers on headers
thinkyhead Jun 2, 2020
1badfff
Update (c), indentation
thinkyhead Jun 2, 2020
3e25d86
Merge branch 'tft_and_touch_screen' of https://github.com/jmz52/Marli…
jmz52 Jun 2, 2020
dd1aa9a
Fix FSMC initialization for STM32F103Vx MCUs
jmz52 Jun 2, 2020
2d868a8
Add FSMC support for STM32F4xxVx and STM32F4xxZx MCUs
jmz52 Jun 3, 2020
7180660
Improve TFT initialization
jmz52 Jun 10, 2020
f0b03ac
Update Conditionals_LCD.h
thinkyhead Jun 11, 2020
a77b2dc
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jun 11, 2020
17f4a31
Implement TFT UI for ADVANCED_PAUSE_FEATURE
jmz52 Jun 11, 2020
e7f1b50
Various style adjustments
thinkyhead Jun 11, 2020
fa47c57
…etc…
thinkyhead Jun 11, 2020
fe80e23
Update tft_fsmc.cpp
thinkyhead Jun 12, 2020
ca1b9a9
Implement TFT UI for AUTO_BED_LEVELING_UBL
jmz52 Jun 14, 2020
a7ce846
Merge branch 'tft_and_touch_screen' of https://github.com/jmz52/Marli…
jmz52 Jun 14, 2020
2a9fe2e
STM32 bootloader and MKS encryption scripts
jmz52 Jun 14, 2020
df569e8
Fix compilation errors
jmz52 Jun 14, 2020
9e44367
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jun 16, 2020
2d8f324
Add conditional and sanity checks
jmz52 Jun 17, 2020
3e90f1d
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jun 17, 2020
c0a24bb
Slow down FSMC to improve stability
jmz52 Jun 17, 2020
09c87fa
Add new build environment for MKS Robin
jmz52 Jun 17, 2020
eec5965
Restore Configuration.h
jmz52 Jun 17, 2020
67abc5d
Add touch screen calibration - M995
jmz52 Jun 22, 2020
2f7dd35
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jun 22, 2020
79aa48e
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bf2_tft_tou…
thinkyhead Jun 22, 2020
958dc61
Update M995.cpp
thinkyhead Jun 23, 2020
afc29e7
Update platformio.ini
thinkyhead Jun 23, 2020
0adc6ed
Update platformio.ini
thinkyhead Jun 23, 2020
52e2a39
Add 'variant' for STM32F103Vx boards to build with HAL STM32
jmz52 Jun 23, 2020
369115f
Code cleanup
jmz52 Jun 23, 2020
6f3bf22
Update Sd2Card_sdio_stm32duino.cpp
thinkyhead Jun 26, 2020
a712196
Implement UI for 480x320 TFT with optional touch screen
jmz52 Jun 26, 2020
b546e8f
Merge branch 'tft_and_touch_screen' of https://github.com/jmz52/Marli…
jmz52 Jun 26, 2020
ffe422c
Fix BGR/RGB bits order configuration
jmz52 Jun 26, 2020
9052a5b
Fix BGR/RGB bits order configuration - take two
jmz52 Jun 26, 2020
bd37801
Add driver definition for LERDGE init sequence.
xC0000005 Jun 27, 2020
6128419
Merge pull request #1 from xC0000005/tft_and_touch_screen
jmz52 Jun 27, 2020
13b928f
Merge branch 'bugfix-2.0.x' into tft_and_touch_screen
thinkyhead Jul 3, 2020
9eba0cb
Update UBL Mesh Edit
jmz52 Jul 3, 2020
bb2b61e
Merge branch 'bugfix-2.0.x' into tft_and_touch_screen
thinkyhead Jul 12, 2020
4e6afb0
Tweak tft.cpp
thinkyhead Jul 12, 2020
22633bc
Update platformio.ini
thinkyhead Jul 12, 2020
7c37a40
Fix LERDGE_ST7796 and TFT_DRIVER handling
jmz52 Jul 12, 2020
8a72270
Merge branch 'bugfix-2.0.x' into tft_and_touch_screen
thinkyhead Jul 22, 2020
8ece3dd
Update platformio.ini
thinkyhead Jul 22, 2020
f66faad
Update menu_ubl.cpp
thinkyhead Jul 22, 2020
f92cea3
Filter 6 files with HAS_GRAPHICAL_TFT
thinkyhead Jul 22, 2020
1790dd1
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/18130
thinkyhead Jul 22, 2020
add86fc
Clean up some conditions
thinkyhead Jul 22, 2020
784fbad
Move bitmaps to cpp
thinkyhead Jul 22, 2020
8e25974
Throw error for unsupported HALs
thinkyhead Jul 22, 2020
9727210
Allow SDSUPPORT to be disabled
thinkyhead Jul 22, 2020
94bdc21
Move font data to cpp
thinkyhead Jul 22, 2020
4c8b9d4
Update platformio.ini
thinkyhead Jul 22, 2020
9691e67
Fix compilation problems
jmz52 Jul 23, 2020
43aeaab
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jul 23, 2020
24067ed
Fix merge conflict
jmz52 Jul 24, 2020
d29e6fb
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jul 24, 2020
49316ba
Update URL to black STM32F407 board
jmz52 Jul 24, 2020
445dc7a
Robin nano V2, TFT LVGL UI parameters, and more (#18500)
MKS-Sean Jul 25, 2020
3a77a64
Merge branch 'bugfix-2.0.x' into tft_and_touch_screen
thinkyhead Jul 25, 2020
a81f1f7
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/18130
thinkyhead Jul 25, 2020
c78361b
HAL-specific conditionals
thinkyhead Jul 25, 2020
d8fe483
Update Conditionals_post.h
thinkyhead Jul 25, 2020
4b90093
Update Conditionals_LCD.h
thinkyhead Jul 25, 2020
5d9b2a3
Update license links
thinkyhead Jul 25, 2020
5005158
spacing
thinkyhead Jul 25, 2020
a4514c0
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/18130
thinkyhead Jul 25, 2020
d7ef525
Format pins_MKS_ROBIN.h
thinkyhead Jul 25, 2020
90b88c6
AFAIK 'platform' is needed
thinkyhead Jul 25, 2020
fc9a24f
Add support for ST7796 with SPI interface
jmz52 Jul 26, 2020
c41a532
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into tft_and_tou…
jmz52 Jul 26, 2020
7ee2f53
Add '$' character and negative index substitution
jmz52 Jul 26, 2020
b4d7bfe
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into pr/18130
thinkyhead Jul 28, 2020
c098cd3
Was option, now conditional
thinkyhead Jul 28, 2020
da13b80
General sweep
thinkyhead Jul 28, 2020
c5b19b5
Include full prefix for HAS_XPT2046_BUTTONS
thinkyhead Jul 28, 2020
14952d7
I believe opt_add should… prepend?
thinkyhead Jul 28, 2020
f310de0
Grab test from import, temporarily
thinkyhead Jul 28, 2020
fd1117f
Import more tests
thinkyhead Jul 28, 2020
f2515af
More flexible test script
thinkyhead Jul 28, 2020
98c8358
Another…
thinkyhead Jul 28, 2020
ad9bef8
Allow TFT for STM32F1
thinkyhead Jul 28, 2020
119ec93
Update Conditionals_LCD.h
thinkyhead Jul 28, 2020
e68f4d4
Merge branch 'bugfix-2.0.x' into tft_and_touch_screen
thinkyhead Jul 30, 2020
829b0ab
Use new option name
thinkyhead Jul 30, 2020
bba784f
CHange define to reflect
thinkyhead Jul 30, 2020
c0079bc
Update pins checks
thinkyhead Jul 30, 2020
cc39ca6
Can use bugfix-2.0.x tests
thinkyhead Jul 30, 2020
2470b9a
Test mks_robin_stm32 with new config
thinkyhead Jul 30, 2020
d0b4080
ABM hint for mks_robin_stm32
thinkyhead Jul 30, 2020
41db12e
I are confused
thinkyhead Jul 30, 2020
c7fc512
Missing include
thinkyhead Jul 30, 2020
46f86c2
Separate ULTRA_LCD block
thinkyhead Jul 30, 2020
3653cb5
Bring it
thinkyhead Jul 30, 2020
3286f97
Swaptions
thinkyhead Jul 30, 2020
307debc
HAS_TFT_XPT2046
thinkyhead Jul 30, 2020
194f99e
Comment
thinkyhead Jul 30, 2020
17e01da
Apply indentation
thinkyhead Jul 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
- BIGTREE_SKR_PRO
- BIGTREE_GTR_V1_0
- mks_robin
- mks_robin_stm32
- ARMED
- FYSETC_S6
- STM32F070RB_malyan
Expand Down
22 changes: 20 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,22 @@
//=============================== Graphical TFTs ==============================
//=============================================================================

//
// TFT display with optional touch screen
// Color Marlin UI with standard menu system
//
//#define TFT_320x240
//#define TFT_320x240_SPI
//#define TFT_480x320
//#define TFT_480x320_SPI

//
// Skip autodetect and force specific TFT driver
// Mandatory for SPI screens with no MISO line
// Available drivers are: ST7735, ST7789, ST7796, R61505, ILI9328, ILI9341, ILI9488
//
//#define TFT_DRIVER AUTO

//
// FSMC display (MKS Robin, Alfawise U20, JGAurora A5S, REXYZ A1, etc.)
// Upscaled 128x64 Marlin UI
Expand Down Expand Up @@ -2190,11 +2206,13 @@
//
// ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
//
//#define TOUCH_BUTTONS
#if ENABLED(TOUCH_BUTTONS)
//#define TOUCH_SCREEN
#if ENABLED(TOUCH_SCREEN)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TOUCH_BUTTONS is going away completely as a separate user-configurable option, then I will follow up shortly with a suitable conditional to replace it. There are several pins files that still refer to TOUCH_BUTTONS and I want make it clear this refers specifically to the XPT2046 device.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the xpt2046 of the emulated DOGM migrated to the new implementation? Right now, I think every TOUCH_BUTTONS pin refer to specifically emulated DOGM and software spi.

#define BUTTON_DELAY_EDIT 50 // (ms) Button repeat delay for edit screens
#define BUTTON_DELAY_MENU 250 // (ms) Button repeat delay for menus

#define TOUCH_SCREEN_CALIBRATION

//#define XPT2046_X_CALIBRATION 12316
//#define XPT2046_Y_CALIBRATION -8981
//#define XPT2046_X_OFFSET -43
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/HAL/AVR/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/AVR."
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/DUE/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/DUE."
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/ESP32/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/ESP32."
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/LINUX/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/LINUX."
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/LPC1768."
#endif
4 changes: 4 additions & 0 deletions Marlin/src/HAL/SAMD51/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
*
*/
#pragma once

#if HAS_SPI_TFT || HAS_FSMC_TFT
#error "Sorry! TFT displays are not available for HAL/SAMD51."
#endif
5 changes: 5 additions & 0 deletions Marlin/src/HAL/STM32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,10 @@ uint16_t HAL_adc_get_result();
#define GET_PIN_MAP_INDEX(pin) pin
#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)

#ifdef STM32F1xx
#define JTAG_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
#define JTAGSWD_DISABLE() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_DISABLE)
#endif

#define PLATFORM_M997_SUPPORT
void flashFirmware(const int16_t);
73 changes: 54 additions & 19 deletions Marlin/src/HAL/STM32/Sd2Card_sdio_stm32duino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,24 @@

SD_HandleTypeDef hsd; // create SDIO structure

#define TRANSFER_CLOCK_DIV (uint8_t(SDIO_INIT_CLK_DIV) / 40)
/*
SDIO_INIT_CLK_DIV is 118
SDIO clock frequency is 48MHz / (TRANSFER_CLOCK_DIV + 2)
SDIO init clock frequency should not exceed 400KHz = 48MHz / (118 + 2)

Default TRANSFER_CLOCK_DIV is 2 (118 / 40)
Default SDIO clock frequency is 48MHz / (2 + 2) = 12 MHz
This might be too fast for stable SDIO operations

MKS Robin board seems to have stable SDIO with BusWide 1bit and ClockDiv 8 i.e. 4.8MHz SDIO clock frequency
Additional testing is required as there are clearly some 4bit initialization problems

Add -DTRANSFER_CLOCK_DIV=8 to build parameters to improve SDIO stability
*/

#ifndef TRANSFER_CLOCK_DIV
#define TRANSFER_CLOCK_DIV (uint8_t(SDIO_INIT_CLK_DIV) / 40)
#endif

#ifndef USBD_OK
#define USBD_OK 0
Expand All @@ -100,35 +117,39 @@
void SD_LowLevel_Init(void) {
uint32_t tempreg;

GPIO_InitTypeDef GPIO_InitStruct;

__HAL_RCC_SDIO_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE(); //enable GPIO clocks
__HAL_RCC_GPIOD_CLK_ENABLE(); //enable GPIO clocks

GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_12; // D0 & SCK
GPIO_InitTypeDef GPIO_InitStruct;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = 1; //GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;

#if DISABLED(STM32F1xx)
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
#endif

GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_12; // D0 & SCK
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

#if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // define D1-D3 only if have a four bit wide SDIO bus
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11; // D1-D3
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = 1; // GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
#endif

// Configure PD.02 CMD line
GPIO_InitStruct.Pin = GPIO_PIN_2;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST_Msk; // take SDIO out of reset
RCC->APB2ENR |= RCC_APB2RSTR_SDIORST_Msk; // enable SDIO clock

// Enable the DMA2 Clock
#if DISABLED(STM32F1xx)
// TODO: use __HAL_RCC_SDIO_RELEASE_RESET() and __HAL_RCC_SDIO_CLK_ENABLE();
RCC->APB2RSTR &= ~RCC_APB2RSTR_SDIORST_Msk; // take SDIO out of reset
RCC->APB2ENR |= RCC_APB2RSTR_SDIORST_Msk; // enable SDIO clock
// Enable the DMA2 Clock
#endif

//Initialize the SDIO (with initial <400Khz Clock)
tempreg = 0; //Reset value
Expand Down Expand Up @@ -156,10 +177,21 @@
bool status;
hsd.Instance = SDIO;
hsd.State = (HAL_SD_StateTypeDef) 0; // HAL_SD_STATE_RESET

/*
hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING;
hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE;
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
hsd.Init.ClockDiv = 8;
*/

SD_LowLevel_Init();

uint8_t retry_Cnt = retryCnt;
for (;;) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
status = (bool) HAL_SD_Init(&hsd);
if (!status) break;
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
Expand All @@ -170,6 +202,7 @@
#if PINS_EXIST(SDIO_D1, SDIO_D2, SDIO_D3) // go to 4 bit wide mode if pins are defined
retry_Cnt = retryCnt;
for (;;) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
if (!HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B)) break; // some cards are only 1 bit wide so a pass here is not required
if (!--retry_Cnt) break;
}
Expand All @@ -178,6 +211,7 @@
SD_LowLevel_Init();
retry_Cnt = retryCnt;
for (;;) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
status = (bool) HAL_SD_Init(&hsd);
if (!status) break;
if (!--retry_Cnt) return false; // return failing status if retries are exhausted
Expand All @@ -187,15 +221,15 @@

return true;
}

/*
void init_SDIO_pins(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};

/**SDIO GPIO Configuration
PC8 ------> SDIO_D0
PC12 ------> SDIO_CK
PD2 ------> SDIO_CMD
*/
// SDIO GPIO Configuration
// PC8 ------> SDIO_D0
// PC12 ------> SDIO_CK
// PD2 ------> SDIO_CMD

GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
Expand All @@ -217,7 +251,7 @@
GPIO_InitStruct.Alternate = GPIO_AF12_SDIO;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
}

*/
//bool SDIO_init() { return (bool) (SD_SDIO_Init() ? 1 : 0);}
//bool SDIO_Init_C() { return (bool) (SD_SDIO_Init() ? 1 : 0);}

Expand All @@ -227,6 +261,7 @@

bool status;
for (;;) {
TERN_(USE_WATCHDOG, HAL_watchdog_refresh());
status = (bool) HAL_SD_ReadBlocks(&hsd, (uint8_t*)dst, block, 1, 1000); // read one 512 byte block with 500mS timeout
status |= (bool) HAL_SD_GetCardState(&hsd); // make sure all is OK
if (!status) break; // return passing status
Expand Down
Loading