Thank you for the clarifications.
Sharing SPI between ili9341 + xpt2046 is already supported.
Did you try it, without the SDCard? Let’s first make sure it works for you.
This is achieved on ili9341.py and xpt2046.py by passing -1
to SPI related parameters.
Here is the relevant code snippet from these drivers:
if buscfg.miso_io_num >= 0 and \
buscfg.mosi_io_num >= 0 and \
buscfg.sclk_io_num >= 0:
esp.gpio_pad_select_gpio(self.miso)
esp.gpio_pad_select_gpio(self.mosi)
esp.gpio_pad_select_gpio(self.clk)
esp.gpio_set_direction(self.miso, esp.GPIO_MODE.INPUT)
esp.gpio_set_pull_mode(self.miso, esp.GPIO.PULLUP_ONLY)
esp.gpio_set_direction(self.mosi, esp.GPIO_MODE.OUTPUT)
esp.gpio_set_direction(self.clk, esp.GPIO_MODE.OUTPUT)
ret = esp.spi_bus_initialize(self.spihost, buscfg, 1)
if ret != 0: raise RuntimeError("Failed initializing SPI bus")
so basically, when you pass -1
the miso/mosi/clk pins are not initialized and spi_bus_initialize
is not called, assuming a previous driver already did that.
Did you try to debug why the mcu freezes? If you can connect a debugger through JTAG it can be helpful.
If you cannot, try adding some prints (or even flash a led) to find out where the code reaches and where it doesn’t inside the driver.
One more thing you can try is using SPI functions from espidf
module instead of machine
module, the same way ili9341.py and xpt2046.py do.
I made a decision to maintain the Python driver and not the C driver.
The Python can work in hybrid mode where initialization is done in Python and fast operations such as handling DMA (“flush” function) is done in C.
The C driver is inferior as it’s less configurable, slower and not really doing DMA in the background.
The downside of the Python driver is that it’s a bit more complex, and apparently doesn’t work well with SD-card on the same bus (but it works well with other drivers on the same bus, such as xpt2046).
I’m not using SD card for my projects so I never had the chance to actually try and debug this, hopefully you or someone else from the community would eventually get to the bottom of this.
I’m planning, at some point, to update lv_micropython to newer micropython version. Micropython didn’t publish new releases recently and no one knows when it will (not even its maintainer…), so I might as well update it to recent mainline.
See Timing of next release? · Issue #6017 · micropython/micropython · GitHub
I’m not sure aligning to Micropython upstream would solve this problem, though, especially when we are not sure what the problem is yet.
Currently I cannot debug it myself, but I’ll do my best answering questions etc.
Please let us know if you make any progress!