LVGL and SD Card won't share SPI bus
Re: LVGL and SD Card won't share SPI bus
N/A
Last edited by Saul on Thu Oct 21, 2021 5:13 am, edited 1 time in total.
Re: LVGL and SD Card won't share SPI bus
MikeMike Teachman wrote: ↑Sat May 23, 2020 3:03 pm
No. I have never used the ILI9341 micropython driver in any of my littlevgl projects. At this point I have no reason to switch to the micropython driver as the modified C driver does what I need. It's a case of "if it's not broken, don't fix it".
How would I go about adding the modxpt2046.c touch driver?
BTW the fix for the incorrect colors was to comment out...
Code: Select all
/*Byte swapping is required RMG I removed because I did'nt see any like code in ili9341.py
uint32_t i;
uint8_t * color_u8 = (uint8_t *) color_p;
uint8_t color_tmp;
for(i = 0; i < size * 2; i += 2) {
color_tmp = color_u8[i + 1];
color_u8[i + 1] = color_u8[i];
color_u8[i] = color_tmp;
}
*/
- Mike Teachman
- Posts: 155
- Joined: Mon Jun 13, 2016 3:19 pm
- Location: Victoria, BC, Canada
Re: LVGL and SD Card won't share SPI bus
For the touch driver: sorry, I do not have any experience with this feature. I have only used LVGL to display graphics. The MicroPython category at the LVGL forum might have some ideas on adding this to the build and getting it working?
https://forum.lvgl.io/c/micropython
Congrats on getting your display to work !
Re: LVGL and SD Card won't share SPI bus
Looks like no fix has been mainlined.
I tried to change the python driver by adding a sharedspi flag to the init functions, which would skip the gpios setup and spi master init but, if the sharedspi flag is set to true, the subsequent call spi_bus_add_device() fails with ret = 259 (0x103, ESP_ERR_INVALID_STATE in esp_err.h). No need to say that the SPI bus is already initialized by sd card driver.
So I modified modILI9341.c driver as Mike Teachman did, but I got an "ImportError: no module named 'ILI9341'". I guessed the C driver was replaced by the pure/hybrid python driver, so I re-added ${LV_BINDINGS_DIR}/driver/esp32/modlvesp32.c to lv_bindings/mkrules.cmake . And I can see the object file being built. But still, can't load ILI9341 module. What am I missing?
regards
I tried to change the python driver by adding a sharedspi flag to the init functions, which would skip the gpios setup and spi master init but, if the sharedspi flag is set to true, the subsequent call spi_bus_add_device() fails with ret = 259 (0x103, ESP_ERR_INVALID_STATE in esp_err.h). No need to say that the SPI bus is already initialized by sd card driver.
So I modified modILI9341.c driver as Mike Teachman did, but I got an "ImportError: no module named 'ILI9341'". I guessed the C driver was replaced by the pure/hybrid python driver, so I re-added ${LV_BINDINGS_DIR}/driver/esp32/modlvesp32.c to lv_bindings/mkrules.cmake . And I can see the object file being built. But still, can't load ILI9341 module. What am I missing?
regards
Re: LVGL and SD Card won't share SPI bus
With these following changes I was able to Share SPI with TFT, Touch, and SDCard module that came with uP
by using modILI9341.c and modxpt2046.c drivers.
In file mpconfigport.h from the ports/esp32 directory un-comment the mp_module_ILI9341 and mp_module_xpt2046 in two locations.
These are the .c drivers to include in build
I remove ...
ili9XXX.py
ili9341.py
xpt2046.py
files from "lv_micropython\lib\lv_bindings\driver\esp32\" directory.
In modILI9341.c and modxpt2046.c files change...
.flags=SPI_DEVICE_HALFDUPLEX to .flags=0
and in modILI9341.c move */ down to comment out "Byte swapping" which caused color issue.
In Main.py code use your specific pins but use spihost=2, miso=19, mosi=23, clk=18 only.
This all worked with LVGL v6
But new problem with v7
Using esp-idf v4.1 lv_micropython dev micropython v1.14
I no longer get touch callbacks...
I believe the issue to be this line....
STATIC bool xpt2046_read(lv_indev_data_t *data); ~line119
but the doc states...
bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
I can not build using this different line.
Someone who understands .c code would probably see the problem.
Hope This Helps
by using modILI9341.c and modxpt2046.c drivers.
In file mpconfigport.h from the ports/esp32 directory un-comment the mp_module_ILI9341 and mp_module_xpt2046 in two locations.
These are the .c drivers to include in build
Code: Select all
extern const struct _mp_obj_module_t mp_module_rtch;
extern const struct _mp_obj_module_t mp_module_lodepng;
extern const struct _mp_obj_module_t mp_module_ILI9341;
extern const struct _mp_obj_module_t mp_module_xpt2046;
#if MICROPY_PY_LVGL
#define MICROPY_PORT_LVGL_DEF \
{ MP_OBJ_NEW_QSTR(MP_QSTR_lvgl), (mp_obj_t)&mp_module_lvgl }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_lvesp32), (mp_obj_t)&mp_module_lvesp32 }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_ILI9341), (mp_obj_t)&mp_module_ILI9341 }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_xpt2046), (mp_obj_t)&mp_module_xpt2046 },
// lvesp needs to delete the timer task upon soft reset
ili9XXX.py
ili9341.py
xpt2046.py
files from "lv_micropython\lib\lv_bindings\driver\esp32\" directory.
In modILI9341.c and modxpt2046.c files change...
.flags=SPI_DEVICE_HALFDUPLEX to .flags=0
and in modILI9341.c move */ down to comment out "Byte swapping" which caused color issue.
Code: Select all
/*Byte swapping is required
uint32_t i;
uint8_t * color_u8 = (uint8_t *) color_p;
uint8_t color_tmp;
for(i = 0; i < size * 2; i += 2) {
color_tmp = color_u8[i + 1];
color_u8[i + 1] = color_u8[i];
color_u8[i] = color_tmp;
}
*/
Code: Select all
from machine import Pin, SPI
import lvgl as lv
import lvesp32
import ILI9341 as ili
from xpt2046 import xpt2046
lv.init()
sd = SDCard(slot=2, cs=Pin(14), freq=20_000_000)
# vspi = SPI(2, miso=Pin(19), mosi=Pin(23), sck=Pin(18)) # use this if you don't want SDCard
# -----------------------------------------------------------------------------
disp = ili.display(spihost=2, miso=19, mosi=23, clk=18, cs=15, \
dc=13, rst=0, backlight=27, mhz=20)
disp.init()
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.init()
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = disp.flush
disp_drv.hor_res = 240
disp_drv.ver_res = 320
disp_drv.register()
# -----------------------------------------------------------------------------
touch = xpt2046(spihost=2, cs=5, irq=4, mhz=5, x_inv=False, \
y_inv=True, x_min=240, y_min=320, x_max=3783, y_max=3948)
touch.init()
indev_drv = lv.indev_drv_t()
indev_drv.init()
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = touch.read
indev_drv.register()
But new problem with v7
Using esp-idf v4.1 lv_micropython dev micropython v1.14
I no longer get touch callbacks...
I believe the issue to be this line....
STATIC bool xpt2046_read(lv_indev_data_t *data); ~line119
but the doc states...
bool xpt2046_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
I can not build using this different line.
Someone who understands .c code would probably see the problem.
Hope This Helps
Re: LVGL and SD Card won't share SPI bus
Hello guys,
I resolved this problem with buildin espidf functions on esp32 board and lv_micropython v1.15
Please see : https://github.com/favnec5/micropython- ... /README.md
1) init the SPI bus with ILI9XXX.py driver
2) use the "inside SPI" version of sdcard.py to add a second device (the sdcard) on the Bus.
It work on my M5 core2.
best reguards,
Thomas
I resolved this problem with buildin espidf functions on esp32 board and lv_micropython v1.15
Please see : https://github.com/favnec5/micropython- ... /README.md
1) init the SPI bus with ILI9XXX.py driver
2) use the "inside SPI" version of sdcard.py to add a second device (the sdcard) on the Bus.
It work on my M5 core2.
best reguards,
Thomas
Re: LVGL and SD Card won't share SPI bus
Great thanks to Thomas,
I saw the PR on lvgl repo. I am so happy to find it.
SD card works great , at the same time the display works.
My devices are,
LOLIN D32 pro with builtin SD card slot.
with GC9A01 display(no touch module)
Is there any performance difference between half_dulplex and full duplex?
Thanks again:)
I saw the PR on lvgl repo. I am so happy to find it.
SD card works great , at the same time the display works.
My devices are,
LOLIN D32 pro with builtin SD card slot.
with GC9A01 display(no touch module)
Is there any performance difference between half_dulplex and full duplex?
Thanks again:)
Last edited by divekr on Thu Oct 21, 2021 6:25 am, edited 1 time in total.
Re: LVGL and SD Card won't share SPI bus
hello divekr,
on my device (with illi9341 screen), the half-duplex=true do not work with the SDCard addon on the bus (white screen).
But i don't see difference on the speed result with half-duplex=false.
best reguards,
Thomas
on my device (with illi9341 screen), the half-duplex=true do not work with the SDCard addon on the bus (white screen).
But i don't see difference on the speed result with half-duplex=false.
best reguards,
Thomas
Re: LVGL and SD Card won't share SPI bus
Hi all,
thank you for all these informations.
I experienced some problems by using sdcard driver.
The display and sdcard initialisation are OK but as soon as I try to mount the sdcard with, I have this error :
I have the same error even if I initialise only the sdcard.
The SDCard works with the native micropython machine.SDCard driver.
An idea regarding this error code ?
Thanks
thank you for all these informations.
I experienced some problems by using sdcard driver.
The display and sdcard initialisation are OK but as soon as I try to mount the sdcard with
Code: Select all
sd = sdcard.SDCard(lv_spi.SPI(), machine.Pin(4))
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV
The SDCard works with the native micropython machine.SDCard driver.
An idea regarding this error code ?
Thanks
Re: LVGL and SD Card won't share SPI bus
Hi Patrice,
Before use lv_spi (just used to share the SPI Bus between screen and sdcard), you can try the sdcard.py driver with native machine.SPI without screen :
If it work, next step is sharing the bus with lv_spi.
Few comments :
- lv_spi.py use espidf module of ESP32 only (check if module exists)
- My 2GB SD card don't work with sdcard.py (i dont know why). I use 4GB without problem.
- Check if YOUR_SD_CARD_CS_PIN is the good
- To share the SPI bus, Screen driver need to be init first with half_duplex=False
Best Reguards,
Thomas
Before use lv_spi (just used to share the SPI Bus between screen and sdcard), you can try the sdcard.py driver with native machine.SPI without screen :
Code: Select all
import machine, sdcard, os
sd = sdcard.SDCard(machine.SPI(1), machine.Pin(YOUR_SD_CARD_CS_PIN))
os.mount(sd, '/sd')
print(os.listdir('/'))
Few comments :
- lv_spi.py use espidf module of ESP32 only (check if module exists)
- My 2GB SD card don't work with sdcard.py (i dont know why). I use 4GB without problem.
- Check if YOUR_SD_CARD_CS_PIN is the good
- To share the SPI bus, Screen driver need to be init first with half_duplex=False
Best Reguards,
Thomas