Browse Source

Fix ESP32 servos, platformio.ini, etc. (#14247)

felixstorm 5 years ago
parent
commit
9439fab7fd

+ 3
- 0
Marlin/src/HAL/HAL_ESP32/HAL.cpp View File

@@ -193,6 +193,9 @@ void HAL_adc_start_conversion(uint8_t adc_pin) {
193 193
 }
194 194
 
195 195
 void analogWrite(int pin, int value) {
196
+
197
+  if (!PWM_PIN(pin)) return;
198
+
196 199
   static int cnt_channel = 1,
197 200
              pin_to_channel[40] = {};
198 201
   if (pin_to_channel[pin] == 0) {

+ 4
- 2
Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp View File

@@ -27,7 +27,9 @@
27 27
 
28 28
 #include "HAL_Servo_ESP32.h"
29 29
 
30
-int Servo::channel_next_free = 0;
30
+// Adjacent channels (0/1, 2/3 etc.) share the same timer and therefore the same frequency and resolution settings on ESP32,
31
+// so we only allocate servo channels up high to avoid side effects with regards to analogWrite (fans, leds, laser pwm etc.)
32
+int Servo::channel_next_free = 12;
31 33
 
32 34
 Servo::Servo() {
33 35
   this->channel = channel_next_free++;
@@ -42,7 +44,7 @@ int8_t Servo::attach(const int pin) {
42 44
   return true;
43 45
 }
44 46
 
45
-void Servo::detach() { ledcDetachPin(this->pin) }
47
+void Servo::detach() { ledcDetachPin(this->pin); }
46 48
 
47 49
 int Servo::read() { return this->degrees; }
48 50
 

+ 2
- 1
Marlin/src/HAL/HAL_ESP32/i2s.cpp View File

@@ -21,10 +21,11 @@
21 21
  */
22 22
 #ifdef ARDUINO_ARCH_ESP32
23 23
 
24
+#include "../../inc/MarlinConfigPre.h"
25
+
24 26
 #include "i2s.h"
25 27
 
26 28
 #include "../shared/Marduino.h"
27
-#include "../../core/macros.h"
28 29
 #include "driver/periph_ctrl.h"
29 30
 #include "rom/lldesc.h"
30 31
 #include "soc/i2s_struct.h"

+ 0
- 6
Marlin/src/HAL/HAL_ESP32/i2s.h View File

@@ -33,9 +33,3 @@ uint8_t i2s_state(uint8_t pin);
33 33
 void i2s_write(uint8_t pin, uint8_t val);
34 34
 
35 35
 void i2s_push_sample();
36
-
37
-// pin definitions
38
-
39
-#define I2S_WS 25
40
-#define I2S_BCK 26
41
-#define I2S_DATA 27

+ 11
- 5
Marlin/src/pins/pins_ESP32.h View File

@@ -31,17 +31,23 @@
31 31
 #define BOARD_NAME "Espressif ESP32"
32 32
 
33 33
 //
34
+// I2S (steppers & other output-only pins)
35
+//
36
+#define I2S_STEPPER_STREAM
37
+#define I2S_WS              25
38
+#define I2S_BCK             26
39
+#define I2S_DATA            27
40
+
41
+//
34 42
 // Limit Switches
35 43
 //
36
-#define X_MIN_PIN          34
37
-#define Y_MIN_PIN          35
38
-#define Z_MIN_PIN          15
44
+#define X_MIN_PIN           34
45
+#define Y_MIN_PIN           35
46
+#define Z_MIN_PIN           15
39 47
 
40 48
 //
41 49
 // Steppers
42 50
 //
43
-#define I2S_STEPPER_STREAM
44
-
45 51
 #define X_STEP_PIN         128
46 52
 #define X_DIR_PIN          129
47 53
 #define X_ENABLE_PIN       130

+ 4
- 4
platformio.ini View File

@@ -403,10 +403,10 @@ lib_ignore  =
403 403
 # Espressif ESP32
404 404
 #
405 405
 [env:esp32]
406
-platform    = https://github.com/platformio/platform-espressif32.git ; #feature/stage
407
-board       = esp32dev
408
-framework   = arduino
409
-upload_speed = 115200
406
+platform      = espressif32
407
+board         = esp32dev
408
+framework     = arduino
409
+upload_speed  = 115200
410 410
 monitor_speed = 115200
411 411
 upload_port = /dev/ttyUSB0
412 412
 lib_deps =

Loading…
Cancel
Save