Skip to content

Commit

Permalink
Merge branch 'bugfix-2.0.x' into PR/STM32_1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
sjasonsmith committed Aug 13, 2020
2 parents e93e6bd + ff5c8d3 commit 09d65b9
Show file tree
Hide file tree
Showing 79 changed files with 1,444 additions and 1,065 deletions.
31 changes: 31 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,37 @@
*/
//#define PRINTCOUNTER

/**
* Password
*
* Set a numerical password for the printer which can be requested:
*
* - When the printer boots up
* - Upon opening the 'Print from Media' Menu
* - When SD printing is completed or aborted
*
* The following G-codes can be used:
*
* M510 - Lock Printer. Blocks all commands except M511.
* M511 - Unlock Printer.
* M512 - Set, Change and Remove Password.
*
* If you forget the password and get locked out you'll need to re-flash
* the firmware with the feature disabled, reset EEPROM, and (optionally)
* re-flash the firmware again with this feature enabled.
*/
//#define PASSWORD_FEATURE
#if ENABLED(PASSWORD_FEATURE)
#define PASSWORD_LENGTH 4 // (#) Number of digits (1-9). 3 or 4 is recommended
#define PASSWORD_ON_STARTUP
#define PASSWORD_UNLOCK_GCODE // Unlock with the M511 P<password> command. Disable to prevent brute-force attack.
#define PASSWORD_CHANGE_GCODE // Change the password with M512 P<old> N<new>.
//#define PASSWORD_ON_SD_PRINT_MENU // This does not prevent gcodes from running
//#define PASSWORD_AFTER_SD_PRINT_END
//#define PASSWORD_AFTER_SD_PRINT_ABORT
//#include "Configuration_Secure.h" // External file with PASSWORD_DEFAULT_VALUE
#endif

//=============================================================================
//============================= LCD and SD support ============================
//=============================================================================
Expand Down
4 changes: 2 additions & 2 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@
// @section lcd

#if EITHER(ULTIPANEL, EXTENSIBLE_UI)
#define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // Feedrates for manual moves along X, Y, Z, E from panel
#define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // (mm/m) Feedrates for manual moves along X, Y, Z, E from panel
#define SHORT_MANUAL_Z_MOVE 0.025 // (mm) Smallest manual Z move (< 0.1mm)
#if ENABLED(ULTIPANEL)
#define MANUAL_E_MOVES_RELATIVE // Display extruder move distance rather than "position"
Expand Down Expand Up @@ -1137,7 +1137,7 @@

//#define MENU_ADDAUTOSTART // Add a menu option to run auto#.g files

#define EVENT_GCODE_SD_STOP "G28XY" // G-code to run on Stop Print (e.g., "G28XY" or "G27")
#define EVENT_GCODE_SD_ABORT "G28XY" // G-code to run on SD Abort Print (e.g., "G28XY" or "G27")

#if ENABLED(PRINTER_EVENT_LEDS)
#define PE_LEDS_COMPLETED_TIME (30*60) // (seconds) Time to keep the LED "done" color before restoring normal illumination
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/HAL/STM32F1/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
#undef SD_CHECK_AND_RETRY
#endif

#if HAS_SPI_TFT
#error "Sorry! SPI TFT displays are not available for HAL/STM32F1 (yet)."
#endif

// This platform has 'touch/xpt2046', not 'tft/xpt2046'
#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT
#if ENABLED(TOUCH_SCREEN) && !HAS_FSMC_TFT && !HAS_SPI_TFT
#undef TOUCH_SCREEN
#undef TOUCH_SCREEN_CALIBRATION
#define HAS_TOUCH_XPT2046 1
Expand Down
18 changes: 10 additions & 8 deletions Marlin/src/HAL/STM32F1/tft/tft_fsmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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

#if HAS_FSMC_TFT
#if HAS_FSMC_TFT || ENABLED(TFT_LVGL_UI_FSMC)

#include "tft_fsmc.h"
#include <libmaple/fsmc.h>
Expand Down Expand Up @@ -224,13 +224,15 @@ void TFT_FSMC::Abort() {
}

