main.lua 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. --- 模块功能:airui demo
  2. -- @module airui
  3. -- @author ???
  4. -- @release 2025.05.24
  5. -- LuaTools需要PROJECT和VERSION这两个信息
  6. PROJECT = "airui_demo"
  7. VERSION = "1.0.0"
  8. log.info("main", PROJECT, VERSION)
  9. --加载sys库
  10. _G.sys = require("sys")
  11. local ui_path = "/luadb/air8000.json"
  12. local lcd_chip = "st7796" -- "st7796" or "jd9261t_inited"
  13. function lcd_init()
  14. sys.wait(500)
  15. gpio.setup(164, 1, gpio.PULLUP)
  16. gpio.setup(141, 1, gpio.PULLUP)
  17. sys.wait(1000)
  18. if lcd_chip == "st7796" then
  19. lcd.init("st7796", {
  20. port = lcd.HWID_0, -- 使用的spi id 号
  21. pin_dc = 0xff, -- 命令选择硬件,不设置
  22. pin_pwr = 9, -- 背光控制管脚,默认打开背光,不设置
  23. pin_rst = 2, -- 屏幕reset 管脚
  24. direction = 0, -- 屏幕方向 0: 0度 1:90度 2:180度 3:270度
  25. w = 320, -- 屏幕宽度
  26. h = 480, -- 屏幕高度
  27. xoffset = 0, -- X轴偏移像素
  28. yoffset = 0, -- Y轴偏移像素
  29. sleepcmd = 0x10, -- LCD睡眠命令
  30. wakecmd = 0x11, -- LCD唤醒命令
  31. })
  32. elseif lcd_chip == "jd9261t_inited" then
  33. lcd.init("jd9261t_inited", {
  34. port = lcd.HWID_0, -- 使用的spi id 号
  35. pin_pwr = 160, -- 背光控制管脚
  36. pin_rst = 36, -- 屏幕reset 管脚
  37. direction = 0, -- 屏幕方向 0: 0度 1:90度 2:180度 3:270度
  38. w = 480, -- 屏幕宽度
  39. h = 480, -- 屏幕高度
  40. xoffset = 0, -- X轴偏移像素
  41. yoffset = 0, -- Y轴偏移像素
  42. interface_mode = lcd.QSPI_MODE, -- 接口模式 qspi
  43. bus_speed = 70000000, -- SPI总线速度
  44. flush_rate = 658, -- 刷新率
  45. vbp = 19, vfp = 108, vs = 2 -- VBP:垂直后沿, VFP:垂直前沿, VS:垂直同步
  46. })
  47. end
  48. gpio.setup(160, 1, gpio.PULLUP) -- 单独拉高背光
  49. if lcd_chip == "jd9261t_inited" then
  50. lcd.setupBuff(nil, true) -- 开启buff缓存,更适合lvgl场景
  51. lcd.autoFlush(false)
  52. end
  53. end
  54. function tp_init()
  55. if tp then
  56. local function tp_callBack(tp_device, tp_data)
  57. log.info("TP", tp_data[1].x, tp_data[1].y, tp_data[1].event)
  58. sys.publish("TP", tp_device, tp_data)
  59. end
  60. local i2c_id = 0
  61. i2c.setup(i2c_id)
  62. if lcd_chip == "st7796" then
  63. tp_device = tp.init("gt911",{port=i2c_id, pin_int = gpio.WAKEUP0},tp_callBack)
  64. elseif lcd_chip == "jd9261t_inited" then
  65. tp_device = tp.init("jd9261t_inited", {port = i2c_id, pin_int = gpio.WAKEUP0}, tp_callBack)
  66. end
  67. lvgl.indev_drv_register("pointer", "touch", tp_device) -- 注册触摸屏驱动
  68. else
  69. log.info("TP", "not found")
  70. end
  71. end
  72. sys.taskInit(function()
  73. -- local uiJson = io.open("/luadb/ui.json")
  74. local uiJson = io.open(ui_path)
  75. local ui = json.decode(uiJson:read("*a"))
  76. log.info("ui", ui, ui.pages[1].children[1].name)
  77. lcd_init()
  78. log.info("初始化lvgl", lvgl.init(ui.project_settings.resolution.width, ui.project_settings.resolution.height))
  79. tp_init()
  80. -- airui.init("/luadb/ui.json")
  81. airui.init(ui_path)
  82. end)
  83. sys.run()