Skip to content

Commit

Permalink
🐛 Fix TFT_LTDC::writeReg
Browse files Browse the repository at this point in the history
Followup to #25939
  • Loading branch information
thinkyhead committed Jun 24, 2023
1 parent 60f591f commit 9bf9541
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/HAL/LPC1768/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ uint32_t TFT_SPI::getID() {
return id;
}

uint32_t TFT_SPI::readID(uint16_t reg) {
uint32_t TFT_SPI::readID(const uint16_t inReg) {
uint32_t data = 0;

#if PIN_EXISTS(TFT_MISO)
Expand All @@ -72,7 +72,7 @@ uint32_t TFT_SPI::readID(uint16_t reg) {
SPIx.setClock(SPI_CLOCK_DIV64);
SPIx.begin();
WRITE(TFT_CS_PIN, LOW);
writeReg(reg);
writeReg(inReg);

for (uint8_t i = 0; i < 4; ++i) {
SPIx.read((uint8_t*)&d, 1);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/LPC1768/tft/tft_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

class TFT_SPI {
private:
static uint32_t readID(uint16_t reg);
static uint32_t readID(const uint16_t inReg);
static void transmit(uint16_t data);
static void transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
Expand All @@ -74,7 +74,7 @@ class TFT_SPI {
static void dataTransferAbort();

static void writeData(uint16_t data) { transmit(data); }
static void writeReg(uint16_t reg) { WRITE(TFT_DC_PIN, LOW); transmit(reg); WRITE(TFT_DC_PIN, HIGH); }
static void writeReg(const uint16_t inReg) { WRITE(TFT_DC_PIN, LOW); transmit(inReg); WRITE(TFT_DC_PIN, HIGH); }

static void writeSequence_DMA(uint16_t *data, uint16_t count) { transmitDMA(DMA_MINC_ENABLE, data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { static uint16_t data; data = color; transmitDMA(DMA_MINC_DISABLE, &data, count); }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/NATIVE_SIM/tft/tft_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

class TFT_SPI {
private:
static uint32_t readID(uint16_t reg);
static uint32_t readID(const uint16_t inReg);
static void transmit(uint16_t data);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);

Expand All @@ -57,7 +57,7 @@ class TFT_SPI {
static void dataTransferAbort();

static void writeData(uint16_t data);
static void writeReg(uint16_t reg);
static void writeReg(const uint16_t inReg);

static void writeSequence_DMA(uint16_t *data, uint16_t count) { writeSequence(data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { writeMultiple(color, count); }
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ uint32_t TFT_FSMC::getID() {
return id;
}

uint32_t TFT_FSMC::readID(tft_data_t reg) {
uint32_t TFT_FSMC::readID(const tft_data_t inReg) {
uint32_t id;
writeReg(reg);
writeReg(inReg);
id = LCD->RAM; // dummy read
id = reg << 24;
id = inReg << 24;
id |= (LCD->RAM & 0x00FF) << 16;
id |= (LCD->RAM & 0x00FF) << 8;
id |= LCD->RAM & 0x00FF;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TFT_FSMC {

static LCD_CONTROLLER_TypeDef *LCD;

static uint32_t readID(tft_data_t reg);
static uint32_t readID(const tft_data_t reg);
static void transmit(tft_data_t data) { LCD->RAM = data; __DSB(); }
static void transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
Expand All @@ -77,7 +77,7 @@ class TFT_FSMC {
static void dataTransferEnd() {}

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 writeReg(const uint16_t inReg) { LCD->REG = tft_data_t(inReg); __DSB(); }

static void writeSequence_DMA(uint16_t *data, uint16_t count) { transmitDMA(DMA_PINC_ENABLE, data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { static uint16_t data; data = color; transmitDMA(DMA_PINC_DISABLE, &data, count); }
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/HAL/STM32/tft/tft_ltdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ uint32_t TFT_LTDC::getID() {
return 0xABAB;
}

uint32_t TFT_LTDC::readID(tft_data_t reg) {
uint32_t TFT_LTDC::readID(const tft_data_t inReg) {
return 0xABAB;
}

Expand Down Expand Up @@ -352,10 +352,6 @@ void TFT_LTDC::transmit(tft_data_t data) {
}
}

void TFT_LTDC::writeReg(uint16_t reg) {
reg = reg;
}

void TFT_LTDC::transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {

while (x_cur != x_min && count) {
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_ltdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TFT_LTDC {
static uint16_t x_min, x_max, y_min, y_max, x_cur, y_cur;
static uint8_t reg;

static uint32_t readID(tft_data_t reg);
static uint32_t readID(const tft_data_t inReg);

static uint16_t readPoint(uint16_t x, uint16_t y);
static void drawPoint(uint16_t x, uint16_t y, uint16_t color);
Expand All @@ -62,7 +62,7 @@ class TFT_LTDC {
static void dataTransferEnd() {};

static void writeData(uint16_t data);
static void writeReg(uint16_t reg);
static void writeReg(const uint16_t inReg) { reg = inReg; }

// Non-blocking DMA data transfer is not implemented for LTDC interface
inline static void writeSequence_DMA(uint16_t *data, uint16_t count) { writeSequence(data, count); }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ uint32_t TFT_SPI::getID() {
return id;
}

uint32_t TFT_SPI::readID(uint16_t reg) {
uint32_t TFT_SPI::readID(const uint16_t inReg) {
uint32_t data = 0;
#if PIN_EXISTS(TFT_MISO)
uint32_t BaudRatePrescaler = SPIx.Init.BaudRatePrescaler;
uint32_t i;

SPIx.Init.BaudRatePrescaler = SPIx.Instance == SPI1 ? SPI_BAUDRATEPRESCALER_8 : SPI_BAUDRATEPRESCALER_4;
dataTransferBegin(DATASIZE_8BIT);
writeReg(reg);
writeReg(inReg);

if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_RX(&SPIx);
__HAL_SPI_ENABLE(&SPIx);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32/tft/tft_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TFT_SPI {
static SPI_HandleTypeDef SPIx;
static DMA_HandleTypeDef DMAtx;

static uint32_t readID(uint16_t reg);
static uint32_t readID(const uint16_t inReg);
static void transmit(uint16_t data);
static void transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
Expand All @@ -65,7 +65,7 @@ class TFT_SPI {
static void dataTransferAbort();

static void writeData(uint16_t data) { transmit(data); }
static void writeReg(uint16_t reg) { WRITE(TFT_A0_PIN, LOW); transmit(reg); WRITE(TFT_A0_PIN, HIGH); }
static void writeReg(const uint16_t inReg) { WRITE(TFT_A0_PIN, LOW); transmit(inReg); WRITE(TFT_A0_PIN, HIGH); }

static void writeSequence_DMA(uint16_t *data, uint16_t count) { transmitDMA(DMA_MINC_ENABLE, data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { static uint16_t data; data = color; transmitDMA(DMA_MINC_DISABLE, &data, count); }
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ void TFT_FSMC::transmit(uint16_t data) {
__DSB();
}

void TFT_FSMC::writeReg(uint16_t reg) {
LCD->REG = reg;
void TFT_FSMC::writeReg(const uint16_t inReg) {
LCD->REG = inReg;
__DSB();
}

Expand All @@ -205,11 +205,11 @@ uint32_t TFT_FSMC::getID() {
return id;
}

uint32_t TFT_FSMC::readID(uint16_t reg) {
uint32_t TFT_FSMC::readID(const uint16_t inReg) {
uint32_t id;
writeReg(reg);
writeReg(inReg);
id = LCD->RAM; // dummy read
id = reg << 24;
id = inReg << 24;
id |= (LCD->RAM & 0x00FF) << 16;
id |= (LCD->RAM & 0x00FF) << 8;
id |= LCD->RAM & 0x00FF;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32F1/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TFT_FSMC {
private:
static LCD_CONTROLLER_TypeDef *LCD;

static uint32_t readID(uint16_t reg);
static uint32_t readID(const uint16_t inReg);
static void transmit(uint16_t data);
static void transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
Expand All @@ -69,7 +69,7 @@ class TFT_FSMC {
static void dataTransferEnd() {};

static void writeData(uint16_t data) { transmit(data); }
static void writeReg(uint16_t reg);
static void writeReg(const uint16_t inReg);

static void writeSequence_DMA(uint16_t *data, uint16_t count) { transmitDMA(DMA_PINC_ENABLE, data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { static uint16_t data; data = color; transmitDMA(DMA_PINC_DISABLE, &data, count); }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ uint32_t TFT_SPI::getID() {
return id;
}

uint32_t TFT_SPI::readID(uint16_t reg) {
uint32_t TFT_SPI::readID(const uint16_t inReg) {
uint32_t data = 0;

#if PIN_EXISTS(TFT_MISO)
SPIx.setClockDivider(SPI_CLOCK_DIV16);
dataTransferBegin(DATASIZE_8BIT);
writeReg(reg);
writeReg(inReg);

for (uint8_t i = 0; i < 4; ++i) {
uint8_t d;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/HAL/STM32F1/tft/tft_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

class TFT_SPI {
private:
static uint32_t readID(uint16_t reg);
static uint32_t readID(const uint16_t inReg);
static void transmit(uint16_t data);
static void transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
static void transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count);
Expand All @@ -81,7 +81,7 @@ class TFT_SPI {
static void dataTransferAbort();

static void writeData(uint16_t data) { transmit(data); }
static void writeReg(uint16_t reg) { WRITE(TFT_DC_PIN, LOW); transmit(reg); WRITE(TFT_DC_PIN, HIGH); }
static void writeReg(const uint16_t inReg) { WRITE(TFT_DC_PIN, LOW); transmit(inReg); WRITE(TFT_DC_PIN, HIGH); }

static void writeSequence_DMA(uint16_t *data, uint16_t count) { transmitDMA(DMA_MINC_ENABLE, data, count); }
static void writeMultiple_DMA(uint16_t color, uint16_t count) { static uint16_t data; data = color; transmitDMA(DMA_MINC_DISABLE, &data, count); }
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/dogm/u8g_dev_tft_upscale_from_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ TFT_IO tftio;
#define TFT_BTOKMENU_COLOR COLOR_RED
#endif

static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
tftio.set_window(Xmin, Ymin, Xmax, Ymax);
static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t xMin, uint16_t yMin, uint16_t xMax, uint16_t yMax) {
tftio.set_window(xMin, yMin, xMax, yMax);
}

#if HAS_TOUCH_BUTTONS
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft/tft.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TFT {
static void abort() { io.abort(); }
static void write_multiple(uint16_t data, uint16_t count) { io.WriteMultipleDMA(data, count); }
static void write_sequence(uint16_t *data, uint16_t count) { io.writeSequenceDMA(data, count); }
static void set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) { io.set_window(Xmin, Ymin, Xmax, Ymax); }
static void set_window(uint16_t xMin, uint16_t yMin, uint16_t xMax, uint16_t yMax) { io.set_window(xMin, yMin, xMax, yMax); }

static void fill(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color) { queue.fill(x, y, width, height, color); }
static void canvas(uint16_t x, uint16_t y, uint16_t width, uint16_t height) { queue.canvas(x, y, width, height); }
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/tft_io/tft_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TFT_IO {
inline static void dataTransferEnd() { io.dataTransferEnd(); }

inline static void writeData(uint16_t data) { io.writeData(data); }
inline static void writeReg(uint16_t reg) { io.writeReg(reg); }
inline static void writeReg(const uint16_t inReg) { io.writeReg(inReg); }

// Blocking IO used by TFT_CLASSIC_UI and TFT_LVGL_UI
// These functions start data transfer and WAIT for data transfer completion
Expand Down

0 comments on commit 9bf9541

Please sign in to comment.