lv_binding_micropython icon indicating copy to clipboard operation
lv_binding_micropython copied to clipboard

Support ESP32-S2, ESP32-C3, ESP32-S3

Open amirgon opened this issue 3 years ago • 186 comments

Micropython already supports ESP32, ESP32-S2, ESP32-C3, ESP32-S3. However lv_micropython only supports ESP32 today.

The goal is to add support for ESP32-S2, ESP32-C3, ESP32-S3 in lv_binding_micropython and lv_micropython.

This includes:

Related issues:

  • https://github.com/lvgl/lv_binding_micropython/issues/208
  • https://github.com/lvgl/lv_binding_micropython/issues/197
  • https://forum.lvgl.io/t/micropython-v1-19-1-and-lvgl-v8-3/9340/2

This is a sponsored issue, meaning that if someone implements it he or she gets a payment from the Accumulated donations of LVGL. Learn more HERE.

We can give 100 USD for fully implementing this.

CC: @kisvegabor @embeddedt

amirgon avatar Jul 29 '22 21:07 amirgon

Run in to this issue while I was looking for support for imxrt11xx platforms, since the main repo already supported them.

I would like to do it my own, but I could not find any detailed document for what exactly need to be done.

The readme of this repo is all about how to use this lvgl as a mp module, but mothing about porting.

Another article I could find is this https://blog.lvgl.io/2019-02-20/micropython-bindings "Can I use LittlevGL binding on XXXX Micropython fork? Probably yes! You would need to add Micropython Binding for LittlevGL as a submodule in your fork, and make some small changes to the Makefile and mpconfigport.h in your port, but that’s about it. For more details please have a look at the README."

The readme link is link to this repo's readme, bruh... And about "make some small changes", sure, but what? This is the same felling of MS error messages says "Something went wrong" My honest suggestion, better use that $100 hire someone for documentation on and create some examples, that allows people who want help could help right the way, instad of read all sources and scripts to understand what to do first.

424778940z avatar Nov 19 '22 11:11 424778940z

@424778940z - See https://github.com/lvgl/lv_binding_micropython/pull/242. That PR still needs some work, but when it's merged you will be able to add LVGL as a Micropython external C module, so porting to new architectures will be much easier.

This issue is about supporting ESP32-S2, ESP32-C3, ESP32-S3 because ESP ports have an extra complication where in addition to LVGL, the ESP BSP library API (ESP-IDF) is automatically converted too, so users can use it directly in Python code. (See Pure Micropython Display Driver in the blog).

You are right that the documentation focuses mostly on how to use the Micropython bindings. That's what interest most users. Advanced users who want to port to new architectures are welcome to diff micropython repo with lv_micropython and learn from the differences.

Remember that all the work, including the documentation, was done by volunteers on their spare time. So comparing this to Microsoft error message is not really fair.
If you are unhappy with the documentation or any other part, feel free to contribute by submitting a PR!

amirgon avatar Nov 19 '22 21:11 amirgon

I have been using esp32s3 for a whole day, and I keep reporting errors. It turns out that esp32s3 chip is not supported yet!!

ruihua-code avatar Nov 20 '22 09:11 ruihua-code

It turns out that esp32s3 chip is not supported yet!!

Correct. See https://github.com/lvgl/lv_binding_micropython/pull/243

amirgon avatar Nov 20 '22 09:11 amirgon

Waiting for Support ESP32-S2, ESP32-C3, ESP32-S3! Lvgl docs has a lot of micropython examples codes, that's cool! Especially ESP32-S3,many borads use it instead of ESP32, but they can't be used in micropython yet, what's pity

jd3096-mpy avatar Dec 13 '22 07:12 jd3096-mpy

Especially ESP32-S3,many borads use it instead of ESP32, but they can't be used in micropython yet,

@jd3096-mpy see https://github.com/lvgl/lv_binding_micropython/pull/243 - this adds ESP32-S3 support. Could you try this PR on your side and see if it works for you?

amirgon avatar Dec 13 '22 07:12 amirgon

I hope this gets added soon. I just wrote a python driver for the ili934 using an 8bit parallel interface. all of the work functions are decorated with micropython.viper so it should run with ample speed.

I am not able to test it because I only have s3's on hand at the moment. It looks like it should work without an issue.

