Skip to content

Commit

Permalink
Merge branch 'bugfix-2.1.x' of github.com:MarlinFirmware/Marlin into …
Browse files Browse the repository at this point in the history
…leo_1S_S6_btt_mini
  • Loading branch information
JaxTheWolf committed Jan 8, 2024
2 parents 7e65e46 + b2dd2dc commit a0c3036
Show file tree
Hide file tree
Showing 30 changed files with 246 additions and 161 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@
* Commands to execute at the end of G29 probing.
* Useful to retract or move the Z probe out of the way.
*/
//#define Z_PROBE_END_SCRIPT "G1 Z10 F12000\nG1 X15 Y330\nG1 Z0.5\nG1 Z10"
//#define EVENT_GCODE_AFTER_G29 "G1 Z10 F12000\nG1 X15 Y330\nG1 Z0.5\nG1 Z10"

/**
* Normally G28 leaves leveling disabled on completion. Enable one of
Expand Down
2 changes: 1 addition & 1 deletion Marlin/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* here we define this default string as the date where the latest release
* version was tagged.
*/
//#define STRING_DISTRIBUTION_DATE "2024-01-06"
//#define STRING_DISTRIBUTION_DATE "2024-01-08"

/**
* Defines a generic printer name to be output to the LCD after booting Marlin.
Expand Down
58 changes: 38 additions & 20 deletions Marlin/src/HAL/ESP32/i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include <freertos/queue.h>
#include "../../module/stepper.h"

#if ENABLED(FT_MOTION)
#include "../../module/ft_motion.h"
#endif

#define DMA_BUF_COUNT 8 // number of DMA buffers to store data
#define DMA_BUF_LEN 4092 // maximum size in bytes
#define I2S_SAMPLE_SIZE 4 // 4 bytes, 32 bits per sample
Expand Down Expand Up @@ -134,8 +138,8 @@ static void IRAM_ATTR i2s_intr_handler_default(void *arg) {

if (high_priority_task_awoken == pdTRUE) portYIELD_FROM_ISR();

// clear interrupt
I2S0.int_clr.val = I2S0.int_st.val; //clear pending interrupt
// Clear pending interrupt
I2S0.int_clr.val = I2S0.int_st.val;
}

void stepperTask(void *parameter) {
Expand All @@ -148,29 +152,43 @@ void stepperTask(void *parameter) {
xQueueReceive(dma.queue, &dma.current, portMAX_DELAY);
dma.rw_pos = 0;

const bool using_ftMotion = TERN0(FT_MOTION, ftMotion.cfg.mode);

while (dma.rw_pos < DMA_SAMPLE_COUNT) {
if (!nextMainISR) {
Stepper::pulse_phase_isr();
nextMainISR = Stepper::block_phase_isr();
}
#if ENABLED(LIN_ADVANCE)
else if (!nextAdvanceISR) {
Stepper::advance_isr();
nextAdvanceISR = Stepper::la_interval;
}
#endif
else
i2s_push_sample();

nextMainISR--;
#if ENABLED(FT_MOTION)

#if ENABLED(LIN_ADVANCE)
if (nextAdvanceISR == Stepper::LA_ADV_NEVER)
nextAdvanceISR = Stepper::la_interval;
if (using_ftMotion) {
if (!nextMainISR) stepper.ftMotion_stepper();
nextMainISR = 0;
}

if (nextAdvanceISR && nextAdvanceISR != Stepper::LA_ADV_NEVER)
nextAdvanceISR--;
#endif

if (!using_ftMotion) {
if (!nextMainISR) {
Stepper::pulse_phase_isr();
nextMainISR = Stepper::block_phase_isr();
}
#if ENABLED(LIN_ADVANCE)
else if (!nextAdvanceISR) {
Stepper::advance_isr();
nextAdvanceISR = Stepper::la_interval;
}
#endif
else
i2s_push_sample();

nextMainISR--;

#if ENABLED(LIN_ADVANCE)
if (nextAdvanceISR == Stepper::LA_ADV_NEVER)
nextAdvanceISR = Stepper::la_interval;

if (nextAdvanceISR && nextAdvanceISR != Stepper::LA_ADV_NEVER)
nextAdvanceISR--;
#endif
}
}
}
}
Expand Down
111 changes: 66 additions & 45 deletions Marlin/src/HAL/STM32/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include "tft_spi.h"
#include "pinconfig.h"

//#define DEBUG_TFT_IO
#define DEBUG_OUT ENABLED(DEBUG_TFT_IO)
#include "../../../core/debug_out.h"

SPI_HandleTypeDef TFT_SPI::SPIx;
DMA_HandleTypeDef TFT_SPI::DMAtx;

Expand All @@ -43,8 +47,9 @@ void TFT_SPI::init() {
if ((spiInstance = (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK)) == NP) return;
if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI)) return;

#if PIN_EXISTS(TFT_MISO) && TFT_MISO_PIN != TFT_MOSI_PIN
if (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO)) return;
#if PIN_EXISTS(TFT_MISO)
// Check these pins in code because they are sometimes defined as analog pin references
if ((TFT_MISO_PIN != TFT_MOSI_PIN) && (spiInstance != (SPI_TypeDef *)pinmap_peripheral(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO))) return;
#endif

SPIx.Instance = spiInstance;
Expand Down Expand Up @@ -76,10 +81,13 @@ void TFT_SPI::init() {

pinmap_pinout(digitalPinToPinName(TFT_SCK_PIN), PinMap_SPI_SCLK);
pinmap_pinout(digitalPinToPinName(TFT_MOSI_PIN), PinMap_SPI_MOSI);
#if PIN_EXISTS(TFT_MISO) && TFT_MISO_PIN != TFT_MOSI_PIN
pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
#if PIN_EXISTS(TFT_MISO)
// Check these pins in code because they are sometimes defined as analog pin references
if (TFT_MISO_PIN != TFT_MOSI_PIN) pinmap_pinout(digitalPinToPinName(TFT_MISO_PIN), PinMap_SPI_MISO);
#endif

//pin_PullConfig(get_GPIO_Port(STM_PORT(digitalPinToPinName(TFT_SCK_PIN))), STM_LL_GPIO_PIN(digitalPinToPinName(TFT_SCK_PIN)), GPIO_PULLDOWN);

#ifdef SPI1_BASE
if (SPIx.Instance == SPI1) {
__HAL_RCC_SPI1_CLK_ENABLE();
Expand Down Expand Up @@ -151,29 +159,47 @@ void TFT_SPI::dataTransferBegin(uint16_t dataSize) {
WRITE(TFT_CS_PIN, LOW);
}

#ifdef TFT_DEFAULT_DRIVER
#include "../../../lcd/tft_io/tft_ids.h"
#endif
#include "../../../lcd/tft_io/tft_ids.h"

uint32_t TFT_SPI::getID() {
uint32_t id;
id = readID(LCD_READ_ID);
DEBUG_ECHOLNPGM("TFT_SPI::getID()");

uint32_t id = readID(LCD_READ_ID);
#if ENABLED(DEBUG_TFT_IO)
char debug_register[3], debug_value[5];
sprintf_P(debug_register, PSTR("%02X"), LCD_READ_ID);
sprintf_P(debug_value, PSTR("%04X"), uint16_t(id));
DEBUG_ECHOLNPGM(" readID(0x", debug_register, ") : 0x", debug_value);
#endif

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;
#if ENABLED(DEBUG_TFT_IO)
sprintf_P(debug_register, PSTR("%02X"), LCD_READ_ID4);
sprintf_P(debug_value, PSTR("%04X"), uint16_t(id));
DEBUG_ECHOLNPGM(" readID(0x", debug_register, ") : 0x", debug_value);
#endif
}
}

#ifdef TFT_DEFAULT_DRIVER
if ((id & 0xFFFF) == 0 || (id & 0xFFFF) == 0xFFFF) {
id = TFT_DEFAULT_DRIVER;
#if ENABLED(DEBUG_TFT_IO)
sprintf_P(debug_value, PSTR("%04X"), uint16_t(id));
DEBUG_ECHOLNPGM(" Fallback to TFT_DEFAULT_DRIVER : 0x", debug_value);
#endif
}
#endif

return id;
}

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

uint32_t BaudRatePrescaler = SPIx.Init.BaudRatePrescaler;
SPIx.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;

dataTransferBegin(DATASIZE_8BIT);
writeReg(inReg);

Expand All @@ -185,10 +211,8 @@ uint32_t TFT_SPI::readID(const uint16_t inReg) {
__HAL_SPI_ENABLE(&SPIx);
SET_BIT(SPIx.Instance->CR1, SPI_CR1_CSTART);

#if TFT_MISO_PIN != TFT_MOSI_PIN
SPIx.Instance->TXDR = 0;
#endif
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_EOT)) {}
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) SPIx.Instance->TXDR = 0;
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_EOT)) { /* nada */ }
data = (data << 8) | SPIx.Instance->RXDR;
__HAL_SPI_DISABLE(&SPIx);
__HAL_SPI_CLEAR_EOTFLAG(&SPIx);
Expand All @@ -197,19 +221,22 @@ uint32_t TFT_SPI::readID(const uint16_t inReg) {
#else
__HAL_SPI_ENABLE(&SPIx);
for (uint32_t i = 0; i < 4; i++) {
#if TFT_MISO_PIN != TFT_MOSI_PIN
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) {}
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) {
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) { /* nada */ }
SPIx.Instance->DR = 0;
#endif
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_RXNE)) {}
}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_RXNE)) { /* nada */ }
data = (data << 8) | SPIx.Instance->DR;
}
#endif

