Browse Source

HAL for Espressif ESP32 Wifi

Simon Jouet 6 years ago
parent
commit
e2aeda61ed

+ 9
- 0
Marlin/Configuration_adv.h View File

@@ -1700,4 +1700,13 @@
1700 1700
                               // Default behaviour is limited to Z axis only.
1701 1701
 #endif
1702 1702
 
1703
+/**
1704
+ * WiFi Support (Espressif ESP32 WiFi)
1705
+ */
1706
+//#define WIFISUPPORT
1707
+#if ENABLED(WIFISUPPORT)
1708
+  #define WIFI_SSID "Wifi SSID"
1709
+  #define WIFI_PWD  "Wifi Password"
1710
+#endif
1711
+
1703 1712
 #endif // CONFIGURATION_ADV_H

+ 27
- 14
Marlin/src/HAL/Delay.h View File

@@ -21,14 +21,12 @@
21 21
  */
22 22
 
23 23
 /**
24
-
25
-  Busy wait delay Cycles routines:
26
-
27
-  DELAY_CYCLES(count): Delay execution in cycles
28
-  DELAY_NS(count): Delay execution in nanoseconds
29
-  DELAY_US(count): Delay execution in microseconds
30
-
31
-  */
24
+ * Busy wait delay cycles routines:
25
+ *
26
+ *  DELAY_CYCLES(count): Delay execution in cycles
27
+ *  DELAY_NS(count): Delay execution in nanoseconds
28
+ *  DELAY_US(count): Delay execution in microseconds
29
+ */
32 30
 
33 31
 #ifndef MARLIN_DELAY_H
34 32
 #define MARLIN_DELAY_H
@@ -37,7 +35,7 @@
37 35
 
38 36
 #if defined(__arm__) || defined(__thumb__)
39 37
 
40
-  /* https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles */
38
+  // https://blueprints.launchpad.net/gcc-arm-embedded/+spec/delay-cycles
41 39
 
42 40
   #define nop() __asm__ __volatile__("nop;\n\t":::)
43 41
 
@@ -60,7 +58,7 @@
60 58
     );
61 59
   }
62 60
 
63
-  /* ---------------- Delay in cycles */
61
+  // Delay in cycles
64 62
   FORCE_INLINE static void DELAY_CYCLES(uint32_t x) {
65 63
 
66 64
     if (__builtin_constant_p(x)) {
@@ -98,7 +96,7 @@
98 96
     );
99 97
   }
100 98
 
