浏览代码

SKRmini support for Fysetc Mini Panel (#14319)

Tanguy Pruvot 6 年前
父节点
当前提交
75aeb41ab7

+ 165
- 0
Marlin/src/HAL/HAL_STM32F1/u8g_com_stm32duino_swspi.cpp 查看文件

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+#ifdef __STM32F1__
20
+
21
+#include "../../inc/MarlinConfig.h"
22
+
23
+#if HAS_GRAPHICAL_LCD
24
+
25
+#include "HAL.h"
26
+#include <U8glib.h>
27
+
28
+#undef SPI_SPEED
29
+#define SPI_SPEED 0 // Fastest
30
+//#define SPI_SPEED 2 // Slower
31
+
32
+static uint8_t SPI_speed = SPI_SPEED;
33
+
34
+static inline uint8_t swSpiTransfer_mode_0(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
35
+  for (uint8_t i = 0; i < 8; i++) {
36
+    if (spi_speed == 0) {
37
+      WRITE(DOGLCD_MOSI, !!(b & 0x80));
38
+      WRITE(DOGLCD_SCK, HIGH);
39
+      b <<= 1;
40
+      if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
41
+      WRITE(DOGLCD_SCK, LOW);
42
+    }
43
+    else {
44
+      const uint8_t state = (b & 0x80) ? HIGH : LOW;
45
+      for (uint8_t j = 0; j < spi_speed; j++)
46
+        WRITE(DOGLCD_MOSI, state);
47
+
48
+      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
49
+        WRITE(DOGLCD_SCK, HIGH);
50
+
51
+      b <<= 1;
52
+      if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
53
+
54
+      for (uint8_t j = 0; j < spi_speed; j++)
55
+        WRITE(DOGLCD_SCK, LOW);
56
+    }
57
+  }
58
+  return b;
59
+}
60
+
61
+static inline uint8_t swSpiTransfer_mode_3(uint8_t b, const uint8_t spi_speed, const pin_t miso_pin=-1) {
62
+  for (uint8_t i = 0; i < 8; i++) {
63
+    const uint8_t state = (b & 0x80) ? HIGH : LOW;
64
+    if (spi_speed == 0) {
65
+      WRITE(DOGLCD_SCK, LOW);
66
+      WRITE(DOGLCD_MOSI, state);
67
+      WRITE(DOGLCD_MOSI, state);  // need some setup time
68
+      WRITE(DOGLCD_SCK, HIGH);
69
+    }
70
+    else {
71
+      for (uint8_t j = 0; j < spi_speed + (miso_pin >= 0 ? 0 : 1); j++)
72
+        WRITE(DOGLCD_SCK, LOW);
73
+
74
+      for (uint8_t j = 0; j < spi_speed; j++)
75
+        WRITE(DOGLCD_MOSI, state);
76
+
77
+      for (uint8_t j = 0; j < spi_speed; j++)
78
+        WRITE(DOGLCD_SCK, HIGH);
79
+    }
80
+    b <<= 1;
81
+    if (miso_pin >= 0 && READ(miso_pin)) b |= 1;
82
+  }
83
+  return b;
84
+}
85
+
86
+static void u8g_sw_spi_HAL_STM32F1_shift_out(uint8_t val) {
87
+  #if ENABLED(FYSETC_MINI_12864)
88
+    swSpiTransfer_mode_3(val, SPI_speed);
89
+  #else
90
+    swSpiTransfer_mode_0(val, SPI_speed);
91
+  #endif
92
+}
93
+
94
+static uint8_t swSpiInit(const uint8_t spi_speed) {
95
+  #if PIN_EXISTS(LCD_RESET)
96
+    SET_OUTPUT(LCD_RESET_PIN);
97
+  #endif
98
+  SET_OUTPUT(DOGLCD_A0);
99
+  OUT_WRITE(DOGLCD_SCK, LOW);
100
+  OUT_WRITE(DOGLCD_MOSI, LOW);
101
+  OUT_WRITE(DOGLCD_CS, HIGH);
102
+  return spi_speed;
103
+}
104
+
105
+uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
106
+  switch (msg) {
107
+    case U8G_COM_MSG_INIT:
108
+      SPI_speed = swSpiInit(SPI_SPEED);
109
+      break;
110
+
111
+    case U8G_COM_MSG_STOP:
112
+      break;
113
+
114
+    case U8G_COM_MSG_RESET:
115
+      #if PIN_EXISTS(LCD_RESET)
116
+        WRITE(LCD_RESET_PIN, arg_val);
117
+      #endif
118
+      break;
119
+
120
+    case U8G_COM_MSG_CHIP_SELECT:
121
+      #if ENABLED(FYSETC_MINI_12864) // This LCD SPI is running mode 3 while SD card is running mode 0
122
+        if (arg_val) {               // SCK idle state needs to be set to the proper idle state before
123
+                                     // the next chip select goes active
124
+          WRITE(DOGLCD_SCK, HIGH);   // Set SCK to mode 3 idle state before CS goes active
125
+          WRITE(DOGLCD_CS, LOW);
126
+        }
127
+        else {
128
+          WRITE(DOGLCD_CS, HIGH);
129
+          WRITE(DOGLCD_SCK, LOW);  // Set SCK to mode 0 idle state after CS goes inactive
130
+        }
131
+      #else
132
+        WRITE(DOGLCD_CS, !arg_val);
133
+      #endif
134
+      break;
135
+
136
+    case U8G_COM_MSG_WRITE_BYTE:
137
+      u8g_sw_spi_HAL_STM32F1_shift_out(arg_val);
138
+      break;
139
+
140
+    case U8G_COM_MSG_WRITE_SEQ: {
141
+      uint8_t *ptr = (uint8_t *)arg_ptr;
142
+      while (arg_val > 0) {
143
+        u8g_sw_spi_HAL_STM32F1_shift_out(*ptr++);
144
+        arg_val--;
145
+      }
146
+    } break;
147
+
148
+    case U8G_COM_MSG_WRITE_SEQ_P: {
149
+      uint8_t *ptr = (uint8_t *)arg_ptr;
150
+      while (arg_val > 0) {
151
+        u8g_sw_spi_HAL_STM32F1_shift_out(u8g_pgm_read(ptr));
152
+        ptr++;
153
+        arg_val--;
154
+      }
155
+    } break;
156
+
157
+    case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
158
+      WRITE(DOGLCD_A0, arg_val);
159
+      break;
160
+  }
161
+  return 1;
162
+}
163
+
164
+#endif // HAS_GRAPHICAL_LCD
165
+#endif // STM32F1

