Skip to content

Commit e83d8ad

Browse files
jmz52Andy-Big
authored andcommitted
⚡️ Improve TFT DMA for STM32 (MarlinFirmware#25359)
1 parent ca99060 commit e83d8ad

25 files changed

+207
-167
lines changed

Marlin/Configuration.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -3347,11 +3347,20 @@ EEPROM_W25Q
33473347
//#define TFT_LVGL_UI
33483348

33493349
#if ENABLED(TFT_COLOR_UI)
3350-
//#define TFT_SHARED_SPI // SPI is shared between TFT display and other devices. Disable async data transfer
3350+
/**
3351+
* TFT Font for Color_UI. Choose one of the following:
3352+
*
3353+
* NOTOSANS - Default font with antialiasing. Supports Latin Extended and non-Latin characters.
3354+
* UNIFONT - Lightweight font, no antialiasing. Supports Latin Extended and non-Latin characters.
3355+
* HELVETICA - Lightweight font, no antialiasing. Supports Basic Latin (0x0020-0x007F) and Latin-1 Supplement (0x0080-0x00FF) characters only.
3356+
*/
3357+
#define TFT_FONT NOTOSANS
3358+
3359+
//#define TFT_SHARED_IO // I/O is shared between TFT display and other devices. Disable async data transfer.
33513360
#endif
33523361

33533362
#if ENABLED(TFT_LVGL_UI)
3354-
#define MKS_WIFI_MODULE // MKS WiFi module
3363+
//#define MKS_WIFI_MODULE // MKS WiFi module
33553364
#endif
33563365

33573366
/**

Marlin/src/HAL/LPC1768/tft/tft_spi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
139139
DataTransferBegin(DATASIZE_16BIT);
140140
SPIx.dmaSendAsync(Data, Count, MemoryIncrease);
141141

142-
TERN_(TFT_SHARED_SPI, while (isBusy()));
142+
TERN_(TFT_SHARED_IO, while (isBusy()));
143143
}
144144

145145
#endif // HAS_SPI_TFT

Marlin/src/HAL/STM32/tft/tft_fsmc.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ void TFT_FSMC::Init() {
100100

101101
HAL_SRAM_Init(&SRAMx, &Timing, &ExtTiming);
102102

103-
__HAL_RCC_DMA2_CLK_ENABLE();
104-
105103
#ifdef STM32F1xx
106-
DMAtx.Instance = DMA2_Channel1;
104+
__HAL_RCC_DMA1_CLK_ENABLE();
105+
DMAtx.Instance = DMA1_Channel1;
107106
#elif defined(STM32F4xx)
107+
__HAL_RCC_DMA2_CLK_ENABLE();
108108
DMAtx.Instance = DMA2_Stream0;
109109
DMAtx.Init.Channel = DMA_CHANNEL_0;
110110
DMAtx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
@@ -174,6 +174,8 @@ void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
174174
DMAtx.Init.PeriphInc = MemoryIncrease;
175175
HAL_DMA_Init(&DMAtx);
176176
HAL_DMA_Start(&DMAtx, (uint32_t)Data, (uint32_t)&(LCD->RAM), Count);
177+
178+
TERN_(TFT_SHARED_IO, while (isBusy()));
177179
}
178180

179181
void TFT_FSMC::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {

Marlin/src/HAL/STM32/tft/tft_spi.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
242242

243243
SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); // Enable Tx DMA Request
244244

245-
TERN_(TFT_SHARED_SPI, while (isBusy()));
245+
TERN_(TFT_SHARED_IO, while (isBusy()));
246246
}
247247

248248

@@ -261,6 +261,7 @@ void TFT_SPI::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count)
261261
SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); // Enable Tx DMA Request
262262

263263
HAL_DMA_PollForTransfer(&DMAtx, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY);
264+
while ( __HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) {}
264265
Abort();
265266
}
266267

Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Cou
245245
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count);
246246
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
247247
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
248+
249+
TERN_(TFT_SHARED_IO, while (isBusy()));
248250
}
249251

250252
void TFT_FSMC::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {

Marlin/src/HAL/STM32F1/tft/tft_fsmc.h

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030

3131
#include <libmaple/dma.h>
3232

33+
#ifndef FSMC_DMA_DEV
34+
#define FSMC_DMA_DEV DMA2
35+
#endif
36+
#ifndef FSMC_DMA_CHANNEL
37+
#define FSMC_DMA_CHANNEL DMA_CH5
38+
#endif
39+
3340
#define DATASIZE_8BIT DMA_SIZE_8BITS
3441
#define DATASIZE_16BIT DMA_SIZE_16BITS
3542
#define TFT_IO_DRIVER TFT_FSMC

Marlin/src/HAL/STM32F1/tft/tft_spi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun
154154
DataTransferBegin();
155155
SPIx.dmaSendAsync(Data, Count, MemoryIncrease == DMA_MINC_ENABLE);
156156

157-
TERN_(TFT_SHARED_SPI, while (isBusy()));
157+
TERN_(TFT_SHARED_IO, while (isBusy()));
158158
}
159159

160160
void TFT_SPI::Transmit(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {

Marlin/src/inc/SanityCheck.h

+2
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@
698698
#error "DISABLE_INACTIVE_[XYZIJKUVWE] is now DISABLE_IDLE_[XYZIJKUVWE]."
699699
#elif defined(DEFAULT_STEPPER_DEACTIVE_TIME)
700700
#error "DEFAULT_STEPPER_DEACTIVE_TIME is now DEFAULT_STEPPER_TIMEOUT_SEC."
701+
#elif defined(TFT_SHARED_SPI)
702+
#error "TFT_SHARED_SPI is now TFT_SHARED_IO."
701703
#endif
702704

703705
// L64xx stepper drivers have been removed

Marlin/src/lcd/tft_io/ili9328.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define ILI9328_ETMOD_ID0 0x0010 // 0 - Horizontal Decrement / 1 - Horizontal Increment
4040
#define ILI9328_ETMOD_AM 0x0008 // 0 - Horizontal / 1 - Vertical
4141

42-
// MKS Robin TFT v1.1 - 320x240 ; Cable on the left side
42+
// MKS Robin TFT v1.1 - 320x240 ; FPC cable on the left side
4343

4444
#if TFT_ROTATION == TFT_ROTATE_180
4545
#define ILI9328_DRVCTL_DATA 0x0000

Marlin/src/lcd/tft_io/ili9341.h

+20-19
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
#define ILI9341_MADCTL_RGB 0x00
3434
#define ILI9341_MADCTL_MH 0x04 // Horizontal Refresh Order
3535

36-
#define ILI9341_ORIENTATION_UP ILI9341_MADCTL_MY // 240x320 ; Cable on the upper side
37-
#define ILI9341_ORIENTATION_RIGHT ILI9341_MADCTL_MV // 320x240 ; Cable on the right side
38-
#define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; Cable on the left side
39-
#define ILI9341_ORIENTATION_DOWN ILI9341_MADCTL_MX // 240x320 ; Cable on the upper side
36+
#define ILI9341_ORIENTATION_TOP ILI9341_MADCTL_MY // 240x320 ; FPC cable on the top side
37+
#define ILI9341_ORIENTATION_RIGHT ILI9341_MADCTL_MV // 320x240 ; FPC cable on the right side
38+
#define ILI9341_ORIENTATION_LEFT ILI9341_MADCTL_MY | ILI9341_MADCTL_MX | ILI9341_MADCTL_MV // 320x240 ; FPC cable on the left side
39+
#define ILI9341_ORIENTATION_BOTTOM ILI9341_MADCTL_MX // 240x320 ; FPC cable on the bottom side
4040

4141
#define ILI9341_ORIENTATION IF_0((TFT_ORIENTATION) & TFT_EXCHANGE_XY, ILI9341_MADCTL_MV) | \
4242
IF_0((TFT_ORIENTATION) & TFT_INVERT_X, ILI9341_MADCTL_MX) | \
@@ -52,7 +52,7 @@
5252

5353
#define ILI9341_NOP 0x00 // No Operation
5454
#define ILI9341_SWRESET 0x01 // Software Reset
55-
#define ILI9341_RDDIDIF 0x04 // Read display identification information
55+
#define ILI9341_RDDIDIF 0x04 // Read Display Identification Information
5656
#define ILI9341_RDDST 0x09 // Read Display Status
5757
#define ILI9341_RDDPM 0x0A // Read Display Power Mode
5858
#define ILI9341_RDDMADCTL 0x0B // Read Display MADCTL
@@ -141,20 +141,21 @@ static const uint16_t ili9341_init[] = {
141141
DATASIZE_8BIT,
142142
ESC_REG(ILI9341_SWRESET), ESC_DELAY(100),
143143
ESC_REG(ILI9341_SLPOUT), ESC_DELAY(20),
144-
/*
145-
ESC_REG(ILI9341_PWCTRLA), 0x0039, 0x002C, 0x0000, 0x0034, 0x0002, // Power control A
146-
ESC_REG(ILI9341_PWCTRLB), 0x0000, 0x00C1, 0x0030, // Power control B
147-
ESC_REG(ILI9341_DRVTCTLA1), 0x0085, 0x0000, 0x0078, // Driver timing control A
148-
ESC_REG(ILI9341_DRVTCTLB), 0x0000, 0x0000, // Driver timing control B
149-
ESC_REG(ILI9341_PONSEQCTL), 0x0064, 0x0003, 0x0012, 0x0081, // Power on sequence control
150-
ESC_REG(ILI9341_DISCTRL), 0x0008, 0x0082, 0x0027, // Display Function Control
151-
ESC_REG(ILI9341_PUMPRCTL), 0x0020, // Pump ratio control
152-
ESC_REG(ILI9341_VMCTRL1), 0x003E, 0x0028, // VCOM Control 1
153-
ESC_REG(ILI9341_VMCTRL2), 0x0086, // VCOM Control 2
154-
ESC_REG(ILI9341_FRMCTR1), 0x0000, 0x0018, // Frame Rate Control (In Normal Mode/Full Colors)
155-
ESC_REG(ILI9341_PWCTRL1), 0x0023, // Power Control 1
156-
ESC_REG(ILI9341_PWCTRL2), 0x0010, // Power Control 2
157-
*/
144+
145+
ESC_REG(ILI9341_PWCTRLA), 0x0039, 0x002C, 0x0000, 0x0034, 0x0002,
146+
ESC_REG(ILI9341_PWCTRLB), 0x0000, 0x00C1, 0x0030,
147+
ESC_REG(ILI9341_DRVTCTLA1), 0x0085, 0x0000, 0x0078,
148+
ESC_REG(ILI9341_DRVTCTLB), 0x0000, 0x0000,
149+
ESC_REG(ILI9341_PONSEQCTL), 0x0064, 0x0003, 0x0012, 0x0081,
150+
ESC_REG(ILI9341_DISCTRL), 0x0008, 0x0082, 0x0027, // Source Output Scan Direction: 0, Gate Output Scan Direction: 0
151+
ESC_REG(ILI9341_DINVOFF),
152+
ESC_REG(ILI9341_PUMPRCTL), 0x0020,
153+
ESC_REG(ILI9341_VMCTRL1), 0x003E, 0x0028,
154+
ESC_REG(ILI9341_VMCTRL2), 0x0086,
155+
ESC_REG(ILI9341_FRMCTR1), 0x0000, 0x0018,
156+
ESC_REG(ILI9341_PWCTRL1), 0x0023,
157+
ESC_REG(ILI9341_PWCTRL2), 0x0010,
158+
158159
ESC_REG(ILI9341_MADCTL), ILI9341_MADCTL_DATA,
159160
ESC_REG(ILI9341_PIXSET), 0x0055,
160161

0 commit comments

Comments
 (0)