void TFT_FSMC::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease);
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count);
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);

while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
#if defined(FSMC_DMA_DEV) && defined(FSMC_DMA_CHANNEL)
dma_setup_transfer(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Data, DMA_SIZE_16BITS, &LCD->RAM, DMA_SIZE_16BITS, DMA_MEM_2_MEM | MemoryIncrease);
dma_set_num_transfers(FSMC_DMA_DEV, FSMC_DMA_CHANNEL, Count);
dma_clear_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
dma_enable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);

while ((dma_get_isr_bits(FSMC_DMA_DEV, FSMC_DMA_CHANNEL) & 0x0A) == 0) {};
dma_disable(FSMC_DMA_DEV, FSMC_DMA_CHANNEL);
#endif
}

#endif // HAS_FSMC_TFT
7 changes: 7 additions & 0 deletions Marlin/src/HAL/STM32F1/tft/tft_fsmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ class TFT_FSMC {

static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_PINC_MODE, Data, Count); }
static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_CIRC_MODE, &Data, Count); }
static void WriteMultiple(uint16_t Color, uint32_t Count) {
static uint16_t Data; Data = Color;
while (Count > 0) {
TransmitDMA(DMA_CIRC_MODE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
}
}
};
149 changes: 149 additions & 0 deletions Marlin/src/HAL/STM32F1/tft/tft_spi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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 <https://www.gnu.org/licenses/>.
*
*/

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

#if HAS_SPI_TFT || ENABLED(TFT_LVGL_UI_SPI)

#include "tft_spi.h"

// TFT_SPI tft;

SPIClass TFT_SPI::SPIx(1);

#define SPI_TFT_CS_H OUT_WRITE(TFT_CS_PIN, HIGH)
#define SPI_TFT_CS_L OUT_WRITE(TFT_CS_PIN, LOW)

#define SPI_TFT_DC_H OUT_WRITE(TFT_DC_PIN, HIGH)
#define SPI_TFT_DC_L OUT_WRITE(TFT_DC_PIN, LOW)

#define SPI_TFT_RST_H OUT_WRITE(TFT_RST_PIN, HIGH)
#define SPI_TFT_RST_L OUT_WRITE(TFT_RST_PIN, LOW)

#define SPI_TFT_BLK_H OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH)
#define SPI_TFT_BLK_L OUT_WRITE(TFT_BACKLIGHT_PIN, LOW)

void TFT_SPI::Init() {
#if PIN_EXISTS(TFT_RESET)
// OUT_WRITE(TFT_RESET_PIN, HIGH);
SPI_TFT_RST_H;
delay(100);
#endif

#if PIN_EXISTS(TFT_BACKLIGHT)
// OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
SPI_TFT_BLK_H;
#endif

SPI_TFT_DC_H;
SPI_TFT_CS_H;

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

void TFT_SPI::DataTransferBegin(uint16_t DataSize) {
SPIx.setDataSize(DataSize);
SPIx.begin();
SPI_TFT_CS_L;
}

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);
return id;
}

uint32_t TFT_SPI::ReadID(uint16_t Reg) {
#if !PIN_EXISTS(TFT_MISO)
return 0;
#else
uint8_t d = 0;
uint32_t data = 0;
SPIx.setClockDivider(SPI_CLOCK_DIV16);
DataTransferBegin(DATASIZE_8BIT);
WriteReg(Reg);

LOOP_L_N(i, 4) {
SPIx.read((uint8_t*)&d, 1);
data = (data << 8) | d;
}

DataTransferEnd();
SPIx.setClockDivider(SPI_CLOCK_MAX);

return data >> 7;
#endif
}

bool TFT_SPI::isBusy() {
return false;
}

void TFT_SPI::Abort() {
DataTransferEnd();
}

void TFT_SPI::Transmit(uint16_t Data) {
SPIx.send(Data);
}

