def __init__(self, miso=-1, mosi=-1, clk=-1, cs=25, spihost=esp.HSPI_HOST, mhz=5, transpose=False, touch_margin=100): # Initializations self.screen_width = lv.disp_get_hor_res(lv.disp_t.cast(None)) self.screen_height = lv.disp_get_ver_res(lv.disp_t.cast(None)) self.miso = miso self.mosi = mosi self.clk = clk self.cs = cs self.spihost = spihost self.mhz = mhz self.cal_x0 = None self.transpose = transpose self.touch_margin = touch_margin self.touch_count = 0 self.touch_cycles = 0 self.spi_init() # Prepare buffer with commands to send to device nc = len(self.CMDS) self.buflen = 2 * nc * REP + 1 # +1 for final CMD_OFF self.txbuf = esp.heap_caps_malloc(self.buflen, esp.MALLOC_CAP.DMA) txbuf = self.txbuf.__dereference__(self.buflen) for c in range(nc): for r in range(REP): txbuf[(c * REP + r) * 2 + 0] = self.CMDS[c] # first byte is command, second is 0 txbuf[(c * REP + r) * 2 + 1] = 0 txbuf[2 * nc * REP] = CMD_OFF # print("xpt2046 txbuf:", ["%02x" % v for v in txbuf]) self.rxbuf = esp.heap_caps_malloc(self.buflen, esp.MALLOC_CAP.DMA) indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = self.read lv.indev_drv_register(indev_drv) print("xpt2046 touch initialized")
def __init__(self, miso=-1, mosi=-1, clk=-1, cs=25, spihost=esp.HSPI_HOST, mhz=5, max_cmds=16, cal_x0=3783, cal_y0=3948, cal_x1=242, cal_y1=423, transpose=True, samples=3): # Initializations self.screen_width = lv.disp_get_hor_res(lv.disp_t.cast(None)) self.screen_height = lv.disp_get_ver_res(lv.disp_t.cast(None)) self.miso = miso self.mosi = mosi self.clk = clk self.cs = cs self.spihost = spihost self.mhz = mhz self.max_cmds = max_cmds self.cal_x0 = cal_x0 self.cal_y0 = cal_y0 self.cal_x1 = cal_x1 self.cal_y1 = cal_y1 self.transpose = transpose self.samples = samples self.touch_count = 0 self.touch_cycles = 0 self.spi_init() indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = self.read lv.indev_drv_register(indev_drv)
import lvgl as lv lv.init() lv.log_register_print_cb(lambda level, path, line, msg: print( 'LOG: %s(%d): %s' % (path, line, msg))) # Initialize ILI9341 display import lvesp32 from ili9XXX import ili9341 disp = ili9341() HRES = lv.disp_get_hor_res(lv.disp_t.cast(None)) VRES = lv.disp_get_ver_res(lv.disp_t.cast(None)) # Register raw resistive touch driver ''' import rtch touch = rtch.touch(xp = 32, yp = 33, xm = 25, ym = 26, touch_rail = 27, touch_sense = 33, cal_x0=0, cal_x1 = HRES, cal_y0=0, cal_y1 = VRES) touch.init() indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER; indev_drv.read_cb = touch.read; lv.indev_drv_register(indev_drv); ''' # Register xpt touch driver import xpt2046 as xpt2046 touch = xpt2046.xpt2046(cal_x0=0, cal_x1=HRES, cal_y0=0, cal_y1=VRES)