Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LVGL #434

Closed
wants to merge 13 commits into from
Closed

Implement LVGL #434

wants to merge 13 commits into from

Conversation

mutatrum
Copy link
Contributor

@mutatrum mutatrum commented Oct 28, 2024

This PR adds LVGL 8.4 and refactors all current screens to use it.

The font is from https://int10h.org/oldschool-pc-fonts/fontlist/font?portfolio_6x8, converted to an LVGL font. There are also other fonts available, but currently unused.

The logo bitmap has been re-converted into an LVGL image.

This is a very basic implementation, almost pixel perfect close to the current screens. I think it makes sense to have this running for a while, to see if it's stable before venturing further into fancier usage of displays.

I haven't tested the self-test yet.

Fixes #299

@mutatrum
Copy link
Contributor Author

Comparison of the flash size, before and after:

┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Memory Type/Section ┃ Used [bytes] ┃ Used [%] ┃ Remain [bytes] ┃ Total [bytes] ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ Flash Code          │       736098 │     8.78 │        7652478 │       8388576 │
│    .text            │       736098 │     8.78 │                │               │
│ Flash Data          │       192460 │     0.57 │       33361940 │      33554400 │
│    .rodata          │       192204 │     0.57 │                │               │
│    .appdesc         │          256 │      0.0 │                │               │
│ DIRAM               │       123780 │    36.22 │         217980 │        341760 │
│    .text            │        79679 │    23.31 │                │               │
│    .bss             │        21536 │      6.3 │                │               │
│    .data            │        22372 │     6.55 │                │               │
│ IRAM                │        16383 │    99.99 │              1 │         16384 │
│    .text            │        15356 │    93.73 │                │               │
│    .vectors         │         1027 │     6.27 │                │               │
│ RTC FAST            │          284 │     3.47 │           7908 │          8192 │
│    .rtc_reserved    │           24 │     0.29 │                │               │
│    .force_fast      │            4 │     0.05 │                │               │
└─────────────────────┴──────────────┴──────────┴────────────────┴───────────────┘
Total image size: 1046996 bytes (.bin may be padded larger)

┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Memory Type/Section ┃ Used [bytes] ┃ Used [%] ┃ Remain [bytes] ┃ Total [bytes] ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ Flash Code          │       836930 │     9.98 │        7551646 │       8388576 │
│    .text            │       836930 │     9.98 │                │               │
│ Flash Data          │       214292 │     0.64 │       33340108 │      33554400 │
│    .rodata          │       214036 │     0.64 │                │               │
│    .appdesc         │          256 │      0.0 │                │               │
│ DIRAM               │       155796 │    45.59 │         185964 │        341760 │
│    .text            │        79679 │    23.31 │                │               │
│    .bss             │        54272 │    15.88 │                │               │
│    .data            │        21652 │     6.34 │                │               │
│ IRAM                │        16383 │    99.99 │              1 │         16384 │
│    .text            │        15356 │    93.73 │                │               │
│    .vectors         │         1027 │     6.27 │                │               │
│ RTC FAST            │          284 │     3.47 │           7908 │          8192 │
│    .rtc_reserved    │           24 │     0.29 │                │               │
│    .force_fast      │            4 │     0.05 │                │               │
└─────────────────────┴──────────────┴──────────┴────────────────┴───────────────┘
Total image size: 1168940 bytes (.bin may be padded larger)

@mutatrum mutatrum changed the title Implement LVGL 8.4 for #299 Implement LVGL 8.4 Oct 28, 2024
@mutatrum
Copy link
Contributor Author

As a bare minimum for leveraging LVGL, I added scrolling labels for long values. The main one would the the pool url, which is not restricted to 20 characters.

@mutatrum
Copy link
Contributor Author

After 17 hours uptime, nominal hashrate and no memory leaks as far as I can tell.

@mutatrum
Copy link
Contributor Author

mutatrum commented Nov 1, 2024

Using LVGL 9.2 with this display is blocked by espressif/esp-bsp#392.

@eandersson
Copy link
Collaborator

@mutatrum can you rebase this patch.

