Skip to content

Commit

Permalink
Remove support for ESP-IDF version < 4 (esphome#5261)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeMan authored Aug 17, 2023
1 parent 2b4ed0c commit 0af8d0b
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 129 deletions.
4 changes: 0 additions & 4 deletions esphome/components/debug/debug_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
#include <esp_heap_caps.h>
#include <esp_system.h>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <esp32/rom/rtc.h>
#include <esp_chip_info.h>
#else
#include <rom/rtc.h>
#endif

#endif // USE_ESP32

Expand Down
12 changes: 1 addition & 11 deletions esphome/components/esp32/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <esp_timer.h>
#include <soc/rtc.h>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <hal/cpu_hal.h>
#endif

#ifdef USE_ARDUINO
#include <esp32-hal.h>
Expand Down Expand Up @@ -55,15 +53,7 @@ void arch_init() {
void IRAM_ATTR HOT arch_feed_wdt() { esp_task_wdt_reset(); }

uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
uint32_t arch_get_cpu_cycle_count() {
#if ESP_IDF_VERSION_MAJOR >= 4
return cpu_hal_get_cycle_count();
#else
uint32_t ccount;
__asm__ __volatile__("esync; rsr %0,ccount" : "=a"(ccount));
return ccount;
#endif
}
uint32_t arch_get_cpu_cycle_count() { return cpu_hal_get_cycle_count(); }
uint32_t arch_get_cpu_freq_hz() { return rtc_clk_apb_freq_get(); }

#ifdef USE_ESP_IDF
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/esp32_touch/esp32_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

#include <vector>

#if ESP_IDF_VERSION_MAJOR >= 4
#include <driver/touch_sensor.h>
#else
#include <driver/touch_pad.h>
#endif

namespace esphome {
namespace esp32_touch {
Expand Down
41 changes: 2 additions & 39 deletions esphome/components/socket/bsd_sockets_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,25 +87,7 @@ class BSDSocketImpl : public Socket {
int listen(int backlog) override { return ::listen(fd_, backlog); }
ssize_t read(void *buf, size_t len) override { return ::read(fd_, buf, len); }
ssize_t readv(const struct iovec *iov, int iovcnt) override {
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 4
// esp-idf v3 doesn't have readv, emulate it
ssize_t ret = 0;
for (int i = 0; i < iovcnt; i++) {
ssize_t err = this->read(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len);
if (err == -1) {
if (ret != 0) {
// if we already read some don't return an error
break;
}
return err;
}
ret += err;
if (err != iov[i].iov_len)
break;
}
return ret;
#elif defined(USE_ESP32)
// ESP-IDF v4 only has symbol lwip_readv
#if defined(USE_ESP32)
return ::lwip_readv(fd_, iov, iovcnt);
#else
return ::readv(fd_, iov, iovcnt);
Expand All @@ -114,26 +96,7 @@ class BSDSocketImpl : public Socket {
ssize_t write(const void *buf, size_t len) override { return ::write(fd_, buf, len); }
ssize_t send(void *buf, size_t len, int flags) { return ::send(fd_, buf, len, flags); }
ssize_t writev(const struct iovec *iov, int iovcnt) override {
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 4
// esp-idf v3 doesn't have writev, emulate it
ssize_t ret = 0;
for (int i = 0; i < iovcnt; i++) {
ssize_t err =
this->send(reinterpret_cast<uint8_t *>(iov[i].iov_base), iov[i].iov_len, i == iovcnt - 1 ? 0 : MSG_MORE);
if (err == -1) {
if (ret != 0) {
// if we already wrote some don't return an error
break;
}
return err;
}
ret += err;
if (err != iov[i].iov_len)
break;
}
return ret;
#elif defined(USE_ESP32)
// ESP-IDF v4 only has symbol lwip_writev
#if defined(USE_ESP32)
return ::lwip_writev(fd_, iov, iovcnt);
#else
return ::writev(fd_, iov, iovcnt);
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/wifi/wifi_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,7 @@ class WiFiComponent : public Component {
#endif

#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#if ESP_IDF_VERSION_MAJOR >= 4
void wifi_event_callback_(arduino_event_id_t event, arduino_event_info_t info);
#else
void wifi_event_callback_(system_event_id_t event, system_event_info_t info);
#endif
void wifi_scan_done_callback_();
#endif
#ifdef USE_ESP_IDF
Expand Down
63 changes: 0 additions & 63 deletions esphome/components/wifi/wifi_component_esp32_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,10 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
// Units: AP beacon intervals. Defaults to 3 if set to 0.
conf.sta.listen_interval = 0;

#if ESP_IDF_VERSION_MAJOR >= 4
// Protected Management Frame
// Device will prefer to connect in PMF mode if other device also advertises PMF capability.
conf.sta.pmf_cfg.capable = true;
conf.sta.pmf_cfg.required = false;
#endif

// note, we do our own filtering
// The minimum rssi to accept in the fast scan mode
Expand Down Expand Up @@ -314,11 +312,7 @@ const char *get_auth_mode_str(uint8_t mode) {
}
}

#if ESP_IDF_VERSION_MAJOR >= 4
using esphome_ip4_addr_t = esp_ip4_addr_t;
#else
using esphome_ip4_addr_t = ip4_addr_t;
#endif

std::string format_ip4_addr(const esphome_ip4_addr_t &ip) {
char buf[20];
Expand Down Expand Up @@ -404,8 +398,6 @@ const char *get_disconnect_reason_str(uint8_t reason) {
}
}

#if ESP_IDF_VERSION_MAJOR >= 4

#define ESPHOME_EVENT_ID_WIFI_READY ARDUINO_EVENT_WIFI_READY
#define ESPHOME_EVENT_ID_WIFI_SCAN_DONE ARDUINO_EVENT_WIFI_SCAN_DONE
#define ESPHOME_EVENT_ID_WIFI_STA_START ARDUINO_EVENT_WIFI_STA_START
Expand All @@ -426,40 +418,14 @@ const char *get_disconnect_reason_str(uint8_t reason) {
using esphome_wifi_event_id_t = arduino_event_id_t;
using esphome_wifi_event_info_t = arduino_event_info_t;

#else // ESP_IDF_VERSION_MAJOR >= 4

#define ESPHOME_EVENT_ID_WIFI_READY SYSTEM_EVENT_WIFI_READY
#define ESPHOME_EVENT_ID_WIFI_SCAN_DONE SYSTEM_EVENT_SCAN_DONE
#define ESPHOME_EVENT_ID_WIFI_STA_START SYSTEM_EVENT_STA_START
#define ESPHOME_EVENT_ID_WIFI_STA_STOP SYSTEM_EVENT_STA_STOP
#define ESPHOME_EVENT_ID_WIFI_STA_CONNECTED SYSTEM_EVENT_STA_CONNECTED
#define ESPHOME_EVENT_ID_WIFI_STA_DISCONNECTED SYSTEM_EVENT_STA_DISCONNECTED
#define ESPHOME_EVENT_ID_WIFI_STA_AUTHMODE_CHANGE SYSTEM_EVENT_STA_AUTHMODE_CHANGE
#define ESPHOME_EVENT_ID_WIFI_STA_GOT_IP SYSTEM_EVENT_STA_GOT_IP
#define ESPHOME_EVENT_ID_WIFI_STA_LOST_IP SYSTEM_EVENT_STA_LOST_IP
#define ESPHOME_EVENT_ID_WIFI_AP_START SYSTEM_EVENT_AP_START
#define ESPHOME_EVENT_ID_WIFI_AP_STOP SYSTEM_EVENT_AP_STOP
#define ESPHOME_EVENT_ID_WIFI_AP_STACONNECTED SYSTEM_EVENT_AP_STACONNECTED
#define ESPHOME_EVENT_ID_WIFI_AP_STADISCONNECTED SYSTEM_EVENT_AP_STADISCONNECTED
#define ESPHOME_EVENT_ID_WIFI_AP_STAIPASSIGNED SYSTEM_EVENT_AP_STAIPASSIGNED
#define ESPHOME_EVENT_ID_WIFI_AP_PROBEREQRECVED SYSTEM_EVENT_AP_PROBEREQRECVED
using esphome_wifi_event_id_t = system_event_id_t;
using esphome_wifi_event_info_t = system_event_info_t;

#endif // !(ESP_IDF_VERSION_MAJOR >= 4)

void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_wifi_event_info_t info) {
switch (event) {
case ESPHOME_EVENT_ID_WIFI_READY: {
ESP_LOGV(TAG, "Event: WiFi ready");
break;
}
case ESPHOME_EVENT_ID_WIFI_SCAN_DONE: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_scan_done;
#else
auto it = info.scan_done;
#endif
ESP_LOGV(TAG, "Event: WiFi Scan Done status=%u number=%u scan_id=%u", it.status, it.number, it.scan_id);

this->wifi_scan_done_callback_();
Expand All @@ -475,11 +441,7 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
break;
}
case ESPHOME_EVENT_ID_WIFI_STA_CONNECTED: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_sta_connected;
#else
auto it = info.connected;
#endif
char buf[33];
memcpy(buf, it.ssid, it.ssid_len);
buf[it.ssid_len] = '\0';
Expand All @@ -492,11 +454,7 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
break;
}
case ESPHOME_EVENT_ID_WIFI_STA_DISCONNECTED: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_sta_disconnected;
#else
auto it = info.disconnected;
#endif
char buf[33];
memcpy(buf, it.ssid, it.ssid_len);
buf[it.ssid_len] = '\0';
Expand All @@ -522,11 +480,7 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
break;
}
case ESPHOME_EVENT_ID_WIFI_STA_AUTHMODE_CHANGE: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_sta_authmode_change;
#else
auto it = info.auth_change;
#endif
ESP_LOGV(TAG, "Event: Authmode Change old=%s new=%s", get_auth_mode_str(it.old_mode),
get_auth_mode_str(it.new_mode));
// Mitigate CVE-2020-12638
Expand Down Expand Up @@ -570,24 +524,14 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
break;
}
case ESPHOME_EVENT_ID_WIFI_AP_STACONNECTED: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_sta_connected;
auto &mac = it.bssid;
#else
auto it = info.sta_connected;
auto &mac = it.mac;
#endif
ESP_LOGV(TAG, "Event: AP client connected MAC=%s", format_mac_addr(mac).c_str());
break;
}
case ESPHOME_EVENT_ID_WIFI_AP_STADISCONNECTED: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_sta_disconnected;
auto &mac = it.bssid;
#else
auto it = info.sta_disconnected;
auto &mac = it.mac;
#endif
ESP_LOGV(TAG, "Event: AP client disconnected MAC=%s", format_mac_addr(mac).c_str());
break;
}
Expand All @@ -596,11 +540,7 @@ void WiFiComponent::wifi_event_callback_(esphome_wifi_event_id_t event, esphome_
break;
}
case ESPHOME_EVENT_ID_WIFI_AP_PROBEREQRECVED: {
#if ESP_IDF_VERSION_MAJOR >= 4
auto it = info.wifi_ap_probereqrecved;
#else
auto it = info.ap_probereqrecved;
#endif
ESP_LOGVV(TAG, "Event: AP receive Probe Request MAC=%s RSSI=%d", format_mac_addr(it.mac).c_str(), it.rssi);
break;
}
Expand Down Expand Up @@ -742,10 +682,7 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
strncpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), sizeof(conf.ap.ssid));
}

#if ESP_IDF_VERSION_MAJOR >= 4
// pairwise cipher of SoftAP, group cipher will be derived using this.
conf.ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP;
#endif

esp_err_t err = esp_wifi_set_config(WIFI_IF_AP, &conf);
if (err != ESP_OK) {
Expand Down
4 changes: 0 additions & 4 deletions esphome/components/wifi/wifi_component_esp_idf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,10 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) {
// Units: AP beacon intervals. Defaults to 3 if set to 0.
conf.sta.listen_interval = 0;

#if ESP_IDF_VERSION_MAJOR >= 4
// Protected Management Frame
// Device will prefer to connect in PMF mode if other device also advertises PMF capability.
conf.sta.pmf_cfg.capable = true;
conf.sta.pmf_cfg.required = false;
#endif

// note, we do our own filtering
// The minimum rssi to accept in the fast scan mode
Expand Down Expand Up @@ -838,10 +836,8 @@ bool WiFiComponent::wifi_start_ap_(const WiFiAP &ap) {
strncpy(reinterpret_cast<char *>(conf.ap.password), ap.get_password().c_str(), sizeof(conf.ap.password));
}

#if ESP_IDF_VERSION_MAJOR >= 4
// pairwise cipher of SoftAP, group cipher will be derived using this.
conf.ap.pairwise_cipher = WIFI_CIPHER_TYPE_CCMP;
#endif

esp_err_t err = esp_wifi_set_config(WIFI_IF_AP, &conf);
if (err != ESP_OK) {
Expand Down

0 comments on commit 0af8d0b

Please sign in to comment.