From 9439fab7fd415d2a08d8044491145c1b155b20d3 Mon Sep 17 00:00:00 2001 From: felixstorm Date: Tue, 11 Jun 2019 06:22:19 +0200 Subject: [PATCH] Fix ESP32 servos, platformio.ini, etc. (#14247) --- Marlin/src/HAL/HAL_ESP32/HAL.cpp | 3 +++ Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp | 6 ++++-- Marlin/src/HAL/HAL_ESP32/i2s.cpp | 3 ++- Marlin/src/HAL/HAL_ESP32/i2s.h | 6 ------ Marlin/src/pins/pins_ESP32.h | 16 +++++++++++----- platformio.ini | 8 ++++---- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Marlin/src/HAL/HAL_ESP32/HAL.cpp b/Marlin/src/HAL/HAL_ESP32/HAL.cpp index 00a40fbbe..7776eeaa1 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL.cpp @@ -193,6 +193,9 @@ void HAL_adc_start_conversion(uint8_t adc_pin) { } void analogWrite(int pin, int value) { + + if (!PWM_PIN(pin)) return; + static int cnt_channel = 1, pin_to_channel[40] = {}; if (pin_to_channel[pin] == 0) { diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp index bf3d228a6..52e54d471 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp @@ -27,7 +27,9 @@ #include "HAL_Servo_ESP32.h" -int Servo::channel_next_free = 0; +// Adjacent channels (0/1, 2/3 etc.) share the same timer and therefore the same frequency and resolution settings on ESP32, +// so we only allocate servo channels up high to avoid side effects with regards to analogWrite (fans, leds, laser pwm etc.) +int Servo::channel_next_free = 12; Servo::Servo() { this->channel = channel_next_free++; @@ -42,7 +44,7 @@ int8_t Servo::attach(const int pin) { return true; } -void Servo::detach() { ledcDetachPin(this->pin) } +void Servo::detach() { ledcDetachPin(this->pin); } int Servo::read() { return this->degrees; } diff --git a/Marlin/src/HAL/HAL_ESP32/i2s.cpp b/Marlin/src/HAL/HAL_ESP32/i2s.cpp index 87c3959e7..6143775a1 100644 --- a/Marlin/src/HAL/HAL_ESP32/i2s.cpp +++ b/Marlin/src/HAL/HAL_ESP32/i2s.cpp @@ -21,10 +21,11 @@ */ #ifdef ARDUINO_ARCH_ESP32 +#include "../../inc/MarlinConfigPre.h" + #include "i2s.h" #include "../shared/Marduino.h" -#include "../../core/macros.h" #include "driver/periph_ctrl.h" #include "rom/lldesc.h" #include "soc/i2s_struct.h" diff --git a/Marlin/src/HAL/HAL_ESP32/i2s.h b/Marlin/src/HAL/HAL_ESP32/i2s.h index 42c35aa12..42153e329 100644 --- a/Marlin/src/HAL/HAL_ESP32/i2s.h +++ b/Marlin/src/HAL/HAL_ESP32/i2s.h @@ -33,9 +33,3 @@ uint8_t i2s_state(uint8_t pin); void i2s_write(uint8_t pin, uint8_t val); void i2s_push_sample(); - -// pin definitions - -#define I2S_WS 25 -#define I2S_BCK 26 -#define I2S_DATA 27 diff --git a/Marlin/src/pins/pins_ESP32.h b/Marlin/src/pins/pins_ESP32.h index dad1e0d81..cbe955445 100644 --- a/Marlin/src/pins/pins_ESP32.h +++ b/Marlin/src/pins/pins_ESP32.h @@ -30,18 +30,24 @@ #define BOARD_NAME "Espressif ESP32" +// +// I2S (steppers & other output-only pins) +// +#define I2S_STEPPER_STREAM +#define I2S_WS 25 +#define I2S_BCK 26 +#define I2S_DATA 27 + // // Limit Switches // -#define X_MIN_PIN 34 -#define Y_MIN_PIN 35 -#define Z_MIN_PIN 15 +#define X_MIN_PIN 34 +#define Y_MIN_PIN 35 +#define Z_MIN_PIN 15 // // Steppers // -#define I2S_STEPPER_STREAM - #define X_STEP_PIN 128 #define X_DIR_PIN 129 #define X_ENABLE_PIN 130 diff --git a/platformio.ini b/platformio.ini index 6953a9cae..2c244a2ba 100644 --- a/platformio.ini +++ b/platformio.ini @@ -403,10 +403,10 @@ lib_ignore = # Espressif ESP32 # [env:esp32] -platform = https://github.com/platformio/platform-espressif32.git ; #feature/stage -board = esp32dev -framework = arduino -upload_speed = 115200 +platform = espressif32 +board = esp32dev +framework = arduino +upload_speed = 115200 monitor_speed = 115200 upload_port = /dev/ttyUSB0 lib_deps =