There are a couple of things that I have forced like setting the d0-d7 pins sequentially to GPIO pins that are also sequential and are all in the same GPIO register. Makes setting the state of the GPIOs easier to deal with. I still have to tie in the touch interface and this is going to be a tad more challenging to do because of the shared pins. I need to know more about the mechanics of how the input side of things works in lvgl to be able to do this. Or if a Python driver can be written for a touch interface. I don't know how the loop in lvgl works.

I am hoping that the use of viper code isn't going to mess with lvgl either. I am making an assumption that the viper code runs in the same manner as the native code and when the code is running things like ISRs don't break into the running code. The parallel interface should offer a HUGE speed increase because there is no need to swap the high and low bytes for the colors. I am also directly accessing the registers for the GPIOs through pointers and not using the built in machine.Pin class.

Maybe there is someone that would be willing to lend a hand with getting the touch interface working.

kdschlosser avatar Dec 15 '22 07:12 kdschlosser

On a side note I will match the 100.00 already being given to get this done.

kdschlosser avatar Dec 15 '22 07:12 kdschlosser

There is a choice to make here. Code can either be duplicated from the latest micropython esp32 port in the drivers for the esp32 port in lv_binding_micropython OR there can be a minimum micropython version that gets set into place for the esp32 port and includes from micropython can be made in the drivers for lvgl so the code isn't duplicated.

with the esp32s3 there is no adc_gpio_init function available and the way the adc blocks are handled is different. micropython has already sorted out the mechanics of this and created helper functions to deal with it. I think that setting a minimum version of micropython that lv_binding_micropython is allowed to use would the cleanest and also the easiest way to get it working with all of the different esp32 variants.

Most of the issues are differences in the macro names or some macros not being defined all together.

I corrected the errors in the gpio_to_adc array in the modrtch.c file using the following code

#define GPIO_TO_ADC_ELEMENT(adc, x) [x] = CONCAT3(CONCAT3(ADC, adc, _GPIO), x, _CHANNEL)
static const int gpio_to_adc[] = {
#if CONFIG_IDF_TARGET_ESP32
    GPIO_TO_ADC_ELEMENT(2, 0),
#elif CONFIG_IDF_TARGET_ESP32C3
    GPIO_TO_ADC_ELEMENT(1, 0),
#endif
#if CONFIG_IDF_TARGET_ESP32
    GPIO_TO_ADC_ELEMENT(2, 2),
    GPIO_TO_ADC_ELEMENT(2, 4),
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2
    GPIO_TO_ADC_ELEMENT(1, 1),
    GPIO_TO_ADC_ELEMENT(1, 2),
    GPIO_TO_ADC_ELEMENT(1, 3),
    GPIO_TO_ADC_ELEMENT(1, 4),
#endif
#if CONFIG_IDF_TARGET_ESP32C3
    GPIO_TO_ADC_ELEMENT(2, 5),
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2
    GPIO_TO_ADC_ELEMENT(1, 5),
#endif
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
    GPIO_TO_ADC_ELEMENT(1, 6),
    GPIO_TO_ADC_ELEMENT(1, 7),
    GPIO_TO_ADC_ELEMENT(1, 8),
    GPIO_TO_ADC_ELEMENT(1, 9),
    GPIO_TO_ADC_ELEMENT(1, 10),
    GPIO_TO_ADC_ELEMENT(2, 11),
#endif
#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
    GPIO_TO_ADC_ELEMENT(2, 12),
    GPIO_TO_ADC_ELEMENT(2, 13),
    GPIO_TO_ADC_ELEMENT(2, 14),
    GPIO_TO_ADC_ELEMENT(2, 15),
#endif
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
    GPIO_TO_ADC_ELEMENT(2, 16),
    GPIO_TO_ADC_ELEMENT(2, 17),
    GPIO_TO_ADC_ELEMENT(2, 18),
    GPIO_TO_ADC_ELEMENT(2, 19),
    GPIO_TO_ADC_ELEMENT(2, 20),
#endif
#if CONFIG_IDF_TARGET_ESP32
    GPIO_TO_ADC_ELEMENT(2, 25),
    GPIO_TO_ADC_ELEMENT(2, 26),
    GPIO_TO_ADC_ELEMENT(2, 27),
    GPIO_TO_ADC_ELEMENT(1, 32),
    GPIO_TO_ADC_ELEMENT(1, 33),
    GPIO_TO_ADC_ELEMENT(1, 34),
    GPIO_TO_ADC_ELEMENT(1, 35),
    GPIO_TO_ADC_ELEMENT(1, 36),
    GPIO_TO_ADC_ELEMENT(1, 37),
    GPIO_TO_ADC_ELEMENT(1, 38),
    GPIO_TO_ADC_ELEMENT(1, 39)
#endif
};

