Skip to content

Commit

Permalink
🎨 Update MKSPWC, some other pins (MarlinFirmware#22557)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored and AlexColello committed Jan 14, 2022
1 parent 2857f6b commit bb8bb6b
Show file tree
Hide file tree
Showing 41 changed files with 278 additions and 324 deletions.
3 changes: 0 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@
//#define PSU_NAME "Power Supply"

#if ENABLED(PSU_CONTROL)
<<<<<<< HEAD
//#define MKS_PWC // Using the MKS PWC add-on
=======
>>>>>>> 9741be5966 (✨ Power-off confirm / beep options (#22191))
//#define PS_OFF_CONFIRM // Confirm dialog when power off
//#define PS_OFF_SOUND // Beep 1s when power off
#define PSU_ACTIVE_STATE LOW // Set 'LOW' for ATX, 'HIGH' for X-Box
Expand Down
16 changes: 6 additions & 10 deletions Marlin/src/HAL/DUE/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,18 +594,14 @@
SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_MR_PS);
SPI_Enable(SPI0);

SET_OUTPUT(DAC0_SYNC);
SET_OUTPUT(DAC0_SYNC_PIN);
#if HAS_MULTI_EXTRUDER
SET_OUTPUT(DAC1_SYNC);
WRITE(DAC1_SYNC, HIGH);
OUT_WRITE(DAC1_SYNC_PIN, HIGH);
#endif
SET_OUTPUT(SPI_EEPROM1_CS);
SET_OUTPUT(SPI_EEPROM2_CS);
SET_OUTPUT(SPI_FLASH_CS);
WRITE(DAC0_SYNC, HIGH);
WRITE(SPI_EEPROM1_CS, HIGH);
WRITE(SPI_EEPROM2_CS, HIGH);
WRITE(SPI_FLASH_CS, HIGH);
WRITE(DAC0_SYNC_PIN, HIGH);
OUT_WRITE(SPI_EEPROM1_CS_PIN, HIGH);
OUT_WRITE(SPI_EEPROM2_CS_PIN, HIGH);
OUT_WRITE(SPI_FLASH_CS_PIN, HIGH);
WRITE(SD_SS_PIN, HIGH);

OUT_WRITE(SDSS, LOW);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/HAL/STM32F1/eeprom_wired.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool PersistentStore::access_start() {
SET_OUTPUT(BOARD_SPI1_SCK_PIN);
SET_OUTPUT(BOARD_SPI1_MOSI_PIN);
SET_INPUT(BOARD_SPI1_MISO_PIN);
SET_OUTPUT(SPI_EEPROM1_CS);
SET_OUTPUT(SPI_EEPROM1_CS_PIN);
#endif
spiInit(0);
#endif
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/HAL/shared/eeprom_if_spi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static void _eeprom_begin(uint8_t * const pos, const uint8_t cmd) {
(unsigned(pos) >> 8) & 0xFF, // Address High
unsigned(pos) & 0xFF // Address Low
};
WRITE(SPI_EEPROM1_CS, HIGH); // Usually free already
WRITE(SPI_EEPROM1_CS, LOW); // Activate the Bus
WRITE(SPI_EEPROM1_CS_PIN, HIGH); // Usually free already
WRITE(SPI_EEPROM1_CS_PIN, LOW); // Activate the Bus
spiSend(SPI_CHAN_EEPROM1, eeprom_temp, 3);
// Leave the Bus in-use
}
Expand All @@ -60,23 +60,23 @@ uint8_t eeprom_read_byte(uint8_t *pos) {

const uint8_t v = spiRec(SPI_CHAN_EEPROM1); // After READ a value sits on the Bus

WRITE(SPI_EEPROM1_CS, HIGH); // Done with device
WRITE(SPI_EEPROM1_CS_PIN, HIGH); // Done with device

return v;
}

void eeprom_write_byte(uint8_t *pos, uint8_t value) {
const uint8_t eeprom_temp = CMD_WREN;
WRITE(SPI_EEPROM1_CS, LOW);
WRITE(SPI_EEPROM1_CS_PIN, LOW);
spiSend(SPI_CHAN_EEPROM1, &eeprom_temp, 1); // Write Enable

WRITE(SPI_EEPROM1_CS, HIGH); // Done with the Bus
WRITE(SPI_EEPROM1_CS_PIN, HIGH); // Done with the Bus
delay(1); // For a small amount of time

_eeprom_begin(pos, CMD_WRITE); // Set write address and begin transmission

spiSend(SPI_CHAN_EEPROM1, value); // Send the value to be written
WRITE(SPI_EEPROM1_CS, HIGH); // Done with the Bus
WRITE(SPI_EEPROM1_CS_PIN, HIGH); // Done with the Bus
delay(EEPROM_WRITE_DELAY); // Give page write time to complete
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ void setup() {

#if HAS_SUICIDE
SETUP_LOG("SUICIDE_PIN");
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_STATE);
#endif

#ifdef JTAGSWD_RESET
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extern bool wait_for_heatup;
bool pin_is_protected(const pin_t pin);

#if HAS_SUICIDE
inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_INVERTING); }
inline void suicide() { OUT_WRITE(SUICIDE_PIN, SUICIDE_PIN_STATE); }
#endif

#if HAS_KILL
Expand Down
42 changes: 21 additions & 21 deletions Marlin/src/feature/dac/dac_dac084s085.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ void dac084s085::begin() {
uint8_t externalDac_buf[] = { 0x20, 0x00 }; // all off

// All SPI chip-select HIGH
SET_OUTPUT(DAC0_SYNC);
SET_OUTPUT(DAC0_SYNC_PIN);
#if HAS_MULTI_EXTRUDER
SET_OUTPUT(DAC1_SYNC);
SET_OUTPUT(DAC1_SYNC_PIN);
#endif
cshigh();
spiBegin();

//init onboard DAC
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
WRITE(DAC0_SYNC_PIN, LOW);
DELAY_US(2);
WRITE(DAC0_SYNC, HIGH);
WRITE(DAC0_SYNC_PIN, HIGH);
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
WRITE(DAC0_SYNC_PIN, LOW);

spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
WRITE(DAC0_SYNC, HIGH);
WRITE(DAC0_SYNC_PIN, HIGH);

#if HAS_MULTI_EXTRUDER
//init Piggy DAC
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
WRITE(DAC1_SYNC_PIN, LOW);
DELAY_US(2);
WRITE(DAC1_SYNC, HIGH);
WRITE(DAC1_SYNC_PIN, HIGH);
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
WRITE(DAC1_SYNC_PIN, LOW);

spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
WRITE(DAC1_SYNC, HIGH);
WRITE(DAC1_SYNC_PIN, HIGH);
#endif

return;
Expand All @@ -66,32 +66,32 @@ void dac084s085::setValue(const uint8_t channel, const uint8_t value) {
cshigh();

if (channel > 3) { // DAC Piggy E1,E2,E3
WRITE(DAC1_SYNC, LOW);
WRITE(DAC1_SYNC_PIN, LOW);
DELAY_US(2);
WRITE(DAC1_SYNC, HIGH);
WRITE(DAC1_SYNC_PIN, HIGH);
DELAY_US(2);
WRITE(DAC1_SYNC, LOW);
WRITE(DAC1_SYNC_PIN, LOW);
}
else { // DAC onboard X,Y,Z,E0
WRITE(DAC0_SYNC, LOW);
WRITE(DAC0_SYNC_PIN, LOW);
DELAY_US(2);
WRITE(DAC0_SYNC, HIGH);
WRITE(DAC0_SYNC_PIN, HIGH);
DELAY_US(2);
WRITE(DAC0_SYNC, LOW);
WRITE(DAC0_SYNC_PIN, LOW);
}

DELAY_US(2);
spiSend(SPI_CHAN_DAC, externalDac_buf, COUNT(externalDac_buf));
}

void dac084s085::cshigh() {
WRITE(DAC0_SYNC, HIGH);
WRITE(DAC0_SYNC_PIN, HIGH);
#if HAS_MULTI_EXTRUDER
WRITE(DAC1_SYNC, HIGH);
WRITE(DAC1_SYNC_PIN, HIGH);
#endif
WRITE(SPI_EEPROM1_CS, HIGH);
WRITE(SPI_EEPROM2_CS, HIGH);
WRITE(SPI_FLASH_CS, HIGH);
WRITE(SPI_EEPROM1_CS_PIN, HIGH);
WRITE(SPI_EEPROM2_CS_PIN, HIGH);
WRITE(SPI_FLASH_CS_PIN, HIGH);
WRITE(SD_SS_PIN, HIGH);
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M80_M81.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* a print without suicide...
*/
#if HAS_SUICIDE
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING);
OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_STATE);
#endif

TERN_(HAS_LCD_MENU, ui.reset_status());
Expand Down
7 changes: 7 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,13 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#endif
#endif

/**
* Validate MKS_PWC
*/
#if ENABLED(MKS_PWC) && PSU_ACTIVE_STATE != HIGH
#error "MKS_PWC requires PSU_ACTIVE_STATE to be set HIGH."
#endif

/**
* Ensure this option is set intentionally
*/
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus/mks/DGUSDisplayDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#define LOGO_TIME_DELAY TERN(USE_MKS_GREEN_UI, 8000, 1500)

#if ENABLED(DGUS_MKS_RUNOUT_SENSOR)
#define MT_DET_1_PIN 1
#define MT_DET_2_PIN 2
#define MT_DET_PIN_INVERTING false
#define MT_DET_1_PIN 1
#define MT_DET_2_PIN 2
#define MT_DET_PIN_STATE LOW
#endif

#define MKS_FINSH
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/dgus/mks/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1495,17 +1495,17 @@ void DGUSScreenHandler::DGUS_Runout_Idle(void) {
break;

case UNRUNOUT_STATUS:
if (READ(MT_DET_1_PIN) == LOW)
if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE)
runout_mks.runout_status = RUNOUT_STATUS;
break;

case RUNOUT_BEGIN_STATUS:
if (READ(MT_DET_1_PIN) == HIGH)
if (READ(MT_DET_1_PIN) != MT_DET_PIN_STATE)
runout_mks.runout_status = RUNOUT_WAITTING_STATUS;
break;

case RUNOUT_WAITTING_STATUS:
if (READ(MT_DET_1_PIN) == LOW)
if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE)
runout_mks.runout_status = RUNOUT_BEGIN_STATUS;
break;

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/printer_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,23 @@ void filament_check() {
#endif
#if PIN_EXISTS(MT_DET_1)
static int fil_det_count_1 = 0;
if (READ(MT_DET_1_PIN) == MT_DET_PIN_INVERTING)
if (READ(MT_DET_1_PIN) == MT_DET_PIN_STATE)
fil_det_count_1++;
else if (fil_det_count_1 > 0)
fil_det_count_1--;
#endif

#if PIN_EXISTS(MT_DET_2)
static int fil_det_count_2 = 0;
if (READ(MT_DET_2_PIN) == MT_DET_PIN_INVERTING)
if (READ(MT_DET_2_PIN) == MT_DET_PIN_STATE)
fil_det_count_2++;
else if (fil_det_count_2 > 0)
fil_det_count_2--;
#endif

#if PIN_EXISTS(MT_DET_3)
static int fil_det_count_3 = 0;
if (READ(MT_DET_3_PIN) == MT_DET_PIN_INVERTING)
if (READ(MT_DET_3_PIN) == MT_DET_PIN_STATE)
fil_det_count_3++;
else if (fil_det_count_3 > 0)
fil_det_count_3--;
Expand Down
Loading

0 comments on commit bb8bb6b

Please sign in to comment.