101
-  /* ---------------- Delay in cycles */
99
+  // Delay in cycles
102 100
   FORCE_INLINE static void DELAY_CYCLES(uint16_t x) {
103 101
 
104 102
     if (__builtin_constant_p(x)) {
@@ -121,15 +119,30 @@
121 119
   }
122 120
   #undef nop
123 121
 
122
+#elif defined(ESP32)
123
+
124
+  FORCE_INLINE static void DELAY_CYCLES(uint32_t x) {
125
+    unsigned long ccount, stop;
126
+
127
+    __asm__ __volatile__ ( "rsr     %0, ccount" : "=a" (ccount) );
128
+
129
+    stop = ccount + x; // This can overflow
130
+
131
+    while (ccount < stop) { // This doesn't deal with overflows
132
+      __asm__ __volatile__ ( "rsr     %0, ccount" : "=a" (ccount) );
133
+    }
134
+  }
135
+
124 136
 #else
137
+
125 138
   #error "Unsupported MCU architecture"
139
+
126 140
 #endif
127 141
 
128
-/* ---------------- Delay in nanoseconds */
142
+// Delay in nanoseconds
129 143
 #define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) / 1000L )
130 144
 
131
-/* ---------------- Delay in microseconds */
145
+// Delay in microseconds
132 146
 #define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) )
133 147
 
134 148
 #endif // MARLIN_DELAY_H
135
-

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

@@ -0,0 +1,155 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef ARDUINO_ARCH_ESP32
24
+
25
+// --------------------------------------------------------------------------
26
+// Includes
27
+// --------------------------------------------------------------------------
28
+
29
+#include "HAL.h"
30
+#include <rom/rtc.h>
31
+#include <driver/adc.h>
32
+#include <esp_adc_cal.h>
33
+
34
+#include "../../inc/MarlinConfigPre.h"
35
+
36
+#if ENABLED(WIFISUPPORT)
37
+  #include "ota.h"
38
+#endif
39
+
40
+// --------------------------------------------------------------------------
41
+// Externals
42
+// --------------------------------------------------------------------------
43
+
44
+portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
45
+
46
+// --------------------------------------------------------------------------
47
+// Local defines
48
+// --------------------------------------------------------------------------
49
+
50
+#define V_REF 1100
51
+
52
+// --------------------------------------------------------------------------
53
+// Types
54
+// --------------------------------------------------------------------------
55
+
56
+// --------------------------------------------------------------------------
57
+// Variables
58
+// --------------------------------------------------------------------------
59
+
60
+// --------------------------------------------------------------------------
61
+// Public Variables
62
+// --------------------------------------------------------------------------
63
+
64
+uint16_t HAL_adc_result;
65
+
66
+// --------------------------------------------------------------------------
67
+// Private Variables
68
+// --------------------------------------------------------------------------
69
+
70
+esp_adc_cal_characteristics_t characteristics;
71
+
72
+// --------------------------------------------------------------------------
73
+// Function prototypes
74
+// --------------------------------------------------------------------------
75
+
76
+// --------------------------------------------------------------------------
77
+// Private functions
78
+// --------------------------------------------------------------------------
79
+
80
+// --------------------------------------------------------------------------
81
+// Public functions
82
+// --------------------------------------------------------------------------
83
+
84
+void HAL_init(void) {
85
+  #if ENABLED(WIFISUPPORT)
86
+    OTA_init();
87
+  #endif
88
+}
89
+
90
+void HAL_idletask(void) {
91
+  #if ENABLED(WIFISUPPORT)
92
+    OTA_handle();
93
+  #endif
94
+}
95
+
96
+void HAL_clear_reset_source(void) { }
97
+
98
+uint8_t HAL_get_reset_source (void) {
99
+  return rtc_get_reset_reason(1);
100
+}
101
+
102
+void _delay_ms(int delay_ms) {
103
+  delay(delay_ms);
104
+}
105
+
106
+// return free memory between end of heap (or end bss) and whatever is current
107
+int freeMemory() {
108
+  return ESP.getFreeHeap();
109
+}
110
+
111
+// --------------------------------------------------------------------------
112
+// ADC
113
+// --------------------------------------------------------------------------
114
+#define ADC1_CHANNEL(pin) ADC1_GPIO##pin_CHANNEL
115
+
116
+adc1_channel_t get_channel(int pin) {
117
+  switch (pin) {
118
+    case 36: return ADC1_GPIO36_CHANNEL;
119
+    case 39: return ADC1_GPIO39_CHANNEL;
120
+  }
121
+
122
+  return ADC1_CHANNEL_MAX;
123
+}
124
+
125
+void HAL_adc_init() {
126
+  // Configure ADC
127
+  adc1_config_width(ADC_WIDTH_12Bit);
128
+  adc1_config_channel_atten(get_channel(36), ADC_ATTEN_11db);
129
+  adc1_config_channel_atten(get_channel(39), ADC_ATTEN_11db);
130
+
131
+  // Calculate ADC characteristics i.e. gain and offset factors
132
+  esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
133
+}
134
+
135
+void HAL_adc_start_conversion (uint8_t adc_pin) {
136
+  uint32_t mv;
137
+  esp_adc_cal_get_voltage((adc_channel_t)get_channel(adc_pin), &characteristics, &mv);
138
+
139
+  HAL_adc_result = mv*1023.0/3300.0;
140
+}
141
+
142
+int pin_to_channel[40] = {};
143
+int cnt_channel = 1;
144
+void analogWrite(int pin, int value) {
145
+  if (pin_to_channel[pin] == 0) {
146
+    ledcAttachPin(pin, cnt_channel);
147
+    ledcSetup(cnt_channel, 490, 8);
148
+    ledcWrite(cnt_channel, value);
149
+
150
+    pin_to_channel[pin] = cnt_channel++;
151
+  }
152
+
153
+  ledcWrite(pin_to_channel[pin], value);
154
+}
155
+#endif // ARDUINO_ARCH_ESP32

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

@@ -0,0 +1,126 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+/**
21
+ * Description: HAL for Espressif ESP32 WiFi
22
+ */
23
+
24
+#ifndef _HAL_ESP32_H
25
+#define _HAL_ESP32_H
26
+
27
+#define CPU_32_BIT
28
+
29
+// --------------------------------------------------------------------------
30
+// Includes
31
+// --------------------------------------------------------------------------
32
+
33
+#include <stdint.h>
34
+
35
+#undef DISABLED
36
+#undef _BV
37
+
38
+#include <Arduino.h>
39
+
40
+#undef DISABLED
41
+#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
42
+
43
+#include "../math_32bit.h"
44
+#include "../HAL_SPI.h"
45
+
46
+#include "fastio_ESP32.h"
47
+#include "watchdog_ESP32.h"
48
+
49
+#include "HAL_timers_ESP32.h"
50
+
51
+// --------------------------------------------------------------------------
52
+// Defines
53
+// --------------------------------------------------------------------------
54
+
55
+extern portMUX_TYPE spinlock;
56
+
57
+#define NUM_SERIAL 1
58
+#define MYSERIAL0 Serial
59
+
60
+#define CRITICAL_SECTION_START portENTER_CRITICAL(&spinlock)
61
+#define CRITICAL_SECTION_END   portEXIT_CRITICAL(&spinlock)
62
+#define ISRS_ENABLED() (spinlock.owner == portMUX_FREE_VAL)
63
+#define ENABLE_ISRS()  if (spinlock.owner != portMUX_FREE_VAL) portEXIT_CRITICAL(&spinlock)
64
+#define DISABLE_ISRS() portENTER_CRITICAL(&spinlock)
65
+
66
+
67
+// Fix bug in pgm_read_ptr
68
+#undef pgm_read_ptr
69
+#define pgm_read_ptr(addr) (*(addr))
70
+
71
+// --------------------------------------------------------------------------
72
+// Types
73
+// --------------------------------------------------------------------------
74
+
75
+typedef int16_t pin_t;
76
+
77
+// --------------------------------------------------------------------------
78
+// Public Variables
79
+// --------------------------------------------------------------------------
80
+
81
+/** result of last ADC conversion */
82
+extern uint16_t HAL_adc_result;
83
+
84
+// --------------------------------------------------------------------------
85
+// Public functions
86
+// --------------------------------------------------------------------------
87
+
88
+// clear reset reason
89
+void HAL_clear_reset_source (void);
90
+
91
+// reset reason
92
+uint8_t HAL_get_reset_source (void);
93
+
94
+void _delay_ms(int delay);
95
+
96
+int freeMemory(void);
97
+
98
+void analogWrite(int pin, int value);
99
+
100
+// EEPROM
101
+void eeprom_write_byte(unsigned char *pos, unsigned char value);
102
+unsigned char eeprom_read_byte(unsigned char *pos);
103
+void eeprom_read_block (void *__dst, const void *__src, size_t __n);
104
+void eeprom_update_block (const void *__src, void *__dst, size_t __n);
105
+
106
+// ADC
107
+#define HAL_ANALOG_SELECT(pin)
108
+
109
+void HAL_adc_init(void);
110
+
111
+#define HAL_START_ADC(pin)  HAL_adc_start_conversion(pin)
112
+#define HAL_READ_ADC        HAL_adc_result
113
+
114
+void HAL_adc_start_conversion (uint8_t adc_pin);
115
+
116
+#define GET_PIN_MAP_PIN(index) index
117
+#define GET_PIN_MAP_INDEX(pin) pin
118
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
119
+
120
+// Enable hooks into idle and setup for HAL
121
+#define HAL_IDLETASK 1
122
+#define HAL_INIT 1
123
+void HAL_idletask(void);
124
+void HAL_init(void);
125
+
126
+#endif // _HAL_ESP32_H

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

@@ -0,0 +1,109 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ * Copyright (C) 2017 Victor Perez
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
24
+#ifdef ARDUINO_ARCH_ESP32
25
+
26
+// --------------------------------------------------------------------------
27
+// Includes
28
+// --------------------------------------------------------------------------
29
+
30
+#include "HAL.h"
31
+#include "../HAL_SPI.h"
32
+#include "pins_arduino.h"
33
+#include "spi_pins.h"
34
+#include "../../core/macros.h"
35
+#include <SPI.h>
36
+
37
+// --------------------------------------------------------------------------
38
+// Public Variables
39
+// --------------------------------------------------------------------------
40
+
41
+static SPISettings spiConfig;
42
+
43
+// --------------------------------------------------------------------------
44
+// Public functions
45
+// --------------------------------------------------------------------------
46
+
47
+// --------------------------------------------------------------------------
48
+// Hardware SPI
49
+// --------------------------------------------------------------------------
50
+
51
+void spiBegin() {
52
+  #if !PIN_EXISTS(SS)
53
+    #error "SS_PIN not defined!"
54
+  #endif
55
+
56
+  WRITE(SS_PIN, HIGH);
57
+  SET_OUTPUT(SS_PIN);
58
+}
59
+
60
+void spiInit(uint8_t spiRate) {
61
+  uint32_t clock;
62
+
63
+  switch (spiRate) {
64
+    case SPI_FULL_SPEED:    clock = SPI_CLOCK_DIV2 ; break;
65
+    case SPI_HALF_SPEED:    clock = SPI_CLOCK_DIV4 ; break;
66
+    case SPI_QUARTER_SPEED: clock = SPI_CLOCK_DIV8 ; break;
67
+    case SPI_EIGHTH_SPEED:  clock = SPI_CLOCK_DIV16; break;
68
+    case SPI_SPEED_5:       clock = SPI_CLOCK_DIV32; break;
69
+    case SPI_SPEED_6:       clock = SPI_CLOCK_DIV64; break;
70
+    default:                clock = SPI_CLOCK_DIV2; // Default from the SPI library
71
+  }
72
+
73
+  spiConfig = SPISettings(clock, MSBFIRST, SPI_MODE0);
74
+  SPI.begin();
75
+}
76
+
77
+uint8_t spiRec(void) {
78
+  SPI.beginTransaction(spiConfig);
79
+  uint8_t returnByte = SPI.transfer(0xFF);
80
+  SPI.endTransaction();
81
+  return returnByte;
82
+}
83
+
84
+void spiRead(uint8_t* buf, uint16_t nbyte) {
85
+  SPI.beginTransaction(spiConfig);
86
+  SPI.transferBytes(0, buf, nbyte);
87
+  SPI.endTransaction();
88
+}
89
+
90
+void spiSend(uint8_t b) {
91
+  SPI.beginTransaction(spiConfig);
92
+  SPI.transfer(b);
93
+  SPI.endTransaction();
94
+}
95
+
96
+void spiSendBlock(uint8_t token, const uint8_t* buf) {
97
+  SPI.beginTransaction(spiConfig);
98
+  SPI.transfer(token);
99
+  SPI.writeBytes(const_cast<uint8_t*>(buf), 512);
100
+  SPI.endTransaction();
101
+}
102
+
103
+void spiBeginTransaction(uint32_t spiClock, uint8_t bitOrder, uint8_t dataMode) {
104
+  spiConfig = SPISettings(spiClock, bitOrder, dataMode);
105
+
106
+  SPI.beginTransaction(spiConfig);
107
+}
108
+
109
+#endif // ARDUINO_ARCH_ESP32

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

@@ -0,0 +1,202 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef ARDUINO_ARCH_ESP32
24
+
25
+// --------------------------------------------------------------------------
26
+// Includes
27
+// --------------------------------------------------------------------------
28
+
29
+#include <stdio.h>
30
+#include "esp_types.h"
31
+#include "soc/timer_group_struct.h"
32
+#include "driver/periph_ctrl.h"
33
+#include "driver/timer.h"
34
+
35
+#include "HAL.h"
36
+
37
+#include "HAL_timers_ESP32.h"
38
+
39
+// --------------------------------------------------------------------------
40
+// Externals
41
+// --------------------------------------------------------------------------
42
+
43
+// --------------------------------------------------------------------------
44
+// Local defines
45
+// --------------------------------------------------------------------------
46
+
47
+#define NUM_HARDWARE_TIMERS 4
48
+
49
+// --------------------------------------------------------------------------
50
+// Types
51
+// --------------------------------------------------------------------------
52
+
53
+
54
+// --------------------------------------------------------------------------
55
+// Public Variables
56
+// --------------------------------------------------------------------------
57
+
58
+// --------------------------------------------------------------------------
59
+// Private Variables
60
+// --------------------------------------------------------------------------
61
+
62
+static timg_dev_t *TG[2] = {&TIMERG0, &TIMERG1};
63
+
64
+const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
65
+  { TIMER_GROUP_0, TIMER_0, STEPPER_TIMER_PRESCALE, stepTC_Handler }, // 0 - Stepper
66
+  { TIMER_GROUP_0, TIMER_1,    TEMP_TIMER_PRESCALE, tempTC_Handler }, // 1 - Temperature
67
+  { TIMER_GROUP_1, TIMER_0,                      1, NULL }, // 2
68
+  { TIMER_GROUP_1, TIMER_1,                      1, NULL }, // 3
69
+};
70
+
71
+// --------------------------------------------------------------------------
72
+// Function prototypes
73
+// --------------------------------------------------------------------------
74
+
75
+// --------------------------------------------------------------------------
76
+// Private functions
77
+// --------------------------------------------------------------------------
78
+
79
+// --------------------------------------------------------------------------
80
+// Public functions
81
+// --------------------------------------------------------------------------
82
+
83
+void IRAM_ATTR timer_group0_isr(void *para) {
84
+  const int timer_idx = (int)para;
85
+
86
+  // Retrieve the interrupt status and the counter value
87
+  // from the timer that reported the interrupt
88
+  uint32_t intr_status = TIMERG0.int_st_timers.val;
89
+  TIMERG0.hw_timer[timer_idx].update = 1;
90
+
91
+  // Clear the interrupt
92
+  if (intr_status & BIT(timer_idx)) {
93
+    switch (timer_idx) {
94
+      case TIMER_0: TIMERG0.int_clr_timers.t0 = 1; break;
95
+      case TIMER_1: TIMERG0.int_clr_timers.t1 = 1; break;
96
+    }
97
+  }
98
+
99
+  const tTimerConfig timer = TimerConfig[timer_idx];
100
+  timer.fn();
101
+
102
+  // After the alarm has been triggered
103
+  // Enable it again so it gets triggered the next time
104
+  TIMERG0.hw_timer[timer_idx].config.alarm_en = TIMER_ALARM_EN;
105
+}
106
+
107
+/**
108
+ * Enable and initialize the timer
109
+ * @param timer_num timer number to initialize
110
+ * @param frequency frequency of the timer
111
+ */
112
+void HAL_timer_start(const uint8_t timer_num, uint32_t frequency) {
113
+  const tTimerConfig timer = TimerConfig[timer_num];
114
+
115
+  timer_config_t config;
116
+  config.divider     = STEPPER_TIMER_PRESCALE;
117
+  config.counter_dir = TIMER_COUNT_UP;
118
+  config.counter_en  = TIMER_PAUSE;
119
+  config.alarm_en    = TIMER_ALARM_EN;
120
+  config.intr_type   = TIMER_INTR_LEVEL;
121
+  config.auto_reload = true;
122
+
123
+  // Select and initialize the timer
124
+  timer_init(timer.group, timer.idx, &config);
125
+
126
+  // Timer counter initial value and auto reload on alarm
127
+  timer_set_counter_value(timer.group, timer.idx, 0x00000000ULL);
128
+
129
+  // Configure the alam value and the interrupt on alarm
130
+  timer_set_alarm_value(timer.group, timer.idx, (HAL_TIMER_RATE) / timer.divider / frequency - 1);
131
+
132
+  timer_enable_intr(timer.group, timer.idx);
133
+
134
+  // TODO need to deal with timer_group1_isr
135
+  timer_isr_register(timer.group, timer.idx, timer_group0_isr, (void*)timer.idx, NULL, NULL);
136
+
137
+  timer_start(timer.group, timer.idx);
138
+}
139
+
140
+/**
141
+ * Set the upper value of the timer, when the timer reaches this upper value the
142
+ * interrupt should be triggered and the counter reset
143
+ * @param timer_num timer number to set the count to
144
+ * @param count     threshold at which the interrupt is triggered
145
+ */
146
+void HAL_timer_set_compare(const uint8_t timer_num, hal_timer_t count) {
147
+  const tTimerConfig timer = TimerConfig[timer_num];
148
+  timer_set_alarm_value(timer.group, timer.idx, count);
149
+}
150
+
151
+/**
152
+ * Get the current upper value of the timer
153
+ * @param  timer_num timer number to get the count from
154
+ * @return           the timer current threshold for the alarm to be triggered
155
+ */
156
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
157
+  const tTimerConfig timer = TimerConfig[timer_num];
158
+
159
+  uint64_t alarm_value;
160
+  timer_get_alarm_value(timer.group, timer.idx, &alarm_value);
161
+
162
+  return alarm_value;
163
+}
164
+
165
+/**
166
+ * Get the current counter value between 0 and the maximum count (HAL_timer_set_count)
167
+ * @param  timer_num timer number to get the current count
168
+ * @return           the current counter of the alarm
169
+ */
170
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
171
+  const tTimerConfig timer = TimerConfig[timer_num];
172
+
173
+  uint64_t counter_value;
174
+  timer_get_counter_value(timer.group, timer.idx, &counter_value);
175
+
176
+  return counter_value;
177
+}
178
+
179
+/**
180
+ * Enable timer interrupt on the timer
181
+ * @param timer_num timer number to enable interrupts on
182
+ */
183
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
184
+  const tTimerConfig timer = TimerConfig[timer_num];
185
+  //timer_enable_intr(timer.group, timer.idx);
186
+}
187
+
188
+/**
189
+ * Disable timer interrupt on the timer
190
+ * @param timer_num timer number to disable interrupts on
191
+ */
192
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
193
+  const tTimerConfig timer = TimerConfig[timer_num];
194
+  // timer_disable_intr(timer.group, timer.idx);
195
+}
196
+
197
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
198
+  const tTimerConfig timer = TimerConfig[timer_num];
199
+  return TG[timer.group]->int_ena.val | BIT(timer_num);
200
+}
201
+
202
+#endif // ARDUINO_ARCH_ESP32

