diff --git a/src/drivers/nuttx/lv_nuttx_cache.c b/src/drivers/nuttx/lv_nuttx_cache.c index 0d5a9742cc..713e987f21 100644 --- a/src/drivers/nuttx/lv_nuttx_cache.c +++ b/src/drivers/nuttx/lv_nuttx_cache.c @@ -48,6 +48,13 @@ void lv_nuttx_cache_init(void) handlers->flush_cache_cb = flush_cache; } +void lv_nuttx_cache_deinit(void) +{ + lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers(); + handlers->invalidate_cache_cb = NULL; + handlers->flush_cache_cb = NULL; +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/drivers/nuttx/lv_nuttx_cache.h b/src/drivers/nuttx/lv_nuttx_cache.h index 693744ea4c..74be6d3af5 100644 --- a/src/drivers/nuttx/lv_nuttx_cache.h +++ b/src/drivers/nuttx/lv_nuttx_cache.h @@ -28,6 +28,8 @@ extern "C" { void lv_nuttx_cache_init(void); +void lv_nuttx_cache_deinit(void); + /********************** * MACROS **********************/ diff --git a/src/drivers/nuttx/lv_nuttx_entry.c b/src/drivers/nuttx/lv_nuttx_entry.c index 90adf790cb..f1c212ef47 100644 --- a/src/drivers/nuttx/lv_nuttx_entry.c +++ b/src/drivers/nuttx/lv_nuttx_entry.c @@ -177,6 +177,38 @@ uint32_t lv_nuttx_get_idle(void) #endif +void lv_nuttx_deinit(lv_nuttx_result_t * result) +{ +#if !LV_USE_NUTTX_CUSTOM_INIT + if(result) { + if(result->disp) { + lv_display_delete(result->disp); + result->disp = NULL; + } + + if(result->indev) { + lv_indev_delete(result->indev); + result->indev = NULL; + } + + if(result->utouch_indev) { + lv_indev_delete(result->utouch_indev); + result->utouch_indev = NULL; + } + } +#else + lv_nuttx_deinit_custom(result); +#endif + + if(nuttx_ctx_p) { + lv_nuttx_cache_deinit(); + lv_nuttx_image_cache_deinit(); + + lv_free(nuttx_ctx_p); + nuttx_ctx_p = NULL; + } +} + /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/drivers/nuttx/lv_nuttx_entry.h b/src/drivers/nuttx/lv_nuttx_entry.h index 93449e046f..40aefad44c 100644 --- a/src/drivers/nuttx/lv_nuttx_entry.h +++ b/src/drivers/nuttx/lv_nuttx_entry.h @@ -64,6 +64,12 @@ void lv_nuttx_dsc_init(lv_nuttx_dsc_t * dsc); */ void lv_nuttx_init(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result); +/** + * Deinitialize the LVGL display driver for NuttX. + * @param result Pointer to the lv_nuttx_result_t structure containing display and input device handler. + */ +void lv_nuttx_deinit(lv_nuttx_result_t * result); + #if LV_USE_NUTTX_CUSTOM_INIT /** * Initialize the LVGL display driver for NuttX using the provided custom configuration information. @@ -72,6 +78,11 @@ void lv_nuttx_init(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result); */ void lv_nuttx_init_custom(const lv_nuttx_dsc_t * dsc, lv_nuttx_result_t * result); +/** + * Deinitialize the LVGL display driver for NuttX using the provided custom configuration information. + * @param result Pointer to the lv_nuttx_result_t structure containing display and input device handler. + */ +void lv_nuttx_deinit_custom(lv_nuttx_result_t * result); #endif /* LV_USE_NUTTX_CUSTOM_INIT */ /** diff --git a/src/drivers/nuttx/lv_nuttx_image_cache.c b/src/drivers/nuttx/lv_nuttx_image_cache.c index 00efd163a4..9fa210822f 100644 --- a/src/drivers/nuttx/lv_nuttx_image_cache.c +++ b/src/drivers/nuttx/lv_nuttx_image_cache.c @@ -66,6 +66,19 @@ void lv_nuttx_image_cache_init(void) ctx->initialized = false; } +void lv_nuttx_image_cache_deinit(void) +{ + if(ctx->initialized == false) goto FREE_CONTEXT; + + mm_uninitialize(ctx->heap); + free(ctx->mem); + +FREE_CONTEXT: + lv_free(ctx); + + ctx = NULL; +} + /********************** * STATIC FUNCTIONS **********************/ @@ -76,7 +89,7 @@ static bool defer_init(void) return true; } - if(img_cache_p->max_size == 0) { + if(lv_image_cache_is_enabled() == false) { LV_LOG_INFO("Image cache is not initialized yet. Skipping deferred initialization. Because max_size is 0."); return false; } diff --git a/src/drivers/nuttx/lv_nuttx_image_cache.h b/src/drivers/nuttx/lv_nuttx_image_cache.h index d8f74fbca0..105779fa64 100644 --- a/src/drivers/nuttx/lv_nuttx_image_cache.h +++ b/src/drivers/nuttx/lv_nuttx_image_cache.h @@ -30,6 +30,8 @@ extern "C" { void lv_nuttx_image_cache_init(void); +void lv_nuttx_image_cache_deinit(void); + /********************** * MACROS **********************/