dataTransferEnd();
SPIx.Init.BaudRatePrescaler = oldPrescaler;
#if DISABLED(DEBUG_TFT_IO)
SPIx.Init.BaudRatePrescaler = BaudRatePrescaler;
#endif
#endif

DEBUG_ECHOLNPGM(" raw data : ", data);
return data >> 7;
}

Expand Down Expand Up @@ -238,13 +265,13 @@ bool TFT_SPI::isBusy() {
// Check if SPI data transfer is completed
if (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_EOT)) return true;
#else
// Check if SPI is idle
if (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) return true;
// Check if SPI transmit butter is empty and SPI is idle
if ((!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) || (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY))) return true;
#endif
}

abort();
return false;
return true;
}

void TFT_SPI::abort() {
Expand All @@ -263,9 +290,7 @@ void TFT_SPI::abort() {
}

void TFT_SPI::transmit(uint16_t data) {
#if TFT_MISO_PIN == TFT_MOSI_PIN
SPI_1LINE_TX(&SPIx);
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_TX(&SPIx);

#ifdef STM32H7xx
MODIFY_REG(SPIx.Instance->CR2, SPI_CR2_TSIZE, 1);
Expand All @@ -274,30 +299,26 @@ void TFT_SPI::transmit(uint16_t data) {

SPIx.Instance->TXDR = data;

while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_SR_EOT)) {}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_SR_EOT)) { /* nada */ }