+ 114
- 0
Marlin/src/HAL/HAL_ESP32/HAL_timers_ESP32.h View File

@@ -0,0 +1,114 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef _HAL_TIMERS_ESP32_H
24
+#define _HAL_TIMERS_ESP32_H
25
+
26
+// --------------------------------------------------------------------------
27
+// Includes
28
+// --------------------------------------------------------------------------
29
+
30
+#include <stdint.h>
31
+#include "driver/timer.h"
32
+
33
+// --------------------------------------------------------------------------
34
+// Defines
35
+// --------------------------------------------------------------------------
36
+//
37
+#define FORCE_INLINE __attribute__((always_inline)) inline
38
+
39
+typedef uint64_t hal_timer_t;
40
+#define HAL_TIMER_TYPE_MAX 0xFFFFFFFFFFFFFFFFULL
41
+
42
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
43
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
44
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
45
+
46
+#define HAL_TIMER_RATE APB_CLK_FREQ // frequency of timer peripherals
47
+
48
+#define STEPPER_TIMER_PRESCALE     40
49
+#define STEPPER_TIMER_RATE         (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer, 2MHz
50
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)          // stepper timer ticks per µs
51
+
52
+#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
53
+
54
+#define TEMP_TIMER_PRESCALE    1000 // prescaler for setting Temp timer, 72Khz
55
+#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
56
+
57
+#define PULSE_TIMER_RATE         STEPPER_TIMER_RATE   // frequency of pulse timer
58
+#define PULSE_TIMER_PRESCALE     STEPPER_TIMER_PRESCALE
59
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
60
+
61
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
62
+#define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
63
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
64
+
65
+#define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
66
+#define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
67
+
68
+#define HAL_TEMP_TIMER_ISR extern "C" void tempTC_Handler(void)
69
+#define HAL_STEP_TIMER_ISR extern "C" void stepTC_Handler(void)
70
+
71
+extern "C" void tempTC_Handler(void);
72
+extern "C" void stepTC_Handler(void);
73
+
74
+
75
+// --------------------------------------------------------------------------
76
+// Types
77
+// --------------------------------------------------------------------------
78
+
79
+typedef struct {
80
+  timer_group_t  group;
81
+  timer_idx_t    idx;
82
+  uint32_t       divider;
83
+  void           (*fn)(void);
84
+} tTimerConfig;
85
+
86
+// --------------------------------------------------------------------------
87
+// Public Variables
88
+// --------------------------------------------------------------------------
89
+
90
+extern const tTimerConfig TimerConfig[];
91
+
92
+// --------------------------------------------------------------------------
93
+// Public functions
94
+// --------------------------------------------------------------------------
95
+
96
+void HAL_timer_start (const uint8_t timer_num, uint32_t frequency);
97
+void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t count);
98
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
99
+hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
100
+
101
+// if counter too high then bump up compare
102
+FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_ticks) {
103
+  const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_ticks;
104
+  if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp);
105
+}
106
+
107
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
108
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
109
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
110
+
111
+#define HAL_timer_isr_prologue(TIMER_NUM)
112
+#define HAL_timer_isr_epilogue(TIMER_NUM)
113
+
114
+#endif // _HAL_TIMERS_ESP32_H

