@ -33,6 +33,10 @@
# include "../../inc/MarlinConfigPre.h"
# include "../../inc/MarlinConfigPre.h"
# if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
# include "spiffs.h"
# endif
# if ENABLED(WIFISUPPORT)
# if ENABLED(WIFISUPPORT)
# include <ESPAsyncWebServer.h>
# include <ESPAsyncWebServer.h>
# include "wifi.h"
# include "wifi.h"
@ -41,10 +45,7 @@
# endif
# endif
# if ENABLED(WEBSUPPORT)
# if ENABLED(WEBSUPPORT)
# include "web.h"
# include "web.h"
# include "spiffs.h"
# endif
# endif
# elif ENABLED(EEPROM_SETTINGS)
# include "spiffs.h"
# endif
# endif
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
@ -92,21 +93,24 @@ esp_adc_cal_characteristics_t characteristics;
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
void HAL_init ( void ) {
void HAL_init ( void ) {
i2s_init ( ) ;
}
void HAL_init_board ( void ) {
# if EITHER(EEPROM_SETTINGS, WEBSUPPORT)
spiffs_init ( ) ;
# endif
# if ENABLED(WIFISUPPORT)
# if ENABLED(WIFISUPPORT)
wifi_init ( ) ;
wifi_init ( ) ;
# if ENABLED(OTASUPPORT)
# if ENABLED(OTASUPPORT)
OTA_init ( ) ;
OTA_init ( ) ;
# endif
# endif
# if ENABLED(WEBSUPPORT)
# if ENABLED(WEBSUPPORT)
spiffs_init ( ) ;
web_init ( ) ;
web_init ( ) ;
# endif
# endif
server . begin ( ) ;
server . begin ( ) ;
# elif ENABLED(EEPROM_SETTINGS)
spiffs_init ( ) ;
# endif
# endif
i2s_init ( ) ;
}
}
void HAL_idletask ( void ) {
void HAL_idletask ( void ) {
@ -117,18 +121,12 @@ void HAL_idletask(void) {
void HAL_clear_reset_source ( void ) { }
void HAL_clear_reset_source ( void ) { }
uint8_t HAL_get_reset_source ( void ) {
uint8_t HAL_get_reset_source ( void ) { return rtc_get_reset_reason ( 1 ) ; }
return rtc_get_reset_reason ( 1 ) ;
}
void _delay_ms ( int delay_ms ) {
void _delay_ms ( int delay_ms ) { delay ( delay_ms ) ; }
delay ( delay_ms ) ;
}
// return free memory between end of heap (or end bss) and whatever is current
// return free memory between end of heap (or end bss) and whatever is current
int freeMemory ( ) {
int freeMemory ( ) { return ESP . getFreeHeap ( ) ; }
return ESP . getFreeHeap ( ) ;
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
// ADC
// ADC
@ -144,19 +142,41 @@ adc1_channel_t get_channel(int pin) {
case 33 : return ADC1_CHANNEL ( 33 ) ;
case 33 : return ADC1_CHANNEL ( 33 ) ;
case 32 : return ADC1_CHANNEL ( 32 ) ;
case 32 : return ADC1_CHANNEL ( 32 ) ;
}
}
return ADC1_CHANNEL_MAX ;
return ADC1_CHANNEL_MAX ;
}
}
void HAL_adc_init ( ) {
void HAL_adc_init ( ) {
// Configure ADC
// Configure ADC
adc1_config_width ( ADC_WIDTH_12Bit ) ;
adc1_config_width ( ADC_WIDTH_12Bit ) ;
adc1_config_channel_atten ( get_channel ( 39 ) , ADC_ATTEN_11db ) ;
adc1_config_channel_atten ( get_channel ( 36 ) , ADC_ATTEN_11db ) ;
// Configure channels only if used as (re-)configuring a pin for ADC that is used elsewhere might have adverse effects
adc1_config_channel_atten ( get_channel ( 35 ) , ADC_ATTEN_11db ) ;
# if HAS_TEMP_ADC_0
adc1_config_channel_atten ( get_channel ( 34 ) , ADC_ATTEN_11db ) ;
adc1_config_channel_atten ( get_channel ( TEMP_0_PIN ) , ADC_ATTEN_11db ) ;
adc1_config_channel_atten ( get_channel ( 33 ) , ADC_ATTEN_11db ) ;
# endif
adc1_config_channel_atten ( get_channel ( 32 ) , ADC_ATTEN_11db ) ;
# if HAS_TEMP_ADC_1
adc1_config_channel_atten ( get_channel ( TEMP_1_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_TEMP_ADC_2
adc1_config_channel_atten ( get_channel ( TEMP_2_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_TEMP_ADC_3
adc1_config_channel_atten ( get_channel ( TEMP_3_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_TEMP_ADC_4
adc1_config_channel_atten ( get_channel ( TEMP_4_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_TEMP_ADC_5
adc1_config_channel_atten ( get_channel ( TEMP_5_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_HEATED_BED
adc1_config_channel_atten ( get_channel ( TEMP_BED_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if HAS_TEMP_CHAMBER
adc1_config_channel_atten ( get_channel ( TEMP_CHAMBER_PIN ) , ADC_ATTEN_11db ) ;
# endif
# if ENABLED(FILAMENT_WIDTH_SENSOR)
adc1_config_channel_atten ( get_channel ( FILWIDTH_PIN ) , ADC_ATTEN_11db ) ;
# endif
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
// Note that adc2 is shared with the WiFi module, which has higher priority, so the conversion may fail.
// That's why we're not setting it up here.
// That's why we're not setting it up here.
@ -172,9 +192,9 @@ void HAL_adc_start_conversion(uint8_t adc_pin) {
HAL_adc_result = mv * 1023.0 / 3300.0 ;
HAL_adc_result = mv * 1023.0 / 3300.0 ;
}
}
int pin_to_channel [ 40 ] = { } ;
int cnt_channel = 1 ;
void analogWrite ( int pin , int value ) {
void analogWrite ( int pin , int value ) {
static int cnt_channel = 1 ,
pin_to_channel [ 40 ] = { } ;
if ( pin_to_channel [ pin ] = = 0 ) {
if ( pin_to_channel [ pin ] = = 0 ) {
ledcAttachPin ( pin , cnt_channel ) ;
ledcAttachPin ( pin , cnt_channel ) ;
ledcSetup ( cnt_channel , 490 , 8 ) ;
ledcSetup ( cnt_channel , 490 , 8 ) ;
@ -185,4 +205,5 @@ void analogWrite(int pin, int value) {
ledcWrite ( pin_to_channel [ pin ] , value ) ;
ledcWrite ( pin_to_channel [ pin ] , value ) ;
}
}
# endif // ARDUINO_ARCH_ESP32
# endif // ARDUINO_ARCH_ESP32