Fixes for TFTGLCD Panel, FastIO (#19614)

This commit is contained in:
Serhiy-K 2020-10-10 13:01:46 +03:00 committed by Scott Lahteine
parent 406f8363bc
commit 6fdaaf3d20
12 changed files with 112 additions and 162 deletions

View File

@ -51,19 +51,19 @@ void FastIO_init(); // Must be called before using fast io macros
#if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx) #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
#define _WRITE(IO, V) do { \ #define _WRITE(IO, V) do { \
if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \ if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \
else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \ else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(digitalPinToPinName(IO) & 0x1F) ; \
}while(0) }while(0)
#else #else
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16))) #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(digitalPinToPinName(IO) + ((V) ? 0 : 16)))
#endif #endif
#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO])))) #define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(digitalPinToPinName(IO) & 0x1F)))
#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO]))) #define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(digitalPinToPinName(IO) & 0x1F))
#define _GET_MODE(IO) #define _GET_MODE(IO)
#define _SET_MODE(IO,M) pinMode(IO, M) #define _SET_MODE(IO,M) pinMode(IO, M)
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */ #define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) //!< Output Push Pull Mode & GPIO_NOPULL
#define _SET_OUTPUT_OD(IO) pinMode(IO, OUTPUT_OPEN_DRAIN) #define _SET_OUTPUT_OD(IO) pinMode(IO, OUTPUT_OPEN_DRAIN)
#define WRITE(IO,V) _WRITE(IO,V) #define WRITE(IO,V) _WRITE(IO,V)
@ -73,9 +73,9 @@ void FastIO_init(); // Must be called before using fast io macros
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0) #define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
#define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0) #define OUT_WRITE_OD(IO,V) do{ _SET_OUTPUT_OD(IO); WRITE(IO,V); }while(0)
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */ #define SET_INPUT(IO) _SET_MODE(IO, INPUT) //!< Input Floating Mode
#define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) /*!< Input with Pull-up activation */ #define SET_INPUT_PULLUP(IO) _SET_MODE(IO, INPUT_PULLUP) //!< Input with Pull-up activation
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */ #define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) //!< Input with Pull-down activation
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW) #define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
#define SET_PWM(IO) _SET_MODE(IO, PWM) #define SET_PWM(IO) _SET_MODE(IO, PWM)

View File

@ -303,7 +303,7 @@
#define LCD_STR_C STR_C #define LCD_STR_C STR_C
#define LCD_STR_E STR_E #define LCD_STR_E STR_E
#if HAS_MARLINUI_HD44780 #if EITHER(HAS_MARLINUI_HD44780, IS_TFTGLCD_PANEL)
// Custom characters defined in the first 8 characters of the LCD // Custom characters defined in the first 8 characters of the LCD
#define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string! #define LCD_STR_BEDTEMP "\x00" // Print only as a char. This will have 'unexpected' results when used in a string!

View File

@ -71,7 +71,7 @@ public:
inline void restore() { ref_ = val_; } inline void restore() { ref_ = val_; }
}; };
#define REMEMBER(N,X,V...) restorer<typeof(X)> restorer_##N(X, ##V) #define REMEMBER(N,X,V...) restorer<__typeof__(X)> restorer_##N(X, ##V)
#define RESTORE(N) restorer_##N.restore() #define RESTORE(N) restorer_##N.restore()
// Converts from an uint8_t in the range of 0-255 to an uint8_t // Converts from an uint8_t in the range of 0-255 to an uint8_t

View File

@ -226,9 +226,9 @@
#define LCD_PROGRESS_BAR #define LCD_PROGRESS_BAR
#endif #endif
#if ENABLED(TFTGLCD_PANEL_I2C) #if ENABLED(TFTGLCD_PANEL_I2C)
#define LCD_USE_I2C_BUZZER // Enable buzzer on LCD for I2C and SPI buses (LiquidTWI2 not required)
#define LCD_I2C_ADDRESS 0x27 // Must be equal to panel's I2C slave addres #define LCD_I2C_ADDRESS 0x27 // Must be equal to panel's I2C slave addres
#endif #endif
#define LCD_USE_I2C_BUZZER // Enable buzzer on LCD, used for both I2C and SPI buses (LiquidTWI2 not required)
#define STD_ENCODER_PULSES_PER_STEP 2 #define STD_ENCODER_PULSES_PER_STEP 2
#define STD_ENCODER_STEPS_PER_MENU_ITEM 1 #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
#define LCD_WIDTH 20 // 20 or 24 chars in line #define LCD_WIDTH 20 // 20 or 24 chars in line