+ 25
- 0
Marlin/src/HAL/HAL_ESP32/SanityCheck.h View File

@@ -0,0 +1,25 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#if ENABLED(EMERGENCY_PARSER)
24
+  #error "EMERGENCY_PARSER is not yet implemented for ESP32. Disable EMERGENCY_PARSER to continue."
25
+#endif

+ 77
- 0
Marlin/src/HAL/HAL_ESP32/endstop_interrupts.h View File

@@ -0,0 +1,77 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Endstop Interrupts
25
+ *
26
+ * Without endstop interrupts the endstop pins must be polled continually in
27
+ * the stepper-ISR via endstops.update(), most of the time finding no change.
28
+ * With this feature endstops.update() is called only when we know that at
29
+ * least one endstop has changed state, saving valuable CPU cycles.
30
+ *
31
+ * This feature only works when all used endstop pins can generate an 'external interrupt'.
32
+ *
33
+ * Test whether pins issue interrupts on your board by flashing 'pin_interrupt_test.ino'.
34
+ * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
35
+ */
36
+
37
+#ifndef _ENDSTOP_INTERRUPTS_H_
38
+#define _ENDSTOP_INTERRUPTS_H_
39
+
40
+#include "../../module/endstops.h"
41
+
42
+// One ISR for all EXT-Interrupts
43
+void ICACHE_RAM_ATTR endstop_ISR(void) {
44
+  endstops.check_possible_change();
45
+}
46
+
47
+void setup_endstop_interrupts(void) {
48
+  #if HAS_X_MAX
49
+    attachInterrupt(digitalPinToInterrupt(X_MAX_PIN), endstop_ISR, CHANGE);
50
+  #endif
51
+  #if HAS_X_MIN
52
+    attachInterrupt(digitalPinToInterrupt(X_MIN_PIN), endstop_ISR, CHANGE);
53
+  #endif
54
+  #if HAS_Y_MAX
55
+    attachInterrupt(digitalPinToInterrupt(Y_MAX_PIN), endstop_ISR, CHANGE);
56
+  #endif
57
+  #if HAS_Y_MIN
58
+    attachInterrupt(digitalPinToInterrupt(Y_MIN_PIN), endstop_ISR, CHANGE);
59
+  #endif
60
+  #if HAS_Z_MAX
61
+    attachInterrupt(digitalPinToInterrupt(Z_MAX_PIN), endstop_ISR, CHANGE);
62
+  #endif
63
+  #if HAS_Z_MIN
64
+     attachInterrupt(digitalPinToInterrupt(Z_MIN_PIN), endstop_ISR, CHANGE);
65
+  #endif
66
+  #if HAS_Z2_MAX
67
+    attachInterrupt(digitalPinToInterrupt(Z2_MAX_PIN), endstop_ISR, CHANGE);
68
+  #endif
69
+  #if HAS_Z2_MIN
70
+    attachInterrupt(digitalPinToInterrupt(Z2_MIN_PIN), endstop_ISR, CHANGE);
71
+  #endif
72
+  #if HAS_Z_MIN_PROBE_PIN
73
+    attachInterrupt(digitalPinToInterrupt(Z_MIN_PROBE_PIN), endstop_ISR, CHANGE);
74
+  #endif
75
+}
76
+
77
+#endif //_ENDSTOP_INTERRUPTS_H_

