From 01aa87c3077c9bac8e075818a87e52098dbde999 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Sun, 10 Dec 2023 00:23:34 +0000 Subject: [PATCH 1/8] [cron] Bump distribution date (2023-12-10) --- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Version.h b/Marlin/Version.h index 4b493f35ab72..c171a6fc25fe 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ -//#define STRING_DISTRIBUTION_DATE "2023-12-09" +//#define STRING_DISTRIBUTION_DATE "2023-12-10" /** * Defines a generic printer name to be output to the LCD after booting Marlin. diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 02525afb5437..cc6ab3ec6611 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2023-12-09" + #define STRING_DISTRIBUTION_DATE "2023-12-10" #endif /** From b94a3354932dbcf6680e8d378219e9f41f29873e Mon Sep 17 00:00:00 2001 From: rondlh <77279634+rondlh@users.noreply.github.com> Date: Tue, 12 Dec 2023 08:48:02 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E2=9C=A8=20SERIAL=5FDMA=20(for=20some=20ST?= =?UTF-8?q?M32Fx)=20(#26328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration_adv.h | 24 +- Marlin/src/HAL/AVR/MarlinSerial.h | 4 - Marlin/src/HAL/AVR/inc/Conditionals_LCD.h | 4 + Marlin/src/HAL/LPC1768/MarlinSerial.h | 10 - Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h | 4 + Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h | 7 + Marlin/src/HAL/STM32/HardwareSerial.cpp | 449 ++++++++++++++++++ Marlin/src/HAL/STM32/HardwareSerial.h | 85 ++++ Marlin/src/HAL/STM32/MarlinSerial.cpp | 60 ++- Marlin/src/HAL/STM32/MarlinSerial.h | 37 +- Marlin/src/inc/SanityCheck.h | 9 + buildroot/tests/STM32F103RE_btt | 1 + 12 files changed, 637 insertions(+), 57 deletions(-) create mode 100644 Marlin/src/HAL/STM32/HardwareSerial.cpp create mode 100644 Marlin/src/HAL/STM32/HardwareSerial.h diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 5871c99a215f..e4f85a8d87b7 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -2649,10 +2649,12 @@ //#define FULL_REPORT_TO_HOST_FEATURE // Auto-report the machine status like Grbl CNC #endif -// Bad Serial-connections can miss a received command by sending an 'ok' -// Therefore some clients abort after 30 seconds in a timeout. -// Some other clients start sending commands while receiving a 'wait'. -// This "wait" is only sent when the buffer is empty. 1 second is a good value here. +/** + * Bad Serial-connections can miss a received command by sending an 'ok' + * Therefore some clients abort after 30 seconds in a timeout. + * Some other clients start sending commands while receiving a 'wait'. + * This "wait" is only sent when the buffer is empty. 1 second is a good value here. + */ //#define NO_TIMEOUTS 1000 // (ms) // Some clients will have this feature soon. This could make the NO_TIMEOUTS unnecessary. @@ -2665,6 +2667,15 @@ // For serial echo, the number of digits after the decimal point //#define SERIAL_FLOAT_PRECISION 4 +/** + * This feature is EXPERIMENTAL so use with caution and test thoroughly. + * Enable this option to receive data on the serial ports via the onboard DMA + * controller for more stable and reliable high-speed serial communication. + * Only some STM32 MCUs are currently supported. + * Note: This has no effect on emulated USB serial ports. + */ +//#define SERIAL_DMA + /** * Set the number of proportional font spaces required to fill up a typical character space. * This can help to better align the output of commands like `G29 O` Mesh Output. @@ -3442,9 +3453,8 @@ /** * TWI/I2C BUS * - * This feature is an EXPERIMENTAL feature so it shall not be used on production - * machines. Enabling this will allow you to send and receive I2C data from slave - * devices on the bus. + * This feature is EXPERIMENTAL but may be useful for custom I2C peripherals. + * Enable this to send and receive I2C data from slave devices on the bus. * * ; Example #1 * ; This macro send the string "Marlin" to the slave device with address 0x63 (99) diff --git a/Marlin/src/HAL/AVR/MarlinSerial.h b/Marlin/src/HAL/AVR/MarlinSerial.h index f47541f12dc5..a40730e0a87f 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.h +++ b/Marlin/src/HAL/AVR/MarlinSerial.h @@ -37,10 +37,6 @@ #include "../../core/types.h" #include "../../core/serial_hook.h" -#ifndef SERIAL_PORT - #define SERIAL_PORT 0 -#endif - #ifndef USBCON // The presence of the UBRRH register is used to detect a UART. diff --git a/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h b/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h index 5f1c4b16019d..65b019b261a8 100644 --- a/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/AVR/inc/Conditionals_LCD.h @@ -20,3 +20,7 @@ * */ #pragma once + +#ifndef SERIAL_PORT + #define SERIAL_PORT 0 +#endif diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index 3e6848a1e3d0..2fadd8209bdf 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -30,16 +30,6 @@ #endif #include "../../core/serial_hook.h" -#ifndef SERIAL_PORT - #define SERIAL_PORT 0 -#endif -#ifndef RX_BUFFER_SIZE - #define RX_BUFFER_SIZE 128 -#endif -#ifndef TX_BUFFER_SIZE - #define TX_BUFFER_SIZE 32 -#endif - class MarlinSerial : public HardwareSerial { public: MarlinSerial(LPC_UART_TypeDef *UARTx) : HardwareSerial(UARTx) { } diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h index 5f1c4b16019d..65b019b261a8 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_LCD.h @@ -20,3 +20,7 @@ * */ #pragma once + +#ifndef SERIAL_PORT + #define SERIAL_PORT 0 +#endif diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h index 8e7cab185f2a..9d04c4f787c6 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_adv.h @@ -24,3 +24,10 @@ #if DISABLED(NO_SD_HOST_DRIVE) #define HAS_SD_HOST_DRIVE 1 #endif + +#ifndef RX_BUFFER_SIZE + #define RX_BUFFER_SIZE 128 +#endif +#ifndef TX_BUFFER_SIZE + #define TX_BUFFER_SIZE 32 +#endif diff --git a/Marlin/src/HAL/STM32/HardwareSerial.cpp b/Marlin/src/HAL/STM32/HardwareSerial.cpp new file mode 100644 index 000000000000..a6f97f356e2e --- /dev/null +++ b/Marlin/src/HAL/STM32/HardwareSerial.cpp @@ -0,0 +1,449 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// +// HAL_HardwareSerial Class. Adapted from Arduino HardwareSerial. +// + +#include "../platforms.h" + +#ifdef HAL_STM32 + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(SERIAL_DMA) && defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) + +#include +#include "HardwareSerial.h" +#include "uart.h" + +// USART/UART PIN MAPPING FOR STM32F0/F1/F2/F4/F7 +#ifndef PIN_SERIAL1_TX + #define PIN_SERIAL1_TX PA9 +#endif +#ifndef PIN_SERIAL1_RX + #define PIN_SERIAL1_RX PA10 +#endif +#ifndef PIN_SERIAL2_TX + #define PIN_SERIAL2_TX PA2 +#endif +#ifndef PIN_SERIAL2_RX + #define PIN_SERIAL2_RX PA3 +#endif +#ifndef PIN_SERIAL3_TX + #define PIN_SERIAL3_TX PB10 +#endif +#ifndef PIN_SERIAL3_RX + #define PIN_SERIAL3_RX PB11 +#endif +#ifndef PIN_SERIAL4_TX + #define PIN_SERIAL4_TX PC10 +#endif +#ifndef PIN_SERIAL4_RX + #define PIN_SERIAL4_RX PC11 +#endif +#ifndef PIN_SERIAL5_TX + #define PIN_SERIAL5_TX PC12 +#endif +#ifndef PIN_SERIAL5_RX + #define PIN_SERIAL5_RX PD2 +#endif +#ifndef PIN_SERIAL6_TX + #define PIN_SERIAL6_TX PC6 +#endif +#ifndef PIN_SERIAL6_RX + #define PIN_SERIAL6_RX PC7 +#endif + +// TODO: Get from include file + +#if ANY(STM32F2xx, STM32F4xx, STM32F7xx) + + #define RCC_AHB1Periph_DMA1 ((uint32_t)0x00200000) + #define RCC_AHB1Periph_DMA2 ((uint32_t)0x00400000) + + void RCC_AHB1PeriphClockCmd(uint32_t RCC_AHB1Periph, FunctionalState NewState) { + // Check the parameters + assert_param(IS_RCC_AHB1_CLOCK_PERIPH(RCC_AHB1Periph)); + + assert_param(IS_FUNCTIONAL_STATE(NewState)); + if (NewState != DISABLE) + RCC->AHB1ENR |= RCC_AHB1Periph; + else + RCC->AHB1ENR &= ~RCC_AHB1Periph; + } + +#endif + +#if ANY(STM32F0xx, STM32F1xx) + + #define RCC_AHBPeriph_DMA1 ((uint32_t)0x00000001) + #define RCC_AHBPeriph_DMA2 ((uint32_t)0x00000002) + + void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState) { + /* Check the parameters */ + assert_param(IS_RCC_AHB_PERIPH(RCC_AHBPeriph)); + assert_param(IS_FUNCTIONAL_STATE(NewState)); + + if (NewState != DISABLE) + RCC->AHBENR |= RCC_AHBPeriph; + else + RCC->AHBENR &= ~RCC_AHBPeriph; + } + +#endif + +// END OF TODO------------------------------------------------------ + +// SerialEvent functions are weak, so when the user doesn't define them, +// the linker just sets their address to 0 (which is checked below). +#ifdef USING_HW_SERIAL1 + HAL_HardwareSerial HSerial1(USART1); + void serialEvent1() __attribute__((weak)); +#endif +#ifdef USING_HW_SERIAL2 + HAL_HardwareSerial HSerial2(USART2); + void serialEvent2() __attribute__((weak)); +#endif +#ifdef USING_HW_SERIAL3 + HAL_HardwareSerial Serial3(USART3); + void serialEvent3() __attribute__((weak)); +#endif +#ifdef USING_HW_SERIAL4 + #ifdef USART4 + HAL_HardwareSerial HSerial4(USART4); + #else + HAL_HardwareSerial HSerial4(UART4); + #endif + void serialEvent4() __attribute__((weak)); +#endif +#ifdef USING_HW_SERIAL5 + #ifdef USART5 + HAL_HardwareSerial HSerial5(USART5); + #else + HAL_HardwareSerial HSerial5(UART5); + #endif + void serialEvent5() __attribute__((weak)); +#endif +#ifdef USING_HW_SERIAL6 + #ifdef USART6 + HAL_HardwareSerial HSerial5(USART6); + #else + HAL_HardwareSerial HSerial5(UART6); + #endif + void serialEvent5() __attribute__((weak)); +#endif + +// Constructors //////////////////////////////////////////////////////////////// + +HAL_HardwareSerial::HAL_HardwareSerial(void *peripheral) { + if (peripheral == USART1) { + setRx(PIN_SERIAL1_RX); + setTx(PIN_SERIAL1_TX); + _uart_index = 0; + #ifdef DMA2_Stream2 + RX_DMA = { USART1, RCC_AHB1Periph_DMA2, 4, DMA2_Stream2 }; + #endif + #ifdef DMA1_Channel5 + RX_DMA = { USART1, RCC_AHBPeriph_DMA1, DMA1, DMA1_Channel5 }; + #endif + } + else if (peripheral == USART2) { + setRx(PIN_SERIAL2_RX); + setTx(PIN_SERIAL2_TX); + _uart_index = 1; + #ifdef DMA1_Stream5 + RX_DMA = { USART2, RCC_AHB1Periph_DMA1, 4, DMA1_Stream5 }; + #endif + #ifdef DMA1_Channel6 + RX_DMA = { USART2, RCC_AHBPeriph_DMA1, DMA1, DMA1_Channel6 }; + #endif + } + else if (peripheral == USART3) { + setRx(PIN_SERIAL3_RX); + setTx(PIN_SERIAL3_TX); + _uart_index = 2; + #ifdef DMA1_Stream1 + RX_DMA = { USART3, RCC_AHB1Periph_DMA1, 4, DMA1_Stream1 }; + #endif + #ifdef DMA1_Channel3 // F0 has no support for UART3, requires system remapping + RX_DMA = { USART3, RCC_AHBPeriph_DMA1, DMA1, DMA1_Channel3 }; + #endif + } + + #ifdef USART4 // Only F2 / F4 / F7 + else if (peripheral == USART4) { + #ifdef DMA1_Stream2 + RX_DMA = { USART4, RCC_AHB1Periph_DMA1, 4, DMA1_Stream2 }; + #endif + setRx(PIN_SERIAL4_RX); + setTx(PIN_SERIAL4_TX); + _uart_index = 3; + } + #endif + + #ifdef UART4 + else if (peripheral == UART4) { + #ifdef DMA1_Stream2 + RX_DMA = { UART4, RCC_AHB1Periph_DMA1, 4, DMA1_Stream2 }; + #endif + #ifdef DMA2_Channel3 // STM32F0xx has only 3 UARTs + RX_DMA = { UART4, RCC_AHBPeriph_DMA2, DMA2, DMA2_Channel3 }; + #endif + setRx(PIN_SERIAL4_RX); + setTx(PIN_SERIAL4_TX); + _uart_index = 3; + } + #endif + + #ifdef UART5 // Only F2 / F4 / F7 + else if (peripheral == UART5) { + #ifdef DMA1_Stream0 + RX_DMA = { UART5, RCC_AHB1Periph_DMA1, 4, DMA1_Stream0 }; + #endif + setRx(PIN_SERIAL5_RX); + setTx(PIN_SERIAL5_TX); + _uart_index = 4; + } + #endif + + #ifdef USART6 // Only F2 / F4 / F7 + else if (peripheral == USART6) { + #ifdef DMA2_Stream1 + RX_DMA = { USART6, RCC_AHB1Periph_DMA2, 4, DMA2_Stream1 }; + #endif + setRx(PIN_SERIAL6_RX); + setTx(PIN_SERIAL6_TX); + _uart_index = 5; + } + #endif + + else { // else get the pins of the first peripheral occurence in PinMap + _serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX); + _serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX); + } + + init(_serial.pin_rx, _serial.pin_tx); +} + +void HAL_HardwareSerial::setRx(uint32_t _rx) { + _serial.pin_rx = digitalPinToPinName(_rx); +} + +void HAL_HardwareSerial::setTx(uint32_t _tx) { + _serial.pin_tx = digitalPinToPinName(_tx); +} + +void HAL_HardwareSerial::init(PinName _rx, PinName _tx) { + _serial.pin_rx = _rx; + _serial.rx_buff = _rx_buffer; + _serial.rx_head = _serial.rx_tail = 0; + + _serial.pin_tx = _tx; + _serial.tx_buff = _tx_buffer; + _serial.tx_head = _serial.tx_tail = 0; +} + +// Actual interrupt handlers ////////////////////////////////////////////////////////////// + +/** + * @brief Read receive byte from uart + * @param obj : pointer to serial_t structure + * @retval last character received + */ +int HAL_HardwareSerial::_tx_complete_irq(serial_t *obj) { + // If interrupts are enabled, there must be more data in the output buffer. Send the next byte + obj->tx_tail = (obj->tx_tail + 1) % TX_BUFFER_SIZE; + + if (obj->tx_head == obj->tx_tail) return -1; + + return 0; +} + +// Public Methods ////////////////////////////////////////////////////////////// + +void HAL_HardwareSerial::begin(unsigned long baud, uint8_t config) { + uint32_t databits = 0, stopbits = 0, parity = 0; + + _baud = baud; + _config = config; + + // Manage databits + switch (config & 0x07) { + case 0x02: databits = 6; break; + case 0x04: databits = 7; break; + case 0x06: databits = 8; break; + default: databits = 0; break; + } + + if ((config & 0x30) == 0x30) { + parity = UART_PARITY_ODD; + databits++; + } + else if ((config & 0x20) == 0x20) { + parity = UART_PARITY_EVEN; + databits++; + } + else + parity = UART_PARITY_NONE; + + stopbits = (config & 0x08) == 0x08 ? UART_STOPBITS_2 : UART_STOPBITS_1; + + switch (databits) { + #ifdef UART_WORDLENGTH_7B + case 7: databits = UART_WORDLENGTH_7B; break; + #endif + case 8: databits = UART_WORDLENGTH_8B; break; + case 9: databits = UART_WORDLENGTH_9B; break; + default: + case 0: Error_Handler(); break; + } + + uart_init(&_serial, (uint32_t)baud, databits, parity, stopbits); + Serial_DMA_Read_Enable(); // Start the circular DMA serial reading process, no callback needed +} + +void HAL_HardwareSerial::end() { + flush(); // Wait for transmission of outgoing data + uart_deinit(&_serial); + _serial.rx_head = _serial.rx_tail; // Clear any received data +} + +// Update buffer head for DMA progress +void HAL_HardwareSerial::update_rx_head() { + + #if ENABLED(EMERGENCY_PARSER) + static uint32_t flag = 0; + while (flag != _serial.rx_head) { // send all available data to emergency parser immediately + emergency_parser.update(static_cast(this)->emergency_state, _serial.rx_buff[flag]); + flag = (flag + 1) % RX_BUFFER_SIZE; + } + #endif + + #if ANY(STM32F2xx, STM32F4xx, STM32F7xx) + _serial.rx_head = RX_BUFFER_SIZE - RX_DMA.dma_streamRX->NDTR; + #endif + + #if ANY(STM32F0xx, STM32F1xx) + _serial.rx_head = RX_BUFFER_SIZE - RX_DMA.dma_channelRX->CNDTR; + #endif + +} + +int HAL_HardwareSerial::available() { + update_rx_head(); + return ((unsigned int)(RX_BUFFER_SIZE + _serial.rx_head - _serial.rx_tail)) % RX_BUFFER_SIZE; +} + +int HAL_HardwareSerial::peek() { + update_rx_head(); + if (_serial.rx_head == _serial.rx_tail) return -1; + return _serial.rx_buff[_serial.rx_tail]; +} + +int HAL_HardwareSerial::read() { + update_rx_head(); + if (_serial.rx_head == _serial.rx_tail) return -1; // No chars if the head isn't ahead of the tail + + unsigned char c = _serial.rx_buff[_serial.rx_tail]; + _serial.rx_tail = (rx_buffer_index_t)(_serial.rx_tail + 1) % RX_BUFFER_SIZE; + return c; +} + +size_t HAL_HardwareSerial::write(uint8_t c) { // Interrupt based writing + tx_buffer_index_t i = (_serial.tx_head + 1) % TX_BUFFER_SIZE; + + // If the output buffer is full, there's nothing for it other than to + // wait for the interrupt handler to empty it a bit + while (i == _serial.tx_tail) { /* nada */ } // NOP, let the interrupt free up space for us + + _serial.tx_buff[_serial.tx_head] = c; + _serial.tx_head = i; + + if (!serial_tx_active(&_serial)) + uart_attach_tx_callback(&_serial, _tx_complete_irq); // Write next byte, launch interrupt + + return 1; +} + +void HAL_HardwareSerial::flush() { + while ((_serial.tx_head != _serial.tx_tail)) { /* nada */ } // nop, the interrupt handler will free up space for us +} + +#if ANY(STM32F2xx, STM32F4xx, STM32F7xx) + + void HAL_HardwareSerial::Serial_DMA_Read_Enable() { + RCC_AHB1PeriphClockCmd(RX_DMA.dma_rcc, ENABLE); // Enable DMA clock + + #ifdef STM32F7xx + RX_DMA.dma_streamRX->PAR = (uint32_t)(&RX_DMA.uart->RDR); // RX peripheral receive address (usart) F7 + #else + RX_DMA.dma_streamRX->PAR = (uint32_t)(&RX_DMA.uart->DR); // RX peripheral address (usart) F2 / F4 + #endif + RX_DMA.dma_streamRX->M0AR = (uint32_t)_serial.rx_buff; // RX destination address (memory) + RX_DMA.dma_streamRX->NDTR = RX_BUFFER_SIZE; // RX buffer size + + RX_DMA.dma_streamRX->CR = (RX_DMA.dma_channel << 25); // RX channel selection, set to 0 all the other CR bits + + RX_DMA.dma_streamRX->CR |= (3 << 16); // RX priority level: Very High + + //RX_DMA.dma_streamRX->CR &= ~(3 << 13); // RX memory data size: 8 bit + //RX_DMA.dma_streamRX->CR &= ~(3 << 11); // RX peripheral data size: 8 bit + RX_DMA.dma_streamRX->CR |= (1 << 10); // RX memory increment mode + //RX_DMA.dma_streamRX->CR &= ~(1 << 9); // RX peripheral no increment mode + RX_DMA.dma_streamRX->CR |= (1 << 8); // RX circular mode enabled + //RX_DMA.dma_streamRX->CR &= ~(1 << 6); // RX data transfer direction: Peripheral-to-memory + RX_DMA.uart->CR3 |= (1 << 6); // Enable DMA receiver (DMAR) + RX_DMA.dma_streamRX->CR |= (1 << 0); // RX enable DMA + } + +#endif // STM32F2xx || STM32F4xx || STM32F7xx + +#if ANY(STM32F0xx, STM32F1xx) + + void HAL_HardwareSerial::Serial_DMA_Read_Enable() { + RCC_AHBPeriphClockCmd(RX_DMA.dma_rcc, ENABLE); // enable DMA clock + + RX_DMA.dma_channelRX->CPAR = (uint32_t)(&RX_DMA.uart->DR); // RX peripheral address (usart) + RX_DMA.dma_channelRX->CMAR = (uint32_t)_serial.rx_buff; // RX destination address (memory) + RX_DMA.dma_channelRX->CNDTR = RX_BUFFER_SIZE; // RX buffer size + + RX_DMA.dma_channelRX->CCR = 0; // RX channel selection, set to 0 all the other CR bits + + RX_DMA.dma_channelRX->CCR |= (3<<12); // RX priority level: Very High + + //RX_DMA.dma_channelRX->CCR &= ~(1<<10); // RX memory data size: 8 bit + //RX_DMA.dma_channelRX->CCR &= ~(1<<8); // RX peripheral data size: 8 bit + RX_DMA.dma_channelRX->CCR |= (1<<7); // RX memory increment mode + //RX_DMA.dma_channelRX->CCR &= ~(1<<6); // RX peripheral no increment mode + RX_DMA.dma_channelRX->CCR |= (1<<5); // RX circular mode enabled + //RX_DMA.dma_channelRX->CCR &= ~(1<<4); // RX data transfer direction: Peripheral-to-memory + + RX_DMA.uart->CR3 |= (1<<6); // enable DMA receiver (DMAR) + RX_DMA.dma_channelRX->CCR |= (1<<0); // RX enable DMA + } + +#endif // STM32F0xx || STM32F1xx + +#endif // SERIAL_DMA && HAL_UART_MODULE_ENABLED && !HAL_UART_MODULE_ONLY +#endif // HAL_STM32 diff --git a/Marlin/src/HAL/STM32/HardwareSerial.h b/Marlin/src/HAL/STM32/HardwareSerial.h new file mode 100644 index 000000000000..cc564322b4d5 --- /dev/null +++ b/Marlin/src/HAL/STM32/HardwareSerial.h @@ -0,0 +1,85 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +// +// HAL_HardwareSerial Class. Adapted from Arduino HardwareSerial. +// + +#if RX_BUFFER_SIZE == 0 + #undef RX_BUFFER_SIZE + #define RX_BUFFER_SIZE 128 +#endif + +#if TX_BUFFER_SIZE == 0 + #undef TX_BUFFER_SIZE + #define TX_BUFFER_SIZE 64 +#endif + +typedef struct { + USART_TypeDef * uart; + uint32_t dma_rcc; + #if ANY(STM32F0xx, STM32F1xx) // F0 / F1 + DMA_TypeDef * dma_controller; + DMA_Channel_TypeDef * dma_channelRX; + #else // F2 / F4 / F7 + uint32_t dma_channel; + DMA_Stream_TypeDef * dma_streamRX; + #endif +} DMA_CFG; + +class HAL_HardwareSerial : public Stream { + protected: + // Don't put any members after these buffers, since only the first + // 32 bytes of this struct can be accessed quickly using the ldd instruction. + unsigned char _rx_buffer[RX_BUFFER_SIZE]; + unsigned char _tx_buffer[TX_BUFFER_SIZE]; + + serial_t _serial; + + public: + HAL_HardwareSerial(void *peripheral); + void begin(unsigned long, uint8_t); + void end(); + virtual int available(); + virtual int read(); + virtual int peek(); + virtual size_t write(uint8_t); + virtual void flush(); + operator bool() { return true; } + + void setRx(uint32_t _rx); + void setTx(uint32_t _tx); + + static int _tx_complete_irq(serial_t *obj); // Interrupt handler + + private: + uint8_t _uart_index; + bool _rx_enabled; + uint8_t _config; + unsigned long _baud; + void init(PinName _rx, PinName _tx); + void update_rx_head(); + DMA_CFG RX_DMA; + void Serial_DMA_Read_Enable(); +}; diff --git a/Marlin/src/HAL/STM32/MarlinSerial.cpp b/Marlin/src/HAL/STM32/MarlinSerial.cpp index 9f0b003a316b..c4bc62994908 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.cpp +++ b/Marlin/src/HAL/STM32/MarlinSerial.cpp @@ -47,10 +47,15 @@ #define USART9 UART9 #endif -#define DECLARE_SERIAL_PORT(ser_num) \ - void _rx_complete_irq_ ## ser_num (serial_t * obj); \ - MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \ - void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); } +#if ENABLED(SERIAL_DMA) + #define DECLARE_SERIAL_PORT(ser_num) \ + MSerialT MSerial ## ser_num (true, USART ## ser_num); +#else + #define DECLARE_SERIAL_PORT(ser_num) \ + void _rx_complete_irq_ ## ser_num (serial_t * obj); \ + MSerialT MSerial ## ser_num (true, USART ## ser_num, &_rx_complete_irq_ ## ser_num); \ + void _rx_complete_irq_ ## ser_num (serial_t * obj) { MSerial ## ser_num ._rx_complete_irq(obj); } +#endif #if USING_HW_SERIAL1 DECLARE_SERIAL_PORT(1) @@ -87,33 +92,38 @@ #endif void MarlinSerial::begin(unsigned long baud, uint8_t config) { - HardwareSerial::begin(baud, config); - // Replace the IRQ callback with the one we have defined - TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback); + #if ENABLED(SERIAL_DMA) + HAL_HardwareSerial::begin(baud, config); + #else + HardwareSerial::begin(baud, config); + // Replace the IRQ callback with the one we have defined + TERN_(EMERGENCY_PARSER, _serial.rx_callback = _rx_callback); + #endif } -// This function is Copyright (c) 2006 Nicholas Zambetti. -void MarlinSerial::_rx_complete_irq(serial_t *obj) { - // No Parity error, read byte and store it in the buffer if there is room - unsigned char c; +#if DISABLED(SERIAL_DMA) - if (uart_getc(obj, &c) == 0) { + // This function Copyright (c) 2006 Nicholas Zambetti. + void MarlinSerial::_rx_complete_irq(serial_t *obj) { + // No Parity error, read byte and store it in the buffer if there is room + unsigned char c; + if (uart_getc(obj, &c) == 0) { - rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE; + rx_buffer_index_t i = (unsigned int)(obj->rx_head + 1) % SERIAL_RX_BUFFER_SIZE; - // if we should be storing the received character into the location - // just before the tail (meaning that the head would advance to the - // current location of the tail), we're about to overflow the buffer - // and so we don't write the character or advance the head. - if (i != obj->rx_tail) { - obj->rx_buff[obj->rx_head] = c; - obj->rx_head = i; - } + // If tail overlaps head the buffer is overflowed + // so don't write the character or advance the head. + if (i != obj->rx_tail) { + obj->rx_buff[obj->rx_head] = c; + obj->rx_head = i; + } - #if ENABLED(EMERGENCY_PARSER) - emergency_parser.update(static_cast(this)->emergency_state, c); - #endif + #if ENABLED(EMERGENCY_PARSER) + emergency_parser.update(static_cast(this)->emergency_state, c); + #endif + } } -} + +#endif // !SERIAL_DMA #endif // HAL_STM32 diff --git a/Marlin/src/HAL/STM32/MarlinSerial.h b/Marlin/src/HAL/STM32/MarlinSerial.h index bf861fb8a79a..4ab1e4e75a6b 100644 --- a/Marlin/src/HAL/STM32/MarlinSerial.h +++ b/Marlin/src/HAL/STM32/MarlinSerial.h @@ -27,23 +27,38 @@ #include "../../feature/e_parser.h" #endif +#if ENABLED(SERIAL_DMA) + #include "HardwareSerial.h" +#endif + #include "../../core/serial_hook.h" -typedef void (*usart_rx_callback_t)(serial_t * obj); +#if ENABLED(SERIAL_DMA) + + struct MarlinSerial : public HAL_HardwareSerial { + MarlinSerial(void *peripheral) : HAL_HardwareSerial(peripheral) { } + void begin(unsigned long baud, uint8_t config); + inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } + }; + +#else // Arduino non-DMA -struct MarlinSerial : public HardwareSerial { - MarlinSerial(void *peripheral, usart_rx_callback_t rx_callback) : - HardwareSerial(peripheral), _rx_callback(rx_callback) - { } + typedef void (*usart_rx_callback_t)(serial_t * obj); - void begin(unsigned long baud, uint8_t config); - inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } + struct MarlinSerial : public HardwareSerial { + MarlinSerial(void *peripheral, usart_rx_callback_t rx_callback) + : HardwareSerial(peripheral), _rx_callback(rx_callback) { } - void _rx_complete_irq(serial_t *obj); + void begin(unsigned long baud, uint8_t config); + inline void begin(unsigned long baud) { begin(baud, SERIAL_8N1); } -protected: - usart_rx_callback_t _rx_callback; -}; + void _rx_complete_irq(serial_t *obj); + + protected: + usart_rx_callback_t _rx_callback; + }; + +#endif typedef Serial1Class MSerialT; extern MSerialT MSerial1; diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 00e90b618356..70eba0d60c9f 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -254,6 +254,15 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L #error "SERIAL_XON_XOFF and SERIAL_STATS_* features not supported on USB-native AVR devices." #endif +// Serial DMA is only available for some STM32 MCUs +#if ENABLED(SERIAL_DMA) + #if !HAL_STM32 || NONE(STM32F0xx, STM32F1xx, STM32F2xx, STM32F4xx, STM32F7xx) + #error "SERIAL_DMA is only available for some STM32 MCUs and requires HAL/STM32." + #elif !defined(HAL_UART_MODULE_ENABLED) || defined(HAL_UART_MODULE_ONLY) + #error "SERIAL_DMA requires STM32 platform HAL UART (without HAL_UART_MODULE_ONLY)." + #endif +#endif + /** * Multiple Stepper Drivers Per Axis */ diff --git a/buildroot/tests/STM32F103RE_btt b/buildroot/tests/STM32F103RE_btt index 97d7ffec4bdd..197ca775989a 100755 --- a/buildroot/tests/STM32F103RE_btt +++ b/buildroot/tests/STM32F103RE_btt @@ -13,6 +13,7 @@ restore_configs opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP \ SERIAL_PORT 1 SERIAL_PORT_2 -1 \ X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2130 +opt_enable SERIAL_DMA exec_test $1 $2 "BTT SKR E3 DIP 1.0 | Mixed TMC Drivers" "$3" # clean up From f3fd9e28f5d6fae59c55742a2e70e2d6a3330aeb Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Tue, 12 Dec 2023 14:30:28 +1300 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=90=9B=20Fix=20MKS=20TS35=20with=20BT?= =?UTF-8?q?T=20SKR=201.3/1.4=20(#26176)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/HAL/LPC1768/tft/tft_spi.cpp | 8 ++ Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h | 34 +++--- Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h | 123 +++++++++++++++++--- 3 files changed, 133 insertions(+), 32 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp index 2342de002db7..beaadaf51961 100644 --- a/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp +++ b/Marlin/src/HAL/LPC1768/tft/tft_spi.cpp @@ -55,11 +55,19 @@ void TFT_SPI::dataTransferBegin(uint16_t dataSize) { WRITE(TFT_CS_PIN, LOW); } +#ifdef TFT_DEFAULT_DRIVER + #include "../../../lcd/tft_io/tft_ids.h" +#endif + uint32_t TFT_SPI::getID() { uint32_t id; id = readID(LCD_READ_ID); if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) id = readID(LCD_READ_ID4); + #ifdef TFT_DEFAULT_DRIVER + if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) + id = TFT_DEFAULT_DRIVER; + #endif return id; } diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h index 4c621bf5eff6..1cc555aafe08 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h @@ -347,6 +347,10 @@ #define TFT_CS_PIN EXP2_04_PIN #define TFT_DC_PIN EXP2_07_PIN + #define TFT_SCK_PIN EXP2_02_PIN + #define TFT_MISO_PIN EXP2_01_PIN + #define TFT_MOSI_PIN EXP2_06_PIN + #define TOUCH_CS_PIN EXP1_04_PIN #define TOUCH_SCK_PIN EXP1_05_PIN #define TOUCH_MISO_PIN EXP1_06_PIN @@ -355,6 +359,10 @@ #elif ENABLED(MKS_TS35_V2_0) + #ifndef NO_CONTROLLER_CUSTOM_WIRING_WARNING + #error "CAUTION! MKS_TS35_V2_0 requires wiring modifications. The SKR 1.3 EXP ports are rotated 180° from what the MKS_TS35_V2_0 expects. (Define NO_CONTROLLER_CUSTOM_WIRING_WARNING to suppress this error.)" + #endif + /** ------ ------ * BEEPER | 1 2 | BTN_ENC SPI1_MISO | 1 2 | SPI1_SCK * TFT_BKL / LCD_EN | 3 4 | TFT_RESET / LCD_RS BTN_EN1 | 3 4 | SPI1_CS @@ -368,36 +376,36 @@ #define TFT_DC_PIN EXP1_08_PIN #define TFT_RESET_PIN EXP1_04_PIN - #define TFT_BACKLIGHT_PIN EXP1_03_PIN - #define TOUCH_BUTTONS_HW_SPI - #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 - //#define TFT_RST_PIN EXP2_07_PIN #define TFT_SCK_PIN EXP2_02_PIN #define TFT_MISO_PIN EXP2_01_PIN #define TFT_MOSI_PIN EXP2_06_PIN - #define LCD_READ_ID 0xD3 #define LCD_USE_DMA_SPI #define TFT_BUFFER_WORDS 2400 + #define TOUCH_CS_PIN EXP1_05_PIN + #define TOUCH_INT_PIN EXP1_06_PIN + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + #endif #if ENABLED(TFT_CLASSIC_UI) #ifndef TOUCH_CALIBRATION_X - #define TOUCH_CALIBRATION_X -11386 + #define TOUCH_CALIBRATION_X -16794 #endif #ifndef TOUCH_CALIBRATION_Y - #define TOUCH_CALIBRATION_Y 8684 + #define TOUCH_CALIBRATION_Y 11000 #endif #ifndef TOUCH_OFFSET_X - #define TOUCH_OFFSET_X 689 + #define TOUCH_OFFSET_X 1024 #endif #ifndef TOUCH_OFFSET_Y - #define TOUCH_OFFSET_Y -273 + #define TOUCH_OFFSET_Y -352 #endif #elif ENABLED(TFT_COLOR_UI) #ifndef TOUCH_CALIBRATION_X @@ -515,14 +523,6 @@ #endif // HAS_WIRED_LCD -#if NEED_TOUCH_PINS - #define TOUCH_CS_PIN EXP1_05_PIN - #define TOUCH_SCK_PIN EXP2_02_PIN - #define TOUCH_MOSI_PIN EXP2_06_PIN - #define TOUCH_MISO_PIN EXP2_01_PIN - #define TOUCH_INT_PIN EXP1_06_PIN -#endif - /** * Special pins * P1_30 (37) (NOT 5V tolerant) diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index 8d63ab764ebe..51953324a3af 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -395,26 +395,119 @@ #define LCD_BACKLIGHT_PIN -1 #elif HAS_SPI_TFT // Config for Classic UI (emulated DOGM) and Color UI - #define TFT_CS_PIN EXP1_07_PIN - #define TFT_DC_PIN EXP1_08_PIN + + #define SDCARD_CONNECTION ONBOARD + + #define BEEPER_PIN EXP1_01_PIN + + #define BTN_ENC EXP1_02_PIN + #define BTN_EN1 EXP2_03_PIN + #define BTN_EN2 EXP2_05_PIN + #define TFT_A0_PIN TFT_DC_PIN - #define TFT_MISO_PIN EXP2_01_PIN - #define TFT_BACKLIGHT_PIN EXP1_03_PIN - #define TFT_RESET_PIN EXP1_04_PIN - #define LCD_USE_DMA_SPI + #ifndef TFT_WIDTH + #define TFT_WIDTH 480 + #endif + #ifndef TFT_HEIGHT + #define TFT_HEIGHT 320 + #endif + + #if ENABLED(BTT_TFT35_SPI_V1_0) + + /** + * ------ ------ + * BEEPER | 1 2 | LCD-BTN MISO | 1 2 | CLK + * T_MOSI | 3 4 | T_CS LCD-ENCA | 3 4 | TFTCS + * T_CLK | 5 6 T_MISO LCD-ENCB | 5 6 MOSI + * PENIRQ | 7 8 | F_CS RS | 7 8 | RESET + * GND | 9 10 | VCC GND | 9 10 | NC + * ------ ------ + * EXP1 EXP2 + * + * 480x320, 3.5", SPI Display with Rotary Encoder. + * Stock Display for the BIQU B1 SE Series. + * Schematic: https://github.com/bigtreetech/TFT35-SPI/blob/master/v1/Hardware/BTT%20TFT35-SPI%20V1-SCH.pdf + */ + #define TFT_CS_PIN EXP2_04_PIN + #define TFT_DC_PIN EXP2_07_PIN + + #define TFT_SCK_PIN EXP2_02_PIN + #define TFT_MISO_PIN EXP2_01_PIN + #define TFT_MOSI_PIN EXP2_06_PIN + + #define TOUCH_CS_PIN EXP1_04_PIN + #define TOUCH_SCK_PIN EXP1_05_PIN + #define TOUCH_MISO_PIN EXP1_06_PIN + #define TOUCH_MOSI_PIN EXP1_03_PIN + #define TOUCH_INT_PIN EXP1_07_PIN + + #elif ENABLED(MKS_TS35_V2_0) + + #ifndef NO_CONTROLLER_CUSTOM_WIRING_WARNING + #error "CAUTION! MKS_TS35_V2_0 requires wiring modifications. The SKR 1.4 EXP ports are rotated 180° from what the MKS_TS35_V2_0 expects. (Define NO_CONTROLLER_CUSTOM_WIRING_WARNING to suppress this error.)" + #endif + + /** ------ ------ + * BEEPER | 1 2 | BTN_ENC SPI1_MISO | 1 2 | SPI1_SCK + * TFT_BKL / LCD_EN | 3 4 | TFT_RESET / LCD_RS BTN_EN1 | 3 4 | SPI1_CS + * TOUCH_CS / LCD_D4 | 5 6 TOUCH_INT / LCD_D5 BTN_EN2 | 5 6 SPI1_MOSI + * SPI1_CS / LCD_D6 | 7 8 | SPI1_RS / LCD_D7 SPI1_RS | 7 8 | RESET + * GND | 9 10 | VCC GND | 9 10 | VCC + * ------ ------ + * EXP1 EXP2 + */ + #define TFT_CS_PIN EXP1_07_PIN + #define TFT_DC_PIN EXP1_08_PIN + + #define TFT_RESET_PIN EXP1_04_PIN + #define TFT_BACKLIGHT_PIN EXP1_03_PIN + + //#define TFT_RST_PIN EXP2_07_PIN + #define TFT_SCK_PIN EXP2_02_PIN + #define TFT_MISO_PIN EXP2_01_PIN + #define TFT_MOSI_PIN EXP2_06_PIN - #define TOUCH_INT_PIN EXP1_06_PIN - #define TOUCH_CS_PIN EXP1_05_PIN - #define TOUCH_BUTTONS_HW_SPI - #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + #define LCD_USE_DMA_SPI - // SPI 1 - #define SD_SCK_PIN EXP2_02_PIN - #define SD_MISO_PIN EXP2_01_PIN - #define SD_MOSI_PIN EXP2_06_PIN + #define TFT_BUFFER_WORDS 2400 - #define TFT_BUFFER_WORDS 2400 + #define TOUCH_CS_PIN EXP1_05_PIN + #define TOUCH_INT_PIN EXP1_06_PIN + #define TOUCH_BUTTONS_HW_SPI + #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 + + #endif + + #if ENABLED(TFT_CLASSIC_UI) + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -16794 + #endif + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11000 + #endif + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 1024 + #endif + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -352 + #endif + + #elif ENABLED(TFT_COLOR_UI) + #ifndef TOUCH_CALIBRATION_X + #define TOUCH_CALIBRATION_X -16741 + #endif + #ifndef TOUCH_CALIBRATION_Y + #define TOUCH_CALIBRATION_Y 11258 + #endif + #ifndef TOUCH_OFFSET_X + #define TOUCH_OFFSET_X 1024 + #endif + #ifndef TOUCH_OFFSET_Y + #define TOUCH_OFFSET_Y -367 + #endif + #define TFT_BUFFER_WORDS 2400 + #endif #elif IS_TFTGLCD_PANEL From 81cfa2388236820f4ed498ede01fde502a0fdca0 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Tue, 12 Dec 2023 06:09:34 +0000 Subject: [PATCH 4/8] [cron] Bump distribution date (2023-12-12) --- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Version.h b/Marlin/Version.h index c171a6fc25fe..00fbba610d31 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ -//#define STRING_DISTRIBUTION_DATE "2023-12-10" +//#define STRING_DISTRIBUTION_DATE "2023-12-12" /** * Defines a generic printer name to be output to the LCD after booting Marlin. diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index cc6ab3ec6611..3c5a423ec05a 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2023-12-10" + #define STRING_DISTRIBUTION_DATE "2023-12-12" #endif /** From 06710e54de8c83af77a4f57d458f6463fbfcad93 Mon Sep 17 00:00:00 2001 From: Andrew <18502096+classicrocker883@users.noreply.github.com> Date: Wed, 13 Dec 2023 00:33:03 -0500 Subject: [PATCH 5/8] =?UTF-8?q?=E2=9C=A8=20EDITABLE=5FDISPLAY=5FTIMEOUT=20?= =?UTF-8?q?(#26517)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- Marlin/Configuration_adv.h | 14 +++--- Marlin/src/core/types.h | 4 +- Marlin/src/feature/bedlevel/bdl/bdl.cpp | 2 +- Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp | 3 +- Marlin/src/gcode/calibrate/G76_M871.cpp | 2 +- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/gcode.h | 2 +- Marlin/src/gcode/lcd/M255.cpp | 4 +- Marlin/src/inc/Conditionals_adv.h | 6 +-- Marlin/src/inc/SanityCheck.h | 2 +- Marlin/src/lcd/e3v2/common/encoder.cpp | 8 +--- Marlin/src/lcd/e3v2/proui/dwin.cpp | 8 ++-- Marlin/src/lcd/e3v2/proui/plot.cpp | 4 +- Marlin/src/lcd/marlinui.cpp | 27 ++++++----- Marlin/src/lcd/marlinui.h | 16 +++++-- Marlin/src/lcd/menu/menu_configuration.cpp | 10 +++-- Marlin/src/lcd/tft/touch.cpp | 2 +- Marlin/src/lcd/touch/touch_buttons.cpp | 2 +- Marlin/src/module/settings.cpp | 50 +++++++++++---------- Marlin/src/module/temperature.h | 14 +++--- ini/features.ini | 2 +- 21 files changed, 102 insertions(+), 82 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index e4f85a8d87b7..8b4fa1ab7ca1 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1471,11 +1471,6 @@ #define FEEDRATE_CHANGE_BEEP_FREQUENCY 440 #endif -// -// LCD Backlight Timeout -// -//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight - #if HAS_BED_PROBE && ANY(HAS_MARLINUI_MENU, HAS_TFT_LVGL_UI) //#define PROBE_OFFSET_WIZARD // Add a Probe Z Offset calibration option to the LCD menu #if ENABLED(PROBE_OFFSET_WIZARD) @@ -2206,6 +2201,15 @@ //#define TFT_BTOKMENU_COLOR 0x145F // 00010 100010 11111 Cyan #endif +// +// LCD Backlight Timeout +// Requires a display with a controllable backlight +// +//#define LCD_BACKLIGHT_TIMEOUT_MINS 1 // (minutes) Timeout before turning off the backlight +#if defined(DISPLAY_SLEEP_MINUTES) || defined(LCD_BACKLIGHT_TIMEOUT_MINS) + #define EDITABLE_DISPLAY_TIMEOUT // Edit timeout with M255 S and a menu item +#endif + // // ADC Button Debounce // diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index d92dbde8b7a4..bcbf2f07aa45 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -198,7 +198,7 @@ typedef Flags<8> flags_8_t; typedef Flags<16> flags_16_t; // Flags for some axis states, with per-axis aliases xyzijkuvwe -typedef struct AxisFlags { +typedef struct { union { struct Flags flags; struct { bool LOGICAL_AXIS_LIST(e:1, x:1, y:1, z:1, i:1, j:1, k:1, u:1, v:1, w:1); }; @@ -212,7 +212,7 @@ typedef struct AxisFlags { FI bool operator[](const int n) const { return flags[n]; } FI int size() const { return sizeof(flags); } FI operator bool() const { return flags; } -} axis_flags_t; +} AxisFlags; // // Enumerated axis indices diff --git a/Marlin/src/feature/bedlevel/bdl/bdl.cpp b/Marlin/src/feature/bedlevel/bdl/bdl.cpp index 5345bb78c590..d469bb0c0673 100644 --- a/Marlin/src/feature/bedlevel/bdl/bdl.cpp +++ b/Marlin/src/feature/bedlevel/bdl/bdl.cpp @@ -195,7 +195,7 @@ void BDS_Leveling::process() { safe_delay(10); if (config_state == BDS_CALIBRATE_START) { config_state = BDS_CALIBRATING; - REMEMBER(gsit, gcode.stepper_inactive_time, SEC_TO_MS(60 * 5)); + REMEMBER(gsit, gcode.stepper_inactive_time, MIN_TO_MS(5)); SERIAL_ECHOLNPGM("c_z0:", planner.get_axis_position_mm(Z_AXIS), "-", pos_zero_offset); // Move the z axis instead of enabling the Z axis with M17 diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index d136f0000d8c..3d0013b6d2da 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -772,7 +772,8 @@ void unified_bed_leveling::shift_mesh_height() { const grid_count_t point_num = (GRID_MAX_POINTS - count) + 1; SERIAL_ECHOLNPGM("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, "."); TERN_(HAS_STATUS_MESSAGE, ui.status_printf(0, F(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_POINT), point_num, int(GRID_MAX_POINTS))); - TERN_(LCD_BACKLIGHT_TIMEOUT_MINS, ui.refresh_backlight_timeout()); + TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); + TERN_(DWIN_LCD_PROUI, dwinRedrawScreen()); #if HAS_MARLINUI_MENU if (ui.button_pressed()) { diff --git a/Marlin/src/gcode/calibrate/G76_M871.cpp b/Marlin/src/gcode/calibrate/G76_M871.cpp index 6fe3dd89cf17..bb69b75d5056 100644 --- a/Marlin/src/gcode/calibrate/G76_M871.cpp +++ b/Marlin/src/gcode/calibrate/G76_M871.cpp @@ -256,7 +256,7 @@ say_waiting_for_probe_heating(); SERIAL_ECHOLNPGM(" Bed:", target_bed, " Probe:", target_probe); - const millis_t probe_timeout_ms = millis() + SEC_TO_MS(900UL); + const millis_t probe_timeout_ms = millis() + MIN_TO_MS(15); while (thermalManager.degProbe() < target_probe) { if (report_temps(next_temp_report, probe_timeout_ms)) { SERIAL_ECHOLNPGM("!Probe heating timed out."); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index d519bd4e2941..6a0e8cb17142 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -793,7 +793,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 250: M250(); break; // M250: Set LCD contrast #endif - #if HAS_GCODE_M255 + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) case 255: M255(); break; // M255: Set LCD Sleep/Backlight Timeout (Minutes) #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 61ff0b047cac..fffd0d714bea 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -909,7 +909,7 @@ class GcodeSuite { static void M250_report(const bool forReplay=true); #endif - #if HAS_GCODE_M255 + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) static void M255(); static void M255_report(const bool forReplay=true); #endif diff --git a/Marlin/src/gcode/lcd/M255.cpp b/Marlin/src/gcode/lcd/M255.cpp index 8dc8099de149..2b982ee5d9a0 100644 --- a/Marlin/src/gcode/lcd/M255.cpp +++ b/Marlin/src/gcode/lcd/M255.cpp @@ -21,7 +21,7 @@ */ #include "../../inc/MarlinConfig.h" -#if HAS_GCODE_M255 +#if ENABLED(EDITABLE_DISPLAY_TIMEOUT) #include "../gcode.h" #include "../../lcd/marlinui.h" @@ -51,4 +51,4 @@ void GcodeSuite::M255_report(const bool forReplay/*=true*/) { ); } -#endif // HAS_GCODE_M255 +#endif // EDITABLE_DISPLAY_TIMEOUT diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index ba074e256088..755b251b1879 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -893,11 +893,11 @@ #if ALL(HAS_RESUME_CONTINUE, PRINTER_EVENT_LEDS, HAS_MEDIA) #define HAS_LEDS_OFF_FLAG 1 #endif -#if DISPLAY_SLEEP_MINUTES || TOUCH_IDLE_SLEEP_MINS +#if defined(DISPLAY_SLEEP_MINUTES) || defined(TOUCH_IDLE_SLEEP_MINS) #define HAS_DISPLAY_SLEEP 1 #endif -#if HAS_DISPLAY_SLEEP || LCD_BACKLIGHT_TIMEOUT_MINS - #define HAS_GCODE_M255 1 +#ifdef LCD_BACKLIGHT_TIMEOUT_MINS + #define HAS_BACKLIGHT_TIMEOUT 1 #endif #if ANY(DIGIPOT_MCP4018, DIGIPOT_MCP4451) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 70eba0d60c9f..2e1149e66874 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -2762,7 +2762,7 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L #endif #endif -#if LCD_BACKLIGHT_TIMEOUT_MINS +#if HAS_BACKLIGHT_TIMEOUT #if !HAS_ENCODER_ACTION && DISABLED(HAS_DWIN_E3V2) #error "LCD_BACKLIGHT_TIMEOUT_MINS requires an LCD with encoder or keypad." #elif ENABLED(NEOPIXEL_BKGD_INDEX_FIRST) diff --git a/Marlin/src/lcd/e3v2/common/encoder.cpp b/Marlin/src/lcd/e3v2/common/encoder.cpp index eb064950ec59..cb14596849a5 100644 --- a/Marlin/src/lcd/e3v2/common/encoder.cpp +++ b/Marlin/src/lcd/e3v2/common/encoder.cpp @@ -87,9 +87,7 @@ EncoderState encoderReceiveAnalyze() { #if PIN_EXISTS(LCD_LED) //LED_Action(); #endif - #if LCD_BACKLIGHT_TIMEOUT_MINS - ui.refresh_backlight_timeout(); - #endif + TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); if (!ui.backlight) { ui.refresh_brightness(); return ENCODER_DIFF_NO; @@ -161,9 +159,7 @@ EncoderState encoderReceiveAnalyze() { temp_diff = 0; } if (temp_diffState != ENCODER_DIFF_NO) { - #if LCD_BACKLIGHT_TIMEOUT_MINS - ui.refresh_backlight_timeout(); - #endif + TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); if (!ui.backlight) ui.refresh_brightness(); } return temp_diffState; diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 8d4aa9106bfa..7c68c60f8195 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -1249,7 +1249,7 @@ void eachMomentUpdate() { static millis_t next_var_update_ms = 0, next_rts_update_ms = 0, next_status_update_ms = 0; const millis_t ms = millis(); - #if LCD_BACKLIGHT_TIMEOUT_MINS + #if HAS_BACKLIGHT_TIMEOUT if (ui.backlight_off_ms && ELAPSED(ms, ui.backlight_off_ms)) { turnOffBacklight(); // Backlight off ui.backlight_off_ms = 0; @@ -2235,7 +2235,7 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS, #endif -#if LCD_BACKLIGHT_TIMEOUT_MINS +#if ENABLED(EDITABLE_DISPLAY_TIMEOUT) void applyTimer() { ui.backlight_timeout_minutes = menuData.value; } void setTimer() { setIntOnClick(ui.backlight_timeout_min, ui.backlight_timeout_max, ui.backlight_timeout_minutes, applyTimer); } #endif @@ -3123,7 +3123,7 @@ void drawAdvancedSettingsMenu() { #if HAS_LOCKSCREEN MENU_ITEM(ICON_Lock, MSG_LOCKSCREEN, onDrawMenuItem, dwinLockScreen); #endif - #if LCD_BACKLIGHT_TIMEOUT_MINS + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) EDIT_ITEM(ICON_Brightness, MSG_SCREEN_TIMEOUT, onDrawPIntMenu, setTimer, &ui.backlight_timeout_minutes); #endif #if ENABLED(SOUND_MENU_ITEM) @@ -3347,7 +3347,7 @@ void drawTuneMenu() { EDIT_ITEM(ICON_Brightness, MSG_BRIGHTNESS, onDrawPInt8Menu, setBrightness, &ui.brightness); MENU_ITEM(ICON_Brightness, MSG_BRIGHTNESS_OFF, onDrawMenuItem, turnOffBacklight); #endif - #if LCD_BACKLIGHT_TIMEOUT_MINS + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) EDIT_ITEM(ICON_Brightness, MSG_SCREEN_TIMEOUT, onDrawPIntMenu, setTimer, &ui.backlight_timeout_minutes); #endif #if ENABLED(CASE_LIGHT_MENU) diff --git a/Marlin/src/lcd/e3v2/proui/plot.cpp b/Marlin/src/lcd/e3v2/proui/plot.cpp index 92c6c947177b..84c58389a6f7 100644 --- a/Marlin/src/lcd/e3v2/proui/plot.cpp +++ b/Marlin/src/lcd/e3v2/proui/plot.cpp @@ -73,9 +73,7 @@ void Plot::update(const_float_t value) { dwinDrawPoint(COLOR_YELLOW, 1, 1, x2 - 1, y); } graphpoints++; - #if LCD_BACKLIGHT_TIMEOUT_MINS - ui.refresh_backlight_timeout(); - #endif + TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); } #endif // PROUI_TUNING_GRAPH diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 4eb58f52aedf..60fb298dfcde 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -24,7 +24,7 @@ #include "../MarlinCore.h" // for printingIsPaused -#if LED_POWEROFF_TIMEOUT > 0 || ALL(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || (defined(LCD_BACKLIGHT_TIMEOUT_MINS) && defined(NEOPIXEL_BKGD_INDEX_FIRST)) +#if LED_POWEROFF_TIMEOUT > 0 || ALL(HAS_WIRED_LCD, PRINTER_EVENT_LEDS) || (HAS_BACKLIGHT_TIMEOUT && defined(NEOPIXEL_BKGD_INDEX_FIRST)) #include "../feature/leds/leds.h" #endif @@ -185,10 +185,14 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update #endif -#if LCD_BACKLIGHT_TIMEOUT_MINS +#if HAS_BACKLIGHT_TIMEOUT + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load() + #else + constexpr uint8_t MarlinUI::backlight_timeout_minutes; + #endif constexpr uint8_t MarlinUI::backlight_timeout_min, MarlinUI::backlight_timeout_max; - uint8_t MarlinUI::backlight_timeout_minutes; // Initialized by settings.load() millis_t MarlinUI::backlight_off_ms = 0; void MarlinUI::refresh_backlight_timeout() { @@ -203,12 +207,16 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP; #elif HAS_DISPLAY_SLEEP + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load() + #else + constexpr uint8_t MarlinUI::sleep_timeout_minutes; + #endif constexpr uint8_t MarlinUI::sleep_timeout_min, MarlinUI::sleep_timeout_max; - uint8_t MarlinUI::sleep_timeout_minutes; // Initialized by settings.load() - millis_t MarlinUI::screen_timeout_millis = 0; + millis_t MarlinUI::screen_timeout_ms = 0; void MarlinUI::refresh_screen_timeout() { - screen_timeout_millis = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0; + screen_timeout_ms = sleep_timeout_minutes ? millis() + sleep_timeout_minutes * 60UL * 1000UL : 0; sleep_display(false); } @@ -1092,7 +1100,7 @@ void MarlinUI::init() { if (encoderPastThreshold || lcd_clicked) { reset_status_timeout(ms); - #if LCD_BACKLIGHT_TIMEOUT_MINS + #if HAS_BACKLIGHT_TIMEOUT refresh_backlight_timeout(); #elif HAS_DISPLAY_SLEEP refresh_screen_timeout(); @@ -1202,8 +1210,7 @@ void MarlinUI::init() { return_to_status(); #endif - #if LCD_BACKLIGHT_TIMEOUT_MINS - + #if HAS_BACKLIGHT_TIMEOUT if (backlight_off_ms && ELAPSED(ms, backlight_off_ms)) { #ifdef NEOPIXEL_BKGD_INDEX_FIRST neo.set_background_off(); @@ -1214,7 +1221,7 @@ void MarlinUI::init() { backlight_off_ms = 0; } #elif HAS_DISPLAY_SLEEP - if (screen_timeout_millis && ELAPSED(ms, screen_timeout_millis)) + if (screen_timeout_ms && ELAPSED(ms, screen_timeout_ms)) sleep_display(); #endif diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 595b89b6e00f..a463701f566a 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -272,17 +272,25 @@ class MarlinUI { FORCE_INLINE static void refresh_brightness() { set_brightness(brightness); } #endif - #if LCD_BACKLIGHT_TIMEOUT_MINS + #if HAS_BACKLIGHT_TIMEOUT + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + static uint8_t backlight_timeout_minutes; + #else + static constexpr uint8_t backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS; + #endif static constexpr uint8_t backlight_timeout_min = 0; static constexpr uint8_t backlight_timeout_max = 99; - static uint8_t backlight_timeout_minutes; static millis_t backlight_off_ms; static void refresh_backlight_timeout(); #elif HAS_DISPLAY_SLEEP + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + static uint8_t sleep_timeout_minutes; + #else + static constexpr uint8_t sleep_timeout_minutes = DISPLAY_SLEEP_MINUTES; + #endif static constexpr uint8_t sleep_timeout_min = 0; static constexpr uint8_t sleep_timeout_max = 99; - static uint8_t sleep_timeout_minutes; - static millis_t screen_timeout_millis; + static millis_t screen_timeout_ms; static void refresh_screen_timeout(); static void sleep_display(const bool sleep=true); #endif diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 52123d101b68..7347f219e0ab 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -618,10 +618,12 @@ void menu_configuration() { // // Set display backlight / sleep timeout // - #if LCD_BACKLIGHT_TIMEOUT_MINS - EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout); - #elif HAS_DISPLAY_SLEEP - EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout); + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + #if HAS_BACKLIGHT_TIMEOUT + EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.backlight_timeout_minutes, ui.backlight_timeout_min, ui.backlight_timeout_max, ui.refresh_backlight_timeout); + #elif HAS_DISPLAY_SLEEP + EDIT_ITEM(uint8, MSG_SCREEN_TIMEOUT, &ui.sleep_timeout_minutes, ui.sleep_timeout_min, ui.sleep_timeout_max, ui.refresh_screen_timeout); + #endif #endif #if ENABLED(FWRETRACT) diff --git a/Marlin/src/lcd/tft/touch.cpp b/Marlin/src/lcd/tft/touch.cpp index 3c0b21ba8fd3..d325355002f5 100644 --- a/Marlin/src/lcd/tft/touch.cpp +++ b/Marlin/src/lcd/tft/touch.cpp @@ -308,7 +308,7 @@ bool Touch::get_point(int16_t * const x, int16_t * const y) { next_touch_ms = millis() + 100; safe_delay(20); } - next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60); + next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes); } #endif // HAS_TOUCH_SLEEP diff --git a/Marlin/src/lcd/touch/touch_buttons.cpp b/Marlin/src/lcd/touch/touch_buttons.cpp index 7d31b21c04a6..652a043714d8 100644 --- a/Marlin/src/lcd/touch/touch_buttons.cpp +++ b/Marlin/src/lcd/touch/touch_buttons.cpp @@ -147,7 +147,7 @@ uint8_t TouchButtons::read_buttons() { WRITE(TFT_BACKLIGHT_PIN, HIGH); #endif } - next_sleep_ms = millis() + SEC_TO_MS(ui.sleep_timeout_minutes * 60); + next_sleep_ms = millis() + MIN_TO_MS(ui.sleep_timeout_minutes); } #endif // HAS_TOUCH_SLEEP diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index f636b985e1be..b99ae8ddcda7 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -431,10 +431,12 @@ typedef struct SettingsDataStruct { // // Display Sleep // - #if LCD_BACKLIGHT_TIMEOUT_MINS - uint8_t backlight_timeout_minutes; // M255 S - #elif HAS_DISPLAY_SLEEP - uint8_t sleep_timeout_minutes; // M255 S + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + #if HAS_BACKLIGHT_TIMEOUT + uint8_t backlight_timeout_minutes; // M255 S + #elif HAS_DISPLAY_SLEEP + uint8_t sleep_timeout_minutes; // M255 S + #endif #endif // @@ -704,12 +706,8 @@ void MarlinSettings::postprocess() { // Moved as last update due to interference with Neopixel init TERN_(HAS_LCD_CONTRAST, ui.refresh_contrast()); TERN_(HAS_LCD_BRIGHTNESS, ui.refresh_brightness()); - - #if LCD_BACKLIGHT_TIMEOUT_MINS - ui.refresh_backlight_timeout(); - #elif HAS_DISPLAY_SLEEP - ui.refresh_screen_timeout(); - #endif + TERN_(HAS_BACKLIGHT_TIMEOUT, ui.refresh_backlight_timeout()); + TERN_(HAS_DISPLAY_SLEEP, ui.refresh_screen_timeout()); } #if ALL(PRINTCOUNTER, EEPROM_SETTINGS) @@ -1249,10 +1247,12 @@ void MarlinSettings::postprocess() { // // LCD Backlight / Sleep Timeout // - #if LCD_BACKLIGHT_TIMEOUT_MINS - EEPROM_WRITE(ui.backlight_timeout_minutes); - #elif HAS_DISPLAY_SLEEP - EEPROM_WRITE(ui.sleep_timeout_minutes); + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + #if HAS_BACKLIGHT_TIMEOUT + EEPROM_WRITE(ui.backlight_timeout_minutes); + #elif HAS_DISPLAY_SLEEP + EEPROM_WRITE(ui.sleep_timeout_minutes); + #endif #endif // @@ -2294,10 +2294,12 @@ void MarlinSettings::postprocess() { // // LCD Backlight / Sleep Timeout // - #if LCD_BACKLIGHT_TIMEOUT_MINS - EEPROM_READ(ui.backlight_timeout_minutes); - #elif HAS_DISPLAY_SLEEP - EEPROM_READ(ui.sleep_timeout_minutes); + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + #if HAS_BACKLIGHT_TIMEOUT + EEPROM_READ(ui.backlight_timeout_minutes); + #elif HAS_DISPLAY_SLEEP + EEPROM_READ(ui.sleep_timeout_minutes); + #endif #endif // @@ -3451,10 +3453,12 @@ void MarlinSettings::reset() { // // LCD Backlight / Sleep Timeout // - #if LCD_BACKLIGHT_TIMEOUT_MINS - ui.backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS; - #elif HAS_DISPLAY_SLEEP - ui.sleep_timeout_minutes = TERN(TOUCH_SCREEN, TOUCH_IDLE_SLEEP_MINS, DISPLAY_SLEEP_MINUTES); + #if ENABLED(EDITABLE_DISPLAY_TIMEOUT) + #if HAS_BACKLIGHT_TIMEOUT + ui.backlight_timeout_minutes = LCD_BACKLIGHT_TIMEOUT_MINS; + #elif HAS_DISPLAY_SLEEP + ui.sleep_timeout_minutes = TERN(TOUCH_SCREEN, TOUCH_IDLE_SLEEP_MINS, DISPLAY_SLEEP_MINUTES); + #endif #endif // @@ -3827,7 +3831,7 @@ void MarlinSettings::reset() { // // Display Sleep // - TERN_(HAS_GCODE_M255, gcode.M255_report(forReplay)); + TERN_(EDITABLE_DISPLAY_TIMEOUT, gcode.M255_report(forReplay)); // // LCD Brightness diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index d174bfd11dbd..2acc1205b730 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -699,7 +699,7 @@ class Temperature { // Convert the given heater_id_t to idle array index static IdleIndex idle_index_for_id(const int8_t heater_id) { - TERN_(HAS_HEATED_BED, if (heater_id == H_BED) return IDLE_INDEX_BED); + OPTCODE(HAS_HEATED_BED, if (heater_id == H_BED) return IDLE_INDEX_BED) return (IdleIndex)_MAX(heater_id, 0); } @@ -1052,7 +1052,7 @@ class Temperature { } // Start watching the Bed to make sure it's really heating up - static void start_watching_bed() { TERN_(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())); } + static void start_watching_bed() { OPTCODE(WATCH_BED, watch_bed.restart(degBed(), degTargetBed())) } static void setTargetBed(const celsius_t celsius) { #if PREHEAT_TIME_BED_MS > 0 @@ -1108,7 +1108,7 @@ class Temperature { start_watching_chamber(); } // Start watching the Chamber to make sure it's really heating up - static void start_watching_chamber() { TERN_(WATCH_CHAMBER, watch_chamber.restart(degChamber(), degTargetChamber())); } + static void start_watching_chamber() { OPTCODE(WATCH_CHAMBER, watch_chamber.restart(degChamber(), degTargetChamber())) } #endif #if HAS_TEMP_COOLER @@ -1158,7 +1158,7 @@ class Temperature { start_watching_cooler(); } // Start watching the Cooler to make sure it's really cooling down - static void start_watching_cooler() { TERN_(WATCH_COOLER, watch_cooler.restart(degCooler(), degTargetCooler())); } + static void start_watching_cooler() { OPTCODE(WATCH_COOLER, watch_cooler.restart(degCooler(), degTargetCooler())) } #endif /** @@ -1391,9 +1391,9 @@ class Temperature { // Convert the given heater_id_t to runaway state array index static RunawayIndex runaway_index_for_id(const int8_t heater_id) { - TERN_(THERMAL_PROTECTION_CHAMBER, if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER); - TERN_(THERMAL_PROTECTION_COOLER, if (heater_id == H_COOLER) return RUNAWAY_IND_COOLER); - TERN_(THERMAL_PROTECTION_BED, if (heater_id == H_BED) return RUNAWAY_IND_BED); + OPTCODE(THERMAL_PROTECTION_CHAMBER, if (heater_id == H_CHAMBER) return RUNAWAY_IND_CHAMBER) + OPTCODE(THERMAL_PROTECTION_COOLER, if (heater_id == H_COOLER) return RUNAWAY_IND_COOLER) + OPTCODE(THERMAL_PROTECTION_BED, if (heater_id == H_BED) return RUNAWAY_IND_BED) return (RunawayIndex)_MAX(heater_id, 0); } diff --git a/ini/features.ini b/ini/features.ini index 3e50b19bc085..ed755f9ac001 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -330,7 +330,7 @@ SET_PROGRESS_MANUALLY = build_src_filter=+ HAS_PREHEAT = build_src_filter=+ HAS_LCD_CONTRAST = build_src_filter=+ -HAS_GCODE_M255 = build_src_filter=+ +EDITABLE_DISPLAY_TIMEOUT = build_src_filter=+ HAS_LCD_BRIGHTNESS = build_src_filter=+ HAS_SOUND = build_src_filter=+ HAS_MULTI_LANGUAGE = build_src_filter=+ From 775c6bb20ef1bc09632baaf4359efeea6e441451 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Wed, 13 Dec 2023 06:12:17 +0000 Subject: [PATCH 6/8] [cron] Bump distribution date (2023-12-13) --- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Version.h b/Marlin/Version.h index 00fbba610d31..acd87bb99443 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ -//#define STRING_DISTRIBUTION_DATE "2023-12-12" +//#define STRING_DISTRIBUTION_DATE "2023-12-13" /** * Defines a generic printer name to be output to the LCD after booting Marlin. diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 3c5a423ec05a..7b1faa8884cc 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2023-12-12" + #define STRING_DISTRIBUTION_DATE "2023-12-13" #endif /** From fef74398e41a1b492792837941af55057eb694f5 Mon Sep 17 00:00:00 2001 From: jesterhead82 Date: Wed, 13 Dec 2023 08:44:11 +0100 Subject: [PATCH 7/8] =?UTF-8?q?=E2=9C=A8=20MARKFORGED=5FINVERSE=20(#26516)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/Configuration.h | 10 +++++++++- Marlin/src/module/planner.cpp | 12 ++++++------ Marlin/src/module/stepper.cpp | 8 ++++---- buildroot/tests/mks_robin_mini | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 4d0351bb493c..e62637f6462a 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -892,8 +892,16 @@ //#define COREYX //#define COREZX //#define COREZY -//#define MARKFORGED_XY // MarkForged. See https://reprap.org/forum/read.php?152,504042 + +// +// MarkForged Kinematics +// See https://reprap.org/forum/read.php?152,504042 +// +//#define MARKFORGED_XY //#define MARKFORGED_YX +#if ANY(MARKFORGED_XY, MARKFORGED_YX) + //#define MARKFORGED_INVERSE // Enable for an inverted Markforged kinematics belt path +#endif // Enable for a belt style printer with endless "Z" motion //#define BELTPRINTER diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 8e9021b03069..70a1b105db74 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1990,11 +1990,11 @@ bool Planner::_populate_block( dm.c = (CORESIGN(dist.b - dist.c) > 0); // Motor C direction #endif #elif ENABLED(MARKFORGED_XY) - dm.a = (dist.a + dist.b > 0); // Motor A direction + dm.a = (dist.a TERN(MARKFORGED_INVERSE, -, +) dist.b > 0); // Motor A direction dm.b = (dist.b > 0); // Motor B direction #elif ENABLED(MARKFORGED_YX) dm.a = (dist.a > 0); // Motor A direction - dm.b = (dist.b + dist.a > 0); // Motor B direction + dm.b = (dist.b TERN(MARKFORGED_INVERSE, -, +) dist.a > 0); // Motor B direction #else XYZ_CODE( dm.x = (dist.a > 0), @@ -2062,9 +2062,9 @@ bool Planner::_populate_block( #elif CORE_IS_YZ ABS(dist.a), ABS(dist.b + dist.c), ABS(dist.b - dist.c) #elif ENABLED(MARKFORGED_XY) - ABS(dist.a + dist.b), ABS(dist.b), ABS(dist.c) + ABS(dist.a TERN(MARKFORGED_INVERSE, -, +) dist.b), ABS(dist.b), ABS(dist.c) #elif ENABLED(MARKFORGED_YX) - ABS(dist.a), ABS(dist.b + dist.a), ABS(dist.c) + ABS(dist.a), ABS(dist.b TERN(MARKFORGED_INVERSE, -, +) dist.a), ABS(dist.c) #elif IS_SCARA ABS(dist.a), ABS(dist.b), ABS(dist.c) #else // default non-h-bot planning @@ -2110,11 +2110,11 @@ bool Planner::_populate_block( dist_mm.c = CORESIGN(dist.b - dist.c) * mm_per_step[C_AXIS]; #endif #elif ENABLED(MARKFORGED_XY) - dist_mm.a = (dist.a - dist.b) * mm_per_step[A_AXIS]; + dist_mm.a = (dist.a TERN(MARKFORGED_INVERSE, +, -) dist.b) * mm_per_step[A_AXIS]; dist_mm.b = dist.b * mm_per_step[B_AXIS]; #elif ENABLED(MARKFORGED_YX) dist_mm.a = dist.a * mm_per_step[A_AXIS]; - dist_mm.b = (dist.b - dist.a) * mm_per_step[B_AXIS]; + dist_mm.b = (dist.b TERN(MARKFORGED_INVERSE, +, -) dist.a) * mm_per_step[B_AXIS]; #else XYZ_CODE( dist_mm.a = dist.a * mm_per_step[A_AXIS], diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index a6c628e081cc..c68db6bb89b4 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -3287,9 +3287,9 @@ void Stepper::_set_position(const abce_long_t &spos) { // coreyz planning count_position.set(spos.a, spos.b + spos.c, CORESIGN(spos.b - spos.c)); #elif ENABLED(MARKFORGED_XY) - count_position.set(spos.a - spos.b, spos.b, spos.c); + count_position.set(spos.a TERN(MARKFORGED_INVERSE, +, -) spos.b, spos.b, spos.c); #elif ENABLED(MARKFORGED_YX) - count_position.set(spos.a, spos.b - spos.a, spos.c); + count_position.set(spos.a, spos.b TERN(MARKFORGED_INVERSE, +, -) spos.a, spos.c); #endif SECONDARY_AXIS_CODE( count_position.i = spos.i, @@ -3382,12 +3382,12 @@ void Stepper::endstop_triggered(const AxisEnum axis) { ) * double(0.5) #elif ENABLED(MARKFORGED_XY) axis == CORE_AXIS_1 - ? count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2] + ? count_position[CORE_AXIS_1] ENABLED(MARKFORGED_INVERSE, +, -) count_position[CORE_AXIS_2] : count_position[CORE_AXIS_2] #elif ENABLED(MARKFORGED_YX) axis == CORE_AXIS_1 ? count_position[CORE_AXIS_1] - : count_position[CORE_AXIS_2] - count_position[CORE_AXIS_1] + : count_position[CORE_AXIS_2] ENABLED(MARKFORGED_INVERSE, +, -) count_position[CORE_AXIS_1] #else // !IS_CORE count_position[axis] #endif diff --git a/buildroot/tests/mks_robin_mini b/buildroot/tests/mks_robin_mini index 29baee8818d6..902874ce474d 100755 --- a/buildroot/tests/mks_robin_mini +++ b/buildroot/tests/mks_robin_mini @@ -9,6 +9,7 @@ set -e use_example_configs Mks/Robin opt_set MOTHERBOARD BOARD_MKS_ROBIN_MINI EXTRUDERS 1 TEMP_SENSOR_1 0 +opt_enable MARKFORGED_XY MARKFORGED_INVERSE exec_test $1 $2 "MKS Robin mini" "$3" # cleanup From 8bce9dec906d59c3091e870d614f834c73aaeb89 Mon Sep 17 00:00:00 2001 From: thinkyhead Date: Thu, 14 Dec 2023 00:21:11 +0000 Subject: [PATCH 8/8] [cron] Bump distribution date (2023-12-14) --- Marlin/Version.h | 2 +- Marlin/src/inc/Version.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Version.h b/Marlin/Version.h index acd87bb99443..52512a611302 100644 --- a/Marlin/Version.h +++ b/Marlin/Version.h @@ -41,7 +41,7 @@ * here we define this default string as the date where the latest release * version was tagged. */ -//#define STRING_DISTRIBUTION_DATE "2023-12-13" +//#define STRING_DISTRIBUTION_DATE "2023-12-14" /** * Defines a generic printer name to be output to the LCD after booting Marlin. diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 7b1faa8884cc..80b1de278bb1 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2023-12-13" + #define STRING_DISTRIBUTION_DATE "2023-12-14" #endif /**