lvgl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /*********************
  7. * INCLUDES
  8. *********************/
  9. #define LOG_MODULE_CUSTOMER
  10. #include <os_common_api.h>
  11. #include <zephyr.h>
  12. #include "lvgl_inner.h"
  13. #include "../decoder/lv_img_decoder_acts.h"
  14. #ifdef CONFIG_UI_MEMORY_MANAGER
  15. # include LV_MEM_CUSTOM_INCLUDE
  16. #endif
  17. #ifdef CONFIG_LVGL_USE_IMG_DECODER_ACTS
  18. # include <lvgl/lvgl_img_decoder.h>
  19. #endif
  20. #ifdef CONFIG_LVGL_USE_IMG_DECODER_ACTS_RES
  21. # include <lvgl/lvgl_img_res_decoder.h>
  22. #endif
  23. #if LV_USE_THORVG
  24. # if LV_USE_THORVG_EXTERNAL
  25. # include <thorvg_capi.h>
  26. # else
  27. # include "../../src/extra/libs/thorvg/thorvg_capi.h"
  28. # endif
  29. #endif
  30. #define LOG_LEVEL CONFIG_LV_LOG_LEVEL
  31. #include <logging/log.h>
  32. LOG_MODULE_REGISTER(lvgl);
  33. /**********************
  34. * STATIC FUNCTIONS
  35. **********************/
  36. /*
  37. * In LVGLv8 the signature of the logging callback has changes and it no longer
  38. * takes the log level as an integer argument. Instead, the log level is now
  39. *
  40. * already part of the buffer passed to the logging callback. It's not optimal
  41. * but we need to live with it and parse the buffer manually to determine the
  42. * level and then truncate the string we actually pass to the logging framework.
  43. */
  44. static void lvgl_log(const char *buf)
  45. {
  46. #if 1
  47. /*
  48. * This is ugly and should be done in a loop or something but as it
  49. * turned out, Z_LOG()'s first argument (that specifies the log level)
  50. * cannot be an l-value...
  51. *
  52. * We also assume lvgl is sane and always supplies the level string.
  53. */
  54. switch (buf[1]) {
  55. case 'E':
  56. LOG_ERR("%s", buf + strlen("[Error] "));
  57. break;
  58. case 'W':
  59. LOG_WRN("%s", buf + strlen("Warn] "));
  60. break;
  61. case 'I':
  62. LOG_INF("%s", buf + strlen("[Info] "));
  63. break;
  64. case 'T':
  65. LOG_DBG("%s", buf + strlen("[Trace] "));
  66. break;
  67. case 'U':
  68. LOG_WRN("%s", buf);
  69. break;
  70. default:
  71. LOG_WRN("%s", buf);
  72. break;
  73. }
  74. #else
  75. os_printk("%s", buf);
  76. #endif
  77. }
  78. /**********************
  79. * GLOBAL FUNCTIONS
  80. **********************/
  81. lv_res_t lv_port_init(void)
  82. {
  83. #if !defined(CONFIG_UI_SERVICE) && defined(CONFIG_UI_MEMORY_MANAGER)
  84. ui_mem_init();
  85. #endif
  86. #if defined(CONFIG_LV_Z_MEM_POOL_SYS_HEAP) && !defined(CONFIG_UI_MEMORY_MANAGER)
  87. lvgl_heap_init();
  88. #endif
  89. lv_log_register_print_cb(lvgl_log);
  90. lv_init();
  91. lv_img_decoder_acts_basic_init();
  92. #if defined(CONFIG_LVGL_USE_IMG_DECODER_ACTS)
  93. lvgl_img_decoder_acts_init();
  94. #elif LV_USE_GPU_ACTS_JPG
  95. lv_img_decoder_acts_raw_init();
  96. #endif
  97. #if defined(CONFIG_LVGL_USE_IMG_DECODER_ACTS_RES)
  98. lvgl_img_decoder_acts_res_init();
  99. #endif
  100. #if defined(CONFIG_LV_Z_USE_FILESYSTEM)
  101. lvgl_port_z_fs_init();
  102. #endif
  103. #if LV_USE_THORVG
  104. tvg_engine_init(TVG_ENGINE_SW, 0);
  105. #endif
  106. #if !defined(CONFIG_UI_SERVICE)
  107. if (lvgl_port_disp_init()) {
  108. return LV_RES_INV;
  109. }
  110. lvgl_port_indev_pointer_init();
  111. #endif
  112. return LV_RES_OK;
  113. }