__HAL_SPI_CLEAR_EOTFLAG(&SPIx);
__HAL_SPI_CLEAR_TXTFFLAG(&SPIx);
__HAL_SPI_DISABLE(&SPIx);
#else
__HAL_SPI_ENABLE(&SPIx);
SPIx.Instance->DR = data;
while (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) {}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) { /* nada */ } // Wait for data transfer to actually start
while ( __HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) { /* nada */ } // Wait until SPI is idle
#endif

__HAL_SPI_DISABLE(&SPIx);

#if TFT_MISO_PIN != TFT_MOSI_PIN
__HAL_SPI_CLEAR_OVRFLAG(&SPIx); // Clear overrun flag in 2 Lines communication mode because received data is not read
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_2LINES) __HAL_SPI_CLEAR_OVRFLAG(&SPIx); // Clear overrun flag in 2 Lines communication mode because received data is not read
}

void TFT_SPI::transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {
DMAtx.Init.MemInc = memoryIncrease;
HAL_DMA_Init(&DMAtx);

#if TFT_MISO_PIN == TFT_MOSI_PIN
SPI_1LINE_TX(&SPIx);
#endif
if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_TX(&SPIx);

dataTransferBegin();

Expand All @@ -316,17 +337,18 @@ void TFT_SPI::transmitDMA(uint32_t memoryIncrease, uint16_t *data, uint16_t coun
SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); // Enable Tx DMA Request
#endif

TERN_(TFT_SHARED_IO, while (isBusy()));
TERN_(TFT_SHARED_IO, while (isBusy()) { /* nada */ });
}

void TFT_SPI::transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count) {
transmitDMA(memoryIncrease, data, count);

HAL_DMA_PollForTransfer(&DMAtx, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY);
#ifdef STM32H7xx
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_SR_EOT)) {}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_SR_EOT)) { /* nada */ }
#else
while (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) {}
while (!__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_TXE)) { /* nada */ }
while (__HAL_SPI_GET_FLAG(&SPIx, SPI_FLAG_BSY)) { /* nada */ }
#endif
abort();
}
Expand All @@ -337,8 +359,7 @@ void TFT_SPI::transmit(uint32_t memoryIncrease, uint16_t *data, uint16_t count)
DMAtx.Init.MemInc = memoryIncrease;
HAL_DMA_Init(&DMAtx);

if (TFT_MISO_PIN == TFT_MOSI_PIN)
SPI_1LINE_TX(&SPIx);
if (SPIx.Init.Direction == SPI_DIRECTION_1LINE) SPI_1LINE_TX(&SPIx);

dataTransferBegin();

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,11 @@ void unified_bed_leveling::G29() {
ui.release();
#endif

#ifdef Z_PROBE_END_SCRIPT
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
#ifdef EVENT_GCODE_AFTER_G29
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29);
if (probe_deployed) {
planner.synchronize();
gcode.process_subcommands_now(F(Z_PROBE_END_SCRIPT));
gcode.process_subcommands_now(F(EVENT_GCODE_AFTER_G29));
}
#else
UNUSED(probe_deployed);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/bedlevel/abl/G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,10 @@ G29_TYPE GcodeSuite::G29() {

TERN_(HAS_BED_PROBE, probe.move_z_after_probing());

#ifdef Z_PROBE_END_SCRIPT
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
#ifdef EVENT_GCODE_AFTER_G29
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Z Probe End Script: ", EVENT_GCODE_AFTER_G29);
planner.synchronize();
process_subcommands_now(F(Z_PROBE_END_SCRIPT));
process_subcommands_now(F(EVENT_GCODE_AFTER_G29));
#endif

probe.use_probing_tool(false);
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ void GcodeSuite::G28() {
#endif

#ifdef XY_AFTER_HOMING
constexpr xy_pos_t xy_after XY_AFTER_HOMING;
do_blocking_move_to(xy_after);
if (!axes_should_home(_BV(X_AXIS) | _BV(Y_AXIS)))
do_blocking_move_to(xy_pos_t(XY_AFTER_HOMING));
#endif

restore_feedrate_and_scaling();
Expand Down
Loading

0 comments on commit a0c3036

Please sign in to comment.