Created
August 19, 2021 12:14
-
-
Save cibomahto/a29b6662847e13c61b47a194fad4ab11 to your computer and use it in GitHub Desktop.
cJSON SPIRAM allocator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! @brief For cjson: Memory allocator to use SPIRAM | |
//! | |
//! @param[in] sz Size of the memory to allocate | |
//! @return Pointer to the allocated memory if successful, or NULL if not successful | |
void* cjson_caps_malloc(size_t sz) | |
{ | |
return heap_caps_malloc(sz, MALLOC_CAP_SPIRAM); | |
} | |
//! @brief For cjson: Memory allocator to use SPIRAM | |
//! | |
//! @param[in] ptr Pointer to the allocated memory that is to be freed | |
void CJSON_CDECL cjson_caps_free(void* ptr) | |
{ | |
heap_caps_free(ptr); | |
} | |
//! @brief Install function handlers so that cJSON will use SPIRAM | |
static void cjson_mem_init() | |
{ | |
// Configure cJSON to use SPIRAM | |
cJSON_Hooks cjson_hooks = { | |
.malloc_fn = &cjson_caps_malloc, | |
.free_fn = &cjson_caps_free, | |
}; | |
cJSON_InitHooks(&cjson_hooks); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment