airlcd.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local airLCD = {}
  2. function airLCD.lcd_init(sn)
  3. if sn ~= "AirLCD_0001" then
  4. return
  5. end
  6. pm.ioVol(pm.IOVOL_ALL_GPIO, 3000)--所有IO电平开到3V,电平匹配
  7. gpio.setup(29, 1) -- GPIO29 打开给lcd电源供电
  8. local rtos_bsp = rtos.bsp()
  9. -- local chip_type = hmeta.chip()
  10. -- 根据不同的BSP返回不同的值
  11. -- 根据不同的BSP返回不同的值
  12. -- spi_id,pin_reset,pin_dc,pin_cs,bl
  13. local function lcd_pin()
  14. local rtos_bsp = rtos.bsp()
  15. if string.find(rtos_bsp, "780EPM") then
  16. return lcd.HWID_0, 36, 0xff, 0xff, 25 -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
  17. else
  18. log.info("main", "没找到合适的cat.1芯片", rtos_bsp)
  19. return
  20. end
  21. end
  22. local spi_id, pin_reset, pin_dc, pin_cs, bl = lcd_pin()
  23. if spi_id ~= lcd.HWID_0 then
  24. spi_lcd = spi.deviceSetup(spi_id, pin_cs, 0, 0, 8, 20 * 1000 * 1000, spi.MSB, 1, 0)
  25. port = "device"
  26. else
  27. port = spi_id
  28. end
  29. lcd.init("st7796", {
  30. port = port,
  31. pin_dc = pin_dc,
  32. pin_pwr = bl,
  33. pin_rst = pin_reset,
  34. direction = 0,
  35. -- direction0 = 0x00,
  36. w = 320,
  37. h = 480,
  38. xoffset = 0,
  39. yoffset = 0,
  40. sleepcmd = 0x10,
  41. wakecmd = 0x11,
  42. })
  43. lcd.setupBuff(nil, true) -- 使用sys内存, 只需要选一种
  44. lcd.autoFlush(false)
  45. end
  46. return airLCD