luat_lib_lvgl7.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "luat_base.h"
  2. #include "luat_lvgl.h"
  3. #include "luat_malloc.h"
  4. #include "luat_zbuff.h"
  5. #include "luat_lcd.h"
  6. static lv_disp_t* my_disp = NULL;
  7. static lv_disp_buf_t my_disp_buff = {0};
  8. //static lv_disp_drv_t my_disp_drv;
  9. static luat_lcd_conf_t* lcd_conf;
  10. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p) {
  11. //-----
  12. if (lcd_conf != NULL) {
  13. luat_lcd_draw(lcd_conf, area->x1, area->y1, area->x2, area->y2, color_p);
  14. }
  15. // LLOGD("CALL disp_flush (%d, %d, %d, %d)", area->x1, area->y1, area->x2, area->y2);
  16. lv_disp_flush_ready(disp_drv);
  17. }
  18. #ifdef LUA_USE_WINDOWS
  19. #include <windows.h>
  20. extern uint32_t WINDOW_HOR_RES;
  21. extern uint32_t WINDOW_VER_RES;
  22. #endif
  23. int luat_lv_init(lua_State *L) {
  24. if (my_disp != NULL) {
  25. lua_pushboolean(L, 0);
  26. return 1;
  27. }
  28. #ifdef LUA_USE_WINDOWS
  29. if (lua_isnumber(L, 1) && lua_isnumber(L, 2)) {
  30. WINDOW_HOR_RES= luaL_checkinteger(L, 1);
  31. WINDOW_VER_RES = luaL_checkinteger(L, 2);
  32. }
  33. HWND windrv_init(void);
  34. windrv_init();
  35. lua_pushboolean(L, 1);
  36. return 1;
  37. #elif defined(LUA_USE_LINUX)
  38. //lvgl_linux_init();
  39. lua_pushboolean(L, 1);
  40. return 1;
  41. #else
  42. lcd_conf = luat_lcd_get_default();
  43. if (lcd_conf == NULL)
  44. return 0;
  45. lv_color_t *fbuffer = NULL;
  46. size_t fbuff_size = 0;
  47. int w = luaL_optinteger(L, 1, lcd_conf->w);
  48. int h = luaL_optinteger(L, 2, lcd_conf->h);
  49. fbuff_size = w * 10;
  50. LLOGD("w %d h %d buff %d", w, h, fbuff_size);
  51. if (lua_isuserdata(L, 3)) {
  52. luat_zbuff_t *zbuff = tozbuff(L);
  53. fbuffer = (lv_color_t *)zbuff->addr;
  54. fbuff_size = zbuff->len / sizeof(lv_color_t);
  55. }
  56. else {
  57. fbuffer = luat_heap_malloc(fbuff_size * sizeof(lv_color_t));
  58. }
  59. lv_disp_buf_init(&my_disp_buff, fbuffer, NULL, fbuff_size);
  60. lv_disp_drv_t my_disp_drv;
  61. lv_disp_drv_init(&my_disp_drv);
  62. my_disp_drv.flush_cb = disp_flush;
  63. my_disp_drv.hor_res = w;
  64. my_disp_drv.ver_res = h;
  65. my_disp_drv.buffer = &my_disp_buff;
  66. //LLOGD(">>%s %d", __func__, __LINE__);
  67. my_disp = lv_disp_drv_register(&my_disp_drv);
  68. //LLOGD(">>%s %d", __func__, __LINE__);
  69. lua_pushboolean(L, my_disp != NULL ? 1 : 0);
  70. //LLOGD(">>%s %d", __func__, __LINE__);
  71. return 1;
  72. #endif
  73. }