Skip to content

Commit c1a533b

Browse files
authoredAug 8, 2021
📌 MKS pins for PSU_CONTROL (#22528)
1 parent 0f3e938 commit c1a533b

14 files changed

+179
-54
lines changed
 

‎Marlin/src/gcode/lcd/M995.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "../gcode.h"
2828

29-
#if ENABLED(TFT_LVGL_UI)
29+
#if HAS_TFT_LVGL_UI
3030
#include "../../lcd/extui/mks_ui/draw_touch_calibration.h"
3131
#else
3232
#include "../../lcd/menu/menu.h"
@@ -37,7 +37,7 @@
3737
*/
3838
void GcodeSuite::M995() {
3939

40-
#if ENABLED(TFT_LVGL_UI)
40+
#if HAS_TFT_LVGL_UI
4141
lv_draw_touch_calibration_screen();
4242
#else
4343
ui.goto_screen(touch_screen_calibration);

‎Marlin/src/pins/lpc1768/pins_MKS_SBASE.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@
136136
#endif
137137

138138
//
139-
// Misc. Functions
139+
// Power Supply Control
140140
//
141-
#define PS_ON_PIN P0_25 // TH3 Connector
141+
#if ENABLED(PSU_CONTROL) // MKSPWC
142+
#ifndef PS_ON_PIN
143+
#define PS_ON_PIN P0_25 // SERVO
144+
#endif
145+
#ifndef KILL_PIN
146+
#define KILL_PIN P1_29 // Z+
147+
#define KILL_PIN_STATE HIGH
148+
#endif
149+
#endif
142150

143151
//
144152
// Ethernet pins

‎Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h

+13
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@
215215
#define FAN_PIN P2_04
216216
#endif
217217

218+
//
219+
// Power Supply Control
220+
//
221+
#if ENABLED(PSU_CONTROL) // MKSPWC
222+
#ifndef PS_ON_PIN
223+
#define PS_ON_PIN P2_00 // SERVO
224+
#endif
225+
#ifndef KILL_PIN
226+
#define KILL_PIN P1_24 // Z+
227+
#define KILL_PIN_STATE HIGH
228+
#endif
229+
#endif
230+
218231
//
219232
// Misc. Functions
220233
//

‎Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h

+13
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@
226226
//
227227
#define LED_PIN P1_18 // Used as a status indicator
228228

229+
//
230+
// Power Supply Control
231+
//
232+
#if ENABLED(PSU_CONTROL) // MKSPWC
233+
#ifndef PS_ON_PIN
234+
#define PS_ON_PIN P2_00 // Suggestion (SERVO)
235+
#endif
236+
#ifndef KILL_PIN
237+
#define KILL_PIN P1_24 // Suggestion (Z+)
238+
#define KILL_PIN_STATE HIGH
239+
#endif
240+
#endif
241+
229242
//
230243
// RGB LED
231244
//

‎Marlin/src/pins/stm32f1/pins_CHITU3D_common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
#define TFT_RS_PIN FSMC_RS_PIN
148148
#endif
149149

150-
#if ENABLED(TFT_LVGL_UI)
150+
#if HAS_TFT_LVGL_UI
151151
// LVGL
152152
#define HAS_SPI_FLASH_FONT 1
153153
#define HAS_GCODE_PREVIEW 1

‎Marlin/src/pins/stm32f1/pins_FLSUN_HISPEED.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@
195195
//
196196
// Misc. Functions
197197
//
198-
//#define POWER_LOSS_PIN PA1 // PW_SO
199198
#if ENABLED(BACKUP_POWER_SUPPLY)
200199
#define POWER_LOSS_PIN PA2 // PW_DET (UPS) MKSPWC
200+
#else
201+
//#define POWER_LOSS_PIN PA1 // PW_SO
201202
#endif
202203

203204
/**
@@ -217,7 +218,7 @@
217218
//
218219
#if ENABLED(PSU_CONTROL)
219220
#define KILL_PIN PA2 // PW_DET
220-
#define KILL_PIN_INVERTING true
221+
#define KILL_PIN_STATE HIGH
221222
//#define PS_ON_PIN PA3 // PW_CN /PW_OFF
222223
#endif
223224

‎Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,11 @@
183183
// Misc. Functions
184184
//
185185
#if HAS_TFT_LVGL_UI
186-
//#define MKSPWC
187-
#ifdef MKSPWC
188-
#define SUICIDE_PIN PB2 // Enable MKSPWC SUICIDE PIN
189-
#define SUICIDE_PIN_INVERTING false // Enable MKSPWC PIN STATE
190-
#define KILL_PIN PA2 // Enable MKSPWC DET PIN
191-
#define KILL_PIN_STATE true // Enable MKSPWC PIN STATE
186+
#if ENABLED(PSU_CONTROL) // MKSPWC
187+
#define SUICIDE_PIN PB2 // PW_OFF
188+
#define SUICIDE_PIN_INVERTING false
189+
#define KILL_PIN PA2 // PW_DET
190+
#define KILL_PIN_STATE HIGH
192191
#endif
193192

194193
#define MT_DET_1_PIN PA4 // LVGL UI FILAMENT RUNOUT1 PIN

‎Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h

+16-3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@
126126

127127
#define FIL_RUNOUT_PIN PB10 // MT_DET
128128

129+
//
130+
// Power Supply Control
131+
//
132+
#if ENABLED(PSU_CONTROL) // MKSPWC
133+
#ifndef PS_ON_PIN
134+
#define PS_ON_PIN PA14 // PW_OFF
135+
#endif
136+
#ifndef KILL_PIN
137+
#define KILL_PIN PB10 // PW_DET
138+
#define KILL_PIN_STATE HIGH
139+
#endif
140+
#endif
141+
129142
/**
130143
* _____ _____ _____
131144
* (BEEPER) PC1 | 1 2 | PC3 (BTN_ENC) (MISO) PB14 | 1 2 | PB13 (SD_SCK) 5V | 1 2 | GND
@@ -158,7 +171,7 @@
158171
#elif ENABLED(MKS_MINI_12864_V3)
159172
#define DOGLCD_CS PA4
160173
#define DOGLCD_A0 PA5
161-
#define LCD_PINS_DC DOGLCD_A0
174+
#define LCD_PINS_DC DOGLCD_A0
162175
#define LCD_BACKLIGHT_PIN -1
163176
#define LCD_RESET_PIN PA6
164177
#define NEOPIXEL_PIN PA7
@@ -189,8 +202,8 @@
189202
//
190203
// SD Card
191204
//
192-
#define SPI_DEVICE 2
193-
#define ONBOARD_SPI_DEVICE 2
205+
#define SPI_DEVICE 2
206+
#define ONBOARD_SPI_DEVICE 2
194207
#define SDSS SD_SS_PIN
195208
#define SDCARD_CONNECTION ONBOARD
196209
#define SD_DETECT_PIN PC10

‎Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO.h

+19-8
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,28 @@
128128
//#define TEMP_0_CS_PIN PE6 // TC2 - CS2
129129

130130
//
131-
// Misc. Functions
131+
// Power Supply Control
132132
//
133-
#if HAS_TFT_LVGL_UI
134-
//#define MKSPWC
135-
#ifdef MKSPWC
136-
#define SUICIDE_PIN PB2 // Enable MKSPWC SUICIDE PIN
137-
#define SUICIDE_PIN_INVERTING false // Enable MKSPWC PIN STATE
138-
#define KILL_PIN PA2 // Enable MKSPWC DET PIN
139-
#define KILL_PIN_STATE true // Enable MKSPWC PIN STATE
133+
#if ENABLED(PSU_CONTROL) // MKSPWC
134+
#if HAS_TFT_LVGL_UI
135+
#error "PSU_CONTROL cannot be used with TFT_LVGL_UI. Disable PSU_CONTROL to continue."
136+
#endif
137+
#ifndef PS_ON_PIN
138+
#define PS_ON_PIN PB2 // SUICIDE
140139
#endif
140+
#ifndef KILL_PIN
141+
#define KILL_PIN PA2
142+
#define KILL_PIN_STATE HIGH
143+
#endif
144+
#else
145+
#define SUICIDE_PIN PB2
146+
#define SUICIDE_PIN_INVERTING false
147+
#endif
141148

149+
//
150+
// Misc. Functions
151+
//
152+
#if HAS_TFT_LVGL_UI
142153
#define MT_DET_1_PIN PA4 // LVGL UI FILAMENT RUNOUT1 PIN
143154
#define MT_DET_2_PIN PE6 // LVGL UI FILAMENT RUNOUT2 PIN
144155
#define MT_DET_PIN_INVERTING false // LVGL UI filament RUNOUT PIN STATE

‎Marlin/src/pins/stm32f1/pins_MKS_ROBIN_NANO_V2.h

+19-7
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,29 @@
191191
//#define TEMP_0_CS_PIN PE5 // TC1 - CS1
192192
//#define TEMP_0_CS_PIN PE6 // TC2 - CS2
193193

194+
//
195+
// Power Supply Control
196+
//
197+
#if ENABLED(PSU_CONTROL) // MKSPWC
198+
#if HAS_TFT_LVGL_UI
199+
#error "PSU_CONTROL cannot be used with TFT_LVGL_UI. Disable PSU_CONTROL to continue."
200+
#endif
201+
#ifndef PS_ON_PIN
202+
#define PS_ON_PIN PB2 // SUICIDE
203+
#endif
204+
#ifndef KILL_PIN
205+
#define KILL_PIN PA2
206+
#define KILL_PIN_STATE HIGH
207+
#endif
208+
#else
209+
#define SUICIDE_PIN PB2
210+
#define SUICIDE_PIN_INVERTING false
211+
#endif
212+
194213
//
195214
// Misc. Functions
196215
//
197216
#if HAS_TFT_LVGL_UI
198-
//#define MKSPWC
199-
#ifdef MKSPWC
200-
#define SUICIDE_PIN PB2 // Enable MKSPWC SUICIDE PIN
201-
#define SUICIDE_PIN_INVERTING false // Enable MKSPWC PIN STATE
202-
#define KILL_PIN PA2 // Enable MKSPWC DET PIN
203-
#define KILL_PIN_STATE true // Enable MKSPWC PIN STATE
204-
#endif
205217

206218
#define MT_DET_1_PIN PA4 // LVGL UI FILAMENT RUNOUT1 PIN
207219
#define MT_DET_2_PIN PE6 // LVGL UI FILAMENT RUNOUT2 PIN

‎Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,28 @@
179179
//#define TEMP_0_CS_PIN PF11 // TC2 - CS2
180180

181181
#define POWER_LOSS_PIN PA2 // PW_DET
182-
#define PS_ON_PIN PG11 // PW_OFF
183182
#define FIL_RUNOUT_PIN PA4 // MT_DET1
184-
//#define FIL_RUNOUT_PIN PE6 // MT_DET2
185-
//#define FIL_RUNOUT_PIN PG14 // MT_DET3
183+
#define FIL_RUNOUT2_PIN PE6 // MT_DET2
184+
#define FIL_RUNOUT3_PIN PG14 // MT_DET3
185+
186+
//
187+
// Power Supply Control
188+
//
189+
#if ENABLED(PSU_CONTROL) // MKSPWC
190+
#if HAS_TFT_LVGL_UI
191+
#error "PSU_CONTROL cannot be used with TFT_LVGL_UI. Disable PSU_CONTROL to continue."
192+
#endif
193+
#ifndef PS_ON_PIN
194+
#define PS_ON_PIN PG11 // SUICIDE
195+
#endif
196+
#ifndef KILL_PIN
197+
#define KILL_PIN PA2
198+
#define KILL_PIN_STATE HIGH
199+
#endif
200+
#else
201+
#define SUICIDE_PIN PG11
202+
#define SUICIDE_PIN_INVERTING false
203+
#endif
186204

187205
//
188206
// SD Card

‎Marlin/src/pins/stm32f4/pins_MKS_MONSTER8.h

+19-6
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,8 @@
210210
//
211211
// Misc. Functions
212212
//
213-
#define MT_DET_1 Y_MAX_PIN
214-
#define MT_DET_2 Z_MAX_PIN
215-
#define PW_DET Y_MAX_PIN
216-
#define PW_OFF Z_MAX_PIN
213+
#define MT_DET_1 PC5 // Y+
214+
#define MT_DET_2 PB12 // Z+
217215

218216
#ifndef FIL_RUNOUT_PIN
219217
#define FIL_RUNOUT_PIN MT_DET_1
@@ -222,8 +220,23 @@
222220
#define FIL_RUNOUT2_PIN MT_DET_2
223221
#endif
224222

225-
#define POWER_LOSS_PIN PW_DET
226-
#define PS_ON_PIN PW_OFF
223+
//
224+
// Power Supply Control
225+
//
226+
#if ENABLED(PSU_CONTROL) // MKSPWC
227+
#ifndef PS_ON_PIN
228+
#define PS_ON_PIN MT_DET_2 // Z+
229+
#endif
230+
#ifndef KILL_PIN
231+
#define KILL_PIN MT_DET_1 // Y+
232+
#define KILL_PIN_STATE HIGH
233+
#endif
234+
#else
235+
#define PW_DET MT_DET_1
236+
#define PW_OFF MT_DET_2
237+
#define POWER_LOSS_PIN PW_DET
238+
#define PS_ON_PIN PW_OFF
239+
#endif
227240

228241
// Random Info
229242
#define USB_SERIAL -1 // USB Serial

‎Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h

+26-9
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,36 @@
189189
#define FIL_RUNOUT2_PIN MT_DET_2_PIN
190190
#endif
191191

192-
#ifndef POWER_LOSS_PIN
193-
#define POWER_LOSS_PIN PA13 // PW_DET
194-
#endif
195-
#define PS_ON_PIN PB2 // PW_OFF
196-
197192
//
198193
// Enable MKSPWC support
199194
//
200195
//#define SUICIDE_PIN PB2
196+
//#define LED_PIN PB2
201197
//#define KILL_PIN PA2
202-
//#define KILL_PIN_INVERTING true
198+
//#define KILL_PIN_STATE HIGH
203199

204-
//#define LED_PIN PB2
200+
//
201+
// Power Supply Control
202+
//
203+
#if ENABLED(PSU_CONTROL) // MKSPWC
204+
#if HAS_TFT_LVGL_UI
205+
#error "PSU_CONTROL cannot be used with TFT_LVGL_UI. Disable PSU_CONTROL to continue."
206+
#endif
207+
#ifndef PS_ON_PIN
208+
#define PS_ON_PIN PB2 // SUICIDE
209+
#endif
210+
#ifndef KILL_PIN
211+
#define KILL_PIN PA13 // PW_DET
212+
#define KILL_PIN_STATE HIGH
213+
#endif
214+
#else
215+
#define SUICIDE_PIN PB2
216+
#define SUICIDE_PIN_INVERTING false
217+
#endif
218+
219+
#ifndef POWER_LOSS_PIN
220+
#define POWER_LOSS_PIN PA13 // PW_DET
221+
#endif
205222

206223
// Random Info
207224
#define USB_SERIAL -1 // USB Serial
@@ -222,8 +239,8 @@
222239

223240
// MKS TEST
224241
#if ENABLED(MKS_TEST)
225-
#define MKS_TEST_POWER_LOSS_PIN PA13 // PW_DET
226-
#define MKS_TEST_PS_ON_PIN PB2 // PW_OFF
242+
#define MKS_TEST_POWER_LOSS_PIN PA13 // PW_DET
243+
#define MKS_TEST_PS_ON_PIN PB2 // PW_OFF
227244
#endif
228245

229246
//

‎Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,19 @@
195195
//
196196
// Misc. Functions
197197
//
198-
//#define POWER_LOSS_PIN PA2 // PW_DET
199198
//#define PS_ON_PIN PA3 // PW_OFF
200-
//#define SUICIDE_PIN PB2 // Enable MKSPWC support
201-
//#define KILL_PIN PA2 // Enable MKSPWC support
202-
//#define KILL_PIN_INVERTING true // Enable MKSPWC support
203-
//#define LED_PIN PB2
199+
200+
//
201+
// Power Supply Control
202+
//
203+
#if ENABLED(PSU_CONTROL) // MKSPWC
204+
//#define SUICIDE_PIN PB2 // LED
205+
//#define KILL_PIN PA2 // PW_DET
206+
//#define KILL_PIN_STATE HIGH
207+
#else
208+
//#define POWER_LOSS_PIN PA2 // PW_DET
209+
//#define LED_PIN PB2
210+
#endif
204211

205212
#ifndef SDCARD_CONNECTION
206213
#define SDCARD_CONNECTION ONBOARD

3 commit comments

Comments
 (3)

javicarrera commented on Aug 8, 2021

@javicarrera

I have an improvement to this PR.
I have working both PWC and UPS together in my set up (Robin Nano 1.2 + PWC 3.0 + UPS).
UPS is controlled by the definition BACK_POWER_SUPPLY. The signal cable from UPS remains not connected, because the PWC is already controlling this pin.
In this way it is possible to raise Z axis in case of power failure.

I have tried it only on LVGL_UI and all features are working:

  • Push button switches on and off
  • Power failure saves in SD card and raises Z axis.
  • Print continues after power failure
  • Switch on/off works also with the UI.

Just change in pins_MKS_ROBIN_NANO:

#if ENABLED(PSU_CONTROL) // MKSPWC
#if HAS_TFT_LVGL_UI
#error "PSU_CONTROL cannot be used with TFT_LVGL_UI. Disable PSU_CONTROL to continue."
#endif
#ifndef PS_ON_PIN
#define PS_ON_PIN PB2 // PW_OFF
#endif
#ifndef KILL_PIN
#define KILL_PIN PA2 // PW_DET
#define KILL_PIN_STATE HIGH
#endif
#ifdef BACKUP_POWER_SUPPLY
#define POWER_LOSS_PIN KILL_PIN // PW_DET ALLOWS TO USE MKS PWC & UPS TOGETHER - DO NOT PLUG UPS SIGNAL CABLE TO MAIN BOARD
#endif
#else
#ifndef SUICIDE_PIN
#define SUICIDE_PIN PB2 // LVGL UI MKSPWC SUICIDE PIN PB2 - PW_OFF
#define SUICIDE_PIN_INVERTING false // LVGL UI MKSPWC PIN STATE
#endif
#ifndef KILL_PIN
#define KILL_PIN PA2 // LVGL UI MKSPWC PW_DET PIN
#define KILL_PIN_STATE HIGH // LVGL UI MKSPWC PIN STATE
#endif
#ifdef BACKUP_POWER_SUPPLY
#ifndef POWER_LOSS_PIN
#define POWER_LOSS_PIN KILL_PIN // ALLOWS USING BOTH MKS PWC & UPS TOGETHER - DO NOT PLUG UPS SIGNAL CABLE TO MAIN BOARD
#endif
#endif
#endif

I would delete from misc. functions, as are already controlled in previous code.

//#define POWER_LOSS_PIN PA2 // PW_DET
//#define PS_ON_PIN PB2 // PW_OFF

thinkyhead commented on Aug 11, 2021

@thinkyhead
Member

I feel like I saw this posted elsewhere and even edited it to neaten up the code.

javicarrera commented on Aug 12, 2021

@javicarrera

Yes, sorry it is actually here: #22534. At least for me is working flawlessly.

Please sign in to comment.