+ 3
- 6
Marlin/src/inc/Conditionals_LCD.h 查看文件

46
   #define ADC_KEY_NUM 8
46
   #define ADC_KEY_NUM 8
47
   #define ULTIPANEL
47
   #define ULTIPANEL
48
 
48
 
49
-  // this helps to implement ADC_KEYPAD menus
49
+  // This helps to implement ADC_KEYPAD menus
50
   #define REVERSE_MENU_DIRECTION
50
   #define REVERSE_MENU_DIRECTION
51
   #define ENCODER_PULSES_PER_STEP 1
51
   #define ENCODER_PULSES_PER_STEP 1
52
   #define ENCODER_STEPS_PER_MENU_ITEM 1
52
   #define ENCODER_STEPS_PER_MENU_ITEM 1
97
 
97
 
98
   #define U8GLIB_SSD1306
98
   #define U8GLIB_SSD1306
99
   #define ULTIPANEL
99
   #define ULTIPANEL
100
-  #define REVERSE_ENCODER_DIRECTION
101
-  #define REVERSE_MENU_DIRECTION
102
 
100
 
103
 #elif ENABLED(RA_CONTROL_PANEL)
101
 #elif ENABLED(RA_CONTROL_PANEL)
104
 
102
 
141
   #define DEFAULT_LCD_CONTRAST 150
139
   #define DEFAULT_LCD_CONTRAST 150
142
   #define LCD_CONTRAST_MAX 255
140
   #define LCD_CONTRAST_MAX 255
143
 
141
 
144
-#elif ANY(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
142
+#elif ANY(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
145
 
143
 
146
   #define FYSETC_MINI_12864
144
   #define FYSETC_MINI_12864
147
   #define DOGLCD
145
   #define DOGLCD
148
   #define ULTIPANEL
146
   #define ULTIPANEL
149
   #define LCD_CONTRAST_MIN 0
147
   #define LCD_CONTRAST_MIN 0
150
   #define LCD_CONTRAST_MAX 255
148
   #define LCD_CONTRAST_MAX 255
151
-  #define DEFAULT_LCD_CONTRAST 255
149
+  #define DEFAULT_LCD_CONTRAST 220
152
   #define LED_COLORS_REDUCE_GREEN
150
   #define LED_COLORS_REDUCE_GREEN
153
   #if POWER_SUPPLY > 0 && EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
151
   #if POWER_SUPPLY > 0 && EITHER(FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1)
154
     #define LED_BACKLIGHT_TIMEOUT 10000
152
     #define LED_BACKLIGHT_TIMEOUT 10000
181
 