and that has left me with the following compilation errors.

/home/***/lv_micropython/lib/lv_bindings/driver/esp32/modrtch.c: In function 'measure_axis':
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/modrtch.c:440:5: error: implicit declaration of function 'adc_gpio_init'; did you mean 'gpio_init'? [-Werror=implicit-function-declaration]
     adc_gpio_init(ADC_UNIT_1, adc_channel);
     ^~~~~~~~~~~~~
     gpio_init
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:85:18: error: implicit declaration of function 'I2S_TIMING_REG'; did you mean 'I2S_RX_TIMING_REG'? [-Werror=implicit-function-declaration]
     REG_SET_BIT( I2S_TIMING_REG(i2s_num), BIT(9));
                  ^~~~~~~~~~~~~~
/home/***/esp/components/soc/esp32s3/include/soc/soc.h:151:36: note: in definition of macro 'REG_SET_BIT'
             (*(volatile uint32_t*)(_r) |= (_b));                                                                       \
                                    ^~
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:86:18: error: implicit declaration of function 'I2S_CONF_REG'; did you mean 'I2S_TX_CONF_REG'? [-Werror=implicit-function-declaration]
     REG_SET_BIT( I2S_CONF_REG(i2s_num), I2S_RX_MSB_SHIFT);
                  ^~~~~~~~~~~~
/home/***/esp/components/soc/esp32s3/include/soc/soc.h:151:36: note: in definition of macro 'REG_SET_BIT'
             (*(volatile uint32_t*)(_r) |= (_b));                                                                       \
                                    ^~
In file included from /home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.c:7:
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h: At top level:
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:180:21: error: 'SPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_SPI_HOST = SPI_HOST,
                     ^~~~~~~~
                     SPI3_HOST
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:181:22: error: 'HSPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_HSPI_HOST = HSPI_HOST,
                      ^~~~~~~~~
                      SPI3_HOST
/home/***/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:182:22: error: 'VSPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_VSPI_HOST = VSPI_HOST,
                      ^~~~~~~~~
                      SPI3_HOST

as you can see most of the issues at this point are simple macro naming problems. the only one that is a big hang up is the missing adc_gpio_init function and that function is not so simple to replicate what it does.

If a decision is made to use the already written functions to handle this issue in the esp32 port of micropython ass new esp32 boards get released changes will be made to micropython to handle those boards and little to no changes will need to be made in lv_binding_micropython to support the newer boards.

kdschlosser avatar Dec 15 '22 21:12 kdschlosser

is there someone willing to give this a try?

decompress the attached file into driver/esp32

driver.esp32.zip

I was using this command to compile it

make -C ports/esp32 LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1" BOARD=GENERIC_S3_SPIRAM IDF_TARGET=esp32s3

I am getting this error and it might be something in my setup and not with the code changes I have made.