+ 72
- 0
Marlin/src/HAL/HAL_ESP32/fastio_ESP32.h View File

@@ -0,0 +1,72 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef _FASTIO_ESP32_H
24
+#define _FASTIO_ESP32_H
25
+
26
+/**
27
+ * Utility functions
28
+ */
29
+
30
+// set pin as input
31
+#define _SET_INPUT(IO)      pinMode(IO, INPUT)
32
+
33
+// set pin as output
34
+#define _SET_OUTPUT(IO)     pinMode(IO, OUTPUT)
35
+
36
+// set pin as input with pullup mode
37
+#define _PULLUP(IO, v)      pinMode(IO, v ? INPUT_PULLUP : INPUT)
38
+
39
+// Read a pin wrapper
40
+#define READ(IO)            digitalRead(IO)
41
+
42
+// Write to a pin wrapper
43
+#define WRITE(IO, v)        digitalWrite(IO, v)
44
+
45
+// set pin as input wrapper
46
+#define SET_INPUT(IO)       _SET_INPUT(IO)
47
+
48
+// set pin as input with pullup wrapper
49
+#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
50
+
51
+// set pin as output wrapper
52
+#define SET_OUTPUT(IO)  do{ _SET_OUTPUT(IO); WRITE(IO, LOW); }while(0)
53
+
54
+#define OUT_WRITE(IO,V)         do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
55
+
56
+//
57
+// ports and functions
58
+//
59
+
60
+// UART
61
+#define RXD        3
62
+#define TXD        1
63
+
64
+// TWI (I2C)
65
+#define SCL        5
66
+#define SDA        4
67
+
68
+//
69
+// pins
70
+//
71
+
72
+#endif // _FASTIO_ESP32_H

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