void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) {
DataTransferBegin();
SPI_TFT_DC_H;
if (MemoryIncrease == DMA_MINC_ENABLE) {
SPIx.dmaSend(Data, Count, true);
}
else {
SPIx.dmaSend(Data, Count, false);
}

DataTransferEnd();
}

#endif // HAS_SPI_TFT
72 changes: 72 additions & 0 deletions Marlin/src/HAL/STM32F1/tft/tft_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* 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 <https://www.gnu.org/licenses/>.
*
*/
#pragma once

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

#include <SPI.h>

#ifndef LCD_READ_ID
#define LCD_READ_ID 0x04 // Read display identification information (0xD3 on ILI9341)
#endif
#ifndef LCD_READ_ID4
#define LCD_READ_ID4 0xD3 // Read display identification information (0xD3 on ILI9341)
#endif

#define DATASIZE_8BIT DATA_SIZE_8BIT
#define DATASIZE_16BIT DATA_SIZE_16BIT
#define TFT_IO TFT_SPI

#define DMA_MINC_ENABLE 1
#define DMA_MINC_DISABLE 0

class TFT_SPI {
private:
static uint32_t ReadID(uint16_t Reg);
static void Transmit(uint16_t Data);
static void TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count);

public:
static SPIClass SPIx;

static void Init();
static uint32_t GetID();
static bool isBusy();
static void Abort();

static void DataTransferBegin(uint16_t DataWidth = DATA_SIZE_16BIT);
static void DataTransferEnd() { WRITE(TFT_CS_PIN, HIGH); SPIx.end(); };
static void DataTransferAbort();

static void WriteData(uint16_t Data) { Transmit(Data); }
static void WriteReg(uint16_t Reg) { WRITE(TFT_A0_PIN, LOW); Transmit(Reg); WRITE(TFT_A0_PIN, HIGH); }

static void WriteSequence(uint16_t *Data, uint16_t Count) { TransmitDMA(DMA_MINC_ENABLE, Data, Count); }
static void WriteMultiple(uint16_t Color, uint16_t Count) { static uint16_t Data; Data = Color; TransmitDMA(DMA_MINC_DISABLE, &Data, Count); }
static void WriteMultiple(uint16_t Color, uint32_t Count) {
static uint16_t Data; Data = Color;
while (Count > 0) {
TransmitDMA(DMA_MINC_DISABLE, &Data, Count > 0xFFFF ? 0xFFFF : Count);
Count = Count > 0xFFFF ? Count - 0xFFFF : 0;
}
}
};
10 changes: 4 additions & 6 deletions Marlin/src/HAL/STM32F1/tft/xpt2046.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ void XPT2046::Init() {
SET_INPUT(TOUCH_INT_PIN);
#endif

#if ENABLED(TOUCH_BUTTONS_HW_SPI)
touch_spi_init(SPI_SPEED_6);
#endif
TERN_(TOUCH_BUTTONS_HW_SPI, touch_spi_init(SPI_SPEED_6));

// Read once to enable pendrive status pin
getRawData(XPT2046_X);
Expand Down Expand Up @@ -95,12 +93,14 @@ uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
uint16_t data[3];

DataTransferBegin();
TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.begin());

for (uint16_t i = 0; i < 3 ; i++) {
IO(coordinate);
data[i] = (IO() << 4) | (IO() >> 4);
}

TERN_(TOUCH_BUTTONS_HW_SPI, SPIx.end());
DataTransferEnd();

uint16_t delta01 = delta(data[0], data[1]),
Expand All @@ -114,14 +114,12 @@ uint16_t XPT2046::getRawData(const XPTCoordinate coordinate) {
}

uint16_t XPT2046::IO(uint16_t data) {
TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data);
return TERN(TOUCH_BUTTONS_HW_SPI, HardwareIO, SoftwareIO)(data);
}

#if ENABLED(TOUCH_BUTTONS_HW_SPI)
uint16_t XPT2046::HardwareIO(uint16_t data) {
SPIx.begin();
uint16_t result = SPIx.transfer(data);
SPIx.end();
return result;
}
#endif
Expand Down
Loading

0 comments on commit 09d65b9

Please sign in to comment.