@mutatrum mutatrum force-pushed the lvgl branch 2 times, most recently from 7d8b2fb to 7a25942 Compare November 10, 2024 09:30
@mutatrum
Copy link
Contributor Author

Ok, it's clean now. Squashed everything into a single commit. Some notes:

  • This overwrites sdkconfig.defaults as it was generated by idf.py save-defconfig. There were several stale options and some missing options. If you change anything in the menu config, re-run save-defconfig to get an updated state, do not manually edit this.
  • This enables the built-in PSRAM. This is not stricktly neccesary for LVGL, it does run without this enabled but it's running fairly low on memory. I'm not 100% convinced this is a safe thing to do, as I don't know if all the BitAxes ever built use the ESP32S3-WROOM-1-n16r8. If you have a model with different type memory (quad vs octal, or no memory), it'll crash. I don't know if it's possible to auto-detect this.
  • I flipped screen one and two, it now shows IP address and pool as the first screen, as the asic is still ramping up at this time.
  • The font used is: https://int10h.org/oldschool-pc-fonts/fontlist/font?portfolio_6x8, converted with lv_font_conf tool. I think this is exactly the same font.

@mutatrum
Copy link
Contributor Author

I opted to do an almost 1-to-1 implementation first to get a clean change-set. The next step would be to inverse the control of displays, and have it refresh values live. This means that a lot of code from system.c would move to display.c, and the display class pulls data periodically out of the global state. This also make more sense if there are going to be different screen implementations.

sdkconfig.defaults Show resolved Hide resolved
@eandersson
Copy link
Collaborator

There is a crash if the lcd panel isn't installed (or broken) that will need to be fixed.

E (1370) display: Install SSD1306 panel driver
E (1370) i2c.master: I2C transaction unexpected nack detected
E (1380) i2c.master: s_i2c_synchronous_transaction(872): I2C transaction failed
E (1380) i2c.master: i2c_master_transmit(1074): I2C transaction failed
E (1390) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(179): i2c transaction failed
E (1400) lcd_panel.ssd1306: panel_ssd1306_init(147): io tx param SSD1306_CMD_SET_MULTIPLEX failed
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x420128a3
0x420128a3: display_init at /app/main/display.c:69 (discriminator 1)

file: "./main/display.c" line 69
func: display_init
expression: esp_lcd_panel_init(panel_handle)

abort() was called at PC 0x4037d797 on core 0
0x4037d797: _esp_error_check_failed at /opt/esp/idf/components/esp_system/esp_err.c:49

@mutatrum
Copy link
Contributor Author

Without a display, it only fails on the init call, which was a bit unexpected. It now continues and starts hashing without a display:

I (2203) display: Install panel IO
I (2203) display: Install SSD1306 panel driver
I (2213) lcd_panel.ssd1306: ssd1306 init
E (2223) i2c.master: I2C transaction unexpected nack detected
E (2223) i2c.master: s_i2c_synchronous_transaction(872): I2C transaction failed
E (2233) i2c.master: i2c_master_transmit(1074): I2C transaction failed
E (2243) lcd_panel.io.i2c: panel_io_i2c_tx_buffer(204): i2c transaction failed
E (2253) lcd_panel.ssd1306: panel_ssd1306_init(150): io tx param SSD1306_CMD_SET_MULTIPLEX failed
E (2253) display: display_init(82): Display init failed
W (2263) SystemModule: OLED init failed!
I (2273) SystemModule: SYSTEM_task started

@eandersson eandersson dismissed their stale review November 10, 2024 15:03

Changes implemented.

@eandersson
Copy link
Collaborator

Free Heap Memory changed drastically for me, maybe related to the sdk changes?

@eandersson
Copy link
Collaborator

Ah yep. If I use the old sdkconfig heap is the same as in previous versions

CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
CONFIG_ESPTOOLPY_FLASHSIZE="16MB"
CONFIG_HTTPD_WS_SUPPORT=y
CONFIG_SPIFFS_OBJ_NAME_LEN=64
CONFIG_HTTPD_MAX_URI_LEN=2048
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240=y
CONFIG_ESP_WIFI_11KV_SUPPORT=y
CONFIG_LV_USE_THEME_DEFAULT=n
CONFIG_LV_USE_THEME_BASIC=n
CONFIG_LV_USE_SNAPSHOT=n
CONFIG_LV_BUILD_EXAMPLES=n