@@ -0,0 +1,81 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#ifdef ARDUINO_ARCH_ESP32
21
+
22
+#include "../../inc/MarlinConfigPre.h"
23
+
24
+#if ENABLED(WIFISUPPORT)
25
+
26
+#include <WiFi.h>
27
+#include <ESPmDNS.h>
28
+#include <WiFiUdp.h>
29
+#include <ArduinoOTA.h>
30
+#include "driver/timer.h"
31
+
32
+void OTA_init() {
33
+  WiFi.mode(WIFI_STA);
34
+  WiFi.begin(WIFI_SSID, WIFI_PWD);
35
+
36
+  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
37
+    Serial.println("Connection Failed! Rebooting...");
38
+    delay(5000);
39
+    ESP.restart();
40
+  }
41
+
42
+  ArduinoOTA
43
+    .onStart([]() {
44
+      timer_pause(TIMER_GROUP_0, TIMER_0);
45
+      timer_pause(TIMER_GROUP_0, TIMER_1);
46
+
47
+      // U_FLASH or U_SPIFFS
48
+      String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
49
+
50
+      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
51
+      Serial.println("Start updating " + type);
52
+    })
53
+    .onEnd([]() {
54
+      Serial.println("\nEnd");
55
+    })
56
+    .onProgress([](unsigned int progress, unsigned int total) {
57
+      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
58
+    })
59
+    .onError([](ota_error_t error) {
60
+      Serial.printf("Error[%u]: ", error);
61
+      char *str;
62
+      switch (error) {
63
+        case OTA_AUTH_ERROR:    str = "Auth Failed";    break;
64
+        case OTA_BEGIN_ERROR:   str = "Begin Failed";   break;
65
+        case OTA_CONNECT_ERROR: str = "Connect Failed"; break;
66
+        case OTA_RECEIVE_ERROR: str = "Receive Failed"; break;
67
+        case OTA_END_ERROR:     str = "End Failed";     break;
68
+      }
69
+      Serial.println(str);
70
+    });
71
+
72
+  ArduinoOTA.begin();
73
+}
74
+
75
+void OTA_handle() {
76
+  ArduinoOTA.handle();
77
+}
78
+
79
+#endif // WIFISUPPORT
80
+
81
+#endif // ARDUINO_ARCH_ESP32