179
 
182
 #if ENABLED(ULTI_CONTROLLER)
180
 #if ENABLED(ULTI_CONTROLLER)
183
   #define U8GLIB_SSD1309
181
   #define U8GLIB_SSD1309
184
-  #define REVERSE_ENCODER_DIRECTION
185
   #define LCD_RESET_PIN LCD_PINS_D6 //  This controller need a reset pin
182
   #define LCD_RESET_PIN LCD_PINS_D6 //  This controller need a reset pin
186
   #define LCD_CONTRAST_MIN 0
183
   #define LCD_CONTRAST_MIN 0
187
   #define LCD_CONTRAST_MAX 254
184
   #define LCD_CONTRAST_MAX 254

+ 1
- 0
Marlin/src/inc/SanityCheck.h 查看文件

1841
   + ENABLED(G3D_PANEL) \
1841
   + ENABLED(G3D_PANEL) \
1842
   + (ENABLED(MINIPANEL) && DISABLED(MKS_MINI_12864)) \
1842
   + (ENABLED(MINIPANEL) && DISABLED(MKS_MINI_12864)) \
1843
   + ENABLED(MKS_MINI_12864) \
1843
   + ENABLED(MKS_MINI_12864) \
1844
+  + ENABLED(FYSETC_MINI_12864_X_X) \
1844
   + ENABLED(FYSETC_MINI_12864_1_2) \
1845
   + ENABLED(FYSETC_MINI_12864_1_2) \
1845
   + ENABLED(FYSETC_MINI_12864_2_0) \
1846
   + ENABLED(FYSETC_MINI_12864_2_0) \
1846
   + ENABLED(FYSETC_MINI_12864_2_1) \
1847
   + ENABLED(FYSETC_MINI_12864_2_1) \

+ 8
- 5
Marlin/src/lcd/dogm/HAL_LCD_com_defines.h 查看文件

28
   #ifdef __SAM3X8E__
28
   #ifdef __SAM3X8E__
29
     uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
29
     uint8_t u8g_com_HAL_DUE_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
30
     #define U8G_COM_HAL_SW_SPI_FN  u8g_com_HAL_DUE_sw_spi_fn
30
     #define U8G_COM_HAL_SW_SPI_FN  u8g_com_HAL_DUE_sw_spi_fn
31
-
32
     uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
31
     uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
33
     #define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_DUE_shared_hw_spi_fn
32
     #define U8G_COM_HAL_HW_SPI_FN u8g_com_HAL_DUE_shared_hw_spi_fn
34
-
35
     uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
33
     uint8_t u8g_com_HAL_DUE_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
36
     #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_DUE_ST7920_sw_spi_fn
34
     #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_HAL_DUE_ST7920_sw_spi_fn
35
+  #elif defined(__STM32F1__)
36
+    uint8_t u8g_com_HAL_STM32F1_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
37
+    #define U8G_COM_HAL_SW_SPI_FN u8g_com_HAL_STM32F1_sw_spi_fn
38
+    uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
39
+    #define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
40
+    uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
41
+    #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
37
   #else
42
   #else
38
     uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
43
     uint8_t u8g_com_HAL_AVR_sw_sp_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
39
-    #define U8G_COM_HAL_SW_SPI_FN  u8g_com_HAL_AVR_sw_sp_fn
40
-
44
+    #define U8G_COM_HAL_SW_SPI_FN  u8g_com_HAL_AVR_sw_sp_fn // AVR ?
41
     uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
45
     uint8_t u8g_com_arduino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
42
     #define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
46
     #define U8G_COM_HAL_HW_SPI_FN u8g_com_arduino_hw_spi_fn
43
-
44
     uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
47
     uint8_t u8g_com_arduino_st7920_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
45
     #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
48
     #define U8G_COM_ST7920_HAL_SW_SPI u8g_com_arduino_st7920_spi_fn
46
   #endif
49
   #endif

+ 1
- 1
Marlin/src/lcd/dogm/u8g_dev_tft_320x240_upscale_from_128x64.cpp 查看文件

57
 
57
 
58
 #include "../../inc/MarlinConfig.h"
58
 #include "../../inc/MarlinConfig.h"
59
 
59
 
60
-#if HAS_GRAPHICAL_LCD
60
+#if HAS_GRAPHICAL_LCD && PIN_EXISTS(FSMC_CS)
61
 
61
 
62
 #include "U8glib.h"
62
 #include "U8glib.h"
63
 #include "HAL_LCD_com_defines.h"
63
 #include "HAL_LCD_com_defines.h"

