From 74556b28a805657ec4887a049dcbf38dc5e5a07a Mon Sep 17 00:00:00 2001 From: Tom Keller <1083460+kellertk@users.noreply.github.com> Date: Mon, 9 Jan 2023 20:40:04 -0800 Subject: [PATCH] fix: json compilation error on rp2040 (#4273) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/json/json_util.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index 7e701af48b..f105280b23 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -7,6 +7,9 @@ #ifdef USE_ESP32 #include #endif +#ifdef USE_RP2040 +#include +#endif namespace esphome { namespace json { @@ -24,6 +27,8 @@ std::string build_json(const json_build_t &f) { const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance) #elif defined(USE_ESP32) const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT); +#elif defined(USE_RP2040) + const size_t free_heap = rp2040.getFreeHeap(); #endif size_t request_size = std::min(free_heap, (size_t) 512); @@ -64,6 +69,8 @@ void parse_json(const std::string &data, const json_parse_t &f) { const size_t free_heap = ESP.getMaxFreeBlockSize(); // NOLINT(readability-static-accessed-through-instance) #elif defined(USE_ESP32) const size_t free_heap = heap_caps_get_largest_free_block(MALLOC_CAP_8BIT); +#elif defined(USE_RP2040) + const size_t free_heap = rp2040.getFreeHeap(); #endif bool pass = false; size_t request_size = std::min(free_heap, (size_t)(data.size() * 1.5));