/home/****/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-patch5-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_lldesc_num2link_mpobj+0xc): undefined reference to `lldesc_num2link'

I want to rule out the code changes I have made.

kdschlosser avatar Dec 16 '22 06:12 kdschlosser

ok I figured out what functions need to be removed from lv_espidf.c so the compiling completes without error. I need to figure out how to keep gen_mpy from creating those functions. The majority of lv_espidf.c doesn't even need to be created. There is no reason to expose the entire espidf to the python interpreter. The availability of running viper code pretty much negates exposing it all together. Using viper code the GPIO registers can be accessed directly which would allow for fast updates to the GPIO pins.

I am not sure what other need there is to expose any of the espidf other than being able to manipulate the GPIOs

kdschlosser avatar Dec 16 '22 07:12 kdschlosser

If anyone wants to give this a go to see if it works I would appreciate it.

It should compile without errors. I do not have an SPI display to test it with.

https://github.com/kdschlosser/lv_binding_micropython/tree/esp32-s-c-h_support

kdschlosser avatar Dec 16 '22 21:12 kdschlosser

If anyone wants to give this a go to see if it works I would appreciate it.

It should compile without errors. I do not have an SPI display to test it with.

https://github.com/kdschlosser/lv_binding_micropython/tree/esp32-s-c-h_support

Good job! I tried your ways, like this: git clone https://github.com/lvgl/lv_micropython.git cd lv_micropython git submodule update --init --recursive lib/lv_bindings download your dirvers.esp32.zip ,unzip the files and overwrite it. try make -C ports/esp32 LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1" BOARD=GENERIC_S3_SPIRAM IDF_TARGET=esp32s3

but report errors in the last stage: [1497/1499] Linking CXX executable micropython.elf FAILED: micropython.elf

/home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/driver/libdriver.a(gpio.c.obj):(.literal.gpio_force_hold_all+0x0): undefined reference to rtc_gpio_force_hold_all' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/driver/libdriver.a(gpio.c.obj): in function gpio_force_hold_all': /home/jd3096/esp/esp-idf/components/driver/gpio.c:685: undefined reference to rtc_gpio_force_hold_all' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.literal.esp_eth_phy_new_lan8720+0x0): undefined reference to esp_eth_phy_new_lan87xx' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj): in function esp_eth_phy_new_lan8720': /home/jd3096/esp/esp-idf/components/esp_eth/include/esp_eth_phy.h:271: undefined reference to esp_eth_phy_new_lan87xx' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_xt_clock_freq_mpobj+0xc): undefined reference to xt_clock_freq' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_lldesc_build_chain_mpobj+0xc): undefined reference to lldesc_build_chain' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_gpio_input_get_high_mpobj+0xc): undefined reference to gpio_input_get_high' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_gpio_output_set_high_mpobj+0xc): undefined reference to gpio_output_set_high' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_ksz8081_mpobj+0xc): undefined reference to esp_eth_phy_new_ksz8081' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_ksz8041_mpobj+0xc): undefined reference to esp_eth_phy_new_ksz8041' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_dp83848_mpobj+0xc): undefined reference to esp_eth_phy_new_dp83848' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_lan87xx_mpobj+0xc): undefined reference to esp_eth_phy_new_lan87xx' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_rtl8201_mpobj+0xc): undefined reference to esp_eth_phy_new_rtl8201' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_esp_eth_phy_new_ip101_mpobj+0xc): undefined reference to esp_eth_phy_new_ip101' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_lldesc_set_owner_mpobj+0xc): undefined reference to lldesc_set_owner' /home/jd3096/.espressif/tools/xtensa-esp32s3-elf/esp-2021r2-8.4.0/xtensa-esp32s3-elf/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: esp-idf/main/libmain.a(lv_espidf.c.obj):(.rodata.mp_lldesc_num2link_mpobj+0xc): undefined reference to lldesc_num2link' collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. ninja failed with exit code 1 make: *** [Makefile:34: all] Error 2 make: Leaving directory '/home/jd3096/Desktop/01/lv_micropython/ports/esp32' the same error as yours?

jd3096-mpy avatar Dec 17 '22 08:12 jd3096-mpy

did you use the repo I linked to or did you use the files I attached in a zip?? If you used the zipped files don't, use the linked repo instead

kdschlosser avatar Dec 17 '22 16:12 kdschlosser

did you use the repo I linked to or did you use the files I attached in a zip?? If you used the zipped files don't, use the linked repo instead

Sorry,I git the wrong repo branch. Now it can be compiled without errors,I will test it later.

jd3096-mpy avatar Dec 18 '22 02:12 jd3096-mpy

did you use the repo I linked to or did you use the files I attached in a zip?? If you used the zipped files don't, use the linked repo instead

I think there is still something wrong with SPI, Init the screen there is a mistake: ("Failed initializing SPI bus") I tried to trace the source code in ili9XXX ret = esp.spi_bus_initialize(self.spihost, buscfg, 1) ret return value:258 that's not right. I change to ret = esp.spi_bus_initialize(self.spihost, buscfg, 0) it works,but the screen show like this: 7182ed39be5a68ab10226ff8d583ac7

I use lilygo t embed the screen is st7798v3 170x320 or mabey the screen driver init is not corrent

jd3096-mpy avatar Dec 18 '22 04:12 jd3096-mpy

OK so there is a result at least. That's a good thing. going to have to hammer out any kinks in it.

Can you post the exact Micropython code you are using?

And do you have the exact model number of the Lillygo piece you are using? I want to see if everything is aligning properly between the screen the Micropython code and the c code.. Gotta develop a data path to see what is happening.

kdschlosser avatar Dec 18 '22 23:12 kdschlosser

and that returned value is ESP_ERR_INVALID_ARG

hmmm... Time to go digging.

kdschlosser avatar Dec 19 '22 00:12 kdschlosser

spi_bus_initialize

and that returned value is ESP_ERR_INVALID_ARG

hmmm... Time to go digging.

Yes,here is the error code form esp-idf WIKI [ESP_ERR_INVALID_ARG](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/system/esp_err.html#c. ESP_ERR_INVALID_ARG) (0x102): Invalid argument(258)

[ESP_ERR_INVALID_STATE](https://docs.espressif.com/projects/esp-idf/zh_CN/latest/esp32/api-reference/system/esp_err.html#c. ESP_ERR_INVALID_STATE) (0x103): Invalid state(259) Sometimes return 259,when I changed to esp.spi_bus_initialize(self.spihost, buscfg, 0) rutern 0 that's right 0 means dma_channel

here's my mpy code: `import machine import espidf as esp from machine import Pin from fbdriver import st7789 import lvgl as lv power=machine.Pin(46, machine.Pin.OUT) power.value(1) bl=machine.Pin(15, machine.Pin.OUT) bl.value(1)