+ 26
- 0
Marlin/src/HAL/HAL_ESP32/ota.h View File

@@ -0,0 +1,26 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#ifndef _HAL_OTA_H
21
+#define _HAL_OTA_H
22
+
23
+void OTA_init();
24
+void OTA_handle();
25
+
26
+#endif

+ 21
- 0
Marlin/src/HAL/HAL_ESP32/servotimers.h View File

@@ -0,0 +1,21 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */

+ 28
- 0
Marlin/src/HAL/HAL_ESP32/spi_pins.h View File

@@ -0,0 +1,28 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ */
19
+
20
+#ifndef SPI_PINS_H_
21
+#define SPI_PINS_H_
22
+
23
+#define SS_PIN    5
24
+#define SCK_PIN  18
25
+#define MISO_PIN 19
26
+#define MOSI_PIN 23
27
+
28
+#endif // SPI_PINS_H_

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

@@ -0,0 +1,41 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifdef ARDUINO_ARCH_ESP32
24
+
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if ENABLED(USE_WATCHDOG)
28
+
29
+#include "watchdog_ESP32.h"
30
+
31
+void watchdogSetup(void) {
32
+  // do whatever. don't remove this function.
33
+}
34
+
35
+void watchdog_init(void) {
36
+  // TODO
37
+}
38
+
39
+#endif // USE_WATCHDOG
40
+
41
+#endif // ARDUINO_ARCH_ESP32

+ 32
- 0
Marlin/src/HAL/HAL_ESP32/watchdog_ESP32.h View File

@@ -0,0 +1,32 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+#ifndef WATCHDOG_ESP32_H
24
+#define WATCHDOG_ESP32_H
25
+
26
+// Initialize watchdog with a 4 second interrupt time
27
+void watchdog_init();
28
+
29
+// Reset watchdog.
30
+inline void watchdog_reset() {};
31
+
32
+#endif // WATCHDOG_ESP32_H

+ 2
- 0
Marlin/src/HAL/platforms.h View File

@@ -17,6 +17,8 @@
17 17
   #define HAL_PLATFORM HAL_STM32F4
18 18
 #elif defined(STM32F7)