View File

@ -2457,7 +2457,7 @@
/** /**
* Buzzer/Speaker * Buzzer/Speaker
*/ */
#if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER, IS_TFTGLCD_PANEL) #if PIN_EXISTS(BEEPER) || ANY(LCD_USE_I2C_BUZZER, PCA9632_BUZZER)
#define HAS_BUZZER 1 #define HAS_BUZZER 1
#if PIN_EXISTS(BEEPER) #if PIN_EXISTS(BEEPER)
#define USE_BEEPER 1 #define USE_BEEPER 1

View File

@ -32,7 +32,7 @@
* and supports color output. * and supports color output.
*/ */
#if NONE(__AVR__, MCU_LPC1768, __STM32F1__, STM32F4xx) #if NONE(__AVR__, TARGET_LPC1768, __STM32F1__, STM32F4xx)
#warning "Selected platform not yet tested. Please contribute your good pin mappings." #warning "Selected platform not yet tested. Please contribute your good pin mappings."
#endif #endif
@ -80,8 +80,9 @@ TFTGLCD lcd;
#define LED_MASK 0x0F #define LED_MASK 0x0F
#define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2) #define FBSIZE (LCD_WIDTH * LCD_HEIGHT + 2)
#define MIDDLE_Y ((LCD_HEIGHT - 1) / 2)
//markers for change line color // Markers for change line colors
#define COLOR_EDIT '#' #define COLOR_EDIT '#'
#define COLOR_ERROR '!' #define COLOR_ERROR '!'
@ -114,7 +115,8 @@ enum Commands { // based on Smoothieware commands
GET_LCD_ROW = 0xE0, // for detect panel GET_LCD_ROW = 0xE0, // for detect panel
GET_LCD_COL, // reserved for compatibility with Smoothieware, not used GET_LCD_COL, // reserved for compatibility with Smoothieware, not used
LCD_PUT, // write one line to LCD LCD_PUT, // write one line to LCD
INIT_SCREEN = 0xFE, // clear panel buffer CLR_SCREEN,
INIT_SCREEN = 0xFE // clear panel buffer
}; };
static unsigned char framebuffer[FBSIZE]; static unsigned char framebuffer[FBSIZE];
@ -123,28 +125,62 @@ static uint8_t cour_line;
static uint8_t picBits, ledBits, hotBits; static uint8_t picBits, ledBits, hotBits;
static uint8_t PanelDetected = 0; static uint8_t PanelDetected = 0;
// Different platforms use different SPI methods
#if ANY(__AVR__, TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
#define SPI_SEND_ONE(V) SPI.transfer(V);
#define SPI_SEND_TWO(V) SPI.transfer16(V);
#elif defined(STM32F4xx)
#define SPI_SEND_ONE(V) SPI.transfer(V, SPI_CONTINUE);
#define SPI_SEND_TWO(V) SPI.transfer16(V, SPI_CONTINUE);
#elif defined(ARDUINO_ARCH_ESP32)
#define SPI_SEND_ONE(V) SPI.write(V);
#define SPI_SEND_TWO(V) SPI.write16(V);
#endif
#if ANY(__AVR__, ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
#define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L);
#elif defined(STM32F4xx)
#define SPI_SEND_SOME(V,L,Z) SPI.transfer(&V[Z], L, SPI_CONTINUE);
#elif ANY(TARGET_LPC1768, __STM32F1__, ARDUINO_ARCH_ESP32)
#define SPI_SEND_SOME(V,L,Z) do{ for (uint16_t i = 0; i < L; i++) SPI_SEND_ONE(V[(Z)+i]); }while(0)
#endif
// Constructor // Constructor
TFTGLCD::TFTGLCD() {} TFTGLCD::TFTGLCD() {}
//clearing local buffer // Clear local buffer
void TFTGLCD::clear_buffer() { void TFTGLCD::clear_buffer() {
memset(&framebuffer[0], ' ', FBSIZE - 2); memset(&framebuffer[0], ' ', FBSIZE - 2);
framebuffer[FBSIZE - 1] = framebuffer[FBSIZE - 2] = 0; framebuffer[FBSIZE - 1] = framebuffer[FBSIZE - 2] = 0;
picBits = ledBits = 0; picBits = ledBits = 0;
} }
//set new text cursor position // Clear panel's screen
void TFTGLCD::clr_screen() {
if (!PanelDetected) return;
#if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW);
SPI_SEND_ONE(CLR_SCREEN);
WRITE(TFTGLCD_CS, HIGH);
#else
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
Wire.write(CLR_SCREEN);
Wire.endTransmission(); //transmit data
#endif
}
// Set new text cursor position
void TFTGLCD::setCursor(uint8_t col, uint8_t row) { void TFTGLCD::setCursor(uint8_t col, uint8_t row) {
fb = &framebuffer[0] + col + row * LCD_WIDTH; fb = &framebuffer[0] + col + row * LCD_WIDTH;
cour_line = row; cour_line = row;
} }
//send char to buffer // Send char to buffer
void TFTGLCD::write(char c) { void TFTGLCD::write(char c) {
*fb++ = c; *fb++ = c;
} }
//send text line to buffer // Send text line to buffer
void TFTGLCD::print(const char *line) { void TFTGLCD::print(const char *line) {
while (*line) *fb++ = *line++; while (*line) *fb++ = *line++;
} }
@ -154,27 +190,9 @@ void TFTGLCD::print_line() {
if (!PanelDetected) return; if (!PanelDetected) return;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#ifdef __AVR__ SPI_SEND_ONE(LCD_PUT);
SPI.transfer(LCD_PUT); SPI_SEND_ONE(cour_line);
SPI.transfer(cour_line); SPI_SEND_SOME(framebuffer, LCD_WIDTH, cour_line * LCD_WIDTH);
SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH);
#elif EITHER(MCU_LPC1768, __STM32F1__)
SPI.transfer(LCD_PUT);
SPI.transfer(cour_line);
for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.transfer(framebuffer[cour_line * LCD_WIDTH + i]);
#elif defined(STM32F4xx)
SPI.transfer(LCD_PUT, SPI_CONTINUE);
SPI.transfer(cour_line, SPI_CONTINUE);
SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(LCD_PUT);
SPI.transfer(cour_line);
SPI.transfer(&framebuffer[cour_line * LCD_WIDTH], LCD_WIDTH);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(LCD_PUT);
SPI.write(cour_line);
for (uint16_t i = 0; i < LCD_WIDTH; i++) SPI.write(framebuffer[cour_line * LCD_WIDTH + i]);
#endif
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
#else #else
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); //set I2C device address
@ -193,22 +211,8 @@ void TFTGLCD::print_screen(){
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
// Send all framebuffer to panel // Send all framebuffer to panel
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#ifdef __AVR__ SPI_SEND_ONE(LCD_WRITE);
SPI.transfer(LCD_WRITE); SPI_SEND_SOME(framebuffer, FBSIZE, 0);
SPI.transfer(&framebuffer[0], FBSIZE);
#elif EITHER(MCU_LPC1768, __STM32F1__)
SPI.transfer(LCD_WRITE);
for (uint16_t i = 0; i < FBSIZE; i++) SPI.transfer(framebuffer[i]);
#elif defined(STM32F4xx)
SPI.transfer(LCD_WRITE, SPI_CONTINUE);
SPI.transfer(&framebuffer[0], FBSIZE, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(LCD_WRITE);
SPI.transfer(&framebuffer[0], FBSIZE);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(LCD_WRITE);
for (uint16_t i = 0; i < FBSIZE; i++) SPI.write(framebuffer[i]);
#endif
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
#else #else
uint8_t r; uint8_t r;
@ -235,19 +239,8 @@ void TFTGLCD::setContrast(uint16_t contrast) {
if (!PanelDetected) return; if (!PanelDetected) return;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#if ANY(__AVR__, MCU_LPC1768, __STM32F1__) SPI_SEND_ONE(CONTRAST);
SPI.transfer(CONTRAST); SPI_SEND_ONE((uint8_t)contrast);
SPI.transfer((uint8_t)contrast);
#elif defined(STM32F4xx)
SPI.transfer(CONTRAST, SPI_CONTINUE);
SPI.transfer((uint8_t)contrast, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(CONTRAST);
SPI.transfer((uint8_t)contrast);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(CONTRAST);
SPI.write((uint8_t)contrast);
#endif
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
#else #else
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
@ -257,37 +250,24 @@ void TFTGLCD::setContrast(uint16_t contrast) {
#endif #endif
} }
//reading buttons and encoder states
extern volatile int8_t encoderDiff; extern volatile int8_t encoderDiff;
// Read buttons and encoder states
uint8_t MarlinUI::read_slow_buttons(void) { uint8_t MarlinUI::read_slow_buttons(void) {
if (!PanelDetected) return 0; if (!PanelDetected) return 0;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
uint8_t b = 0; uint8_t b = 0;
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#if ANY(__AVR__, MCU_LPC1768, __STM32F1__) SPI_SEND_ONE(READ_ENCODER);
SPI.transfer(READ_ENCODER); #ifndef STM32F4xx
WRITE(TFTGLCD_CS, LOW); // for delay WRITE(TFTGLCD_CS, LOW); // for delay
encoderDiff += SPI.transfer(READ_BUTTONS);
WRITE(TFTGLCD_CS, LOW); //for delay
b = SPI.transfer(GET_SPI_DATA);
#elif defined(STM32F4xx)
SPI.transfer(READ_ENCODER, SPI_CONTINUE);
encoderDiff += SPI.transfer(READ_BUTTONS, SPI_CONTINUE);
b = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(READ_ENCODER);
WRITE(TFTGLCD_CS, LOW); //for delay ????
encoderDiff += SPI.transfer(READ_BUTTONS);
WRITE(TFTGLCD_CS, LOW); //for delay ????
b = SPI.transfer(GET_SPI_DATA);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.transfer(READ_ENCODER);
WRITE(TFTGLCD_CS, LOW); //for delay ????
encoderDiff += SPI.transfer(READ_BUTTONS);
WRITE(TFTGLCD_CS, LOW); //for delay ????
b = SPI.transfer(GET_SPI_DATA);
#endif #endif
encoderDiff += SPI_SEND_ONE(READ_BUTTONS);
#ifndef STM32F4xx
WRITE(TFTGLCD_CS, LOW); // for delay
WRITE(TFTGLCD_CS, LOW);
#endif
b = SPI_SEND_ONE(GET_SPI_DATA);
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
return b; return b;
#else #else
@ -298,7 +278,7 @@ uint8_t MarlinUI::read_slow_buttons(void) {
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1); Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 2, 0, 0, 1);
#elif defined(__STM32F1__) #elif defined(__STM32F1__)
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2); Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, (uint8_t)2);
#elif EITHER(STM32F4xx, MCU_LPC1768) #elif EITHER(STM32F4xx, TARGET_LPC1768)
Wire.requestFrom(LCD_I2C_ADDRESS, 2); Wire.requestFrom(LCD_I2C_ADDRESS, 2);
#endif #endif
encoderDiff += Wire.read(); encoderDiff += Wire.read();
@ -306,28 +286,14 @@ uint8_t MarlinUI::read_slow_buttons(void) {
#endif #endif
} }
// duration in ms, freq in Hz // Duration in ms, freq in Hz
void MarlinUI::buzz(const long duration, const uint16_t freq) { void MarlinUI::buzz(const long duration, const uint16_t freq) {
if (!PanelDetected) return; if (!PanelDetected) return;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#if ANY(__AVR__, MCU_LPC1768, __STM32F1__) SPI_SEND_ONE(BUZZER);
SPI.transfer(BUZZER); SPI_SEND_TWO((uint16_t)duration);
SPI.transfer16((uint16_t)duration); SPI_SEND_TWO(freq);
SPI.transfer16(freq);
#elif defined(STM32F4xx)
SPI.transfer(BUZZER, SPI_CONTINUE);
SPI.transfer16((uint16_t)duration, SPI_CONTINUE);
SPI.transfer16(freq, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(BUZZER);
SPI.transfer16((uint16_t)duration);
SPI.transfer16(freq);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(BUZZER);
SPI.write16((uint16_t)duration);
SPI.write16(freq);
#endif
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
#else #else
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
@ -346,24 +312,14 @@ void MarlinUI::init_lcd() {
t = 0; t = 0;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
// SPI speed must be less 10MHz // SPI speed must be less 10MHz
OUT_WRITE(TFTGLCD_CS, HIGH); _SET_OUTPUT(TFTGLCD_CS);
WRITE(TFTGLCD_CS, HIGH);
spiInit(TERN(__STM32F1__, SPI_QUARTER_SPEED, SPI_FULL_SPEED)); spiInit(TERN(__STM32F1__, SPI_QUARTER_SPEED, SPI_FULL_SPEED));
WRITE(TFTGLCD_CS, LOW); WRITE(TFTGLCD_CS, LOW);
#if ANY(__AVR__, MCU_LPC1768, __STM32F1__) SPI_SEND_ONE(GET_LCD_ROW);
SPI.transfer(GET_LCD_ROW); t = SPI_SEND_ONE(GET_SPI_DATA);
t = SPI.transfer(GET_SPI_DATA);
#elif defined(STM32F4xx)
SPI.transfer(GET_LCD_ROW, SPI_CONTINUE);
t = SPI.transfer(GET_SPI_DATA, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(GET_LCD_ROW);
t = SPI.transfer(GET_SPI_DATA);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(GET_LCD_ROW);
t = SPI.transfer(GET_SPI_DATA);
#endif
#else #else
#ifdef MCU_LPC1768 #ifdef TARGET_LPC1768
Wire.begin(); //init twi/I2C Wire.begin(); //init twi/I2C
#else #else
Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C Wire.begin((uint8_t)LCD_I2C_ADDRESS); //init twi/I2C
@ -373,7 +329,7 @@ void MarlinUI::init_lcd() {
Wire.endTransmission(); // send buffer Wire.endTransmission(); // send buffer
#ifdef __AVR__ #ifdef __AVR__
Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1); Wire.requestFrom((uint8_t)LCD_I2C_ADDRESS, 1, 0, 0, 1);
#elif ANY(__STM32F1__, STM32F4xx, MCU_LPC1768) #elif ANY(__STM32F1__, STM32F4xx, TARGET_LPC1768)
Wire.requestFrom(LCD_I2C_ADDRESS, 1); Wire.requestFrom(LCD_I2C_ADDRESS, 1);
#endif #endif
t = (uint8_t)Wire.read(); t = (uint8_t)Wire.read();
@ -382,20 +338,8 @@ void MarlinUI::init_lcd() {
if (t == LCD_HEIGHT) { if (t == LCD_HEIGHT) {
PanelDetected = 1; PanelDetected = 1;
#if ENABLED(TFTGLCD_PANEL_SPI) #if ENABLED(TFTGLCD_PANEL_SPI)
PanelDetected = 1; SPI_SEND_ONE(INIT_SCREEN);
#if ANY(__AVR__, MCU_LPC1768, __STM32F1__) SPI_SEND_ONE(Marlin);
SPI.transfer(INIT_SCREEN);
SPI.transfer(Marlin);
#elif defined(STM32F4xx)
SPI.transfer(INIT_SCREEN, SPI_CONTINUE);
SPI.transfer(Marlin, SPI_CONTINUE);
#elif ANY(ARDUINO_ARCH_SAM, __SAMD51__, __MK20DX256__, __MK64FX512__)
SPI.transfer(INIT_SCREEN);
SPI.transfer(Marlin);
#elif defined(ARDUINO_ARCH_ESP32)
SPI.write(INIT_SCREEN);
SPI.write(Marlin);
#endif
WRITE(TFTGLCD_CS, HIGH); WRITE(TFTGLCD_CS, HIGH);
#else #else
Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS); Wire.beginTransmission((uint8_t)LCD_I2C_ADDRESS);
@ -415,8 +359,8 @@ bool MarlinUI::detected() {
void MarlinUI::clear_lcd() { void MarlinUI::clear_lcd() {
if (!PanelDetected) return; if (!PanelDetected) return;
lcd.clr_screen();
lcd.clear_buffer(); lcd.clear_buffer();
lcd.print_screen();
} }
int16_t MarlinUI::contrast; // Initialized by settings.load() int16_t MarlinUI::contrast; // Initialized by settings.load()
@ -583,10 +527,10 @@ FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char *p
lcd.write('%'); lcd.write(percent); lcd.write('%'); lcd.write(percent);
} }
else { // For progress bar test else { // For progress bar test
lcd.setCursor(LCD_WIDTH / 2 - 2, LCD_HEIGHT / 2 - 2); lcd.setCursor(LCD_WIDTH / 2 - 2, MIDDLE_Y);
lcd.print(i16tostr3rj(percent)); lcd.write('%'); lcd.print(i16tostr3rj(percent)); lcd.write('%');
lcd.print_line(); lcd.print_line();
lcd.setCursor(0, LCD_HEIGHT / 2 - 1); lcd.setCursor(0, MIDDLE_Y + 1);
lcd.write('%'); lcd.write(percent); lcd.write('%'); lcd.write(percent);
lcd.print_line(); lcd.print_line();
} }
@ -912,15 +856,16 @@ void MarlinUI::draw_status_screen() {
} }
// Low-level draw_edit_screen can be used to draw an edit screen from anyplace // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
// This line moves to the last line of the screen for UBL plot screen on the panel side
void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) {
if (!PanelDetected) return; if (!PanelDetected) return;
ui.encoder_direction_normal(); ui.encoder_direction_normal();
lcd.setCursor(0, LCD_HEIGHT - 1); //last line is free most time lcd.setCursor(0, MIDDLE_Y);
lcd.write(COLOR_EDIT); lcd.write(COLOR_EDIT);
lcd_put_u8str_P(pstr); lcd_put_u8str_P(pstr);
if (value != nullptr) { if (value != nullptr) {
lcd.write(':'); lcd.write(':');
lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), LCD_HEIGHT - 1); // Right-justified, padded by spaces lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), MIDDLE_Y); // Right-justified, padded by spaces
lcd.write(' '); // Overwrite char if value gets shorter lcd.write(' '); // Overwrite char if value gets shorter
lcd.print(value); lcd.print(value);
lcd.write(' '); lcd.write(' ');
@ -932,10 +877,10 @@ void MarlinUI::draw_status_screen() {
void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff) { void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const bool yesno, PGM_P const pref, const char * const string, PGM_P const suff) {
if (!PanelDetected) return; if (!PanelDetected) return;
ui.draw_select_screen_prompt(pref, string, suff); ui.draw_select_screen_prompt(pref, string, suff);
lcd.setCursor(0, LCD_HEIGHT - 1); lcd.setCursor(0, MIDDLE_Y);
lcd.write(COLOR_EDIT); lcd.write(COLOR_EDIT);
lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']'); lcd.write(yesno ? ' ' : '['); lcd_put_u8str_P(no); lcd.write(yesno ? ' ' : ']');
lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, LCD_HEIGHT - 1); lcd.setCursor(LCD_WIDTH - utf8_strlen_P(yes) - 3, MIDDLE_Y);
lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' '); lcd.write(yesno ? '[' : ' '); lcd_put_u8str_P(yes); lcd.write(yesno ? ']' : ' ');
lcd.print_line(); lcd.print_line();
} }

View File

@ -45,6 +45,7 @@ class TFTGLCD {
public: public:
TFTGLCD(); TFTGLCD();
void clear_buffer(); void clear_buffer();
void clr_screen();
void setCursor(uint8_t col, uint8_t row); void setCursor(uint8_t col, uint8_t row);
void write(char c); void write(char c);
void print(const char *line); void print(const char *line);

View File

@ -92,7 +92,7 @@
// //
// LCD / Controller // LCD / Controller
// //
#if HAS_WIRED_LCD #if HAS_WIRED_LCD && DISABLED(LCD_USE_I2C_BUZZER)
#define BEEPER_PIN P1_30 // (37) not 5V tolerant #define BEEPER_PIN P1_30 // (37) not 5V tolerant
#endif #endif

View File

@ -33,6 +33,9 @@
// //
#if NO_EEPROM_SELECTED #if NO_EEPROM_SELECTED
#define FLASH_EEPROM_EMULATION #define FLASH_EEPROM_EMULATION
#ifndef MARLIN_EEPROM_SIZE
#define MARLIN_EEPROM_SIZE 0x800U // 2KB
#endif
#endif #endif
// //

View File

@ -89,3 +89,4 @@
// //
#define LED_PIN PC13 #define LED_PIN PC13
#define SDSS PA3 #define SDSS PA3
#define TFTGLCD_CS PA4