Skip to content

Commit

Permalink
Anet ET4 / ET4P and Anet TFT28 / TFT35 (MarlinFirmware#20280)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisiskeithb authored and dpreed committed Feb 5, 2021
1 parent 66a63e0 commit fd9b059
Show file tree
Hide file tree
Showing 17 changed files with 407 additions and 84 deletions.
10 changes: 10 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,16 @@
//
//#define LONGER_LK_TFT28

//
// 320x240, 2.8", FSMC Stock Display from ET4
//
//#define ANET_ET4_TFT28

//
// 480x320, 3.5", FSMC Stock Display from ET5
//
//#define ANET_ET5_TFT35

//
// Generic TFT with detailed options
//
Expand Down
35 changes: 18 additions & 17 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ void TFT_FSMC::Init() {

uint32_t NSBank = (uint32_t)pinmap_peripheral(digitalPinToPinName(TFT_CS_PIN), PinMap_FSMC_CS);

// Perform the SRAM1 memory initialization sequence
SRAMx.Instance = FSMC_NORSRAM_DEVICE;
SRAMx.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
/* SRAMx.Init */
// SRAMx.Init
SRAMx.Init.NSBank = NSBank;
SRAMx.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
SRAMx.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
SRAMx.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
SRAMx.Init.MemoryDataWidth = TERN(TFT_INTERFACE_FSMC_8BIT, FSMC_NORSRAM_MEM_BUS_WIDTH_8, FSMC_NORSRAM_MEM_BUS_WIDTH_16);
SRAMx.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
SRAMx.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
SRAMx.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
Expand All @@ -67,17 +68,17 @@ void TFT_FSMC::Init() {
#ifdef STM32F4xx
SRAMx.Init.PageSize = FSMC_PAGE_SIZE_NONE;
#endif
/* Read Timing - relatively slow to ensure ID information is correctly read from TFT controller */
/* Can be decreases from 15-15-24 to 4-4-8 with risk of stability loss */
// Read Timing - relatively slow to ensure ID information is correctly read from TFT controller
// Can be decreases from 15-15-24 to 4-4-8 with risk of stability loss
Timing.AddressSetupTime = 15;
Timing.AddressHoldTime = 15;
Timing.DataSetupTime = 24;
Timing.BusTurnAroundDuration = 0;
Timing.CLKDivision = 16;
Timing.DataLatency = 17;
Timing.AccessMode = FSMC_ACCESS_MODE_A;
/* Write Timing */
/* Can be decreases from 8-15-8 to 0-0-1 with risk of stability loss */
// Write Timing
// Can be decreases from 8-15-8 to 0-0-1 with risk of stability loss
ExtTiming.AddressSetupTime = 8;
ExtTiming.AddressHoldTime = 15;
ExtTiming.DataSetupTime = 8;
Expand Down Expand Up @@ -131,7 +132,7 @@ void TFT_FSMC::Init() {

uint32_t TFT_FSMC::GetID() {
uint32_t id;
WriteReg(0x0000);
WriteReg(0);
id = LCD->RAM;

if (id == 0)
Expand All @@ -141,16 +142,16 @@ uint32_t TFT_FSMC::GetID() {
return id;
}

uint32_t TFT_FSMC::ReadID(uint16_t Reg) {
uint32_t id;
WriteReg(Reg);
id = LCD->RAM; // dummy read
id = Reg << 24;
id |= (LCD->RAM & 0x00FF) << 16;
id |= (LCD->RAM & 0x00FF) << 8;
id |= LCD->RAM & 0x00FF;
return id;
}
uint32_t TFT_FSMC::ReadID(tft_data_t Reg) {
uint32_t id;
WriteReg(Reg);
id = LCD->RAM; // dummy read
id = Reg << 24;
id |= (LCD->RAM & 0x00FF) << 16;
id |= (LCD->RAM & 0x00FF) << 8;
id |= LCD->RAM & 0x00FF;
return id;
}

bool TFT_FSMC::isBusy() {
if (__IS_DMA_ENABLED(&DMAtx))
Expand Down
41 changes: 25 additions & 16 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
#define DATASIZE_16BIT SPI_DATASIZE_16BIT
#define TFT_IO_DRIVER TFT_FSMC

#define TFT_DATASIZE TERN(TFT_INTERFACE_FSMC_8BIT, DATASIZE_8BIT, DATASIZE_16BIT)
typedef TERN(TFT_INTERFACE_FSMC_8BIT, uint8_t, uint16_t) tft_data_t;

typedef struct {
__IO uint16_t REG;
__IO uint16_t RAM;
__IO tft_data_t REG;
__IO tft_data_t RAM;
} LCD_CONTROLLER_TypeDef;

class TFT_FSMC {
Expand All @@ -56,8 +59,8 @@ class TFT_FSMC {

static LCD_CONTROLLER_TypeDef *LCD;

static uint32_t ReadID(uint16_t Reg);
static void Transmit(uint16_t Data) { LCD->RAM = Data; __DSB(); }
static uint32_t ReadID(tft_data_t Reg);
static void Transmit(tft_data_t Data) { LCD->RAM = Data; __DSB(); }
static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);

public:
Expand All @@ -66,11 +69,11 @@ class TFT_FSMC {
static bool isBusy();
static void Abort() { __HAL_DMA_DISABLE(&DMAtx); }

static void DataTransferBegin(uint16_t DataWidth = DATASIZE_16BIT) {}
static void DataTransferBegin(uint16_t DataWidth = TFT_DATASIZE) {}
static void DataTransferEnd() {};

static void WriteData(uint16_t Data) { Transmit(Data); }
static void WriteReg(uint16_t Reg) { LCD->REG = Reg; __DSB(); }
static void WriteData(uint16_t Data) { Transmit(tft_data_t(Data)); }
static void WriteReg(uint16_t Reg) { LCD->REG = tft_data_t(Reg); __DSB(); }

static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_ENABLE, Data, Count); }
static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_PINC_DISABLE, &Data, Count); }
Expand Down Expand Up @@ -98,14 +101,16 @@ const PinMap PinMap_FSMC[] = {
{PE_8, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D05
{PE_9, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D06
{PE_10, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D07
{PE_11, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D08
{PE_12, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D09
{PE_13, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D10
{PE_14, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D11
{PE_15, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D12
{PD_8, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D13
{PD_9, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D14
{PD_10, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D15
#if DISABLED(TFT_INTERFACE_FSMC_8BIT)
{PE_11, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D08
{PE_12, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D09
{PE_13, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D10
{PE_14, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D11
{PE_15, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D12
{PD_8, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D13
{PD_9, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D14
{PD_10, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_D15
#endif
{PD_4, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_NOE
{PD_5, FSMC_NORSRAM_DEVICE, FSMC_PIN_DATA}, // FSMC_NWE
{NC, NP, 0}
Expand All @@ -121,7 +126,11 @@ const PinMap PinMap_FSMC_CS[] = {
{NC, NP, 0}
};

#define FSMC_RS(A) (void *)((2 << A) - 2)
#if ENABLED(TFT_INTERFACE_FSMC_8BIT)
#define FSMC_RS(A) (void *)((2 << (A-1)) - 1)
#else
#define FSMC_RS(A) (void *)((2 << A) - 2)
#endif

const PinMap PinMap_FSMC_RS[] = {
#ifdef PF0
Expand Down
9 changes: 2 additions & 7 deletions Marlin/src/HAL/STM32/tft/xpt2046.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

#ifdef STM32F1xx
#include <stm32f1xx_hal.h>
#define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN)
#elif defined(STM32F4xx)
#include <stm32f4xx_hal.h>
#define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN)
#endif

#include "../../../inc/MarlinConfig.h"
Expand Down Expand Up @@ -60,13 +62,6 @@ enum XPTCoordinate : uint8_t {
#define XPT2046_Z1_THRESHOLD 10
#endif

#ifdef STM32F1xx
#define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CCR & DMA_CCR_EN)
#elif defined(STM32F4xx)
#define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN)
#endif


class XPT2046 {
private:
static SPI_HandleTypeDef SPIx;
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@
#define BOARD_MKS_ROBIN2 4218 // MKS_ROBIN2 (STM32F407ZE)
#define BOARD_MKS_ROBIN_PRO_V2 4219 // MKS Robin Pro V2 (STM32F407VE)
#define BOARD_MKS_ROBIN_NANO_V3 4220 // MKS Robin Nano V3 (STM32F407VG)
#define BOARD_ANET_ET4 4221 // ANET ET4 V1.x (STM32F407VGT6)
#define BOARD_ANET_ET4P 4222 // ANET ET4P V1.x (STM32F407VGT6)

//
// ARM Cortex M7
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@

#endif

// Macros to chain up to 12 conditions
// Macros to chain up to 14 conditions
#define _DO_1(W,C,A) (_##W##_1(A))
#define _DO_2(W,C,A,B) (_##W##_1(A) C _##W##_1(B))
#define _DO_3(W,C,A,V...) (_##W##_1(A) C _DO_2(W,C,V))
Expand All @@ -164,6 +164,8 @@
#define _DO_10(W,C,A,V...) (_##W##_1(A) C _DO_9(W,C,V))
#define _DO_11(W,C,A,V...) (_##W##_1(A) C _DO_10(W,C,V))
#define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V))
#define _DO_13(W,C,A,V...) (_##W##_1(A) C _DO_12(W,C,V))
#define _DO_14(W,C,A,V...) (_##W##_1(A) C _DO_13(W,C,V))
#define __DO_N(W,C,N,V...) _DO_##N(W,C,V)
#define _DO_N(W,C,N,V...) __DO_N(W,C,N,V)
#define DO(W,C,V...) (_DO_N(W,C,NUM_ARGS(V),V))
Expand Down
38 changes: 19 additions & 19 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -1073,28 +1073,23 @@
* - TFT_COLOR
* - GRAPHICAL_TFT_UPSCALE
*/
#if ENABLED(MKS_TS35_V2_0)
// Most common: ST7796
#if ENABLED(MKS_TS35_V2_0) // Most common: ST7796
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY)
#define TFT_RES_480x320
#define TFT_INTERFACE_SPI
#elif ENABLED(MKS_ROBIN_TFT24)
// Most common: ST7789
#elif ENABLED(MKS_ROBIN_TFT24) // Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif ENABLED(MKS_ROBIN_TFT28)
// Most common: ST7789
#elif ENABLED(MKS_ROBIN_TFT28) // Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif ENABLED(MKS_ROBIN_TFT32)
// Most common: ST7789
#elif ENABLED(MKS_ROBIN_TFT32) // Most common: ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif ENABLED(MKS_ROBIN_TFT35)
// Most common: ILI9488
#elif ENABLED(MKS_ROBIN_TFT35) // Most common: ILI9488
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_RES_480x320
#define TFT_INTERFACE_FSMC
Expand All @@ -1103,12 +1098,11 @@
#define TFT_DRIVER SSD1963
#define TFT_RES_480x272
#define TFT_INTERFACE_FSMC
#elif ENABLED(MKS_ROBIN_TFT_V1_1R)
// ILI9328 or R61505
#elif ENABLED(MKS_ROBIN_TFT_V1_1R) // ILI9328 or R61505
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35)
#elif EITHER(TFT_TRONXY_X5SA, ANYCUBIC_TFT35) // ILI9488
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_DRIVER ILI9488
#define TFT_RES_480x320
Expand All @@ -1117,6 +1111,14 @@
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif ENABLED(ANET_ET4_TFT28) // ST7789
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_Y)
#define TFT_RES_320x240
#define TFT_INTERFACE_FSMC
#elif ENABLED(ANET_ET5_TFT35) // ST7796
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY)
#define TFT_RES_480x320
#define TFT_INTERFACE_FSMC
#elif ENABLED(TFT_GENERIC)
#define TFT_DEFAULT_ORIENTATION (TFT_EXCHANGE_XY | TFT_INVERT_X | TFT_INVERT_Y)
#if NONE(TFT_RES_320x240, TFT_RES_480x272, TFT_RES_480x320)
Expand Down Expand Up @@ -1197,11 +1199,9 @@
#define TOUCH_OFFSET_X XPT2046_X_OFFSET
#define TOUCH_OFFSET_Y XPT2046_Y_OFFSET
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#else
#define TOUCH_CALIBRATION_X 0
#define TOUCH_CALIBRATION_Y 0
#define TOUCH_OFFSET_X 0
#define TOUCH_OFFSET_Y 0
#define TOUCH_ORIENTATION TOUCH_ORIENTATION_NONE
#endif
#endif

#if MB(ANET_ET4, ANET_ET4P)
#define IS_ANET_ET 1
#endif
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
+ COUNT_ENABLED(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_GENERIC_12864_1_1) \
+ COUNT_ENABLED(LCD_SAINSMART_I2C_1602, LCD_SAINSMART_I2C_2004) \
+ COUNT_ENABLED(MKS_12864OLED, MKS_12864OLED_SSD1306) \
+ COUNT_ENABLED(MKS_TS35_V2_0, MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R) \
+ COUNT_ENABLED(MKS_TS35_V2_0, MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R, ANET_ET4_TFT28, ANET_ET5_TFT35) \
+ COUNT_ENABLED(TFTGLCD_PANEL_SPI, TFTGLCD_PANEL_I2C) \
+ COUNT_ENABLED(VIKI2, miniVIKI) \
+ COUNT_ENABLED(ZONESTAR_12864LCD, ZONESTAR_12864OLED, ZONESTAR_12864OLED_SSD1306) \
Expand Down Expand Up @@ -2347,7 +2347,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#undef IS_EXTUI
#undef IS_LEGACY_TFT

#if ANY(TFT_GENERIC, MKS_TS35_V2_0, MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R, TFT_TRONXY_X5SA, ANYCUBIC_TFT35, ANYCUBIC_TFT35, LONGER_LK_TFT28)
#if ANY(TFT_GENERIC, MKS_TS35_V2_0, MKS_ROBIN_TFT24, MKS_ROBIN_TFT28, MKS_ROBIN_TFT32, MKS_ROBIN_TFT35, MKS_ROBIN_TFT43, MKS_ROBIN_TFT_V1_1R, TFT_TRONXY_X5SA, ANYCUBIC_TFT35, ANYCUBIC_TFT35, LONGER_LK_TFT28, ANET_ET4_TFT28, ANET_ET5_TFT35)
#if NONE(TFT_COLOR_UI, TFT_CLASSIC_UI, TFT_LVGL_UI)
#error "TFT_COLOR_UI, TFT_CLASSIC_UI, TFT_LVGL_UI is required for your TFT. Please enable one."
#elif 1 < ENABLED(TFT_COLOR_UI) + ENABLED(TFT_CLASSIC_UI) + ENABLED(TFT_LVGL_UI)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void CANVAS::AddImage(int16_t x, int16_t y, MarlinImage image, uint16_t *colors)
if (line >= startLine && line < endLine) {
uint16_t *pixel = buffer + x + (line - startLine) * width;
for (int16_t j = 0; j < image_width; j++) {
if ((x + j >= 0) && (x + j < width)) *pixel = *data;
if ((x + j >= 0) && (x + j < width)) *pixel = ENDIAN_COLOR(*data);
pixel++;
data++;
}
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/lcd/tft/tft.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@

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

#if TFT_INTERFACE_FSMC_8BIT
// When we have a 8 bit interface, we need to invert the bytes of the color
#define ENDIAN_COLOR(C) (((C) >> 8) | ((C) << 8))
#else
#define ENDIAN_COLOR(C) (C)
#endif

#if HAS_UI_320x240
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
Expand Down
Loading

0 comments on commit fd9b059

Please sign in to comment.