@mutatrum
Copy link
Contributor Author

mutatrum commented Nov 10, 2024

This enables the built-in PSRAM. This is not stricktly neccesary for LVGL, it does run without this enabled but it's running fairly low on memory. I'm not 100% convinced this is a safe thing to do, as I don't know if all the BitAxes ever built use the ESP32S3-WROOM-1-n16r8. If you have a model with different type memory (quad vs octal, or no memory), it'll crash. I don't know if it's possible to auto-detect this.

No it's not the sdk version, it's enabled because the n16r8 has 8MB of PSRAM on board. This is enabled by:

CONFIG_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y

As said above, not 100% sure about this. I think this is the model that's on the BOM, so I would assume everyone picked this variant. But no way to know for sure. I have a few other S3's, but they are all the same variant so I cannot test otherwise.

@eandersson
Copy link
Collaborator

eandersson commented Nov 10, 2024

This enables the built-in PSRAM. This is not stricktly neccesary for LVGL, it does run without this enabled but it's running fairly low on memory. I'm not 100% convinced this is a safe thing to do, as I don't know if all the BitAxes ever built use the ESP32S3-WROOM-1-n16r8. If you have a model with different type memory (quad vs octal, or no memory), it'll crash. I don't know if it's possible to auto-detect this.

No, it's enabled because the n16r8 has 8MB of PSRAM on board. This is enabled by:

CONFIG_SPIRAM=y
CONFIG_SPIRAM_MODE_OCT=y

As said above, not 100% sure about this. I think this is the model that's on the BOM, so I would assume everyone picked this variant. But no way to know for sure. I have a few other S3's, but they are all the same variant so I cannot test otherwise.

Yea - I would def prefer reducing the scope of the changes to make it easier to test, reduce the chance of red herrings etc and you can open a second PR if you want to make additional changes.

@eandersson
Copy link
Collaborator

Oher than that this PR looks solid now.

@mutatrum
Copy link
Contributor Author

mutatrum commented Nov 10, 2024

Current free ram after an hour: 92k.

I'll run it for a while to see if this causes issues.

@mutatrum mutatrum mentioned this pull request Nov 10, 2024
sdkconfig.defaults Outdated Show resolved Hide resolved
@mutatrum
Copy link
Contributor Author

Current free ram after an hour: 92k.

Still 92k free ran after 16 hours. Not a lot but stable.

@mutatrum
Copy link
Contributor Author

Probably better to bump this over to at least the next version. I think they'll merge the fix for LVGL 9.2 soon, and I want to move to a minimal lv_conf.h so it only compiles LVGL features that are actually used. Which is almost nothing at the moment.

@mutatrum
Copy link
Contributor Author

After rebase on top of 2.4.0, free memory is ~71kb. Binary size is a tad smaller due to disabling all unused LVGL features.

@skot
Copy link
Owner

skot commented Nov 22, 2024

This looks good to me.. Are we waiting for LVGL 9.2 support to merge?

@mutatrum mutatrum changed the title Implement LVGL 8.4 Implement LVGL Nov 22, 2024
@mutatrum
Copy link
Contributor Author

Missed your comment, yes, at this point I would wait. Fix on their side needs approval and merge, which should only take a few days.

@mutatrum
Copy link
Contributor Author

Free Heap Memory: 37612 👀

I'll keep an eye out, otherwise maybe get the PSRAM enabled as well for this?

@mutatrum
Copy link
Contributor Author

mutatrum commented Dec 1, 2024

esp_lvgl_port has been fixed in 2.4.3, so this is now properly on LVGL 9.

@mutatrum mutatrum mentioned this pull request Dec 1, 2024
@mutatrum
Copy link
Contributor Author

mutatrum commented Dec 1, 2024

superseded by #539.

@mutatrum mutatrum closed this Dec 1, 2024
@mutatrum mutatrum deleted the lvgl branch December 11, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to a proper LCD library for the OLED
3 participants