airlcd.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. function lcd_pin()
  14. return lcd.HWID_0, 36, 0xff, 0xff, 160 -- 注意:EC718P有硬件lcd驱动接口, 无需使用spi,当然spi驱动也支持
  15. -- return 0,1,10,8,22
  16. end
  17. local spi_id, pin_reset, pin_dc, pin_cs, bl = lcd_pin()
  18. if spi_id ~= lcd.HWID_0 then
  19. spi_lcd = spi.deviceSetup(spi_id, pin_cs, 0, 0, 8, 20 * 1000 * 1000, spi.MSB, 1, 0)
  20. port = "device"
  21. else
  22. port = spi_id
  23. end
  24. lcd.init("st7796",{port = port,pin_dc = pin_dc, pin_pwr = bl, pin_rst = pin_reset,direction = 0,w = 320,h = 480,xoffset = 0,yoffset = 0},spi_lcd)
  25. lcd.setupBuff(nil, true) -- 使用sys内存, 只需要选一种
  26. lcd.autoFlush(false)
  27. log.info("tp", "tp init")
  28. local function tp_callBack(tp_device,tp_data)
  29. sys.publish("TP",tp_device,tp_data)
  30. log.info("TP",tp_data[1].x,tp_data[1].y,tp_data[1].event)
  31. end
  32. -- local softI2C = i2c.createSoft(20, 21, 2) -- SCL, SDA
  33. -- local softI2C = i2c.createSoft(28, 26, 1) -- SCL, SDA
  34. -- tp_device = tp.init("jd9261t_inited",{port=softI2C, pin_rst = 27,pin_int = gpio.CHG_DET,w = width,h = height,int_type=gpio.FALLING, refresh_rate = 60},tp_callBack)
  35. -- tp_device = tp.init("jd9261t_inited",{port=0, pin_rst = 20,pin_int = gpio.WAKEUP0,w = width,h = height,int_type=gpio.FALLING, refresh_rate = 60},tp_callBack)
  36. local i2c_id = 0
  37. i2c.setup(i2c_id, i2c.SLOW)
  38. tp_device = tp.init("gt911",{port=i2c_id, pin_rst = 20,pin_int = gpio.WAKEUP0,},tp_callBack)
  39. -- gpio.setup(gpio.WAKEUP0, function ()
  40. -- log.info("tp", "tp interrupt")
  41. -- end, gpio.PULLUP, gpio.FALLING)
  42. if tp_device then
  43. print(tp_device)
  44. sys.taskInit(function()
  45. while 1 do
  46. local result, tp_device, tp_data = sys.waitUntil("TP")
  47. if result then
  48. lcd.drawPoint(tp_data[1].x, tp_data[1].y, 0xF800)
  49. lcd.flush()
  50. end
  51. end
  52. end)
  53. end
  54. end
  55. return airLCD