19 19
   #define HAL_PLATFORM HAL_STM32F7
20
+#elif defined(ARDUINO_ARCH_ESP32)
21
+  #define HAL_PLATFORM HAL_ESP32
20 22
 #else
21 23
   #error "Unsupported Platform!"
22 24
 #endif

+ 2
- 2
Marlin/src/Marlin.cpp View File

@@ -702,10 +702,10 @@ void setup() {
702 702
 
703 703
   #if NUM_SERIAL > 0
704 704
     uint32_t serial_connect_timeout = millis() + 1000UL;
705
-    while(!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
705
+    while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
706 706
     #if NUM_SERIAL > 1
707 707
       serial_connect_timeout = millis() + 1000UL;
708
-      while(!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
708
+      while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
709 709
     #endif
710 710
   #endif
711 711
 

+ 9
- 0
Marlin/src/config/default/Configuration_adv.h View File

@@ -1700,4 +1700,13 @@
1700 1700
                               // Default behaviour is limited to Z axis only.
1701 1701
 #endif
1702 1702
 
1703
+/**
1704
+ * WiFi Support (Espressif ESP32 WiFi)
1705
+ */
1706
+//#define WIFISUPPORT
1707
+#if ENABLED(WIFISUPPORT)
1708
+  #define WIFI_SSID "Wifi SSID"
1709
+  #define WIFI_PWD  "Wifi Password"
1710
+#endif
1711
+
1703 1712
 #endif // CONFIGURATION_ADV_H

+ 4
- 0
Marlin/src/core/boards.h View File

@@ -225,6 +225,10 @@
225 225
 
226 226
 #define BOARD_THE_BORG         1860   // THE-BORG (Power outputs: Hotend0, Hotend1, Bed, Fan)
227 227
 
228
+//
229
+// Espressif ESP32 WiFi
230
+//
231
+#define BOARD_ESP32            1900
228 232
 
229 233
 #define MB(board) (defined(BOARD_##board) && MOTHERBOARD==BOARD_##board)
230 234
 

+ 7
- 0
Marlin/src/pins/pins.h View File

@@ -381,6 +381,13 @@
381 381
 #elif MB(THE_BORG)
382 382
   #include "pins_THE_BORG.h"          // STM32F7                                    env:STM32F7
383 383
 
384
+//
385
+// Espressif ESP32
386
+//
387
+
388
+#elif MB(ESP32)
389
+  #include "pins_ESP32.h"
390
+
384 391
 #else
385 392
   #error "Unknown MOTHERBOARD value set in Configuration.h"
386 393
 #endif

+ 72
- 0
Marlin/src/pins/pins_ESP32.h View File

@@ -0,0 +1,72 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * Espressif ESP32 (Tensilica Xtensa LX6) pin assignments
25
+ */
26
+
27
+#ifndef BOARD_NAME
28
+  #define BOARD_NAME "Espressif ESP32"
29
+#endif
30
+
31
+//
32
+// Limit Switches
33
+//
34
+#define X_MIN_PIN          34
35
+#define Y_MIN_PIN          35
36
+#define Z_MIN_PIN          15
37
+
38
+//
39
+// Steppers
40
+//
41
+#define X_STEP_PIN         27
42
+#define X_DIR_PIN          26
43
+#define X_ENABLE_PIN       25
44
+//#define X_CS_PIN            0
45
+
46
+#define Y_STEP_PIN         33
47
+#define Y_DIR_PIN          32
48
+#define Y_ENABLE_PIN       X_ENABLE_PIN
49
+//#define Y_CS_PIN           13
50
+
51
+#define Z_STEP_PIN         14
52
+#define Z_DIR_PIN          12
53
+#define Z_ENABLE_PIN       X_ENABLE_PIN
54
+//#define Z_CS_PIN            5 // SS_PIN
55
+
56
+#define E0_STEP_PIN        16
57
+#define E0_DIR_PIN         17
58
+#define E0_ENABLE_PIN      X_ENABLE_PIN
59
+//#define E0_CS_PIN          21
60
+
61
+//
62
+// Temperature Sensors
63
+//
64
+#define TEMP_0_PIN         36   // Analog Input
65
+#define TEMP_BED_PIN       39   // Analog Input
66
+
67
+//
68
+// Heaters / Fans
69
+//
70
+#define HEATER_0_PIN        2
71
+#define FAN_PIN            13
72
+#define HEATER_BED_PIN      4

+ 16
- 0
platformio.ini View File

@@ -318,3 +318,19 @@ lib_ignore  =
318 318
   U8glib-HAL
319 319
   TMC2208Stepper
320 320
   c1921b4
321
+
322
+#
323
+# Espressif ESP32
324
+#
325
+[env:esp32]
326
+platform = https://github.com/platformio/platform-espressif32.git#feature/stage
327
+board = esp32dev
328
+framework = arduino
329
+upload_port = COM3
330
+lib_ignore  =
331
+  LiquidCrystal_I2C
332
+  LiquidCrystal
333
+  NewliquidCrystal
334
+  LiquidTWI2
335
+  TMC26XStepper
336
+  c1921b4

Loading…
Cancel
Save