mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 17:18:40 +00:00
Use if-else instead of switch to avoid CSWTCH in rodata
On ESP8266, GCC generates a lookup table in .rodata for switch statements, which lives in flash. Use if-else chain to keep the logic entirely in IRAM.
This commit is contained in:
@@ -637,21 +637,19 @@ void WiFiComponent::wifi_pre_setup_() {
|
||||
|
||||
WiFiSTAConnectStatus WiFiComponent::wifi_sta_connect_status_() const {
|
||||
// Use cached state from wifi_event_callback() instead of calling
|
||||
// wifi_station_get_connect_status() which queries the SDK every time
|
||||
switch (s_sta_state) {
|
||||
case ESP8266WiFiSTAState::CONNECTED:
|
||||
return WiFiSTAConnectStatus::CONNECTED;
|
||||
case ESP8266WiFiSTAState::ERROR_NOT_FOUND:
|
||||
return WiFiSTAConnectStatus::ERROR_NETWORK_NOT_FOUND;
|
||||
case ESP8266WiFiSTAState::ERROR_FAILED:
|
||||
return WiFiSTAConnectStatus::ERROR_CONNECT_FAILED;
|
||||
case ESP8266WiFiSTAState::CONNECTING:
|
||||
case ESP8266WiFiSTAState::ASSOCIATED:
|
||||
return WiFiSTAConnectStatus::CONNECTING;
|
||||
case ESP8266WiFiSTAState::IDLE:
|
||||
default:
|
||||
return WiFiSTAConnectStatus::IDLE;
|
||||
}
|
||||
// wifi_station_get_connect_status() which queries the SDK every time.
|
||||
// Use if-else instead of switch to avoid GCC generating a CSWTCH
|
||||
// lookup table in .rodata (flash) on ESP8266.
|
||||
auto state = s_sta_state;
|
||||
if (state == ESP8266WiFiSTAState::CONNECTED)
|
||||
return WiFiSTAConnectStatus::CONNECTED;
|
||||
if (state == ESP8266WiFiSTAState::ERROR_NOT_FOUND)
|
||||
return WiFiSTAConnectStatus::ERROR_NETWORK_NOT_FOUND;
|
||||
if (state == ESP8266WiFiSTAState::ERROR_FAILED)
|
||||
return WiFiSTAConnectStatus::ERROR_CONNECT_FAILED;
|
||||
if (state == ESP8266WiFiSTAState::CONNECTING || state == ESP8266WiFiSTAState::ASSOCIATED)
|
||||
return WiFiSTAConnectStatus::CONNECTING;
|
||||
return WiFiSTAConnectStatus::IDLE;
|
||||
}
|
||||
bool WiFiComponent::wifi_scan_start_(bool passive) {
|
||||
// enable STA
|
||||
|
||||
Reference in New Issue
Block a user