47 lines
929 B
C++
47 lines
929 B
C++
#ifdef ESP_PLATFORM
|
|
|
|
#include <tactility/log.h>
|
|
#include <tactility/check.h>
|
|
|
|
#include <Tactility/PartitionsEsp.h>
|
|
|
|
#include "esp_event.h"
|
|
#include "esp_netif.h"
|
|
|
|
constexpr auto* TAG = "Tactility";
|
|
|
|
#include <cJSON.h>
|
|
#include <esp_heap_caps.h>
|
|
|
|
namespace tt {
|
|
|
|
static void* cjson_psram_malloc(size_t size) {
|
|
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
}
|
|
|
|
static void cjson_psram_free(void* ptr) {
|
|
heap_caps_free(ptr);
|
|
}
|
|
|
|
static void initNetwork() {
|
|
LOG_I(TAG, "Init network");
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
}
|
|
|
|
void initEsp() {
|
|
cJSON_Hooks hooks = {
|
|
.malloc_fn = cjson_psram_malloc,
|
|
.free_fn = cjson_psram_free
|
|
};
|
|
cJSON_InitHooks(&hooks);
|
|
LOG_I(TAG, "cJSON hooks initialized to use PSRAM");
|
|
|
|
check(initPartitionsEsp(), "Failed to init partitions");
|
|
initNetwork();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
#endif
|