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 zillarob committed Feb 25, 2021
1 parent be7c879 commit 8186fce
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 63 deletions.
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 @@ -46,9 +46,12 @@
#define __IS_DMA_ENABLED(__HANDLE__) ((__HANDLE__)->Instance->CR & DMA_SxCR_EN)
#endif

#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 @@ -58,8 +61,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 @@ -68,11 +71,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 @@ -100,14 +103,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 @@ -123,7 +128,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 @@ -20,8 +20,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 @@ -57,13 +59,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
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
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
27 changes: 14 additions & 13 deletions Marlin/src/lcd/tft/tft_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void TFT_Queue::fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui
task_parameters->y = y;
task_parameters->width = width;
task_parameters->height = height;
task_parameters->color = color;
task_parameters->color = ENDIAN_COLOR(color);
task_parameters->count = width * height;

*end_of_queue = TASK_END_OF_QUEUE;
Expand Down Expand Up @@ -215,7 +215,7 @@ void TFT_Queue::set_background(uint16_t color) {
parametersCanvasBackground_t *parameters = (parametersCanvasBackground_t *)end_of_queue;

parameters->type = CANVAS_SET_BACKGROUND;
parameters->color = color;
parameters->color = ENDIAN_COLOR(color);

end_of_queue += sizeof(parametersCanvasBackground_t);
task_parameters->count++;
Expand All @@ -230,7 +230,7 @@ void TFT_Queue::add_text(uint16_t x, uint16_t y, uint16_t color, uint8_t *string
parameters->type = CANVAS_ADD_TEXT;
parameters->x = x;
parameters->y = y;
parameters->color = color;
parameters->color = ENDIAN_COLOR(color);
parameters->stringLength = 0;
parameters->maxWidth = maxWidth;

Expand Down Expand Up @@ -260,18 +260,19 @@ void TFT_Queue::add_image(int16_t x, int16_t y, MarlinImage image, uint16_t *col
if (color_mode == HIGHCOLOR) return;

uint16_t *color = (uint16_t *)end_of_queue;
uint8_t number_of_color = 0;
uint8_t color_count = 0;

switch (color_mode) {
case GREYSCALE1: number_of_color = 1; break;
case GREYSCALE2: number_of_color = 3; break;
case GREYSCALE4: number_of_color = 15; break;
default:
break;
case GREYSCALE1: color_count = 1; break;
case GREYSCALE2: color_count = 3; break;
case GREYSCALE4: color_count = 15; break;
default: break;
}

while (number_of_color--) {
*color++ = *colors++;
uint16_t tmp;
while (color_count--) {
tmp = *colors++;
*color++ = ENDIAN_COLOR(tmp);
}

end_of_queue = (uint8_t *)color;
Expand Down Expand Up @@ -322,7 +323,7 @@ void TFT_Queue::add_bar(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
parameters->y = y;
parameters->width = width;
parameters->height = height;
parameters->color = color;
parameters->color = ENDIAN_COLOR(color);

end_of_queue += sizeof(parametersCanvasBar_t);
task_parameters->count++;
Expand All @@ -337,7 +338,7 @@ void TFT_Queue::add_rectangle(uint16_t x, uint16_t y, uint16_t width, uint16_t h
parameters->y = y;
parameters->width = width;
parameters->height = height;
parameters->color = color;
parameters->color = ENDIAN_COLOR(color);

end_of_queue += sizeof(parametersCanvasRectangle_t);
task_parameters->count++;
Expand Down
14 changes: 7 additions & 7 deletions Marlin/src/lcd/tft/ui_320x240.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,21 @@ void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const valu
extern screenFunc_t _manual_move_func_ptr;
if (ui.currentScreen != _manual_move_func_ptr && !ui.external_control) {

#define SLIDER_LENGHT 224
#define SLIDER_LENGTH 224
#define SLIDER_Y_POSITION 140

tft.canvas((TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION, SLIDER_LENGHT, 16);
tft.canvas((TFT_WIDTH - SLIDER_LENGTH) / 2, SLIDER_Y_POSITION, SLIDER_LENGTH, 16);
tft.set_background(COLOR_BACKGROUND);

int16_t position = (SLIDER_LENGHT - 2) * ui.encoderPosition / maxEditValue;
int16_t position = (SLIDER_LENGTH - 2) * ui.encoderPosition / maxEditValue;
tft.add_bar(0, 7, 1, 2, ui.encoderPosition == 0 ? COLOR_SLIDER_INACTIVE : COLOR_SLIDER);
tft.add_bar(1, 6, position, 4, COLOR_SLIDER);
tft.add_bar(position + 1, 6, SLIDER_LENGHT - 2 - position, 4, COLOR_SLIDER_INACTIVE);
tft.add_bar(SLIDER_LENGHT - 1, 7, 1, 2, int32_t(ui.encoderPosition) == maxEditValue ? COLOR_SLIDER : COLOR_SLIDER_INACTIVE);
tft.add_bar(position + 1, 6, SLIDER_LENGTH - 2 - position, 4, COLOR_SLIDER_INACTIVE);
tft.add_bar(SLIDER_LENGTH - 1, 7, 1, 2, int32_t(ui.encoderPosition) == maxEditValue ? COLOR_SLIDER : COLOR_SLIDER_INACTIVE);

#if ENABLED(TOUCH_SCREEN)
tft.add_image((SLIDER_LENGHT - 8) * ui.encoderPosition / maxEditValue, 0, imgSlider, COLOR_SLIDER);
touch.add_control(SLIDER, (TFT_WIDTH - SLIDER_LENGHT) / 2, SLIDER_Y_POSITION - 8, SLIDER_LENGHT, 32, maxEditValue);
tft.add_image((SLIDER_LENGTH - 8) * ui.encoderPosition / maxEditValue, 0, imgSlider, COLOR_SLIDER);
touch.add_control(SLIDER, (TFT_WIDTH - SLIDER_LENGTH) / 2, SLIDER_Y_POSITION - 8, SLIDER_LENGTH, 32, maxEditValue);
#endif
}

Expand Down
14 changes: 13 additions & 1 deletion Marlin/src/lcd/tft_io/tft_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,20 @@
#define TOUCH_LANDSCAPE 1
#define TOUCH_PORTRAIT 2

#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
#define TOUCH_ORIENTATION TOUCH_LANDSCAPE
#endif

#define SSD1963 0x5761
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/pins/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,10 @@
#include "stm32f4/pins_MKS_ROBIN_PRO_V2.h" // STM32F4 env:mks_robin_pro2
#elif MB(MKS_ROBIN_NANO_V3)
#include "stm32f4/pins_MKS_ROBIN_NANO_V3.h" // STM32F4 env:mks_robin_nano_v3
#elif MB(ANET_ET4)
#include "stm32f4/pins_ANET_ET4.h" // STM32F4 env:Anet_ET4_OpenBLT
#elif MB(ANET_ET4P)
#include "stm32f4/pins_ANET_ET4P.h" // STM32F4 env:Anet_ET4_OpenBLT

//
// ARM Cortex M7
Expand Down
Loading

0 comments on commit 8186fce

Please sign in to comment.