Skip to content

Commit

Permalink
ESP: Fix compile errors for ESP32H2 based on IDF v5.0-dev (#15291)
Browse files Browse the repository at this point in the history
* Prepare support for IDF version v5.0

* include 'inet/arpa-inet-compatibility.h' in TestInetAddress.cpp
  • Loading branch information
wqx6 authored Feb 22, 2022
1 parent 980cafa commit 2b80c6a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 52 deletions.
5 changes: 4 additions & 1 deletion config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ idf_component_get_property(freertos_dir freertos COMPONENT_DIR)

# ESP-IDF components usually need 'freertos/<header.h>', while
# CHIP might include do 'header.h'.
# In IDF V5.0, this path has been moved to
# '${freertos_component}/FreeRTOS-Kernel/include/freertos'
target_include_directories(${COMPONENT_LIB} PRIVATE
"${freertos_dir}/include/freertos")
"${freertos_dir}/include/freertos"
"${freertos_dir}/FreeRTOS-Kernel/include/freertos")

target_include_directories(${COMPONENT_LIB} INTERFACE
"${CHIP_ROOT}/src/platform/ESP32"
Expand Down
8 changes: 8 additions & 0 deletions src/inet/arpa-inet-compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@
#include <lwip/opt.h>

#if defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS)
#ifndef htons
#define htons(x) lwip_htons(x)
#endif
#ifndef ntohs
#define ntohs(x) lwip_ntohs(x)
#endif
#ifndef htonl
#define htonl(x) lwip_htonl(x)
#endif
#ifndef ntohl
#define ntohl(x) lwip_ntohl(x)
#endif
#endif // defined(LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS)

#endif // CHIP_SYSTEM_CONFIG_USE_LWIP
Expand Down
4 changes: 1 addition & 3 deletions src/inet/tests/TestInetAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#include <lwip/init.h>
#include <lwip/ip_addr.h>

#if LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
#define htonl(x) lwip_htonl(x)
#endif
#include <inet/arpa-inet-compatibility.h>

#else
#include <netinet/in.h>
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ESP32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static_library("ESP32") {

if (chip_enable_openthread) {
sources += [
"../OpenThread/DnssdImpl.cpp",
"../OpenThread/OpenThreadUtils.cpp",
"ESPThreadConfig.h",
"ThreadStackManagerImpl.cpp",
"ThreadStackManagerImpl.h",
]
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#define CHIP_DEVICE_CONFIG_ENABLE_THREAD CONFIG_OPENTHREAD_ENABLED
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT CONFIG_OPENTHREAD_SRP_CLIENT
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT CONFIG_OPENTHREAD_SRP_CLIENT

#if CONFIG_IDF_TARGET_ESP32H2
#define CHIP_DEVICE_CONFIG_ENABLE_WIFI 0
Expand Down
40 changes: 0 additions & 40 deletions src/platform/ESP32/ESPThreadConfig.h

This file was deleted.

22 changes: 16 additions & 6 deletions src/platform/ESP32/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <platform/ThreadStackManager.h>

#include <platform/ESP32/ESPThreadConfig.h>
#include <platform/ESP32/ThreadStackManagerImpl.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp>

Expand Down Expand Up @@ -90,12 +89,23 @@ void ThreadStackManagerImpl::_OnCHIPoBLEAdvertisingStop()
// Intentionally empty.
}

void ThreadStackManagerImpl::ESPThreadTask(void * arg)
void ThreadStackManagerImpl::_OnPlatformEvent(const ChipDeviceEvent * event)
{
esp_openthread_launch_mainloop();
esp_openthread_netif_glue_deinit();
esp_vfs_eventfd_unregister();
vTaskDelete(NULL);
Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>::_OnPlatformEvent(event);

if (event->Type == DeviceEventType::kThreadStateChange && event->ThreadStateChange.RoleChanged)
{
const bool isAttached = IsThreadAttached();
VerifyOrReturn(isAttached != mIsAttached);
ChipDeviceEvent attachEvent;
attachEvent.Type = DeviceEventType::kThreadConnectivityChange;
attachEvent.ThreadConnectivityChange.Result = isAttached ? kConnectivity_Established : kConnectivity_Lost;

CHIP_ERROR error = PlatformMgr().PostEvent(&attachEvent);
VerifyOrReturn(error == CHIP_NO_ERROR,
ChipLogError(DeviceLayer, "Failed to post Thread connectivity change: %" CHIP_ERROR_FORMAT, error.Format()));
mIsAttached = isAttached;
}
}

} // namespace DeviceLayer
Expand Down
4 changes: 3 additions & 1 deletion src/platform/ESP32/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
void _ProcessThreadActivity();
void _OnCHIPoBLEAdvertisingStart();
void _OnCHIPoBLEAdvertisingStop();
void _OnPlatformEvent(const ChipDeviceEvent * event);

private:
friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
static ThreadStackManagerImpl sInstance;
ThreadStackManagerImpl() = default;
static void ESPThreadTask(void * arg);

bool mIsAttached = false;
};

/**
Expand Down

0 comments on commit 2b80c6a

Please sign in to comment.