disp = st7789( mosi=11, clk=12, cs=10, dc=13, rst=9,width=135, height=240, rot=-1, factor=4,spihost=esp.VSPI_HOST)

lv.init() scr = lv.obj() btn = lv.btn(scr) label = lv.label(btn) label.set_text("Button")

Load the screen

lv.scr_load(scr)`

fbdriver is the copy of ili9XXX.py so I can test the driver.

jd3096-mpy avatar Dec 19 '22 03:12 jd3096-mpy

OK so there is a result at least. That's a good thing. going to have to hammer out any kinks in it.

Can you post the exact Micropython code you are using?

And do you have the exact model number of the Lillygo piece you are using? I want to see if everything is aligning properly between the screen the Micropython code and the c code.. Gotta develop a data path to see what is happening.

Here is the offical repo: https://github.com/Xinyuan-LilyGO/T-Embed

The GPIO marked in the picture is wrong, I am sure. I tried to use other st7789 driver on this board,it works normally. You can find the right GPIO in source code .h they defined.

https://github.com/Xinyuan-LilyGO/T-Embed/blob/main/example/tft/pin_config.h

#define PIN_LCD_BL 15 #define PIN_LCD_DC 13 #define PIN_LCD_CS 10 #define PIN_LCD_CLK 12 #define PIN_LCD_MOSI 11 #define PIN_LCD_RES 9

jd3096-mpy avatar Dec 19 '22 03:12 jd3096-mpy

I believe I found the issue.

I committed the changes to that same branch on my fork that I linked to in a previous post.

Give it a try again. It has to do with the DMA channel being used. If you have the repl open when you boot the ESP it will spit out any error codes if one does show up.

kdschlosser avatar Dec 19 '22 07:12 kdschlosser

Use the script below to run the test with

import machine
import ili9XXX
import lvgl as lv

disp = ili9XXX.st7789(
    mosi=11, 
    clk=12, 
    cs=10, 
    dc=13, 
    rst=9,
    power=46,
    backlight=15,
    backlight_on=0,
    power_on=0,
    width=170, 
    height=240,
    rot=ili9XXX.LANDSCAPE
)

lv.init()
scr = lv.obj()
btn = lv.btn(scr)
label = lv.label(btn)
label.set_text("Button")

kdschlosser avatar Dec 19 '22 07:12 kdschlosser

Traceback (most recent call last): File "", line 2, in File "ili9XXX.py", line 64, in AttributeError: 'module' object has no attribute 'ENUM_SPI_HOST'

Also no attribute: SPI_DMA_DISABLED ENUM_VSPI_HOST ENUM_HSPI_HOST

import espidf as esp help(esp)

SPI_HOST -- 0 VSPI_HOST -- 1 HSPI_HOST -- 2 SPI1_HOST -- 0 SPI2_HOST -- 1 SPI3_HOST -- 2 portMAX_DELAY -- -1 I2S_PIN_NO_CHANGE -- -1

only these const are defined

I try to chagne these const with value instead

It shows the same screen. I think mabey I should change another st7789 screen 320x240 That's more easy to use.

jd3096-mpy avatar Dec 19 '22 08:12 jd3096-mpy

Especially ESP32-S3,many borads use it instead of ESP32, but they can't be used in micropython yet,

@jd3096-mpy see #243 - this adds ESP32-S3 support. Could you try this PR on your side and see if it works for you?

Oh my god ,this repo works!!! Here is my mpy code: import machine import ili9XXX import lvgl as lv

power=machine.Pin(46, machine.Pin.OUT) power.value(1) bl=machine.Pin(15, machine.Pin.OUT) bl.value(1)

disp = ili9XXX.st7789( mosi=11, clk=12, cs=10, dc=13, rst=9, width=320, height=170, start_x=0, start_y=35, rot=-2 )

lv.init()

style_base = lv.style_t() style_base.init() style_base.set_bg_color(lv.palette_main(lv.PALETTE.LIGHT_BLUE)) style_base.set_border_color(lv.palette_darken(lv.PALETTE.LIGHT_BLUE, 3)) style_base.set_border_width(2) style_base.set_radius(10) style_base.set_shadow_width(10) style_base.set_shadow_ofs_y(5) style_base.set_shadow_opa(lv.OPA._50) style_base.set_text_color(lv.color_white()) style_base.set_width(100) style_base.set_height(lv.SIZE_CONTENT)

Set only the properties that should be different

style_warning = lv.style_t() style_warning.init() style_warning.set_bg_color(lv.palette_main(lv.PALETTE.YELLOW)) style_warning.set_border_color(lv.palette_darken(lv.PALETTE.YELLOW, 3)) style_warning.set_text_color(lv.palette_darken(lv.PALETTE.YELLOW, 4))

Create an object with the base style only

obj_base = lv.obj(lv.scr_act()) obj_base.add_style(style_base, 0) obj_base.align(lv.ALIGN.LEFT_MID, 20, 0)

label = lv.label(obj_base) label.set_text("Base") label.center()

Create another object with the base style and earnings style too

obj_warning = lv.obj(lv.scr_act()) obj_warning.add_style(style_base, 0) obj_warning.add_style(style_warning, 0) obj_warning.align(lv.ALIGN.RIGHT_MID, -20, 0)

label = lv.label(obj_warning) label.set_text("Warning") label.center()

screen: 0aa98da879ff9222534de6bde4bebaa

jd3096-mpy avatar Dec 19 '22 08:12 jd3096-mpy

If anyone wants to give this a go to see if it works I would appreciate it.

It should compile without errors. I do not have an SPI display to test it with.

https://github.com/kdschlosser/lv_binding_micropython/tree/esp32-s-c-h_support

GOD,I just found this repo works! https://github.com/imliubo/lv_binding_micropython/tree/dev_esp32_s3

Thanks for you working,too.

jd3096-mpy avatar Dec 19 '22 08:12 jd3096-mpy

Alot of the same changes I made except the adc blocks that can be used for the touch interfaces. With my changes all of the adc blocks are available.

kdschlosser avatar Dec 19 '22 13:12 kdschlosser

I have a board with esp32s3 N16R8 which I would like to use with lv_micropython. I am glad to read that you guys are developing patches for the lvgl implementation to work with the esp32s3. However, I fail in trying to compile the lv_micropython code for esp32-s3. It is not clear to me which repository to use. I tried the following:

  • using idf 4.4
  • cloning lv_micropython
  • git clone https://github.com/lvgl/lv_micropython.git
  • cd lv_micropython/
  • git submodule update --init --recursive lib/lv_bindings

then 1) cloning the esp32-s-c-h_support branch from https://github.com/kdschlosser/lv_binding_micropython

  • copying all the files in this reposotry to the lv_micropython directory

  • then following the steps to compile lvgl:

  • make -C mpy-cross make -C ports/esp32 submodules make -C ports/esp32 LV_CFLAGS="-DLV_COLOR_DEPTH=16 -DLV_COLOR_16_SWAP=1" BOARD=GENERIC_S3_SPIRAM IDF_TARGET=esp32s3

  • I get this error:

In file included from /opt/esp/idf/components/esp_rom/include/esp32s3/rom/ets_sys.h:19,
                 from /opt/esp/idf/components/freertos/port/xtensa/include/freertos/FreeRTOSConfig_arch.h:51,
                 from /opt/esp/idf/components/freertos/include/esp_additions/freertos/FreeRTOSConfig.h:16,
                 from /opt/esp/idf/components/freertos/include/freertos/FreeRTOS.h:57,
                 from /project/lv_micropython/ports/esp32/mpconfigport.h:10,
                 from /project/lv_micropython/py/mpconfig.h:62,
                 from /project/lv_micropython/py/obj.h:31,
                 from /project/lv_micropython/ports/esp32/build-GENERIC_S3_SPIRAM/lv_espidf.c:20:
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h: In function 'SPH0645_WORKAROUND':
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:85:18: error: implicit declaration of function 'I2S_TIMING_REG'; did you mean 'I2S_TX_TIMING_REG'? [-Werror=implicit-function-declaration]
     REG_SET_BIT( I2S_TIMING_REG(i2s_num), BIT(9));
                  ^~~~~~~~~~~~~~
/opt/esp/idf/components/soc/esp32s3/include/soc/soc.h:151:36: note: in definition of macro 'REG_SET_BIT'
             (*(volatile uint32_t*)(_r) |= (_b));
\
                                    ^~
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:86:18: error: implicit declaration of function 'I2S_CONF_REG'; did you mean 'I2S_TX_CONF_REG'? [-Werror=implicit-function-declaration]
     REG_SET_BIT( I2S_CONF_REG(i2s_num), I2S_RX_MSB_SHIFT);
                  ^~~~~~~~~~~~
/opt/esp/idf/components/soc/esp32s3/include/soc/soc.h:151:36: note: in definition of macro 'REG_SET_BIT'
             (*(volatile uint32_t*)(_r) |= (_b));
\
                                    ^~
In file included from /project/lv_micropython/ports/esp32/build-GENERIC_S3_SPIRAM/lv_espidf.c:33:
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h: At top level:
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:180:21: error: 'SPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_SPI_HOST = SPI_HOST,
                     ^~~~~~~~
                     SPI3_HOST
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:181:22: error: 'HSPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_HSPI_HOST = HSPI_HOST,
                      ^~~~~~~~~
                      SPI3_HOST
/project/lv_micropython/lib/lv_bindings/driver/esp32/espidf.h:182:22: error: 'VSPI_HOST' undeclared here (not in a function); did you mean 'SPI3_HOST'?
     ENUM_VSPI_HOST = VSPI_HOST,
                      ^~~~~~~~~
                      SPI3_HOST
cc1: some warnings being treated as errors
[33/187] Building C object esp-idf/lvgl/CMakeFiles/__idf_lvgl.dir/src/draw/sw/lv_draw_sw_rect.c.obj
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
make: *** [Makefile:34: all] Error 2
make: Leaving directory '/project/lv_micropython/ports/esp32'

2- cloning the https://github.com/imliubo/lv_binding_micropython/tree/dev_esp32_s3 repository. Trying same steps as above, results in the same error.

Question: can someone describe all the steps (including which branch of which repository) I have to follow to compile a correct version of lv_micropython for the esp32s3. I would be glad to test the firmware on my board and comment on the results.

ste7anste7an avatar Dec 26 '22 07:12 ste7anste7an

It's all still a work in progress I don't have an SPI TFT to test with and only having an esp32-s3 makes it a bit harder for me to make changes ans test because I don't know what would be broken the 8 bit parallel side of things or the esp32-s3 side of things.

I am going to order up an SPI screen pretty soon tho and that will make it easier for me to get running.

kdschlosser avatar Dec 26 '22 09:12 kdschlosser

If I only could get a firmware that would run on my 16MB flash/8MBpsram, I could test it on my self-developed s3 board. Would it be possible to build one that I test?

Here is what I developed: an ESP32-s3 board with an SPI ili9341 touch display. The tft and touch share the same SPI. 20221226_225134 20221226_225209

ste7anste7an avatar Dec 26 '22 22:12 ste7anste7an

Here is a compiled firmware for the ESP32-S3 That has modified partitions to support the larger firmware and also supports SPIRAM.

Everything should be good to go with it you just need to upload it to your ESP32-S3 and then create a main.py file with the code for the display.

lvgl.zip

uncompress that into a folder and navigate to that folder and run the following command. You have to replace {port} with the serial port that you have the ESP attached to

You need to have the esptool python library installed.

esptool -p {PORT} -b 460800 --before default_reset --after no_reset --chip esp32s3  write_flash --flash_mode dio --flash_size detect --flash_freq 80m 0x0 bootloader.bin 0x8000 partition-table.bin 0x10000 micropython.bin

kdschlosser avatar Dec 27 '22 04:12 kdschlosser