Skip to content

Commit

Permalink
✨ ESP32 Panda_ZHU and Panda_M4 (MarlinFirmware#22644)
Browse files Browse the repository at this point in the history
  • Loading branch information
markniu authored and Darred committed Dec 1, 2021
1 parent 607961d commit e3e933b
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 32 deletions.
4 changes: 3 additions & 1 deletion Marlin/src/HAL/AVR/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include "../../inc/MarlinConfig.h"

void spiBegin() {
OUT_WRITE(SD_SS_PIN, HIGH);
#if PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif
SET_OUTPUT(SD_SCK_PIN);
SET_INPUT(SD_MISO_PIN);
SET_OUTPUT(SD_MOSI_PIN);
Expand Down
28 changes: 26 additions & 2 deletions Marlin/src/HAL/ESP32/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <esp_adc_cal.h>
#include <HardwareSerial.h>

#if ENABLED(USE_ESP32_TASK_WDT)
#include <esp_task_wdt.h>
#endif

#if ENABLED(WIFISUPPORT)
#include <ESPAsyncWebServer.h>
#include "wifi.h"
Expand Down Expand Up @@ -90,8 +94,24 @@ volatile int numPWMUsed = 0,

#endif

void HAL_init_board() {
#if ENABLED(USE_ESP32_EXIO)
HardwareSerial YSerial2(2);

void Write_EXIO(uint8_t IO, uint8_t v) {
if (ISRS_ENABLED()) {
DISABLE_ISRS();
YSerial2.write(0x80 | (((char)v) << 5) | (IO - 100));
ENABLE_ISRS();
}
else
YSerial2.write(0x80 | (((char)v) << 5) | (IO - 100));
}
#endif

void HAL_init_board() {
#if ENABLED(USE_ESP32_TASK_WDT)
esp_task_wdt_init(10, true);
#endif
#if ENABLED(ESP3D_WIFISUPPORT)
esp3dlib.init();
#elif ENABLED(WIFISUPPORT)
Expand Down Expand Up @@ -127,7 +147,11 @@ void HAL_init_board() {
// Initialize the i2s peripheral only if the I2S stepper stream is enabled.
// The following initialization is performed after Serial1 and Serial2 are defined as
// their native pins might conflict with the i2s stream even when they are remapped.
TERN_(I2S_STEPPER_STREAM, i2s_init());
#if ENABLED(USE_ESP32_EXIO)
YSerial2.begin(460800 * 3, SERIAL_8N1, 16, 17);
#elif ENABLED(I2S_STEPPER_STREAM)
i2s_init();
#endif
}

void HAL_idletask() {
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/HAL/ESP32/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ void HAL_idletask();
inline void HAL_init() {}
void HAL_init_board();

#if ENABLED(USE_ESP32_EXIO)
void Write_EXIO(uint8_t IO, uint8_t v);
#endif

//
// Delay in cycles (used by DELAY_NS / DELAY_US)
//
Expand Down
6 changes: 2 additions & 4 deletions Marlin/src/HAL/ESP32/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ static SPISettings spiConfig;
// ------------------------

void spiBegin() {
#if !PIN_EXISTS(SD_SS)
#error "SD_SS_PIN not defined!"
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif

OUT_WRITE(SD_SS_PIN, HIGH);
}

void spiInit(uint8_t spiRate) {
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/HAL/ESP32/esp32.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xe000, 0x2000,
app0, app, ota_0, 0x10000, 0x180000,
app1, app, ota_1, 0x190000, 0x180000,
spiffs, data, spiffs, 0x310000, 0xF0000,
20 changes: 13 additions & 7 deletions Marlin/src/HAL/ESP32/fastio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@
// Set pin as input with pullup mode
#define _PULLUP(IO, v) pinMode(IO, v ? INPUT_PULLUP : INPUT)

// Read a pin wrapper
#define READ(IO) (IS_I2S_EXPANDER_PIN(IO) ? i2s_state(I2S_EXPANDER_PIN_INDEX(IO)) : digitalRead(IO))

// Write to a pin wrapper
#define WRITE(IO, v) (IS_I2S_EXPANDER_PIN(IO) ? i2s_write(I2S_EXPANDER_PIN_INDEX(IO), v) : digitalWrite(IO, v))

// Set pin as input wrapper
#if ENABLED(USE_ESP32_EXIO)
// Read a pin wrapper
#define READ(IO) digitalRead(IO)
// Write to a pin wrapper
#define WRITE(IO, v) (IO >= 100 ? Write_EXIO(IO, v) : digitalWrite(IO, v))
#else
// Read a pin wrapper
#define READ(IO) (IS_I2S_EXPANDER_PIN(IO) ? i2s_state(I2S_EXPANDER_PIN_INDEX(IO)) : digitalRead(IO))
// Write to a pin wrapper
#define WRITE(IO, v) (IS_I2S_EXPANDER_PIN(IO) ? i2s_write(I2S_EXPANDER_PIN_INDEX(IO), v) : digitalWrite(IO, v))
#endif

// Set pin as input wrapper (0x80 | (v << 5) | (IO - 100))
#define SET_INPUT(IO) _SET_INPUT(IO)

// Set pin as input with pullup wrapper
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/HAL/ESP32/i2s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include "../../inc/MarlinConfigPre.h"

#if DISABLED(USE_ESP32_EXIO)

#include "i2s.h"

#include "../shared/Marduino.h"
Expand Down Expand Up @@ -340,4 +342,5 @@ void i2s_push_sample() {
dma.current[dma.rw_pos++] = i2s_port_data;
}

#endif // !USE_ESP32_EXIO
#endif // ARDUINO_ARCH_ESP32
2 changes: 1 addition & 1 deletion Marlin/src/HAL/ESP32/watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
extern "C" {
#endif

esp_err_t esp_task_wdt_reset();
esp_err_t esp_task_wdt_reset();

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/HAL/STM32/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ static SPISettings spiConfig;
#include "../shared/Delay.h"

void spiBegin(void) {
OUT_WRITE(SD_SS_PIN, HIGH);
#if PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif
OUT_WRITE(SD_SCK_PIN, HIGH);
SET_INPUT(SD_MISO_PIN);
OUT_WRITE(SD_MOSI_PIN, HIGH);
Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/HAL/TEENSY31_32/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ static SPISettings spiConfig;

// Initialize SPI bus
void spiBegin() {
#if !PIN_EXISTS(SD_SS)
#error "SD_SS_PIN not defined!"
#if PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif
OUT_WRITE(SD_SS_PIN, HIGH);
SET_OUTPUT(SD_SCK_PIN);
SET_INPUT(SD_MISO_PIN);
SET_OUTPUT(SD_MOSI_PIN);
Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/HAL/TEENSY35_36/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@
static SPISettings spiConfig;

void spiBegin() {
#if !PIN_EXISTS(SD_SS)
#error "SD_SS_PIN not defined!"
#if PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif
OUT_WRITE(SD_SS_PIN, HIGH);
SET_OUTPUT(SD_SCK_PIN);
SET_INPUT(SD_MISO_PIN);
SET_OUTPUT(SD_MOSI_PIN);
Expand Down
7 changes: 2 additions & 5 deletions Marlin/src/HAL/TEENSY40_41/HAL_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,9 @@ static SPISettings spiConfig;
// ------------------------

void spiBegin() {
#ifndef SD_SS_PIN
#error "SD_SS_PIN is not defined!"
#if PIN_EXISTS(SD_SS)
OUT_WRITE(SD_SS_PIN, HIGH);
#endif

OUT_WRITE(SD_SS_PIN, HIGH);

//SET_OUTPUT(SD_SCK_PIN);
//SET_INPUT(SD_MISO_PIN);
//SET_OUTPUT(SD_MOSI_PIN);
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@
#define BOARD_MRR_ESPE 6002 // MRR ESPE based on ESP32 (with I2S stepper stream)
#define BOARD_E4D_BOX 6003 // E4d@BOX
#define BOARD_FYSETC_E4 6004 // FYSETC E4
#define BOARD_PANDA_ZHU 6005 // Panda_ZHU
#define BOARD_PANDA_M4 6006 // Panda_M4

//
// SAMD51 ARM Cortex M4
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/gcode/sd/M1001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "../gcode.h"
#include "../../module/planner.h"
#include "../../module/printcounter.h"
#include "../../module/temperature.h"
#include "../../sd/cardreader.h"

#ifdef SD_FINISHED_RELEASECOMMAND
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,9 @@
#error "SPINDLE_LASER_PWM (true) is now set with SPINDLE_LASER_USE_PWM (enabled)."
#endif

#if MOTHERBOARD == BOARD_DUE3DOM_MINI && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD)
#if MB(DUE3DOM_MINI) && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD)
#warning "Onboard temperature sensor for BOARD_DUE3DOM_MINI has moved from TEMP_SENSOR_2 (TEMP_2_PIN) to TEMP_SENSOR_BOARD (TEMP_BOARD_PIN)."
#elif MOTHERBOARD == BOARD_BTT_SKR_E3_TURBO && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD)
#elif MB(BTT_SKR_E3_TURBO) && PIN_EXISTS(TEMP_2) && DISABLED(TEMP_SENSOR_BOARD)
#warning "Onboard temperature sensor for BOARD_BTT_SKR_E3_TURBO has moved from TEMP_SENSOR_2 (TEMP_2_PIN) to TEMP_SENSOR_BOARD (TEMP_BOARD_PIN)."
#endif

Expand Down
38 changes: 38 additions & 0 deletions Marlin/src/pins/esp32/pins_PANDA_M4.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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

/**
* Panda M4 pin assignments
*/

#define BOARD_INFO_NAME "Panda_M4"

#include "pins_PANDA_common.h"

//
// Steppers
//
#define X_ENABLE_PIN 115
#define Y_ENABLE_PIN 114
#define Z_ENABLE_PIN 113
#define E0_ENABLE_PIN 112
61 changes: 61 additions & 0 deletions Marlin/src/pins/esp32/pins_PANDA_ZHU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2021 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

/**
* Panda ZHU pin assignments
*/

#define BOARD_INFO_NAME "Panda_ZHU"

#include "pins_PANDA_common.h"

//
// Steppers
//
#define X_ENABLE_PIN 128 // Shared with all steppers
#define Y_ENABLE_PIN X_ENABLE_PIN
#define Z_ENABLE_PIN X_ENABLE_PIN
#define E0_ENABLE_PIN X_ENABLE_PIN

//#define X_CS_PIN 0
//#define Y_CS_PIN 13
//#define Z_CS_PIN 5 // SS_PIN
//#define E0_CS_PIN 21

#define E1_STEP_PIN 115
#define E1_DIR_PIN 114
#define E1_ENABLE_PIN X_ENABLE_PIN

#define E2_STEP_PIN 112
#define E2_DIR_PIN 113
#define E2_ENABLE_PIN X_ENABLE_PIN

#define E3_STEP_PIN 110
#define E3_DIR_PIN 111
#define E3_ENABLE_PIN X_ENABLE_PIN

#define E4_STEP_PIN 121
#define E4_DIR_PIN 122
#define E4_ENABLE_PIN X_ENABLE_PIN

#define HEATER_1_PIN 123
Loading

0 comments on commit e3e933b

Please sign in to comment.