+ 42
- 10
Marlin/src/pins/pins_BIGTREE_SKR_MINI_V1_1.h 查看文件

28
   #define BOARD_NAME "BIGTREE SKR mini V1.1"
28
   #define BOARD_NAME "BIGTREE SKR mini V1.1"
29
 #endif
29
 #endif
30
 
30
 
31
-  //#define DISABLE_DEBUG
32
-  #define DISABLE_JTAG
31
+//#define DISABLE_DEBUG
32
+#define DISABLE_JTAG
33
 
33
 
34
 // Ignore temp readings during develpment.
34
 // Ignore temp readings during develpment.
35
 //#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
35
 //#define BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
98
  *  (MOSI)   PB5 | · · | PB8 (BTN_EN2)               (LCD_D5)  PB7 | · · | PC13 (LCD_D4)
98
  *  (MOSI)   PB5 | · · | PB8 (BTN_EN2)               (LCD_D5)  PB7 | · · | PC13 (LCD_D4)
99
  * (SD_SS)  PA15 | · · | PD2 (BTN_EN1)               (LCD_RS) PC12 | · · | PB6  (LCD_EN)
99
  * (SD_SS)  PA15 | · · | PD2 (BTN_EN1)               (LCD_RS) PC12 | · · | PB6  (LCD_EN)
100
  *   (SCK)   PB3 | · · | PB4 (MISO)                 (BTN_ENC) PC11 | · · | PC10 (BEEPER)
100
  *   (SCK)   PB3 | · · | PB4 (MISO)                 (BTN_ENC) PC11 | · · | PC10 (BEEPER)
101
- *                 ̄ ̄ ̄                                              ̄ ̄ ̄
101
+ *                -----                                             -----
102
  *                EXP2                                              EXP1
102
  *                EXP2                                              EXP1
103
  */
103
  */
104
 
104
 
105
 #if ENABLED(ULTRA_LCD)
105
 #if ENABLED(ULTRA_LCD)
106
-
107
   #define BEEPER_PIN       PC10
106
   #define BEEPER_PIN       PC10
108
   #define BTN_ENC          PC11
107
   #define BTN_ENC          PC11
109
   #define LCD_PINS_RS      PC12
108
   #define LCD_PINS_RS      PC12
112
   #define BTN_EN2          PB8
111
   #define BTN_EN2          PB8
113
 
112
 
114
   #define LCD_PINS_ENABLE  PB6
113
   #define LCD_PINS_ENABLE  PB6
115
-  #define LCD_PINS_D4      PC13
116
 
114
 
117
-  #if ENABLED(ULTIPANEL)
118
-    #define LCD_PINS_D5    PB7
119
-    #define LCD_PINS_D6    PC15
120
-    #define LCD_PINS_D7    PC14
121
-  #endif
115
+  #if ENABLED(FYSETC_MINI_12864)
116
+
117
+    #define LCD_BACKLIGHT_PIN -1
118
+    #define LCD_RESET_PIN  PC13
119
+    #define DOGLCD_A0      PC12
120
+    #define DOGLCD_CS      PB6
121
+    #define DOGLCD_SCK     PB3
122
+    #define DOGLCD_MOSI    PB5
123
+
124
+    #define FORCE_SOFT_SPI   // SPI MODE3
125
+
126
+    #define LED_PIN        PB7   // red pwm
127
+    //#define LED_PIN        PC15   // green
128
+    //#define LED_PIN        PC14   // blue
129
+
130
+    //#if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0)
131
+    //  #ifndef RGB_LED_R_PIN
132
+    //    #define RGB_LED_R_PIN PB7
133
+    //  #endif
134
+    //  #ifndef RGB_LED_G_PIN
135
+    //    #define RGB_LED_G_PIN PC15
136
+    //  #endif
137
+    //  #ifndef RGB_LED_B_PIN
138
+    //    #define RGB_LED_B_PIN PC14
139
+    //  #endif
140
+    //#elif ENABLED(FYSETC_MINI_12864_2_1)
141
+    //  #define NEOPIXEL_PIN    PB7
142
+    //#endif
143
+
144
+  #else // !FYSETC_MINI_12864
145
+
146
+    #define LCD_PINS_D4    PC13
147
+    #if ENABLED(ULTIPANEL)
148
+      #define LCD_PINS_D5  PB7
149
+      #define LCD_PINS_D6  PC15
150
+      #define LCD_PINS_D7  PC14
151
+    #endif
152
+
153
+  #endif // !FYSETC_MINI_12864
122
 
154
 
123
 #endif // ULTRA_LCD
155
 #endif // ULTRA_LCD
124
 
156
 

正在加载...
取消
保存