|
@@ -33,6 +33,10 @@
|
33
|
33
|
|
34
|
34
|
#include "../../inc/MarlinConfigPre.h"
|
35
|
35
|
|
|
36
|
+#if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
|
|
37
|
+ #include "spiffs.h"
|
|
38
|
+#endif
|
|
39
|
+
|
36
|
40
|
#if ENABLED(WIFISUPPORT)
|
37
|
41
|
#include <ESPAsyncWebServer.h>
|
38
|
42
|
#include "wifi.h"
|
|
@@ -41,10 +45,7 @@
|
41
|
45
|
#endif
|
42
|
46
|
#if ENABLED(WEBSUPPORT)
|
43
|
47
|
#include "web.h"
|
44
|
|
- #include "spiffs.h"
|
45
|
48
|
#endif
|
46
|
|
-#elif ENABLED(EEPROM_SETTINGS)
|
47
|
|
- #include "spiffs.h"
|
48
|
49
|
#endif
|
49
|
50
|
|
50
|
51
|
// --------------------------------------------------------------------------
|
|
@@ -92,21 +93,24 @@ esp_adc_cal_characteristics_t characteristics;
|
92
|
93
|
// --------------------------------------------------------------------------
|
93
|
94
|
|
94
|
95
|
void HAL_init(void) {
|
|
96
|
+ i2s_init();
|
|
97
|
+}
|
|
98
|
+
|
|
99
|
+void HAL_init_board(void) {
|
|
100
|
+ #if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
|
|
101
|
+ spiffs_init();
|
|
102
|
+ #endif
|
|
103
|
+
|
95
|
104
|
#if ENABLED(WIFISUPPORT)
|
96
|
105
|
wifi_init();
|
97
|
106
|
#if ENABLED(OTASUPPORT)
|
98
|
107
|
OTA_init();
|
99
|
108
|
#endif
|
100
|
109
|
#if ENABLED(WEBSUPPORT)
|
101
|
|
- spiffs_init();
|
102
|
110
|
web_init();
|
103
|
111
|
#endif
|
104
|
112
|
server.begin();
|
105
|
|
- #elif ENABLED(EEPROM_SETTINGS)
|
106
|
|
- spiffs_init();
|
107
|
113
|
#endif
|
108
|
|
-
|
109
|
|
- i2s_init();
|
110
|
114
|
}
|
111
|
115
|
|
112
|
116
|
void HAL_idletask(void) {
|
|
@@ -117,18 +121,12 @@ void HAL_idletask(void) {
|
117
|
121
|
|
118
|
122
|
void HAL_clear_reset_source(void) { }
|
119
|
123
|
|
120
|
|
-uint8_t HAL_get_reset_source(void) {
|
121
|
|
- return rtc_get_reset_reason(1);
|
122
|
|
-}
|
|
124
|
+uint8_t HAL_get_reset_source(void) { return rtc_get_reset_reason(1); }
|
123
|
125
|
|
124
|
|
-void _delay_ms(int delay_ms) {
|
125
|
|
- delay(delay_ms);
|
126
|
|
-}
|
|
126
|
+void _delay_ms(int delay_ms) { delay(delay_ms); }
|
127
|
127
|
|
128
|
128
|
// return free memory between end of heap (or end bss) and whatever is current
|
129
|
|
-int freeMemory() {
|
130
|
|
- return ESP.getFreeHeap();
|
131
|
|
-}
|
|
129
|
+int freeMemory() { return ESP.getFreeHeap(); }
|
132
|
130
|
|
133
|
131
|
// --------------------------------------------------------------------------
|
134
|
132
|
// ADC
|
|
@@ -144,19 +142,41 @@ adc1_channel_t get_channel(int pin) {
|
144
|
142
|
case 33: return ADC1_CHANNEL(33);
|
145
|
143
|
case 32: return ADC1_CHANNEL(32);
|
146
|
144
|
}
|
147
|
|
-
|
148
|
145
|
return ADC1_CHANNEL_MAX;
|
149
|
146
|
}
|
150
|
147
|
|
151
|
148
|
void HAL_adc_init() {
|
152
|
149
|
// Configure ADC
|
153
|
150
|
adc1_config_width(ADC_WIDTH_12Bit);
|
154
|
|
- adc1_config_channel_atten(get_channel(39), ADC_ATTEN_11db);
|
155
|
|
- adc1_config_channel_atten(get_channel(36), ADC_ATTEN_11db);
|
156
|
|
- adc1_config_channel_atten(get_channel(35), ADC_ATTEN_11db);
|
157
|
|
- adc1_config_channel_atten(get_channel(34), ADC_ATTEN_11db);
|
158
|
|
- adc1_config_channel_atten(get_channel(33), ADC_ATTEN_11db);
|
159
|
|
- adc1_config_channel_atten(get_channel(32), ADC_ATTEN_11db);
|
|
151
|
+
|
|
152
|
+ // Configure channels only if used as (re-)configuring a pin for ADC that is used elsewhere might have adverse effects
|
|
153
|
+ #if HAS_TEMP_ADC_0
|
|
154
|
+ adc1_config_channel_atten(get_channel(TEMP_0_PIN), ADC_ATTEN_11db);
|
|
155
|
+ #endif
|
|
156
|
+ #if HAS_TEMP_ADC_1
|
|
157
|
+ adc1_config_channel_atten(get_channel(TEMP_1_PIN), ADC_ATTEN_11db);
|
|
158
|
+ #endif
|
|
159
|
+ #if HAS_TEMP_ADC_2
|
|
160
|
+ adc1_config_channel_atten(get_channel(TEMP_2_PIN), ADC_ATTEN_11db);
|
|
161
|
+ #endif
|
|
162
|
+ #if HAS_TEMP_ADC_3
|
|
163
|
+ adc1_config_channel_atten(get_channel(TEMP_3_PIN), ADC_ATTEN_11db);
|
|
164
|
+ #endif
|
|
165
|
+ #if HAS_TEMP_ADC_4
|
|
166
|
+ adc1_config_channel_atten(get_channel(TEMP_4_PIN), ADC_ATTEN_11db);
|
|
167
|
+ #endif
|
|
168
|
+ #if HAS_TEMP_ADC_5
|
|
169
|
+ adc1_config_channel_atten(get_channel(TEMP_5_PIN), ADC_ATTEN_11db);
|
|
170
|
+ #endif
|
|
171
|
+ #if HAS_HEATED_BED
|
|
172
|
+ adc1_config_channel_atten(get_channel(TEMP_BED_PIN), ADC_ATTEN_11db);
|
|
173
|
+ #endif
|
|
174
|
+ #if HAS_TEMP_CHAMBER
|
|
175
|
+ adc1_config_channel_atten(get_channel(TEMP_CHAMBER_PIN), ADC_ATTEN_11db);
|
|
176
|
+ #endif
|
|
177
|
+ #if ENABLED(FILAMENT_WIDTH_SENSOR)
|
|
178
|
+ adc1_config_channel_atten(get_channel(FILWIDTH_PIN), ADC_ATTEN_11db);
|
|
179
|
+ #endif
|
160
|
180
|
|
161
|
181
|
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
|
162
|
182
|
// That's why we're not setting it up here.
|
|
@@ -172,9 +192,9 @@ void HAL_adc_start_conversion(uint8_t adc_pin) {
|
172
|
192
|
HAL_adc_result = mv*1023.0/3300.0;
|
173
|
193
|
}
|
174
|
194
|
|
175
|
|
-int pin_to_channel[40] = {};
|
176
|
|
-int cnt_channel = 1;
|
177
|
195
|
void analogWrite(int pin, int value) {
|
|
196
|
+ static int cnt_channel = 1,
|
|
197
|
+ pin_to_channel[40] = {};
|
178
|
198
|
if (pin_to_channel[pin] == 0) {
|
179
|
199
|
ledcAttachPin(pin, cnt_channel);
|
180
|
200
|
ledcSetup(cnt_channel, 490, 8);
|
|
@@ -185,4 +205,5 @@ void analogWrite(int pin, int value) {
|
185
|
205
|
|
186
|
206
|
ledcWrite(pin_to_channel[pin], value);
|
187
|
207
|
}
|
|
208
|
+
|
188
|
209
|
#endif // ARDUINO_ARCH_ESP32
|