SKRmini support for Fysetc Mini Panel (#14319)

This commit is contained in:
Tanguy Pruvot 2019-06-19 02:34:16 +02:00 committed by Scott Lahteine
parent bf64dd4db6
commit 75aeb41ab7
6 changed files with 222 additions and 24 deletions

View File

@ -0,0 +1,165 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* 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 <http://www.gnu.org/licenses/>.
*
*/
#ifdef __STM32F1__
#include "../../inc/MarlinConfig.h"
#if HAS_GRAPHICAL_LCD
#include "HAL.h"
#include <U8glib.h>
#undef SPI_SPEED
#define SPI_SPEED 0 // Fastest
//#define SPI_SPEED 2 // Slower
static uint8_t SPI_speed = SPI_SPEED;
static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
if (spi_speed == 0) {
WRITE(DOGLCD_MOSI, !!(b & 0x80));
WRITE(DOGLCD_SCK, HIGH);
b <<= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
WRITE(DOGLCD_SCK, LOW);
}
else {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
WRITE(DOGLCD_SCK, HIGH);
b <<= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(DOGLCD_SCK, LOW);
}
}
return b;
}
static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
for (uint8_t i = 0; i < 8; i++) {
const uint8_t state = (b & 0x80) ? HIGH : LOW;
if (spi_speed == 0) {
WRITE(DOGLCD_SCK, LOW);
WRITE(DOGLCD_MOSI, state);
WRITE(DOGLCD_MOSI, state); // need some setup time
WRITE(DOGLCD_SCK, HIGH);
}
else {
for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
WRITE(DOGLCD_SCK, LOW);
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(DOGLCD_MOSI, state);
for (uint8_t j = 0; j < spi_speed; j++)
WRITE(DOGLCD_SCK, HIGH);
}
b <<= 1;
if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
}
return b;
}
static void u8g_sw_spi_HAL_STM32F1_shift_out(uint8_t val) {
#if ENABLED(FYSETC_MINI_12864)
swSpiTransfer_mode_3(val, SPI_speed);
#else
swSpiTransfer_mode_0(val, SPI_speed);
#endif
}
static uint8_t swSpiInit(const uint8_t spi_speed) {
#if PIN_EXISTS(LCD_RESET)
SET_OUTPUT(LCD_RESET_PIN);
#endif
SET_OUTPUT(DOGLCD_A0);
OUT_WRITE(DOGLCD_SCK, LOW);
OUT_WRITE(DOGLCD_MOSI, LOW);
OUT_WRITE(DOGLCD_CS, HIGH);
return spi_speed;
}
uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
switch (msg) {
case U8G_COM_MSG_INIT:
SPI_speed = swSpiInit(SPI_SPEED);
break;
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_RESET:
#if PIN_EXISTS(LCD_RESET)
WRITE(LCD_RESET_PIN, arg_val);
#endif
break;
case U8G_COM_MSG_CHIP_SELECT:
#if ENABLED(FYSETC_MINI_12864) // This LCD SPI is running mode 3 while SD card is running mode 0
if (arg_val) { // SCK idle state needs to be set to the proper idle state before
// the next chip select goes active
WRITE(DOGLCD_SCK, HIGH); // Set SCK to mode 3 idle state before CS goes active
WRITE(DOGLCD_CS, LOW);
}
else {
WRITE(DOGLCD_CS, HIGH);
WRITE(DOGLCD_SCK, LOW); // Set SCK to mode 0 idle state after CS goes inactive
}
#else
WRITE(DOGLCD_CS, !arg_val);
#endif
break;
case U8G_COM_MSG_WRITE_BYTE:
u8g_sw_spi_HAL_STM32F1_shift_out(arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ: {
uint8_t *ptr = (uint8_t *)arg_ptr;
while (arg_val > 0) {
u8g_sw_spi_HAL_STM32F1_shift_out(*ptr++);
arg_val--;
}
} break;
case U8G_COM_MSG_WRITE_SEQ_P: {
uint8_t *ptr = (uint8_t *)arg_ptr;
while (arg_val > 0) {
u8g_sw_spi_HAL_STM32F1_shift_out(u8g_pgm_read(ptr));
ptr++;
arg_val--;
}
} break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
WRITE(DOGLCD_A0, arg_val);
break;
}
return 1;
}
#endif // HAS_GRAPHICAL_LCD
#endif // STM32F1

View File

