Skip to content

Commit

Permalink
Revert "SPI Emulated DOGM (like FSMC_GRAPHICAL_TFT, but SPI) (MarlinF…
Browse files Browse the repository at this point in the history
…irmware#18817)"

This reverts commit 797d457.
  • Loading branch information
ahmetcemturan committed Jan 23, 2021
1 parent 6863714 commit 93c1355
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 532 deletions.
5 changes: 2 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1509,10 +1509,9 @@
#endif

//
// FSMC / SPI Graphical TFT
// FSMC Graphical TFT
//
#if TFT_SCALED_DOGLCD
//#define GRAPHICAL_TFT_ROTATE_180
#if ENABLED(FSMC_GRAPHICAL_TFT)
//#define TFT_MARLINUI_COLOR 0xFFFF // White
//#define TFT_MARLINBG_COLOR 0x0000 // Black
//#define TFT_DISABLED_COLOR 0x0003 // Almost black
Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/HAL/STM32F1/SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ class SPIClass {
*/
void setDataSize(uint32_t ds);

uint32_t getDataSize() { return _currentSetting->dataSize; }

/* Victor Perez 2017. Added to set and clear callback functions for callback
* on DMA transfer completion.
* onReceive used to set the callback in case of dmaTransfer (tx/rx), once rx is completed
Expand Down
236 changes: 0 additions & 236 deletions Marlin/src/HAL/STM32F1/dogm/u8g_com_stm32duino_hwspi.cpp

This file was deleted.

84 changes: 18 additions & 66 deletions Marlin/src/feature/touch/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@

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

#if TFT_SCALED_DOGLCD
#if ENABLED(FSMC_GRAPHICAL_TFT)
#include "../../lcd/dogm/ultralcd_DOGM.h" // for LCD_FULL_PIXEL_WIDTH, etc.
#endif

#ifndef XPT2046_Z1_THRESHOLD
#define XPT2046_Z1_THRESHOLD 10
#endif

/*
* Draw and Touch processing
Expand Down Expand Up @@ -121,15 +117,10 @@ uint8_t XPT2046::read_buttons() {
// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.

if (!isTouched()) return 0;
uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
const uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.

#if ENABLED(GRAPHICAL_TFT_ROTATE_180)
x = TOUCH_SCREEN_WIDTH - x;
y = TOUCH_SCREEN_HEIGHT - y;
#endif

// Touch within the button area simulates an encoder button
if (y > BUTTON_AREA_TOP && y < BUTTON_AREA_BOT)
return WITHIN(x, 14, 77) ? EN_D
Expand Down Expand Up @@ -160,69 +151,30 @@ bool XPT2046::isTouched() {
);
}

#if ENABLED(TOUCH_BUTTONS_HW_SPI)
#include <SPI.h>

static void touch_spi_init(uint8_t spiRate) {
/**
* STM32F1 APB2 = 72MHz, APB1 = 36MHz, max SPI speed of this MCU if 18Mhz
* STM32F1 has 3 SPI ports, SPI1 in APB2, SPI2/SPI3 in APB1
* so the minimum prescale of SPI1 is DIV4, SPI2/SPI3 is DIV2
*/
uint8_t clock;
switch (spiRate) {
case SPI_FULL_SPEED: clock = SPI_CLOCK_DIV4; break;
case SPI_HALF_SPEED: clock = SPI_CLOCK_DIV4; break;
case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8; break;
case SPI_EIGHTH_SPEED: clock = SPI_CLOCK_DIV16; break;
case SPI_SPEED_5: clock = SPI_CLOCK_DIV32; break;
case SPI_SPEED_6: clock = SPI_CLOCK_DIV64; break;
default: clock = SPI_CLOCK_DIV2; // Default from the SPI library
}
SPI.setModule(TOUCH_BUTTONS_HW_SPI_DEVICE);
SPI.begin();
SPI.setClockDivider(clock);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
}
#endif // TOUCH_BUTTONS_HW_SPI

uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
uint16_t data[3];
const uint8_t coord = uint8_t(coordinate) | XPT2046_CONTROL | XPT2046_DFR_MODE;

#if ENABLED(TOUCH_BUTTONS_HW_SPI)
OUT_WRITE(TOUCH_CS_PIN, LOW);

touch_spi_init(SPI_SPEED_6);
for (uint16_t i = 0; i < 3; i++) {
OUT_WRITE(TOUCH_CS_PIN, LOW);
SPI.transfer(coord);
data[i] = (((SPI.transfer(0xFF) << 8) | SPI.transfer(0xFF)) >> 3) & 0x0FFF;
WRITE(TOUCH_CS_PIN, HIGH);
const uint8_t coord = uint8_t(coordinate) | XPT2046_CONTROL | XPT2046_DFR_MODE;
for (uint16_t i = 0; i < 3 ; i++) {
for (uint8_t j = 0x80; j; j >>= 1) {
WRITE(TOUCH_SCK_PIN, LOW);
WRITE(TOUCH_MOSI_PIN, bool(coord & j));
WRITE(TOUCH_SCK_PIN, HIGH);
}

#else // !TOUCH_BUTTONS_HW_SPI

OUT_WRITE(TOUCH_CS_PIN, LOW);
for (uint16_t i = 0; i < 3; i++) {
for (uint8_t j = 0x80; j; j >>= 1) {
WRITE(TOUCH_SCK_PIN, LOW);
WRITE(TOUCH_MOSI_PIN, bool(coord & j));
WRITE(TOUCH_SCK_PIN, HIGH);
}

data[i] = 0;
for (uint16_t j = 0x8000; j; j >>= 1) {
WRITE(TOUCH_SCK_PIN, LOW);
if (READ(TOUCH_MISO_PIN)) data[i] |= j;
WRITE(TOUCH_SCK_PIN, HIGH);
}
data[i] = 0;
for (uint16_t j = 0x8000; j; j >>= 1) {
WRITE(TOUCH_SCK_PIN, LOW);
data[i] >>= 4;
if (READ(TOUCH_MISO_PIN)) data[i] |= j;
WRITE(TOUCH_SCK_PIN, HIGH);
}
WRITE(TOUCH_CS_PIN, HIGH);
WRITE(TOUCH_SCK_PIN, LOW);
data[i] >>= 4;
}

#endif // !TOUCH_BUTTONS_HW_SPI
WRITE(TOUCH_CS_PIN, HIGH);

uint16_t delta01 = _MAX(data[0], data[1]) - _MIN(data[0], data[1]),
delta02 = _MAX(data[0], data[2]) - _MIN(data[0], data[2]),
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/feature/touch/xpt2046.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ enum XPTCoordinate : uint8_t {
XPT2046_Z2 = 0x40
};

#ifndef XPT2046_Z1_THRESHOLD
#define XPT2046_Z1_THRESHOLD 10
#endif

class XPT2046 {
public:
static void init();
Expand Down
Loading

0 comments on commit 93c1355

Please sign in to comment.