No callback using xpt2046.c

esp-idf v4.1
lv_micropython dev
micropython v1.14


ILI9341.c and xpt2046.c initialize.
When touching screen I received x and y from
printf(“data: x = %d, y = %d\n”, data->point.x, data->point.y);
that was placed in xpt2046.c file.
But def touch_event() is not called

import utime
from machine import Pin, SPI
import lvgl as lv
# import lvesp32
import ILI9341 as ili
from xpt2046 import xpt2046

vspi = SPI(2, miso=Pin(19), mosi=Pin(23), sck=Pin(18))

disp = ili.display(spihost=2, miso=19, mosi=23, clk=18, cs=15, \
dc=13, rst=0, backlight=27, mhz=20) 

disp_buf1 = lv.disp_buf_t()
buf1_1 = bytearray(320*10)
disp_buf1.init(buf1_1, None, len(buf1_1) //4)
disp_drv = lv.disp_drv_t()
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = disp.flush
disp_drv.hor_res = 240
disp_drv.ver_res = 320

touch = xpt2046(spihost=2, cs=5, irq=4, mhz=5, \
x_inv=False, y_inv=True, x_min=240, y_min=320)

indev_drv = lv.indev_drv_t()
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb =	

# -----------------------------------------------------------------------------
tp_irq = Pin(4, Pin.IN)
def touched(pin):		
	# works... print stament from xpt2046.c (data: x = 132, y = 74)
	for _ in range(5):

def touch_event(obj, event):
	# not called
	if event == lv.EVENT.RELEASED:
		p = lv.point_t()
		lv.indev_get_point(lv.indev_get_next(None), p)
		l.set_text("x=%d, y=%d" % (p.x, p.y))
		l.align(scr, lv.ALIGN.CENTER, 0, 0)
		print("x=%d, y=%d" % (p.x, p.y))

# -----------------------------------------------------------------------------
scr = lv.scr_act()

t_scrn = lv.obj(scr, None)
t_scrn.set_size(scr.get_width(), scr.get_height()) # touch anywhere on screen
l = lv.label(scr, None)
l.set_text("p o s i t i o n")
l.align(scr, lv.ALIGN.CENTER, 0, 0)

tp_irq.irq(trigger=Pin.IRQ_FALLING, handler=touched)

I also tried from samples…

indev_drv = lv.indev_drv_t()
lv.indev_drv.init(indev_drv)    # AttributeError: 'module' object has no attribute 'indev_drv'
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb =  
lv.indev_drv.register(indev_drv)  # AttributeError: 'module' object has no attribute 'indev_drv'

I get run errors.

Does it work for you with the Python driver?
You may need to uncomment import lvesp32

According to this post, they want to use the C drivers because of that SPI sharing issue from a while back.

Still, would be interesting to know if the same code on the same HW works or not with the Python driver. That could hint if the problem is related to the C driver or to something else.


I removed the comment on lvesp32 for .c driver,
still no response from touch.

The reason I comment out lvesp32 is to stop the background scheduling !!
Bluetooth scan will freezes after some time with lvesp32 enabled.
I manually updated screen when needed with lv.task_handler() and
no longer have Bluetooth lockup issues.

Q. can the ili9341.c and xpt2046.c be converted to .mpy ?

Do you mean if they can be re-written in Python?
Probably, but we already have Python drivers so it makes more sense to support them instead of creating new Python drivers that do the same thing.

Personally I’m not using the C drivers so they are no so well maintained. I’m relying on the Python drivers.