@ -46,7 +46,7 @@
#define ADC_KEY_NUM 8
#define ULTIPANEL
// this helps to implement ADC_KEYPAD menus
// This helps to implement ADC_KEYPAD menus
#define REVERSE_MENU_DIRECTION
#define ENCODER_PULSES_PER_STEP 1
#define ENCODER_STEPS_PER_MENU_ITEM 1
@ -97,8 +97,6 @@
#define U8GLIB_SSD1306
#define ULTIPANEL
#define REVERSE_ENCODER_DIRECTION
#define REVERSE_MENU_DIRECTION
#elif ENABLED(RA_CONTROL_PANEL)
@ -141,14 +139,14 @@
#define DEFAULT_LCD_CONTRAST 150
#define LCD_CONTRAST_MAX 255
#elif ANY(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
#elif ANY(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
#define FYSETC_MINI_12864
#define DOGLCD
#define ULTIPANEL
#define LCD_CONTRAST_MIN 0
#define LCD_CONTRAST_MAX 255
#define DEFAULT_LCD_CONTRAST 255
#define DEFAULT_LCD_CONTRAST 220
#define LED_COLORS_REDUCE_GREEN
#if POWER_SUPPLY > 0 && EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
#define LED_BACKLIGHT_TIMEOUT 10000
@ -181,7 +179,6 @@
#if ENABLED(ULTI_CONTROLLER)
#define U8GLIB_SSD1309
#define REVERSE_ENCODER_DIRECTION
#define LCD_RESET_PIN LCD_PINS_D6 // This controller need a reset pin
#define LCD_CONTRAST_MIN 0
#define LCD_CONTRAST_MAX 254

View File

@ -1841,6 +1841,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
+ ENABLED(G3D_PANEL) \
+ (ENABLED(MINIPANEL) && DISABLED(MKS_MINI_12864)) \
+ ENABLED(MKS_MINI_12864) \
+ ENABLED(FYSETC_MINI_12864_X_X) \
+ ENABLED(FYSETC_MINI_12864_1_2) \
+ ENABLED(FYSETC_MINI_12864_2_0) \
+ ENABLED(FYSETC_MINI_12864_2_1) \

View File

@ -28,19 +28,22 @@
#ifdef __SAM3X8E__
uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_DUE_sw_spi_fn
uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_DUE_shared_hw_spi_fn
uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_DUE_ST7920_sw_spi_fn
#else
uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_AVR_sw_sp_fn
#elif defined(__STM32F1__)
uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_STM32F1_sw_spi_fn
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
#else
uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_AVR_sw_sp_fn // AVR ?
uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
#endif

View File

@ -57,7 +57,7 @@
#include "../../inc/MarlinConfig.h"
#if HAS_GRAPHICAL_LCD
#if HAS_GRAPHICAL_LCD && PIN_EXISTS(FSMC_CS)
#include "U8glib.h"
#include "HAL_LCD_com_defines.h"

View File

@ -28,8 +28,8 @@
#define BOARD_NAME "BIGTREE SKR mini V1.1"
#endif
//#define DISABLE_DEBUG
#define DISABLE_JTAG
//#define DISABLE_DEBUG
#define DISABLE_JTAG
// Ignore temp readings during develpment.
//#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
@ -98,12 +98,11 @@
* (MOSI) PB5 | · · | PB8 (BTN_EN2) (LCD_D5) PB7 | · · | PC13 (LCD_D4)
* (SD_SS) PA15 | · · | PD2 (BTN_EN1) (LCD_RS) PC12 | · · | PB6 (LCD_EN)
* (SCK) PB3 | · · | PB4 (MISO) (BTN_ENC) PC11 | · · | PC10 (BEEPER)
*
* ----- -----
* EXP2 EXP1
*/
#if ENABLED(ULTRA_LCD)
#define BEEPER_PIN PC10
#define BTN_ENC PC11
#define LCD_PINS_RS PC12
@ -112,13 +111,46 @@
#define BTN_EN2 PB8
#define LCD_PINS_ENABLE PB6
#define LCD_PINS_D4 PC13
#if ENABLED(ULTIPANEL)
#define LCD_PINS_D5 PB7
#define LCD_PINS_D6 PC15
#define LCD_PINS_D7 PC14
#endif
#if ENABLED(FYSETC_MINI_12864)
#define LCD_BACKLIGHT_PIN -1
#define LCD_RESET_PIN PC13
#define DOGLCD_A0 PC12
#define DOGLCD_CS PB6
#define DOGLCD_SCK PB3
#define DOGLCD_MOSI PB5
#define FORCE_SOFT_SPI // SPI MODE3
#define LED_PIN PB7 // red pwm
//#define LED_PIN PC15 // green
//#define LED_PIN PC14 // blue
//#if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)
// #ifndef RGB_LED_R_PIN
// #define RGB_LED_R_PIN PB7
// #endif
// #ifndef RGB_LED_G_PIN
// #define RGB_LED_G_PIN PC15
// #endif
// #ifndef RGB_LED_B_PIN
// #define RGB_LED_B_PIN PC14
// #endif
//#elif ENABLED(FYSETC_MINI_12864_2_1)
// #define NEOPIXEL_PIN PB7
//#endif
#else // !FYSETC_MINI_12864
#define LCD_PINS_D4 PC13
#if ENABLED(ULTIPANEL)
#define LCD_PINS_D5 PB7
#define LCD_PINS_D6 PC15
#define LCD_PINS_D7 PC14
#endif
#endif // !FYSETC_MINI_12864
#endif // ULTRA_LCD